term: restore cursor position after draw calls

This keeps the cursor position at the last %hop location. And being able
to go back to that position without relying on state is just plain
convenient.

The exception here is %nel blits, which move the cursor (down and) to
the start of the line, as expected of "new line" semantics.
This commit is contained in:
fang 2021-02-18 13:46:51 +01:00
parent 0d8288e666
commit d974d4cc4e
No known key found for this signature in database
GPG Key ID: EB035760C1BBA972
2 changed files with 11 additions and 6 deletions

View File

@ -199,6 +199,8 @@
uv_buf_t el_u; // clr_bol clear to beginning uv_buf_t el_u; // clr_bol clear to beginning
// uv_buf_t el1_u; // clr_eol clear to end // uv_buf_t el1_u; // clr_eol clear to end
uv_buf_t ed_u; // clear to end of screen uv_buf_t ed_u; // clear to end of screen
uv_buf_t sc_u; // save cursor position
uv_buf_t rc_u; // restore cursor position
uv_buf_t bel_u; // bel sound bell uv_buf_t bel_u; // bel sound bell
uv_buf_t cub1_u; // parm_left uv_buf_t cub1_u; // parm_left
uv_buf_t cuf1_u; // parm_right uv_buf_t cuf1_u; // parm_right

View File

@ -167,6 +167,8 @@ u3_term_log_init(void)
uty_u->ufo_u.out.el_u = TERM_LIT_BUF("\033[K"); uty_u->ufo_u.out.el_u = TERM_LIT_BUF("\033[K");
// uty_u->ufo_u.out.el1_u = TERM_LIT_BUF("\033[1K"); // uty_u->ufo_u.out.el1_u = TERM_LIT_BUF("\033[1K");
uty_u->ufo_u.out.ed_u = TERM_LIT_BUF("\033[J"); uty_u->ufo_u.out.ed_u = TERM_LIT_BUF("\033[J");
uty_u->ufo_u.out.sc_u = TERM_LIT_BUF("\033[s");
uty_u->ufo_u.out.rc_u = TERM_LIT_BUF("\033[u");
uty_u->ufo_u.out.bel_u = TERM_LIT_BUF("\x7"); uty_u->ufo_u.out.bel_u = TERM_LIT_BUF("\x7");
uty_u->ufo_u.out.cub1_u = TERM_LIT_BUF("\x8"); uty_u->ufo_u.out.cub1_u = TERM_LIT_BUF("\x8");
uty_u->ufo_u.out.cuf1_u = TERM_LIT_BUF("\033[C"); uty_u->ufo_u.out.cuf1_u = TERM_LIT_BUF("\033[C");
@ -475,9 +477,9 @@ _term_it_clear_line(u3_utty* uty_u)
if ( uty_u->tat_u.siz.col_l ) { if ( uty_u->tat_u.siz.col_l ) {
_term_it_dump(uty_u, TERM_LIT("\r")); _term_it_dump(uty_u, TERM_LIT("\r"));
_term_it_dump_buf(uty_u, &uty_u->ufo_u.out.el_u); _term_it_dump_buf(uty_u, &uty_u->ufo_u.out.el_u);
_term_it_dump_buf(uty_u, &uty_u->ufo_u.out.rc_u);
uty_u->tat_u.mir.wor_w = 0; uty_u->tat_u.mir.wor_w = 0;
uty_u->tat_u.mir.cus_w = 0;
} }
} }
@ -487,6 +489,7 @@ static void
_term_it_show_blank(u3_utty* uty_u) _term_it_show_blank(u3_utty* uty_u)
{ {
_term_it_dump_buf(uty_u, &uty_u->ufo_u.out.clear_u); _term_it_dump_buf(uty_u, &uty_u->ufo_u.out.clear_u);
_term_it_dump_buf(uty_u, &uty_u->ufo_u.out.rc_u);
} }
/* _term_it_move_cursor(): move cursor to row & column /* _term_it_move_cursor(): move cursor to row & column
@ -504,9 +507,8 @@ _term_it_move_cursor(u3_utty* uty_u, c3_w row_w, c3_w col_w)
if ( col_w >= col_l ) { col_w = col_l - 1; } if ( col_w >= col_l ) { col_w = col_l - 1; }
_term_it_send_csi(uty_u, 'H', 2, row_l - row_w, col_w + 1); _term_it_send_csi(uty_u, 'H', 2, row_l - row_w, col_w + 1);
//TODO send s for saving cursor position? _term_it_dump_buf(uty_u, &uty_u->ufo_u.out.sc_u);
//TODO how does this interact with window resizing?
uty_u->tat_u.mir.rus_w = row_w; uty_u->tat_u.mir.rus_w = row_w;
uty_u->tat_u.mir.cus_w = col_w; uty_u->tat_u.mir.cus_w = col_w;
} }
@ -528,11 +530,11 @@ _term_it_show_line(u3_utty* uty_u, c3_w wor_w)
memcpy(hun_y, tat_u->mir.lin_y, len_w); memcpy(hun_y, tat_u->mir.lin_y, len_w);
_term_it_send(uty_u, len_w, hun_y); _term_it_send(uty_u, len_w, hun_y);
_term_it_dump_buf(uty_u, &uty_u->ufo_u.out.rc_u);
} }
// XX refactor to avoid updating state // XX refactor to avoid updating state
// //
tat_u->mir.cus_w += wor_w;
tat_u->mir.wor_w = wor_w; tat_u->mir.wor_w = wor_w;
} }
@ -543,11 +545,11 @@ _term_it_refresh_line(u3_utty* uty_u)
{ {
u3_utat* tat_u = &uty_u->tat_u; u3_utat* tat_u = &uty_u->tat_u;
c3_w wor_w = tat_u->mir.wor_w; c3_w wor_w = tat_u->mir.wor_w;
c3_w cus_w = tat_u->mir.cus_w;
_term_it_move_cursor(uty_u, 0, 0);
_term_it_clear_line(uty_u); _term_it_clear_line(uty_u);
_term_it_show_line(uty_u, wor_w); _term_it_show_line(uty_u, wor_w);
_term_it_move_cursor(uty_u, 0, cus_w); _term_it_dump_buf(uty_u, &uty_u->ufo_u.out.rc_u);
} }
/* _term_it_set_line(): set current line. /* _term_it_set_line(): set current line.
@ -617,6 +619,7 @@ _term_it_show_more(u3_utty* uty_u)
if ( uty_u->tat_u.mir.rus_w > 0 ) { if ( uty_u->tat_u.mir.rus_w > 0 ) {
uty_u->tat_u.mir.rus_w--; uty_u->tat_u.mir.rus_w--;
} }
_term_it_dump_buf(uty_u, &uty_u->ufo_u.out.sc_u);
} }
/* _term_it_path(): path for console file. /* _term_it_path(): path for console file.