From c47cfb32f4ca9ed7bbb360053d90f1fb52a95708 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Fri, 9 Oct 2026 03:41:56 +0000 Subject: add line editor history --- src/line/mode.cc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/line/mode.cc') 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); +} + } -- cgit v1.3.1-4-g156e