/* Screen functions for the VT100 terminal * * JWD - 11/12/18 * * ANSI Escape Sequences * * cursor position - ESC[n;nH where n is in ASCII * erase in line - ESC[K * clear screen - ESC[nJ where n is 2 for clear all * line insert - ESC[L */ char bep[1]; char eol[3]; char clr[4]; char ins[3]; char sup[3]; scr_init () { eol[0] = clr[0] = ins[0] = sup[0] = 0x1b; eol[1] = clr[1] = ins[1] = sup[1] = '['; eol[2] = 'K'; clr[2] = '2'; clr[3] = 'J'; ins[2] = 'L'; sup[2] = 'S'; bep[0] = 0x07; } scr_curs (y, x) int y, x; { /* xy cursor position */ char curs[9]; sprintf (curs, "\x1b[%d;%dH", y+1, x+1); write (1, curs, strlen(curs)); } scr_beep () { /* ring the bell */ write (1, bep, 1); } scr_eol () { /* erase from cursor to end of line */ write (1, eol, 3); } scr_clear () { /* clear the screen */ write (1, clr, 4); scr_curs (0, 0); } scr_linsert () { /* line insert */ write (1, ins, 3); } scr_scrlup () { /* scroll up */ write (1, sup, 3); }