@@ -20,8 +20,8 @@ static void vt_put_char(struct vt_decoder_state *state,
20
20
int row , int col , wchar_t ch , struct vt_decoder_attr * attr );
21
21
static void vt_init_colors (void );
22
22
static void vt_trace (struct vt_decoder_state * state , char * format , ...);
23
- static void vt_cursor (struct vt_decoder_state * state );
24
23
static void vt_dump (struct vt_decoder_state * state , uint8_t * buffer , int count );
24
+ void vt_move_cursor (struct vt_decoder_state * state );
25
25
26
26
void
27
27
vt_decoder_init (struct vt_decoder_state * state )
@@ -34,10 +34,11 @@ vt_decoder_init(struct vt_decoder_state *state)
34
34
}
35
35
}
36
36
37
+ curs_set (0 );
37
38
state -> flags .is_cursor_on = false;
38
- curs_set (state -> force_cursor );
39
39
vt_new_frame (state );
40
40
vt_get_char_code (state , true, false, 0 , 2 , & state -> space );
41
+ wrefresh (state -> win );
41
42
}
42
43
43
44
void
@@ -87,8 +88,8 @@ vt_decoder_decode(struct vt_decoder_state *state, uint8_t *buffer, int count)
87
88
}
88
89
}
89
90
91
+ vt_move_cursor (state );
90
92
vt_trace (state , "BS" );
91
- vt_cursor (state );
92
93
continue ;
93
94
case 9 : // h-tab
94
95
++ state -> col ;
@@ -102,13 +103,20 @@ vt_decoder_decode(struct vt_decoder_state *state, uint8_t *buffer, int count)
102
103
}
103
104
}
104
105
106
+ vt_move_cursor (state );
105
107
vt_trace (state , "H-TAB" );
106
- vt_cursor (state );
107
108
continue ;
108
- case 10 : // LF (end of row)
109
- vt_next_row (state );
109
+ case 10 : // LF
110
+ ++ state -> row ;
111
+
112
+ if (state -> row >= MAX_ROWS ) {
113
+ state -> row = 0 ;
114
+ }
115
+
116
+ vt_reset_flags (state );
117
+ vt_reset_after_flags (state );
118
+ vt_move_cursor (state );
110
119
vt_trace (state , "LF (new row)" );
111
- vt_cursor (state );
112
120
continue ;
113
121
case 11 : // v-tab
114
122
-- state -> row ;
@@ -117,36 +125,39 @@ vt_decoder_decode(struct vt_decoder_state *state, uint8_t *buffer, int count)
117
125
state -> row = MAX_ROWS - 1 ;
118
126
}
119
127
128
+ vt_move_cursor (state );
120
129
vt_trace (state , "V-TAB" );
121
- vt_cursor (state );
122
130
continue ;
123
131
case 12 :
124
132
// FF (new frame/clear screen)
125
133
vt_new_frame (state );
134
+ vt_move_cursor (state );
126
135
vt_trace (state , "FF (new frame)" );
127
- vt_cursor (state );
128
136
continue ;
129
137
case 13 : // CR
130
138
vt_fill_end (state );
131
139
state -> col = 0 ;
140
+ vt_move_cursor (state );
132
141
vt_trace (state , "CR (fill to end)" );
133
- vt_cursor (state );
134
142
continue ;
135
143
case 17 : // DC1 - cursor on
144
+ curs_set (1 );
136
145
state -> flags .is_cursor_on = true;
146
+ vt_move_cursor (state );
137
147
vt_trace (state , "DC1 (cursor on)" );
138
148
continue ;
139
149
case 20 : // DC4 - cursor off
150
+ curs_set (0 );
140
151
state -> flags .is_cursor_on = false;
141
- curs_set (state -> force_cursor );
152
+ vt_move_cursor (state );
142
153
vt_trace (state , "DC4 (cursor off)" );
143
154
continue ;
144
155
case 30 : // RS - back to origin
145
156
vt_fill_end (state );
146
157
state -> col = 0 ;
147
158
state -> row = 0 ;
159
+ vt_move_cursor (state );
148
160
vt_trace (state , "RS (fill to end, back to origin)" );
149
- vt_cursor (state );
150
161
continue ;
151
162
}
152
163
@@ -314,47 +325,78 @@ vt_decoder_decode(struct vt_decoder_state *state, uint8_t *buffer, int count)
314
325
wmove (state -> win , state -> row , state -> col );
315
326
wrefresh (state -> win );
316
327
}
328
+ }
317
329
318
- // Move the cursor to the last character displayed
319
- curs_set (state -> force_cursor || state -> flags .is_cursor_on );
330
+ void
331
+ vt_move_cursor (struct vt_decoder_state * state )
332
+ {
320
333
wmove (state -> win , state -> row , state -> col );
321
- wrefresh (state -> win );
334
+
335
+ if (state -> flags .is_cursor_on ) {
336
+ wrefresh (state -> win );
337
+ }
322
338
}
323
339
324
340
void
325
341
vt_decoder_toggle_flash (struct vt_decoder_state * state )
326
342
{
343
+ bool needs_refresh = false;
344
+ int curs = curs_set (0 );
327
345
state -> screen_flash_state = !state -> screen_flash_state ;
328
346
347
+ if (curs ) {
348
+ wrefresh (state -> win );
349
+ }
350
+
329
351
for (int r = 0 ; r < MAX_ROWS ; ++ r ) {
330
352
for (int c = 0 ; c < MAX_COLS ; ++ c ) {
331
353
struct vt_decoder_cell * cell = & state -> cells [r ][c ];
332
354
333
355
if (cell -> attr .has_flash ) {
334
356
vt_put_char (state , r , c , cell -> character , & cell -> attr );
357
+ needs_refresh = true;
335
358
}
336
359
}
337
360
}
338
361
339
- wrefresh (state -> win );
362
+ curs_set (curs );
363
+
364
+ if (needs_refresh || curs ) {
365
+ // restore cursor position
366
+ wmove (state -> win , state -> row , state -> col );
367
+ wrefresh (state -> win );
368
+ }
340
369
}
341
370
342
371
void
343
372
vt_decoder_toggle_reveal (struct vt_decoder_state * state )
344
373
{
374
+ bool needs_refresh = false;
375
+ int curs = curs_set (0 );
345
376
state -> screen_revealed_state = !state -> screen_revealed_state ;
346
377
378
+ if (curs ) {
379
+ wrefresh (state -> win );
380
+ }
381
+
347
382
for (int r = 0 ; r < MAX_ROWS ; ++ r ) {
348
383
for (int c = 0 ; c < MAX_COLS ; ++ c ) {
349
384
struct vt_decoder_cell * cell = & state -> cells [r ][c ];
350
385
351
386
if (cell -> attr .has_concealed ) {
352
387
vt_put_char (state , r , c , cell -> character , & cell -> attr );
388
+ needs_refresh = true;
353
389
}
354
390
}
355
391
}
356
392
357
- wrefresh (state -> win );
393
+ curs_set (curs );
394
+
395
+ if (needs_refresh || curs ) {
396
+ // restore cursor position
397
+ wmove (state -> win , state -> row , state -> col );
398
+ wrefresh (state -> win );
399
+ }
358
400
}
359
401
360
402
static void
@@ -472,7 +514,7 @@ vt_reset_flags(struct vt_decoder_state *state)
472
514
state -> flags .is_mosaic_held = false;
473
515
state -> flags .held_mosaic = state -> space ;
474
516
state -> flags .is_double_height = false;
475
- // Leave cursor ON
517
+ // leave cursor as is
476
518
}
477
519
478
520
static void
@@ -567,8 +609,12 @@ vt_init_colors(void)
567
609
static void
568
610
vt_trace (struct vt_decoder_state * state , char * format , ...)
569
611
{
612
+ int cy = 0 ;
613
+ int cx = 0 ;
614
+
570
615
if (state -> trace_file != NULL ) {
571
- fprintf (state -> trace_file , "%02d,%02d\t" , state -> row , state -> col );
616
+ getyx (state -> win , cy , cx );
617
+ fprintf (state -> trace_file , "%02d,%02d (%02d,%02d)\t" , state -> row , state -> col , cy , cx );
572
618
va_list args ;
573
619
va_start (args , format );
574
620
vfprintf (state -> trace_file , format , args );
@@ -577,15 +623,6 @@ vt_trace(struct vt_decoder_state *state, char *format, ...)
577
623
}
578
624
}
579
625
580
- static void
581
- vt_cursor (struct vt_decoder_state * state )
582
- {
583
- if (state -> force_cursor ) {
584
- wmove (state -> win , state -> row , state -> col );
585
- wrefresh (state -> win );
586
- }
587
- }
588
-
589
626
static void
590
627
vt_dump (struct vt_decoder_state * state , uint8_t * buffer , int count )
591
628
{
0 commit comments