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

@@ -5,6 +5,7 @@
#include "buffer.h"
#include "cursor.h"
#include "hl-range.h"
#include "tty.h"
/* prints the provided string to the terminal, applying any relevant highlight ranges.
* this function prints all characters in `s` until it encounters a null char (\0) or
@@ -105,7 +106,8 @@ void put_refresh(struct line_ed *ed, struct refresh_state *state)
if (ed->l_flags & LINE_ED_FULL_REPRINT) {
if (start_x) {
fprintf(stdout, "\033[%uD", start_x);
//fprintf(stdout, "\033[%uD", start_x);
s_tty_move_cursor_x(ed->l_tty, TTY_POS_CURSOR, -start_x);
}
start_x = 0;
@@ -117,10 +119,13 @@ void put_refresh(struct line_ed *ed, struct refresh_state *state)
* so that the physical cursor will be placed AFTER the character that
* was just inserted. */
cursor_rdelta--;
s_tty_move_cursor_x(ed->l_tty, TTY_POS_CURSOR, -cursor_rdelta);
#if 0
for (unsigned int i = 0; i < cursor_rdelta; i++) {
fputs("\010", stdout);
}
#endif
fflush(stdout);
}
@@ -156,17 +161,22 @@ void backspace_nl_refresh(struct line_ed *ed, struct refresh_state *state)
/* the physical cursor is currently at the beginning of the line that
* has just been moved up. from here, clear this line and the rest
* from the screen. */
fputs("\033[J", stdout);
//fputs("\033[J", stdout);
s_tty_clear(ed->l_tty, TTY_CLEAR_SCREEN | TTY_CLEAR_FROM_CURSOR);
if (ed->l_flags & LINE_ED_FULL_REPRINT) {
/* next, move the physical cursor up and to the beginning of the previous line */
unsigned int tmp_x;
line_ed_coords_to_physical_coords(ed, 0, ed->l_cursor_y, &tmp_x, NULL);
fprintf(stdout, "\033[A\033[%uG", tmp_x + 1);
s_tty_move_cursor_y(ed->l_tty, TTY_POS_CURSOR, -1);
s_tty_move_cursor_x(ed->l_tty, TTY_POS_START, tmp_x);
//fprintf(stdout, "\033[A\033[%uG", tmp_x + 1);
start_x = 0;
} else {
/* next, move the physical cursor up and to the end of the previous line */
fprintf(stdout, "\033[A\033[%uG", new_x);
//fprintf(stdout, "\033[A\033[%uG", new_x);
s_tty_move_cursor_y(ed->l_tty, TTY_POS_CURSOR, -1);
s_tty_move_cursor_x(ed->l_tty, TTY_POS_START, new_x);
}
/* now reprint all of the buffer lines, starting with the first of the
@@ -191,10 +201,12 @@ void backspace_nl_refresh(struct line_ed *ed, struct refresh_state *state)
/* finally, move the cursor BACK to the point where the two lines
* were concatenated. */
if (ydiff) {
fprintf(stdout, "\033[%uA", ydiff);
//fprintf(stdout, "\033[%uA", ydiff);
s_tty_move_cursor_y(ed->l_tty, TTY_POS_CURSOR, ydiff);
}
fprintf(stdout, "\033[%uG", new_x);
//fprintf(stdout, "\033[%uG", new_x);
s_tty_move_cursor_x(ed->l_tty, TTY_POS_START, new_x);
fflush(stdout);
}
@@ -219,13 +231,15 @@ void backspace_simple_refresh(struct line_ed *ed, struct refresh_state *state)
if (ed->l_flags & LINE_ED_FULL_REPRINT) {
if (start_x) {
fprintf(stdout, "\033[%uD", start_x);
//fprintf(stdout, "\033[%uD", start_x);
s_tty_move_cursor_x(ed->l_tty, TTY_POS_CURSOR, -start_x);
}
start_x = 0;
}
fputc('\010', stdout);
//fputc('\010', stdout);
s_tty_move_cursor_x(ed->l_tty, TTY_POS_CURSOR, -1);
print_text(ed, start_x, ed->l_cursor_y, line_buf + start_x);
fputc(' ', stdout);
@@ -234,9 +248,13 @@ void backspace_simple_refresh(struct line_ed *ed, struct refresh_state *state)
* the fact that backspace was just pressed) */
cursor_rdelta++;
s_tty_move_cursor_x(ed->l_tty, TTY_POS_CURSOR, -cursor_rdelta);
#if 0
for (unsigned int i = 0; i < cursor_rdelta; i++) {
fputs("\010", stdout);
}
#endif
fflush(stdout);
}