diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-12 07:15:46 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-12 07:15:46 +0000 |
| commit | f23f6b9ea8204a63d17baa712db06aac1ea1c3ad (patch) | |
| tree | 61576744c514476be276f035f16122fe4118924c /src | |
| parent | 7ae4c2d4b67ce40a5434b5195e14085cadf6e22f (diff) | |
add terminal window size update
Diffstat (limited to 'src')
| -rw-r--r-- | src/line/cursor.cc | 20 | ||||
| -rw-r--r-- | src/line/mode.cc | 3 | ||||
| -rw-r--r-- | src/signal/sigwinch_handler.cc | 13 |
3 files changed, 36 insertions, 0 deletions
diff --git a/src/line/cursor.cc b/src/line/cursor.cc index 02e43cf..538dfca 100644 --- a/src/line/cursor.cc +++ b/src/line/cursor.cc @@ -21,6 +21,8 @@ namespace ov4 void print_override(const std::string &s) { + check_window_update(); + // save current cursor position // print("\x1b[s"); fflush(stdout); // WTF @@ -43,6 +45,8 @@ void print_override(const std::string &s) void move_cursor(char c) { + check_window_update(); + switch (c) { case 'A': @@ -64,6 +68,8 @@ void move_cursor(char c) void cursor_input_char(char c) { + check_window_update(); + // if receives any input // it should move to the latest history history_index = get_last_index(); @@ -97,6 +103,8 @@ void update_window_size() void move_cursor(T_cursor_movement_direction d) { + void check_window_update(); + switch (d) { case T_cursor_movement_direction::LEFT: @@ -159,6 +167,8 @@ void move_cursor(T_cursor_movement_direction d) void switch_history(T_cursor_movement_direction d) { + check_window_update(); + switch (d) { case T_cursor_movement_direction::UP: @@ -209,4 +219,14 @@ void cursor_skip_prompt() print("\r\x1b[{}C", prompt_pos-1); fflush(stdout); } +void check_window_update() +{ + if (windows_size_changed) + { + update_window_size(); + clear_below(); + windows_size_changed = false; + } +} + } diff --git a/src/line/mode.cc b/src/line/mode.cc index 06f1727..208465b 100644 --- a/src/line/mode.cc +++ b/src/line/mode.cc @@ -8,6 +8,7 @@ #include "line/cursor.h" #include "line/getter.h" #include "history.h" +#include "signal_handler.h" using namespace std; @@ -57,6 +58,8 @@ void enable_raw() atexit(disable_raw); + Signal(SIGWINCH, sigwinch_handler); + // TCSAFLUSH // the change shall occur after all output written to fildes is transmitted // and all input so far received but not read shall be discarded before the change is made diff --git a/src/signal/sigwinch_handler.cc b/src/signal/sigwinch_handler.cc new file mode 100644 index 0000000..4b692ed --- /dev/null +++ b/src/signal/sigwinch_handler.cc @@ -0,0 +1,13 @@ +#include "signal_handler.h" + +#include "line/getter.h" + +namespace ov4 +{ + +void sigwinch_handler([[maybe_unused]] int sig) +{ + windows_size_changed = true; +} + +}
\ No newline at end of file |
