aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/terminal/terminalfunctions.cc
blob: a0210e3429530726f21c2721e4369fcab2b63ffe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
/*
    Mosh: the mobile shell
    Copyright 2012 Keith Winstein

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

    In addition, as a special exception, the copyright holders give
    permission to link the code of portions of this program with the
    OpenSSL library under certain conditions as described in each
    individual source file, and distribute linked combinations including
    the two.

    You must obey the GNU General Public License in all respects for all
    of the code used other than OpenSSL. If you modify file(s) with this
    exception, you may extend this exception to your version of the
    file(s), but you are not obligated to do so. If you do not wish to do
    so, delete this exception statement from your version. If you delete
    this exception statement from all source files in the program, then
    also delete it here.
*/

#include <unistd.h>
#include <algorithm>
#include <string>
#include <stdio.h>

#include "terminaldispatcher.h"
#include "terminalframebuffer.h"
#include "parseraction.h"

using namespace Terminal;
using namespace std;

/* Terminal functions -- routines activated by CSI, escape or a control char */

static void clearline( Framebuffer *fb, int row, int start, int end )
{
  for ( int col = start; col <= end; col++ ) {
    fb->reset_cell( fb->get_mutable_cell( row, col ) );
  }
}

/* erase in line */
static void CSI_EL( Framebuffer *fb, Dispatcher *dispatch )
{
  switch ( dispatch->getparam( 0, 0 ) ) {
  case 0: /* default: active position to end of line, inclusive */
    clearline( fb, -1, fb->ds.get_cursor_col(), fb->ds.get_width() - 1 );    
    break;
  case 1: /* start of screen to active position, inclusive */
    clearline( fb, -1, 0, fb->ds.get_cursor_col() );
    break;
  case 2: /* all of line */
    fb->reset_row( fb->get_mutable_row( -1 ) );
    break;
  default:
    break;
  }
}

static Function func_CSI_EL( CSI, "K", CSI_EL );

/* erase in display */
static void CSI_ED( Framebuffer *fb, Dispatcher *dispatch ) {
  switch ( dispatch->getparam( 0, 0 ) ) {
  case 0: /* active position to end of screen, inclusive */
    clearline( fb, -1, fb->ds.get_cursor_col(), fb->ds.get_width() - 1 );
    for ( int y = fb->ds.get_cursor_row() + 1; y < fb->ds.get_height(); y++ ) {
      fb->reset_row( fb->get_mutable_row( y ) );
    }
    break;
  case 1: /* start of screen to active position, inclusive */
    for ( int y = 0; y < fb->ds.get_cursor_row(); y++ ) {
      fb->reset_row( fb->get_mutable_row( y ) );
    }
    clearline( fb, -1, 0, fb->ds.get_cursor_col() );
    break;
  case 2: /* entire screen */
    for ( int y = 0; y < fb->ds.get_height(); y++ ) {
      fb->reset_row( fb->get_mutable_row( y ) );
    }
    break;
  default:
    break;
  }
}

static Function func_CSI_ED( CSI, "J", CSI_ED );

/* cursor movement -- relative and absolute */
static void CSI_cursormove( Framebuffer *fb, Dispatcher *dispatch )
{
  int num = dispatch->getparam( 0, 1 );

  switch ( dispatch->get_dispatch_chars()[ 0 ] ) {
  case 'A':
    fb->ds.move_row( -num, true );
    break;
  case 'B':
    fb->ds.move_row( num, true );
    break;
  case 'C':
    fb->ds.move_col( num, true );
    break;
  case 'D':
    fb->ds.move_col( -num, true );
    break;
  case 'H':
  case 'f':
    fb->ds.move_row( dispatch->getparam( 0, 1 ) - 1 );
    fb->ds.move_col( dispatch->getparam( 1, 1 ) - 1 );
    break;
  default:
    break;
  }
}

static Function func_CSI_cursormove_A( CSI, "A", CSI_cursormove );
static Function func_CSI_cursormove_B( CSI, "B", CSI_cursormove );
static Function func_CSI_cursormove_C( CSI, "C", CSI_cursormove );
static Function func_CSI_cursormove_D( CSI, "D", CSI_cursormove );
static Function func_CSI_cursormove_H( CSI, "H", CSI_cursormove );
static Function func_CSI_cursormove_f( CSI, "f", CSI_cursormove );

