frontend: line-ed: convert all escape code usage to s_tty calls

This commit is contained in:
2024-11-18 21:13:28 +00:00
parent 5a5b0d01d8
commit c5f60c285e
6 changed files with 106 additions and 18 deletions

View File

@@ -347,9 +347,7 @@ s_keycode s_tty_read_key(struct s_tty *tty)
s_keycode key = 0;
if (d.Event.KeyEvent.uChar.UnicodeChar == 0) {
continue;
}
switch (d.Event.KeyEvent.wVirtualKeyCode) {
case VK_CONTROL:
@@ -377,6 +375,10 @@ s_keycode s_tty_read_key(struct s_tty *tty)
key = S_KEY_RETURN;
break;
default:
if (d.Event.KeyEvent.uChar.UnicodeChar == 0) {
continue;
}
key = d.Event.KeyEvent.uChar.AsciiChar;
break;
}
@@ -437,4 +439,55 @@ void s_tty_move_cursor_y(struct s_tty *tty, enum s_tty_position_base base, int p
}
SetConsoleCursorPosition(tty->t_out, cursor_pos);
}
}
void s_tty_clear(struct s_tty *tty, enum s_tty_clear_mode mode)
{
CONSOLE_SCREEN_BUFFER_INFO console = {0};
GetConsoleScreenBufferInfo(tty->t_out, &console);
WCHAR fill = L' ';
DWORD length = 0;
COORD start;
DWORD all_length = 0, line_length = 0;
if (mode & TTY_CLEAR_ALL) {
line_length = console.dwSize.X;
all_length = line_length * console.dwSize.Y;
} else if (mode & TTY_CLEAR_FROM_CURSOR) {
line_length = console.dwSize.X - console.dwCursorPosition.X + 1;
all_length = line_length + ((console.dwSize.Y - console.dwCursorPosition.Y) * console.dwSize.X);
} else if (mode & TTY_CLEAR_TO_CURSOR) {
line_length = console.dwCursorPosition.X;
all_length = line_length
+ ((console.dwCursorPosition.Y - 1) * console.dwSize.X);
} else {
abort();
}
if (mode & TTY_CLEAR_SCREEN) {
length = all_length;
if ((mode & TTY_CLEAR_ALL) || (mode & TTY_CLEAR_TO_CURSOR)) {
start.X = 0;
start.Y = 0;
} else if (mode & TTY_CLEAR_FROM_CURSOR) {
start = console.dwCursorPosition;
}
} else if (mode & TTY_CLEAR_LINE) {
length = line_length;
if ((mode & TTY_CLEAR_ALL) || (mode & TTY_CLEAR_TO_CURSOR)) {
start.X = 0;
start.Y = console.dwCursorPosition.Y;
} else if (mode & TTY_CLEAR_FROM_CURSOR) {
start = console.dwCursorPosition;
}
} else {
abort();
}
DWORD nr_written = 0;
FillConsoleOutputCharacterW(tty->t_out, fill, length, start, &nr_written);
}