diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-09 03:41:56 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-09 03:41:56 +0000 |
| commit | c47cfb32f4ca9ed7bbb360053d90f1fb52a95708 (patch) | |
| tree | 0d186530cbccb6f14f5230da1ad145b4c98aeac0 /src/line/mode.cc | |
| parent | d29590546054feabff2d7e559665811d1d28f538 (diff) | |
add line editor history
Diffstat (limited to 'src/line/mode.cc')
| -rw-r--r-- | src/line/mode.cc | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/line/mode.cc b/src/line/mode.cc index e8024fa..dc9291d 100644 --- a/src/line/mode.cc +++ b/src/line/mode.cc @@ -7,6 +7,7 @@ #include "line/cursor.h" #include "line/getter.h" +#include "history.h" using namespace std; @@ -70,13 +71,16 @@ void clear_below() string readline() { update_window_size(); + history_vec.push_back(""); + history_index = get_last_index(); + reset_editor(); T_position pos = get_cursor_position(); prompt_pos = pos.col; char c; while (read(STDIN_FILENO, &c, 1) == 1) { - if (c == 'Q') break; + if (c == 'Q') editor_exit(-1); // TODO: remove else if (c == 'C') { clear_below(); @@ -92,6 +96,7 @@ string readline() if (c == 13) // \n { //print("line: {}\r\n", line_buffer); + history_vec[get_last_index()] = line_buffer; return line_buffer; } @@ -117,8 +122,16 @@ string readline() print_override(line_buffer); } } + + history_vec[get_last_index()] = line_buffer; return line_buffer; } +void editor_exit(int code) +{ + disable_raw(); + exit(code); +} + } |
