frontend: switch to new bluelib tty interface

This commit is contained in:
2024-11-20 22:14:35 +00:00
parent 92f407ac09
commit 17ee2b6b57
14 changed files with 86 additions and 1666 deletions

View File

@@ -1,10 +1,8 @@
#include "line-ed.h"
#include "history.h"
#include "hook.h"
#include "input.h"
#include "prompt.h"
#include "tty.h"
#include <ctype.h>
#include <stdio.h>
@@ -12,6 +10,7 @@
#include <string.h>
#include <wchar.h>
#include <wctype.h>
#include <blue/term/tty.h>
#define LINE_ED_FROM_LEX_SOURCE(p) \
((struct line_ed *)((char *)p - offsetof(struct line_ed, l_line_source)))
@@ -56,7 +55,7 @@ struct line_ed *line_ed_create(void)
return NULL;
}
out->l_tty = s_get_tty();
out->l_tty = b_stdtty;
out->l_buf_end = out->l_buf + LINE_MAX;
out->l_buf_ptr = out->l_buf;
out->l_line_end = out->l_buf;
@@ -181,8 +180,8 @@ long line_ed_readline(struct line_ed *ed, char *out, size_t max)
append_to_index = ed->l_history_pos;
}
struct s_tty *tty = ed->l_tty;
s_tty_set_raw(tty);
b_tty *tty = ed->l_tty;
b_tty_set_mode(tty, B_TTY_RAW);
show_prompt(ed);
for (int i = 0; ed->l_buf[i]; i++) {
@@ -198,10 +197,10 @@ long line_ed_readline(struct line_ed *ed, char *out, size_t max)
bool eof = false;
while (!end) {
s_keycode key = s_tty_read_key(tty);
b_keycode key = b_tty_read_key(tty);
hook_keypress(ed, key);
if (key == S_TTY_CTRL_KEY('d')) {
if (key == B_TTY_CTRL_KEY('d')) {
if (!input_is_empty(ed)) {
continue;
}
@@ -210,13 +209,13 @@ long line_ed_readline(struct line_ed *ed, char *out, size_t max)
break;
}
if (key & S_MOD_CTRL) {
if (key & B_MOD_CTRL) {
continue;
}
switch (key) {
case S_KEY_RETURN:
s_tty_reset_vmode(tty);
case B_KEY_RETURN:
b_tty_reset_vmode(tty);
if (ed->l_line_end > ed->l_buf
&& *(ed->l_line_end - 1) != '\\') {
end = true;
@@ -243,19 +242,19 @@ long line_ed_readline(struct line_ed *ed, char *out, size_t max)
// fputs("\033[G\n", stdout);
show_prompt(ed);
break;
case S_KEY_BACKSPACE:
case B_KEY_BACKSPACE:
backspace(ed);
break;
case S_KEY_ARROW_LEFT:
case B_KEY_ARROW_LEFT:
cursor_left(ed);
break;
case S_KEY_ARROW_RIGHT:
case B_KEY_ARROW_RIGHT:
cursor_right(ed);
break;
case S_KEY_ARROW_UP:
case B_KEY_ARROW_UP:
arrow_up(ed);
break;
case S_KEY_ARROW_DOWN:
case B_KEY_ARROW_DOWN:
arrow_down(ed);
break;
default:
@@ -266,7 +265,7 @@ long line_ed_readline(struct line_ed *ed, char *out, size_t max)
}
}
s_tty_set_canon(tty);
b_tty_set_mode(tty, B_TTY_CANONICAL);
fputc('\n', stdout);
if (*ed->l_buf == '\0') {