aboutsummaryrefslogtreecommitdiff
path: root/src/line
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-19 09:01:42 +0000
committer_ov4 <ov4@ov4.org>2026-10-19 09:01:42 +0000
commitc23e61b4455cee8669c7d594478a4238048f032f (patch)
tree084e9c90a440483797fdf64fb0fc43470d4b9d16 /src/line
parent83588b7ee9349a941b91294fa83fe6e207883ab6 (diff)
fix vt100 cursor pos race
Diffstat (limited to 'src/line')
-rw-r--r--src/line/getter.cc62
-rw-r--r--src/line/input.cc5
2 files changed, 33 insertions, 34 deletions
diff --git a/src/line/getter.cc b/src/line/getter.cc
index 432ddca..aa05d6b 100644
--- a/src/line/getter.cc
+++ b/src/line/getter.cc
@@ -38,36 +38,36 @@ int T_line_editor::get_terminal_pos_line_end()
}
-T_position T_line_editor::get_cursor_position()
-{
- char c;
- string buffer;
- T_position pos;
- int row, col;
- tcflush(STDIN_FILENO, TCIFLUSH);
- cout << "\x1b[6n" << flush;
- while (read(STDIN_FILENO, &c, 1) == 1)
- {
- if (c == 'R') break;
- buffer += c;
- }
- if (buffer.size() <= 2 || buffer[0] != '\x1b' || buffer[1] != '[')
- {
- pos.row = -1;
- pos.col = -1;
- return pos;
- }
- if ((sscanf(buffer.c_str(), "\x1b[%d;%d", &row, &col)) != 2)
- {
- pos.row = -1;
- pos.col = -1;
- return pos;
- }
- pos.row = row;
- pos.col = col;
- // print("row {}, col {}\r\n", row, col);
- // fflush(stdout);
- return pos;
-}
+// T_position T_line_editor::get_cursor_position()
+// {
+// char c;
+// string buffer;
+// T_position pos;
+// int row, col;
+// tcflush(STDIN_FILENO, TCIFLUSH);
+// cout << "\x1b[6n" << flush;
+// while (read(STDIN_FILENO, &c, 1) == 1)
+// {
+// if (c == 'R') break;
+// buffer += c;
+// }
+// if (buffer.size() <= 2 || buffer[0] != '\x1b' || buffer[1] != '[')
+// {
+// pos.row = -1;
+// pos.col = -1;
+// return pos;
+// }
+// if ((sscanf(buffer.c_str(), "\x1b[%d;%d", &row, &col)) != 2)
+// {
+// pos.row = -1;
+// pos.col = -1;
+// return pos;
+// }
+// pos.row = row;
+// pos.col = col;
+// // print("row {}, col {}\r\n", row, col);
+// // fflush(stdout);
+// return pos;
+// }
} \ No newline at end of file
diff --git a/src/line/input.cc b/src/line/input.cc
index 0a01760..1b9520b 100644
--- a/src/line/input.cc
+++ b/src/line/input.cc
@@ -18,15 +18,14 @@ void T_line_editor::clear_below()
print("\x1b[0J");
}
-string T_line_editor::readline()
+string T_line_editor::readline(int prompt_len)
{
+ prompt_pos = prompt_len+1;
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; int src;
while (non_block_read_char(&c, &src) == 1)
{