Fix clobbering of the default attribute and the screen position in

scteken_init().  Move the internals of scteken_sync() into a local
function to help do this.

scteken_init() reset or adjusted the default attribute and screen
position at least 3 and 5 times, respectively.  Warm init shouldn't
do any more than reset the "input" state.
  (scterm-sc.c (which still works after minor editing), only resets
  the escape state and the saved cursor position, and then does a
  nearly-null sync of the current color.)

This mainly broke mode changes, and was most noticeable when the
background color is not teken's default (usually black).  Then the
screen gets cleared in the wrong color.  vidcontrol restores the
default normal attribute and tries to restore the default reverse
attribute.  vidcontrol doesn't clear the screen again after restoring
the attribute(s), and it is too late to do it there without flicker.
Now the default normal attribute is restored before the change affects
the rendering.

When the foreground color is not teken's default, clearing with the
wrong attributes gave strange cursor colors for some cursor types.

The default reverse attribute is not restored since it is unsupported.

2/3 of the clobbering was from 2 resetting window resizing calls.  The
second one is needed to restore the size, but must not reset.  Window
resizing also sanitizes the cursor position, and after the main reset
resets the window size, the cursor row would often be adjusted from
24 to 23 if it were not already reset to 0.  scteken_sync() is good
for restoring the window size and the cursor position in the correct
order, but was unusable at init time since scp->ts is not always
initialized then.  Adjust to use its internals.

I didn't notice any problems from the cursor reset.  The cursor should
be reset, and a previous fix was to reset it consistently a little
later.

Doing nothing for warm init works almost as well, if not better.  It
is not very useful to reset the escape state for mode changes, since
the reset is especially likely to be null then.  The escape state is
most likely to be non-initial and corrupted by its most normal uses
-- sloppy non-atomic output where a context switch or just mixing
stdout with stderr splits up escape sequences.
This commit is contained in:
bde 2017-04-12 16:21:55 +00:00
parent e10e5b0689
commit 23ecd4abe8

View File

@ -72,6 +72,8 @@ typedef struct {
static teken_stat reserved_teken_stat;
static void scteken_sync_internal(scr_stat *, teken_stat *);
static sc_term_sw_t sc_term_scteken = {
{ NULL, NULL },
"scteken", /* emulator name */
@ -116,7 +118,7 @@ static int
scteken_init(scr_stat *scp, void **softc, int code)
{
teken_stat *ts;
teken_pos_t tp;
teken_attr_t ta;
if (*softc == NULL) {
if (reserved_teken_stat.ts_busy)
@ -131,17 +133,16 @@ scteken_init(scr_stat *scp, void **softc, int code)
ts->ts_busy = 1;
/* FALLTHROUGH */
case SC_TE_WARM_INIT:
ta = *teken_get_defattr(&ts->ts_teken);
teken_init(&ts->ts_teken, &scteken_funcs, scp);
teken_set_defattr(&ts->ts_teken, &ta);
#ifndef TEKEN_UTF8
teken_set_8bit(&ts->ts_teken);
#endif /* !TEKEN_UTF8 */
#ifdef TEKEN_CONS25
teken_set_cons25(&ts->ts_teken);
#endif /* TEKEN_CONS25 */
tp.tp_row = scp->ysize;
tp.tp_col = scp->xsize;
teken_set_winsize(&ts->ts_teken, &tp);
scteken_sync_internal(scp, ts);
break;
}
@ -219,7 +220,7 @@ scteken_clear(scr_stat *scp)
teken_stat *ts = scp->ts;
sc_move_cursor(scp, 0, 0);
scteken_sync(scp);
scteken_sync_internal(scp, ts);
sc_vtb_clear(&scp->vtb, scp->sc->scr_map[0x20],
scteken_te_to_sc_attr(teken_get_curattr(&ts->ts_teken))
<< 8);
@ -284,9 +285,8 @@ scteken_fkeystr(scr_stat *scp, int c)
}
static void
scteken_sync(scr_stat *scp)
scteken_sync_internal(scr_stat *scp, teken_stat *ts)
{
teken_stat *ts = scp->ts;
teken_pos_t tp;
tp.tp_col = scp->xsize;
@ -297,6 +297,12 @@ scteken_sync(scr_stat *scp)
teken_set_cursor(&ts->ts_teken, &tp);
}
static void
scteken_sync(scr_stat *scp)
{
scteken_sync_internal(scp, scp->ts);
}
static void
scteken_nop(void)
{