diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-18 14:47:46 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-18 14:47:46 +0000 |
| commit | cd55aa462b112896240ab736bf60035fdb30ca2d (patch) | |
| tree | 4446cee1af4ba561e46b1587f96bb61aecedceb2 /include | |
| parent | c8479ceff6aea37def538c902324c68930947f21 (diff) | |
adapt line editor
Diffstat (limited to 'include')
| -rw-r--r-- | include/eval.h | 2 | ||||
| -rw-r--r-- | include/line/line_editor.h | 69 |
2 files changed, 70 insertions, 1 deletions
diff --git a/include/eval.h b/include/eval.h index 5ccecf4..6268403 100644 --- a/include/eval.h +++ b/include/eval.h @@ -22,7 +22,7 @@ inline T_pipe T_pipe_not_pipe; int eval_exe(const std::string &s, bool is_async); int eval_exe(const std::string &s, bool is_async, const T_lexer *lexer_instance, size_t i, const T_pipe &pi = T_pipe_not_pipe); int eval_tree_cd(size_t i, const T_lexer &lexer_instance, bool inside_subshell, T_pipe pi = T_pipe_not_pipe); -void eval(char *cmdline); +void eval(const std::string &s); void eval_err(int err); } diff --git a/include/line/line_editor.h b/include/line/line_editor.h new file mode 100644 index 0000000..a97b09c --- /dev/null +++ b/include/line/line_editor.h @@ -0,0 +1,69 @@ +#pragma once + +#include <termios.h> +#include <string> + +#include "line/type.h" + +namespace ov4 +{ + +// mode +inline termios attr; +inline bool raw_enabled = false; + +void disable_raw(); +void enable_raw(); +void editor_exit(int code); + +class T_line_editor +{ +public: + // cursor + + // 1-based + int cursor_row = 1; + int cursor_col = 1; + int prompt_pos = 1; + int window_size_row = 24; + int window_size_col = 80; + + // 0-based index + int buffer_index_cursor = 0; + // index [begin, end] is displayed + // NB: CLOSE interval + int _buffer_index_display_begin = 0; + //int buffer_index_display_end; + + std::string line_buffer; + + void print_override(const std::string &s); + void move_cursor(char c); + void cursor_input_char(char c); + void update_window_size(); + void move_cursor(T_cursor_movement_direction d); + void switch_history(T_cursor_movement_direction d); + void reset_editor(); + void cursor_skip_prompt(); + void check_window_update(); + + + // getter + bool windows_size_changed = false; + + int get_terminal_pos_cursor(); + int get_buffer_index_display_begin(); + int get_buffer_index_display_end(); + int get_terminal_pos_line_end(); + + //void update_line_end_pos(); + + T_position get_cursor_position(); + + + // input + void clear_below(); + std::string readline(); +}; + +}
\ No newline at end of file |