/* device attributes */
static void CSI_DA( Framebuffer *fb __attribute((unused)), Dispatcher *dispatch )
{
  dispatch->terminal_to_host.append( "\033[?62c" ); /* plain vt220 */
}

static Function func_CSI_DA( CSI, "c", CSI_DA );

/* secondary device attributes */
static void CSI_SDA( Framebuffer *fb __attribute((unused)), Dispatcher *dispatch )
{
  dispatch->terminal_to_host.append( "\033[>1;10;0c" ); /* plain vt220 */
}

static Function func_CSI_SDA( CSI, ">c", CSI_SDA );

/* screen alignment diagnostic */
static void Esc_DECALN( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
{
  for ( int y = 0; y < fb->ds.get_height(); y++ ) {
    for ( int x = 0; x < fb->ds.get_width(); x++ ) {
      fb->reset_cell( fb->get_mutable_cell( y, x ) );
      fb->get_mutable_cell( y, x )->append( 'E' );
    }
  }
}

static Function func_Esc_DECALN( ESCAPE, "#8", Esc_DECALN );

/* line feed */
static void Ctrl_LF( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
{
  fb->move_rows_autoscroll( 1 );
}

/* same procedure for index, vertical tab, and form feed control codes */
static Function func_Ctrl_LF( CONTROL, "\x0a", Ctrl_LF );
static Function func_Ctrl_IND( CONTROL, "\x84", Ctrl_LF );
static Function func_Ctrl_VT( CONTROL, "\x0b", Ctrl_LF );
static Function func_Ctrl_FF( CONTROL, "\x0c", Ctrl_LF );

/* carriage return */
static void Ctrl_CR( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
{
  fb->ds.move_col( 0 );
}

static Function func_Ctrl_CR( CONTROL, "\x0d", Ctrl_CR );

/* backspace */
static void Ctrl_BS( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
{
  fb->ds.move_col( -1, true );
}

static Function func_Ctrl_BS( CONTROL, "\x08", Ctrl_BS );

/* reverse index -- like a backwards line feed */
static void Ctrl_RI( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
{
  fb->move_rows_autoscroll( -1 );
}

static Function func_Ctrl_RI( CONTROL, "\x8D", Ctrl_RI );

/* newline */
static void Ctrl_NEL( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
{
  fb->ds.move_col( 0 );
  fb->move_rows_autoscroll( 1 );
}

static Function func_Ctrl_NEL( CONTROL, "\x85", Ctrl_NEL );

/* horizontal tab */
static void HT_n( Framebuffer *fb, size_t count )
{
  int col = fb->ds.get_next_tab( count );
  if ( col == -1 ) { /* no tabs, go to end of line */
    col = fb->ds.get_width() - 1;
  }

  /* A horizontal tab is the only operation that preserves but
     does not set the wrap state. It also starts a new grapheme. */

  bool wrap_state_save = fb->ds.next_print_will_wrap;
  fb->ds.move_col( col, false );
  fb->ds.next_print_will_wrap = wrap_state_save;
}

static void Ctrl_HT( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
{
  HT_n( fb, 1 );
}
static Function func_Ctrl_HT( CONTROL, "\x09", Ctrl_HT, false );

static void CSI_CxT( Framebuffer *fb, Dispatcher *dispatch )
{
  int param = dispatch->getparam( 0, 1 );
  if ( dispatch->get_dispatch_chars()[ 0 ] == 'Z' ) {
    param = -param;
  }
  if ( param == 0 ) {
    return;
  }
  HT_n( fb, param );
}

static Function func_CSI_CHT( CSI, "I", CSI_CxT, false );
static Function func_CSI_CBT( CSI, "Z", CSI_CxT, false );

/* horizontal tab set */
static void Ctrl_HTS( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
{
  fb->ds.set_tab();
}

static Function func_Ctrl_HTS( CONTROL, "\x88", Ctrl_HTS );

/* tabulation clear */
static void CSI_TBC( Framebuffer *fb, Dispatcher *dispatch )
{
  int param = dispatch->getparam( 0, 0 );
  switch ( param ) {
  case 0: /* clear this tab stop */
    fb->ds.clear_tab( fb->ds.get_cursor_col() );    
    break;
  case 3: /* clear all tab stops */
    fb->ds.clear_default_tabs();
    for ( int x = 0; x < fb->ds.get_width(); x++ ) {
      fb->ds.clear_tab( x );
    }
    break;
  default:
    break;
  }
}

/* TBC preserves wrap state */
static Function func_CSI_TBC( CSI, "g", CSI_TBC, false );

static bool *get_DEC_mode( int param, Framebuffer *fb ) {
  switch ( param ) {
  case 1: /* cursor key mode */
    return &(fb->ds.application_mode_cursor_keys);
  case 3: /* 80/132. Ignore but clear screen. */
    /* clear screen */
    fb->ds.move_row( 0 );
    fb->ds.move_col( 0 );
    for ( int y = 0; y < fb->ds.get_height(); y++ ) {
      fb->reset_row( fb->get_mutable_row( y ) );
    }
    return NULL;
  case 5: /* reverse video */
    return &(fb->ds.reverse_video);
  case 6: /* origin */
    fb->ds.move_row( 0 );
    fb->ds.move_col( 0 );
    return &(fb->ds.origin_mode);
  case 7: /* auto wrap */
    return &(fb->ds.auto_wrap_mode);
  case 25:
    return &(fb->ds.cursor_visible);
  case 1004:           /* xterm mouse focus event */
    return &(fb->ds.mouse_focus_event);
  case 1007:           /* xterm mouse alternate scroll */
    return &(fb->ds.mouse_alternate_scroll);
  case 2004: /* bracketed paste */
    return &(fb->ds.bracketed_paste);
  default:
    break;
  }
  return NULL;
}

/* helper for CSI_DECSM and CSI_DECRM */
static void set_if_available( bool *mode, bool value )
{
  if ( mode ) { *mode = value; }
}

/* set private mode */
static void CSI_DECSM( Framebuffer *fb, Dispatcher *dispatch )
{
  for ( int i = 0; i < dispatch->param_count(); i++ ) {
    int param = dispatch->getparam( i, 0 );
    if (param == 9 || (param >= 1000 && param <= 1003)) {
      fb->ds.mouse_reporting_mode = (Terminal::DrawState::MouseReportingMode) param;
    } else if (param == 1005 || param == 1006 || param == 1015) {
      fb->ds.mouse_encoding_mode = (Terminal::DrawState::MouseEncodingMode) param;
    } else {
      set_if_available( get_DEC_mode( param, fb ), true );
    }
  }
}

/* clear private mode */
static void CSI_DECRM( Framebuffer *fb, Dispatcher *dispatch )
{
  for ( int i = 0; i < dispatch->param_count(); i++ ) {
    int param = dispatch->getparam( i, 0 );
    if (param == 9 || (param >= 1000 && param <= 1003)) {
      fb->ds.mouse_reporting_mode = Terminal::DrawState::MOUSE_REPORTING_NONE;
    } else if (param == 1005 || param == 1006 || param == 1015) {
      fb->ds.mouse_encoding_mode = Terminal::DrawState::MOUSE_ENCODING_DEFAULT;
    } else {
      set_if_available( get_DEC_mode( param, fb ), false );
    }
  }
}

/* These functions don't clear wrap state. */
static Function func_CSI_DECSM( CSI, "?h", CSI_DECSM, false );
static Function func_CSI_DECRM( CSI, "?l", CSI_DECRM, false );

static bool *get_ANSI_mode( int param, Framebuffer *fb ) {
  if ( param == 4 ) { /* insert/replace mode */
    return &(fb->ds.insert_mode);
  }
  return NULL;
}

/* set mode */
static void CSI_SM( Framebuffer *fb, Dispatcher *dispatch )
{
  for ( int i = 0; i < dispatch->param_count(); i++ ) {
    bool *mode = get_ANSI_mode( dispatch->getparam( i, 0 ), fb );
    if ( mode ) {
      *mode = true;
    }
  }
}

/* clear mode */
static void CSI_RM( Framebuffer *fb, Dispatcher *dispatch )
{
  for ( int i = 0; i < dispatch->param_count(); i++ ) {
    bool *mode = get_ANSI_mode( dispatch->getparam( i, 0 ), fb );
    if ( mode ) {
      *mode = false;
    }
  }
}

static Function func_CSI_SM( CSI, "h", CSI_SM );
static Function func_CSI_RM( CSI, "l", CSI_RM );

/* set top and bottom margins */
static void CSI_DECSTBM( Framebuffer *fb, Dispatcher *dispatch )
{
  int top = dispatch->getparam( 0, 1 );
  int bottom = dispatch->getparam( 1, fb->ds.get_height() );

  if ( (bottom <= top)
       || (top > fb->ds.get_height())
       || (top == 0 && bottom == 1) ) {
    return; /* invalid, xterm ignores */
  }

  fb->ds.set_scrolling_region( top - 1, bottom - 1 );
  fb->ds.move_row( 0 );
  fb->ds.move_col( 0 );
}

static Function func_CSI_DECSTMB( CSI, "r", CSI_DECSTBM );

/* terminal bell */
static void Ctrl_BEL( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) {
  fb->ring_bell();
}

static Function func_Ctrl_BEL( CONTROL, "\x07", Ctrl_BEL );

/* select graphics rendition -- e.g., bold, blinking, etc. */
static void CSI_SGR( Framebuffer *fb, Dispatcher *dispatch )
{
  for ( int i = 0; i < dispatch->param_count(); i++ ) {
    int rendition = dispatch->getparam( i, 0 );
    /* We need to special-case the handling of [34]8 ; 5 ; Ps,
       because Ps of 0 in that case does not mean reset to default, even
       though it means that otherwise (as usually renditions are applied
       in order). */
    if ((rendition == 38 || rendition == 48) &&
	(dispatch->param_count() - i >= 3) &&
	(dispatch->getparam( i+1, -1 ) == 5)) {
      (rendition == 38) ?
	fb->ds.set_foreground_color( dispatch->getparam( i+2, 0 ) ) :
	fb->ds.set_background_color( dispatch->getparam( i+2, 0 ) );
      i += 2;
      continue;
    }
    fb->ds.add_rendition( rendition );
  }
}

static Function func_CSI_SGR( CSI, "m", CSI_SGR, false ); /* changing renditions doesn't clear wrap flag */

/* save and restore cursor */
static void Esc_DECSC( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
{
  fb->ds.save_cursor();
}

static void Esc_DECRC( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
{
  fb->ds.restore_cursor();
}

static Function func_Esc_DECSC( ESCAPE, "7", Esc_DECSC );
static Function func_Esc_DECRC( ESCAPE, "8", Esc_DECRC );

/* device status report -- e.g., cursor position (used by resize) */
static void CSI_DSR( Framebuffer *fb, Dispatcher *dispatch )
{
  int param = dispatch->getparam( 0, 0 );

  switch ( param ) {
  case 5: /* device status report requested */
    dispatch->terminal_to_host.append( "\033[0n" );
    break;
  case 6: /* report of active position requested */
    char cpr[ 32 ];
    snprintf( cpr, 32, "\033[%d;%dR",
	      fb->ds.get_cursor_row() + 1,
	      fb->ds.get_cursor_col() + 1 );
    dispatch->terminal_to_host.append( cpr );
    break;
  default:
    break;
  }
}

static Function func_CSI_DSR( CSI, "n", CSI_DSR );

/* insert line */
static void CSI_IL( Framebuffer *fb, Dispatcher *dispatch )
{
  int lines = dispatch->getparam( 0, 1 );

  fb->insert_line( fb->ds.get_cursor_row(), lines );

  /* vt220 manual and Ecma-48 say to move to first column */
  /* but xterm and gnome-terminal don't */
  fb->ds.move_col( 0 );
}

static Function func_CSI_IL( CSI, "L", CSI_IL );

/* delete line */
static void CSI_DL( Framebuffer *fb, Dispatcher *dispatch )
{
  int lines = dispatch->getparam( 0, 1 );

  fb->delete_line( fb->ds.get_cursor_row(), lines );

  /* same story -- xterm and gnome-terminal don't
     move to first column */
  fb->ds.move_col( 0 );
}

static Function func_CSI_DL( CSI, "M", CSI_DL );

/* insert characters */
static void CSI_ICH( Framebuffer *fb, Dispatcher *dispatch )
{
  int cells = dispatch->getparam( 0, 1 );

  for ( int i = 0; i < cells; i++ ) {
    fb->insert_cell( fb->ds.get_cursor_row(), fb->ds.get_cursor_col() );
  }
}

static Function func_CSI_ICH( CSI, "@", CSI_ICH );

/* delete character */
static void CSI_DCH( Framebuffer *fb, Dispatcher *dispatch )
{
  int cells = dispatch->getparam( 0, 1 );

  for ( int i = 0; i < cells; i++ ) {
    fb->delete_cell( fb->ds.get_cursor_row(), fb->ds.get_cursor_col() );
  }
}

static Function func_CSI_DCH( CSI, "P", CSI_DCH );

/* line position absolute */
static void CSI_VPA( Framebuffer *fb, Dispatcher *dispatch )
{
  int row = dispatch->getparam( 0, 1 );
  fb->ds.move_row( row - 1 );
}

static Function func_CSI_VPA( CSI, "d", CSI_VPA );

/* character position absolute */
static void CSI_HPA( Framebuffer *fb, Dispatcher *dispatch )
{
  int col = dispatch->getparam( 0, 1 );
  fb->ds.move_col( col - 1 );
}

static Function func_CSI_CHA( CSI, "G", CSI_HPA ); /* ECMA-48 name: CHA */
static Function func_CSI_HPA( CSI, "\x60", CSI_HPA ); /* ECMA-48 name: HPA */

/* erase character */
static void CSI_ECH( Framebuffer *fb, Dispatcher *dispatch )
{
  int num = dispatch->getparam( 0, 1 );
  int limit = fb->ds.get_cursor_col() + num - 1;
  if ( limit >= fb->ds.get_width() ) {
    limit = fb->ds.get_width() - 1;
  }

  clearline( fb, -1, fb->ds.get_cursor_col(), limit );
}

static Function func_CSI_ECH( CSI, "X", CSI_ECH );

/* reset to initial state */
static void Esc_RIS( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
{
  fb->reset();
}

static Function func_Esc_RIS( ESCAPE, "c", Esc_RIS );

/* soft reset */
static void CSI_DECSTR( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
{
  fb->soft_reset();
}

static Function func_CSI_DECSTR( CSI, "!p", CSI_DECSTR );

/* xterm uses an Operating System Command to set the window title */
void Dispatcher::OSC_dispatch( const Parser::OSC_End *act __attribute((unused)), Framebuffer *fb )
{
  /* handle osc copy clipboard sequence 52;c; */
  if ( OSC_string.size() >= 5 && OSC_string[ 0 ] == L'5' &&
       OSC_string[ 1 ] == L'2' && OSC_string[ 2 ] == L';' &&
       OSC_string[ 3 ] == L'c' && OSC_string[ 4 ] == L';') {
      Terminal::Framebuffer::title_type clipboard(
              OSC_string.begin() + 5, OSC_string.end() );
      fb->set_clipboard( clipboard );
  /* handle osc terminal title sequence */
  } else if ( OSC_string.size() >= 1 ) {
    long cmd_num = -1;
    int offset = 0;
    if ( OSC_string[ 0 ] == L';' ) {
      /* OSC of the form "\033];<title>\007" */
      cmd_num = 0; /* treat it as as a zero */
      offset = 1;
    } else if ( (OSC_string.size() >= 2) && (OSC_string[ 1 ] == L';') ) {
      /* OSC of the form "\033]X;<title>\007" where X can be:
       * 0: set icon name and window title
       * 1: set icon name
       * 2: set window title */
      cmd_num = OSC_string[ 0 ] - L'0';
      offset = 2;
    }
    bool set_icon = cmd_num == 0 || cmd_num == 1;
    bool set_title = cmd_num == 0 || cmd_num == 2;
    if ( set_icon || set_title ) {
      fb->set_title_initialized();
      int title_length = min(OSC_string.size(), (size_t)256);
      Terminal::Framebuffer::title_type newtitle( OSC_string.begin() + offset, OSC_string.begin() + title_length );
      if ( set_icon )  { fb->set_icon_name( newtitle ); }
      if ( set_title ) { fb->set_window_title( newtitle ); }
    }
  }
}

/* scroll down or terminfo indn */
static void CSI_SD( Framebuffer *fb, Dispatcher *dispatch )
{
  fb->scroll( dispatch->getparam( 0, 1 ) );
}

static Function func_CSI_SD( CSI, "S", CSI_SD );

/* scroll up or terminfo rin */
static void CSI_SU( Framebuffer *fb, Dispatcher *dispatch )
{
  fb->scroll( -dispatch->getparam( 0, 1 ) );
}

static Function func_CSI_SU( CSI, "T", CSI_SU );