frontend: line-ed: move platform-specific code to separate directory

This commit is contained in:
2024-11-18 15:15:04 +00:00
parent 29447bf5ec
commit 96172eac84
8 changed files with 871 additions and 10 deletions

View File

@@ -112,7 +112,8 @@ void backspace(struct line_ed *ed)
void cursor_left(struct line_ed *ed)
{
if (ed->l_cursor_x != 0) {
fputs("\010", stdout);
//fputs("\010", stdout);
s_tty_move_cursor_x(ed->l_tty, TTY_POS_CURSOR, -1);
fflush(stdout);
ed->l_cursor_x--;
ed->l_buf_ptr--;
@@ -133,7 +134,10 @@ void cursor_left(struct line_ed *ed)
unsigned int len = line_length(ed, ed->l_cursor_y);
ed->l_cursor_x = len - 1;
printf("\033[A\033[%dG", len + prompt_len);
//printf("\033[A\033[%dG", len + prompt_len);
s_tty_move_cursor_y(ed->l_tty, TTY_POS_CURSOR, -1);
s_tty_move_cursor_x(ed->l_tty, TTY_POS_START, len + prompt_len);
fflush(stdout);
}
@@ -146,7 +150,8 @@ void cursor_right(struct line_ed *ed)
if (*ed->l_buf_ptr != '\n') {
ed->l_cursor_x++;
ed->l_buf_ptr++;
fputs("\033[C", stdout);
//fputs("\033[C", stdout);
s_tty_move_cursor_x(ed->l_tty, TTY_POS_CURSOR, 1);
fflush(stdout);
return;
}
@@ -159,7 +164,9 @@ void cursor_right(struct line_ed *ed)
ed->l_cursor_x = 0;
ed->l_buf_ptr++;
printf("\033[B\033[G");
//printf("\033[B\033[G");
s_tty_move_cursor_y(ed->l_tty, TTY_POS_CURSOR, 1);
s_tty_move_cursor_x(ed->l_tty, TTY_POS_START, 0);
fflush(stdout);
}
@@ -170,10 +177,13 @@ void arrow_up(struct line_ed *ed)
}
if (ed->l_cursor_y > 0) {
printf("\033[%uA", ed->l_cursor_y);
//printf("\033[%uA", ed->l_cursor_y);
s_tty_move_cursor_y(ed->l_tty, TTY_POS_CURSOR, ed->l_cursor_y);
}
printf("\033[%zuG\033[J", prompt_length(ed, PROMPT_MAIN) + 1);
s_tty_move_cursor_x(
ed->l_tty, TTY_POS_START, prompt_length(ed, PROMPT_MAIN) + 1);
save_buf_to_history(ed);
ed->l_history_pos--;
@@ -190,10 +200,13 @@ void arrow_down(struct line_ed *ed)
}
if (ed->l_cursor_y > 0) {
printf("\033[%uA", ed->l_cursor_y);
//printf("\033[%uA", ed->l_cursor_y);
s_tty_move_cursor_y(ed->l_tty, TTY_POS_CURSOR, ed->l_cursor_y);
}
printf("\033[%zuG\033[J", prompt_length(ed, PROMPT_MAIN) + 1);
//printf("\033[%zuG\033[J", prompt_length(ed, PROMPT_MAIN) + 1);
s_tty_move_cursor_x(
ed->l_tty, TTY_POS_START, prompt_length(ed, PROMPT_MAIN) + 1);
save_buf_to_history(ed);
ed->l_history_pos++;