aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-12 07:33:04 +0000
committer_ov4 <ov4@ov4.org>2026-10-12 07:33:04 +0000
commit68d763add972c346410c6b9908b516a2ea411341 (patch)
treebfe2c512cb295f6bf2b2bf7ef525f5f73e167aad /src
parentf23f6b9ea8204a63d17baa712db06aac1ea1c3ad (diff)
fix backspace
Diffstat (limited to 'src')
-rw-r--r--src/line/cursor.cc14
-rw-r--r--src/line/input.cc7
2 files changed, 17 insertions, 4 deletions
diff --git a/src/line/cursor.cc b/src/line/cursor.cc
index 538dfca..f95f008 100644
--- a/src/line/cursor.cc
+++ b/src/line/cursor.cc
@@ -74,7 +74,7 @@ void cursor_input_char(char c)
// it should move to the latest history
history_index = get_last_index();
// normal input
- if (c != '\b')
+ if (c != '\b' && c != '\x7f')
{
line_buffer.insert(buffer_index_cursor, 1, c);
move_cursor(T_cursor_movement_direction::RIGHT);
@@ -83,9 +83,15 @@ void cursor_input_char(char c)
}
// BACKSPACE
- line_buffer.erase(buffer_index_cursor, 1);
- // TODO: backspace page
- move_cursor(T_cursor_movement_direction::LEFT);
+ if (buffer_index_cursor != 0)
+ {
+ line_buffer.erase(buffer_index_cursor-1, 1);
+ move_cursor(T_cursor_movement_direction::LEFT);
+ }
+ else
+ {
+ print("\a"); fflush(stdout);
+ }
}
diff --git a/src/line/input.cc b/src/line/input.cc
index 9c593f7..cc5a62b 100644
--- a/src/line/input.cc
+++ b/src/line/input.cc
@@ -69,6 +69,13 @@ string readline()
move_cursor(seq[1]);
}
+
+ // backspace
+ else if (c == '\b' || c == '\x7f')
+ {
+ cursor_input_char(c);
+ print_override(line_buffer);
+ }
}
// normal char