diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-09 03:51:30 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-09 03:51:30 +0000 |
| commit | d25efc7ce2419a2705dd0cc55442cb1c140fa868 (patch) | |
| tree | a443740b44b571cc8d8b2c7fcdf90076900c0cba /src/line/mode.cc | |
| parent | c47cfb32f4ca9ed7bbb360053d90f1fb52a95708 (diff) | |
add control C, and clean dead code
Diffstat (limited to 'src/line/mode.cc')
| -rw-r--r-- | src/line/mode.cc | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/src/line/mode.cc b/src/line/mode.cc index dc9291d..6f59ace 100644 --- a/src/line/mode.cc +++ b/src/line/mode.cc @@ -80,28 +80,34 @@ string readline() char c; while (read(STDIN_FILENO, &c, 1) == 1) { - if (c == 'Q') editor_exit(-1); // TODO: remove - else if (c == 'C') - { - clear_below(); - } - else if (c == 'P') - { - get_cursor_position(); - } - else if (iscntrl(c)) + if (iscntrl(c)) { //print("control: {}\r\n", static_cast<unsigned char>(c)); //fflush(stdout); - if (c == 13) // \n + if (c == 0x0A || c == 0x0D) // \n OR \r { //print("line: {}\r\n", line_buffer); - history_vec[get_last_index()] = line_buffer; + if (line_buffer.empty()) + { + history_index--; + history_vec.pop_back(); + } + else + { + history_vec[get_last_index()] = line_buffer; + } return line_buffer; } + else if (c == 0x03) // control C + { + history_index--; + history_vec.pop_back(); + return ""; + } + // ESC sequence - if (c == '\x1b') + else if (c == '\x1b') { char seq[10]; // eat [ @@ -122,8 +128,16 @@ string readline() print_override(line_buffer); } } - - history_vec[get_last_index()] = line_buffer; + + if (line_buffer.empty()) + { + history_index--; + history_vec.pop_back(); + } + else + { + history_vec[get_last_index()] = line_buffer; + } return line_buffer; } |
