diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/line/cursor.cc | 23 | ||||
| -rw-r--r-- | src/line/mode.cc | 2 |
2 files changed, 22 insertions, 3 deletions
diff --git a/src/line/cursor.cc b/src/line/cursor.cc index ce01466..9ff8bbc 100644 --- a/src/line/cursor.cc +++ b/src/line/cursor.cc @@ -47,12 +47,13 @@ T_position get_cursor_position() void print_override(const std::string &s) { + print("\x1b[s"); fflush(stdout); print("\r"); fflush(stdout); print("{}", s); fflush(stdout); - cursor_col = s.size()+1; - line_end_pos = cursor_col; + //line_end_pos = s.size()+1; + print("\x1b[u"); fflush(stdout); } void move_cursor(char c) @@ -90,4 +91,22 @@ void move_cursor(char c) } } +void cursor_input(char c, std::string &buffer) +{ + if (c != '\b') + { + buffer.insert(cursor_col-1, 1, c); + print("\x1b[C"); fflush(stdout); + cursor_col++; + line_end_pos = buffer.size()+1; + return; + } + + // BACKSPACE + buffer.erase(cursor_col-1, 1); + print("\x1b[D"); fflush(stdout); + cursor_col--; + line_end_pos = buffer.size()+1; +} + } diff --git a/src/line/mode.cc b/src/line/mode.cc index a2236e2..18c7347 100644 --- a/src/line/mode.cc +++ b/src/line/mode.cc @@ -105,7 +105,7 @@ string readline() // normal char else { - buffer += c; + cursor_input(c, buffer); print_override(buffer); } } |
