vt.c 20 KB

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