vt.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. /*
  10. * Known bugs:
  11. *
  12. * 1. We don't handle cursor movement characters inside escape sequences.
  13. * That is, ESC[2C moves two to the right, so ESC[2\bC is supposed to back
  14. * up one and then move two to the right.
  15. *
  16. * 2. We don't handle tabstops past nelem(tabcol) columns.
  17. *
  18. * 3. We don't respect requests to do reverse video for the whole screen.
  19. *
  20. * 4. We ignore the ESC#n codes, so that we don't do double-width nor
  21. * double-height lines, nor the ``fill the screen with E's'' confidence check.
  22. *
  23. * 5. Cursor key sequences aren't selected by keypad application mode.
  24. *
  25. * 6. "VT220" mode (-2) currently just switches the default cursor key
  26. * functions (same as -a); it's still just a VT100 emulation.
  27. *
  28. * 7. VT52 mode and a few other rarely used features are not implemented.
  29. */
  30. #include <u.h>
  31. #include <libc.h>
  32. #include <draw.h>
  33. #include <bio.h>
  34. #include <ctype.h>
  35. #include "cons.h"
  36. int wraparound = 1;
  37. int originrelative = 0;
  38. int tabcol[200];
  39. struct funckey vt100fk[NKEYS] = {
  40. { "up key", "\033OA", },
  41. { "down key", "\033OB", },
  42. { "left key", "\033OD", },
  43. { "right key", "\033OC", },
  44. };
  45. struct funckey ansifk[NKEYS] = {
  46. { "up key", "\033[A", },
  47. { "down key", "\033[B", },
  48. { "left key", "\033[D", },
  49. { "right key", "\033[C", },
  50. { "F1", "\033OP", },
  51. { "F2", "\033OQ", },
  52. { "F3", "\033OR", },
  53. { "F4", "\033OS", },
  54. { "F5", "\033OT", },
  55. { "F6", "\033OU", },
  56. { "F7", "\033OV", },
  57. { "F8", "\033OW", },
  58. { "F9", "\033OX", },
  59. { "F10", "\033OY", },
  60. { "F11", "\033OZ", },
  61. { "F12", "\033O1", },
  62. };
  63. struct funckey vt220fk[NKEYS] = {
  64. { "up key", "\033[A", },
  65. { "down key", "\033[B", },
  66. { "left key", "\033[D", },
  67. { "right key", "\033[C", },
  68. };
  69. struct funckey xtermfk[NKEYS] = {
  70. { "page up", "\033[5~", },
  71. { "page down", "\033[6~", },
  72. { "up key", "\033[A", },
  73. { "down key", "\033[B", },
  74. { "left key", "\033[D", },
  75. { "right key", "\033[C", },
  76. { "F1", "\033[11~", },
  77. { "F2", "\033[12~", },
  78. { "F3", "\033[13~", },
  79. { "F4", "\033[14~", },
  80. { "F5", "\033[15~", },
  81. { "F6", "\033[17~", },
  82. { "F7", "\033[18~", },
  83. { "F8", "\033[19~", },
  84. { "F9", "\033[20~", },
  85. { "F10", "\033[21~", },
  86. { "F11", "\033[22~", },
  87. { "F12", "\033[23~", },
  88. };
  89. char gmap[256] = {
  90. ['_'] = ' ', /* blank */
  91. ['\\'] = '*', /* diamond */
  92. ['a'] = 'X', /* checkerboard */
  93. ['b'] = '\t', /* HT */
  94. ['c'] = '\x0C', /* FF */
  95. ['d'] = '\r', /* CR */
  96. ['e'] = '\n', /* LF */
  97. ['f'] = 'o', /* degree */
  98. ['g'] = '+', /* plus/minus */
  99. ['h'] = '\n', /* NL, but close enough */
  100. ['i'] = '\v', /* VT */
  101. ['j'] = '+', /* lower right corner */
  102. ['k'] = '+', /* upper right corner */
  103. ['l'] = '+', /* upper left corner */
  104. ['m'] = '+', /* lower left corner */
  105. ['n'] = '+', /* crossing lines */
  106. ['o'] = '-', /* horiz line - scan 1 */
  107. ['p'] = '-', /* horiz line - scan 3 */
  108. ['q'] = '-', /* horiz line - scan 5 */
  109. ['r'] = '-', /* horiz line - scan 7 */
  110. ['s'] = '-', /* horiz line - scan 9 */
  111. ['t'] = '+', /* |- */
  112. ['u'] = '+', /* -| */
  113. ['v'] = '+', /* upside down T */
  114. ['w'] = '+', /* rightside up T */
  115. ['x'] = '|', /* vertical bar */
  116. ['y'] = '<', /* less/equal */
  117. ['z'] = '>', /* gtr/equal */
  118. ['{'] = 'p', /* pi */
  119. ['|'] = '!', /* not equal */
  120. ['}'] = 'L', /* pound symbol */
  121. ['~'] = '.', /* centered dot: · */
  122. };
  123. static void setattr(int argc, int *argv);
  124. void
  125. fixops(int *operand)
  126. {
  127. if(operand[0] < 1)
  128. operand[0] = 1;
  129. }
  130. void
  131. emulate(void)
  132. {
  133. char buf[BUFS+1];
  134. int i;
  135. int n;
  136. int c;
  137. int operand[10];
  138. int noperand;
  139. int savex, savey, saveattr, saveisgraphics;
  140. int isgraphics;
  141. int g0set, g1set;
  142. int dch;
  143. isgraphics = 0;
  144. g0set = 'B'; /* US ASCII */
  145. g1set = 'B'; /* US ASCII */
  146. savex = savey = 0;
  147. yscrmin = 0;
  148. yscrmax = ymax;
  149. saveattr = 0;
  150. saveisgraphics = 0;
  151. /* set initial tab stops to DEC-standard 8-column spacing */
  152. for(c=0; (c+=8)<nelem(tabcol);)
  153. tabcol[c] = 1;
  154. for (;;) {
  155. if (y > ymax) {
  156. x = 0;
  157. newline();
  158. }
  159. buf[0] = get_next_char();
  160. buf[1] = '\0';
  161. switch(buf[0]) {
  162. case '\000':
  163. case '\001':
  164. case '\002':
  165. case '\003':
  166. case '\004':
  167. case '\005':
  168. case '\006':
  169. goto Default;
  170. case '\007': /* bell */
  171. ringbell();
  172. break;
  173. case '\010': /* backspace */
  174. if (x > 0)
  175. --x;
  176. break;
  177. case '\011': /* tab to next tab stop; if none, to right margin */
  178. for(c=x+1; c<nelem(tabcol) && !tabcol[c]; c++)
  179. ;
  180. if(c < nelem(tabcol))
  181. x = c;
  182. else
  183. x = xmax;
  184. break;
  185. case '\012': /* linefeed */
  186. case '\013':
  187. case '\014':
  188. newline();
  189. if (ttystate[cs->raw].nlcr)
  190. x = 0;
  191. break;
  192. case '\015': /* carriage return */
  193. x = 0;
  194. if (ttystate[cs->raw].crnl)
  195. newline();
  196. break;
  197. case '\016': /* SO: invoke G1 char set */
  198. isgraphics = (isdigit(g1set));
  199. break;
  200. case '\017': /* SI: invoke G0 char set */
  201. isgraphics = (isdigit(g0set));
  202. break;
  203. case '\020': /* DLE */
  204. case '\021': /* DC1 */
  205. case '\022': /* XON */
  206. case '\023': /* DC3 */
  207. case '\024': /* XOFF */
  208. case '\025': /* NAK */
  209. case '\026': /* SYN */
  210. case '\027': /* ETB */
  211. case '\030': /* CAN: cancel escape sequence, display checkerboard (not implemented) */
  212. case '\031': /* EM */
  213. case '\032': /* SUB: same as CAN */
  214. goto Default;
  215. ;
  216. /* ESC, \033, is handled below */
  217. case '\034': /* FS */
  218. case '\035': /* GS */
  219. case '\036': /* RS */
  220. case '\037': /* US */
  221. break;
  222. case '\177': /* delete: ignored */
  223. break;
  224. case '\033':
  225. switch(dch = get_next_char()){
  226. /*
  227. * 1 - graphic processor option on (no-op; not installed)
  228. */
  229. case '1':
  230. break;
  231. /*
  232. * 2 - graphic processor option off (no-op; not installed)
  233. */
  234. case '2':
  235. break;
  236. /*
  237. * 7 - save cursor position.
  238. */
  239. case '7':
  240. //print("save\n");
  241. savex = x;
  242. savey = y;
  243. saveattr = attr;
  244. saveisgraphics = isgraphics;
  245. break;
  246. /*
  247. * 8 - restore cursor position.
  248. */
  249. case '8':
  250. //print("restore\n");
  251. x = savex;
  252. y = savey;
  253. attr = saveattr;
  254. isgraphics = saveisgraphics;
  255. break;
  256. /*
  257. * c - Reset terminal.
  258. */
  259. case 'c':
  260. print("resetterminal\n");
  261. cursoron = 1;
  262. ttystate[cs->raw].nlcr = 0;
  263. break;
  264. /*
  265. * D - active position down a line, scroll if at bottom margin.
  266. * (Original VT100 had a bug: tracked new-line/line-feed mode.)
  267. */
  268. case 'D':
  269. if(++y > yscrmax) {
  270. y = yscrmax;
  271. scroll(yscrmin+1, yscrmax+1, yscrmin, yscrmax);
  272. }
  273. break;
  274. /*
  275. * E - active position to start of next line, scroll if at bottom margin.
  276. */
  277. case 'E':
  278. x = 0;
  279. if(++y > yscrmax) {
  280. y = yscrmax;
  281. scroll(yscrmin+1, yscrmax+1, yscrmin, yscrmax);
  282. }
  283. break;
  284. /*
  285. * H - set tab stop at current column.
  286. * (This is cursor home in VT52 mode (not implemented).)
  287. */
  288. case 'H':
  289. if(x < nelem(tabcol))
  290. tabcol[x] = 1;
  291. break;
  292. /*
  293. * M - active position up a line, scroll if at top margin..
  294. */
  295. case 'M':
  296. if(--y < yscrmin) {
  297. y = yscrmin;
  298. scroll(yscrmin, yscrmax, yscrmin+1, yscrmin);
  299. }
  300. break;
  301. /*
  302. * Z - identification. the terminal
  303. * emulator will return the response
  304. * code for a generic VT100.
  305. */
  306. case 'Z':
  307. Ident:
  308. sendnchars2(7, "\033[?1;2c"); /* VT100 with AVO option */
  309. // sendnchars2(5, "\033[?6c"); /* VT102 (insert/delete-char, etc.) */
  310. break;
  311. /*
  312. * < - enter ANSI mode
  313. */
  314. case '<':
  315. break;
  316. /*
  317. * > - set numeric keypad mode on (not implemented)
  318. */
  319. case '>':
  320. break;
  321. /*
  322. * = - set numeric keypad mode off (not implemented)
  323. */
  324. case '=':
  325. break;
  326. /*
  327. * # - Takes a one-digit argument
  328. */
  329. case '#':
  330. switch(get_next_char()){
  331. case '3': /* Top half of double-height line */
  332. case '4': /* Bottom half of double-height line */
  333. case '5': /* Single-width single-height line */
  334. case '6': /* Double-width line */
  335. case '7': /* Screen print */
  336. case '8': /* Fill screen with E's */
  337. break;
  338. }
  339. break;
  340. /*
  341. * ( - switch G0 character set
  342. */
  343. case '(':
  344. g0set = get_next_char();
  345. break;
  346. /*
  347. * - switch G1 character set
  348. */
  349. case ')':
  350. g1set = get_next_char();
  351. break;
  352. /*
  353. * Received left bracket.
  354. */
  355. case '[':
  356. /*
  357. * A semi-colon or ? delimits arguments.
  358. */
  359. memset(operand, 0, sizeof(operand));
  360. operand[0] = number(buf, &i);
  361. noperand = 1;
  362. while(buf[0] == ';' || buf[0] == '?'){
  363. if(noperand < nelem(operand)){
  364. noperand++;
  365. operand[noperand-1] = number(buf, nil);
  366. } else
  367. number(buf, nil);
  368. }
  369. /*
  370. * do escape2 stuff
  371. */
  372. switch(dch = buf[0]){
  373. /*
  374. * c - same as ESC Z: what are you?
  375. */
  376. case 'c':
  377. goto Ident;
  378. /*
  379. * g - various tabstop manipulation
  380. */
  381. case 'g':
  382. switch(operand[0]){
  383. case 0: /* clear tab at current column */
  384. if(x < nelem(tabcol))
  385. tabcol[x] = 0;
  386. break;
  387. case 3: /* clear all tabs */
  388. memset(tabcol, 0, sizeof tabcol);
  389. break;
  390. }
  391. break;
  392. /*
  393. * l - clear various options.
  394. */
  395. case 'l':
  396. if(noperand == 1){
  397. switch(operand[0]){
  398. case 20: /* set line feed mode */
  399. ttystate[cs->raw].nlcr = 1;
  400. break;
  401. case 30: /* screen invisible (? not supported through VT220) */
  402. break;
  403. }
  404. }else while(--noperand > 0){
  405. switch(operand[noperand]){
  406. case 1: /* set cursor keys to send ANSI functions: ESC [ A..D */
  407. break;
  408. case 2: /* set VT52 mode (not implemented) */
  409. break;
  410. case 3: /* set 80 columns */
  411. setdim(-1, 80);
  412. break;
  413. case 4: /* set jump scrolling */
  414. break;
  415. case 5: /* set normal video on screen */
  416. break;
  417. case 6: /* set origin to absolute */
  418. originrelative = 0;
  419. x = y = 0;
  420. break;
  421. case 7: /* reset auto-wrap mode */
  422. wraparound = 0;
  423. break;
  424. case 8: /* reset auto-repeat mode */
  425. break;
  426. case 9: /* reset interlacing mode */
  427. break;
  428. case 25: /* text cursor off (VT220) */
  429. cursoron = 0;
  430. break;
  431. }
  432. }
  433. break;
  434. /*
  435. * s - some dec private stuff. actually [ ? num s, but we can't detect it.
  436. */
  437. case 's':
  438. break;
  439. /*
  440. * h - set various options.
  441. */
  442. case 'h':
  443. if(noperand == 1){
  444. switch(operand[0]){
  445. default:
  446. break;
  447. case 20: /* set newline mode */
  448. ttystate[cs->raw].nlcr = 0;
  449. break;
  450. case 30: /* screen visible (? not supported through VT220) */
  451. break;
  452. }
  453. }else while(--noperand > 0){
  454. switch(operand[noperand]){
  455. default:
  456. break;
  457. case 1: /* set cursor keys to send application function: ESC O A..D */
  458. break;
  459. case 2: /* set ANSI */
  460. break;
  461. case 3: /* set 132 columns */
  462. setdim(-1, 132);
  463. break;
  464. case 4: /* set smooth scrolling */
  465. break;
  466. case 5: /* set screen to reverse video (not implemented) */
  467. break;
  468. case 6: /* set origin to relative */
  469. originrelative = 1;
  470. x = 0;
  471. y = yscrmin;
  472. break;
  473. case 7: /* set auto-wrap mode */
  474. wraparound = 1;
  475. break;
  476. case 8: /* set auto-repeat mode */
  477. break;
  478. case 9: /* set interlacing mode */
  479. break;
  480. case 25: /* text cursor on (VT220) */
  481. cursoron = 1;
  482. break;
  483. }
  484. }
  485. break;
  486. /*
  487. * m - change character attrs.
  488. */
  489. case 'm':
  490. setattr(noperand, operand);
  491. break;
  492. /*
  493. * n - request various reports
  494. */
  495. case 'n':
  496. switch(operand[0]){
  497. case 5: /* status */
  498. sendnchars2(4, "\033[0n"); /* terminal ok */
  499. break;
  500. case 6: /* cursor position */
  501. sendnchars2(sprint(buf, "\033[%d;%dR",
  502. originrelative ? y+1 - yscrmin : y+1, x+1), buf);
  503. break;
  504. }
  505. break;
  506. /*
  507. * q - turn on list of LEDs; turn off others.
  508. */
  509. case 'q':
  510. break;
  511. /*
  512. * r - change scrolling region. operand[0] is
  513. * min scrolling region and operand[1] is max
  514. * scrolling region.
  515. */
  516. case 'r':
  517. yscrmin = 0;
  518. yscrmax = ymax;
  519. switch(noperand){
  520. case 2:
  521. yscrmax = operand[1]-1;
  522. if(yscrmax > ymax)
  523. yscrmax = ymax;
  524. case 1:
  525. yscrmin = operand[0]-1;
  526. if(yscrmin < 0)
  527. yscrmin = 0;
  528. }
  529. x = 0;
  530. y = yscrmin;
  531. break;
  532. /*
  533. * x - report terminal parameters
  534. */
  535. case 'x':
  536. sendnchars2(20, "\033[3;1;1;120;120;1;0x");
  537. break;
  538. /*
  539. * y - invoke confidence test
  540. */
  541. case 'y':
  542. break;
  543. /*
  544. * A - cursor up.
  545. */
  546. case 'e':
  547. case 'A':
  548. fixops(operand);
  549. y -= operand[0];
  550. if(y < yscrmin)
  551. y = yscrmin;
  552. olines -= operand[0];
  553. if(olines < 0)
  554. olines = 0;
  555. break;
  556. /*
  557. * B - cursor down
  558. */
  559. case 'B':
  560. fixops(operand);
  561. y += operand[0];
  562. if(y > yscrmax)
  563. y=yscrmax;
  564. break;
  565. /*
  566. * C - cursor right
  567. */
  568. case 'a':
  569. case 'C':
  570. fixops(operand);
  571. x += operand[0];
  572. /*
  573. * VT-100-UG says not to go past the
  574. * right margin.
  575. */
  576. if(x > xmax)
  577. x = xmax;
  578. break;
  579. /*
  580. * D - cursor left
  581. */
  582. case 'D':
  583. fixops(operand);
  584. x -= operand[0];
  585. if(x < 0)
  586. x = 0;
  587. break;
  588. /*
  589. * G - cursor to column
  590. */
  591. case '\'':
  592. case 'G':
  593. fixops(operand);
  594. x = operand[0] - 1;
  595. if(x > xmax)
  596. x = xmax;
  597. break;
  598. /*
  599. * H and f - cursor motion. operand[0] is row and
  600. * operand[1] is column, origin 1.
  601. */
  602. case 'H':
  603. case 'f':
  604. fixops(operand+1);
  605. x = operand[1] - 1;
  606. if(x > xmax)
  607. x = xmax;
  608. /* fallthrough */
  609. /*
  610. * d - cursor to line n (xterm)
  611. */
  612. case 'd':
  613. fixops(operand);
  614. y = operand[0] - 1;
  615. if(originrelative){
  616. y += yscrmin;
  617. if(y > yscrmax)
  618. y = yscrmax;
  619. }else{
  620. if(y > ymax)
  621. y = ymax;
  622. }
  623. break;
  624. /*
  625. * J - clear some or all of the display.
  626. */
  627. case 'J':
  628. switch (operand[0]) {
  629. /*
  630. * operand 2: whole screen.
  631. */
  632. case 2:
  633. clear(Rpt(pt(0, 0), pt(xmax+1, ymax+1)));
  634. break;
  635. /*
  636. * operand 1: start of screen to active position, inclusive.
  637. */
  638. case 1:
  639. clear(Rpt(pt(0, 0), pt(xmax+1, y)));
  640. clear(Rpt(pt(0, y), pt(x+1, y+1)));
  641. break;
  642. /*
  643. * Default: active position to end of screen, inclusive.
  644. */
  645. default:
  646. clear(Rpt(pt(x, y), pt(xmax+1, y+1)));
  647. clear(Rpt(pt(0, y+1), pt(xmax+1, ymax+1)));
  648. break;
  649. }
  650. break;
  651. /*
  652. * K - clear some or all of the line.
  653. */
  654. case 'K':
  655. switch (operand[0]) {
  656. /*
  657. * operand 2: whole line.
  658. */
  659. case 2:
  660. clear(Rpt(pt(0, y), pt(xmax+1, y+1)));
  661. break;
  662. /*
  663. * operand 1: start of line to active position, inclusive.
  664. */
  665. case 1:
  666. clear(Rpt(pt(0, y), pt(x+1, y+1)));
  667. break;
  668. /*
  669. * Default: active position to end of line, inclusive.
  670. */
  671. default:
  672. clear(Rpt(pt(x, y), pt(xmax+1, y+1)));
  673. break;
  674. }
  675. break;
  676. /*
  677. * P - delete character(s) from right of cursor (xterm)
  678. */
  679. case 'P':
  680. fixops(operand);
  681. i = x + operand[0];
  682. draw(screen, Rpt(pt(x, y), pt(xmax+1, y+1)), screen, nil, pt(i, y));
  683. clear(Rpt(pt(xmax-operand[0], y), pt(xmax+1, y+1)));
  684. break;
  685. /*
  686. * @ - insert blank(s) to right of cursor (xterm)
  687. */
  688. case '@':
  689. fixops(operand);
  690. i = x + operand[0];
  691. draw(screen, Rpt(pt(i, y), pt(xmax+1, y+1)), screen, nil, pt(x, y));
  692. clear(Rpt(pt(x, y), pt(i, y+1)));
  693. break;
  694. /*
  695. * X - erase character(s) at cursor and to the right (xterm)
  696. */
  697. case 'X':
  698. fixops(operand);
  699. i = x + operand[0];
  700. clear(Rpt(pt(x, y), pt(i, y+1)));
  701. break;
  702. /*
  703. * L - insert a line at cursor position (VT102 and later)
  704. */
  705. case 'L':
  706. fixops(operand);
  707. for(i = 0; i < operand[0]; ++i)
  708. scroll(y, yscrmax, y+1, y);
  709. break;
  710. /*
  711. * M - delete a line at cursor position (VT102 and later)
  712. */
  713. case 'M':
  714. fixops(operand);
  715. for(i = 0; i < operand[0]; ++i)
  716. scroll(y+1, yscrmax+1, y, yscrmax);
  717. break;
  718. /*
  719. * S,T - scroll up/down (xterm)
  720. */
  721. case 'T':
  722. fixops(operand);
  723. for(i = 0; i < operand[0]; ++i)
  724. scroll(yscrmin, yscrmax, yscrmin+1, yscrmin);
  725. break;
  726. case 'S':
  727. fixops(operand);
  728. for(i = 0; i < operand[0]; ++i)
  729. scroll(yscrmin+1, yscrmax+1, yscrmin, yscrmin);
  730. break;
  731. case '=': /* ? not supported through VT220 */
  732. number(buf, nil);
  733. switch(buf[0]) {
  734. case 'h':
  735. case 'l':
  736. break;
  737. }
  738. break;
  739. /*
  740. * Anything else we ignore for now...
  741. */
  742. default:
  743. print("unknown escape2 '%c' (0x%x)\n", dch, dch);
  744. break;
  745. }
  746. break;
  747. /*
  748. * Collapse multiple '\033' to one.
  749. */
  750. case '\033':
  751. peekc = '\033';
  752. break;
  753. /* set title */
  754. case ']': /* it's actually <esc> ] num ; title <bel> */
  755. {
  756. int ch, fd;
  757. number(buf, nil);
  758. i = 0;
  759. while((ch = get_next_char()) != '\a')
  760. if(i < sizeof buf)
  761. buf[i++] = ch;
  762. fd = open("/dev/label", OWRITE);
  763. write(fd, buf, i);
  764. close(fd);
  765. }
  766. break;
  767. /*
  768. * Ignore other commands.
  769. */
  770. default:
  771. print("unknown command '%c' (0x%x)\n", dch, dch);
  772. break;
  773. }
  774. break;
  775. default: /* ordinary char */
  776. Default:
  777. if(isgraphics && gmap[(uint8_t) buf[0]])
  778. buf[0] = gmap[(uint8_t) buf[0]];
  779. /* line wrap */
  780. if (x > xmax){
  781. if(wraparound){
  782. x = 0;
  783. newline();
  784. }else{
  785. continue;
  786. }
  787. }
  788. n = 1;
  789. c = 0;
  790. while (!cs->raw && host_avail() && x+n<=xmax && n<BUFS
  791. && (c = get_next_char())>=' ' && c<'\177') {
  792. buf[n++] = c;
  793. c = 0;
  794. }
  795. buf[n] = 0;
  796. // clear(Rpt(pt(x,y), pt(x+n, y+1)));
  797. drawstring(pt(x, y), buf, attr);
  798. x += n;
  799. peekc = c;
  800. break;
  801. }
  802. }
  803. }
  804. static void
  805. setattr(int argc, int *argv)
  806. {
  807. int i;
  808. for(i=0; i<argc; i++) {
  809. switch(argv[i]) {
  810. case 0:
  811. attr = defattr;
  812. fgcolor = fgdefault;
  813. bgcolor = bgdefault;
  814. break;
  815. case 1:
  816. attr |= THighIntensity;
  817. break;
  818. case 4:
  819. attr |= TUnderline;
  820. break;
  821. case 5:
  822. attr |= TBlink;
  823. break;
  824. case 7:
  825. attr |= TReverse;
  826. break;
  827. case 8:
  828. attr |= TInvisible;
  829. break;
  830. case 22:
  831. attr &= ~THighIntensity;
  832. break;
  833. case 24:
  834. attr &= ~TUnderline;
  835. break;
  836. case 25:
  837. attr &= ~TBlink;
  838. break;
  839. case 27:
  840. attr &= ~TReverse;
  841. break;
  842. case 28:
  843. attr &= ~TInvisible;
  844. break;
  845. case 30: /* black */
  846. case 31: /* red */
  847. case 32: /* green */
  848. case 33: /* brown */
  849. case 34: /* blue */
  850. case 35: /* purple */
  851. case 36: /* cyan */
  852. case 37: /* white */
  853. fgcolor = (nocolor? fgdefault: colors[argv[i]-30]);
  854. break;
  855. case 39:
  856. fgcolor = fgdefault;
  857. break;
  858. case 40: /* black */
  859. case 41: /* red */
  860. case 42: /* green */
  861. case 43: /* brown */
  862. case 44: /* blue */
  863. case 45: /* purple */
  864. case 46: /* cyan */
  865. case 47: /* white */
  866. bgcolor = (nocolor? bgdefault: colors[argv[i]-40]);
  867. break;
  868. case 49:
  869. bgcolor = bgdefault;
  870. break;
  871. }
  872. }
  873. }