hp.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <ndraw.h>
  4. #include <bio.h>
  5. #include "cons.h"
  6. char *term = "2621";
  7. struct funckey fk[32];
  8. void
  9. emulate(void)
  10. {
  11. char buf[BUFS+1];
  12. int n;
  13. int c;
  14. int standout = 0;
  15. int insmode = 0;
  16. for (;;) {
  17. if (x > xmax || y > ymax) {
  18. x = 0;
  19. newline();
  20. }
  21. buf[0] = get_next_char();
  22. buf[1] = '\0';
  23. switch(buf[0]) {
  24. case '\000': /* nulls, just ignore 'em */
  25. break;
  26. case '\007': /* bell */
  27. ringbell();
  28. break;
  29. case '\t': /* tab modulo 8 */
  30. x = (x|7)+1;
  31. break;
  32. case '\033':
  33. switch(get_next_char()) {
  34. case 'j':
  35. get_next_char();
  36. break;
  37. case '&': /* position cursor &c */
  38. switch(get_next_char()) {
  39. case 'a':
  40. for (;;) {
  41. n = number(buf, nil);
  42. switch(buf[0]) {
  43. case 'r':
  44. case 'y':
  45. y = n;
  46. continue;
  47. case 'c':
  48. x = n;
  49. continue;
  50. case 'R':
  51. case 'Y':
  52. y = n;
  53. break;
  54. case 'C':
  55. x = n;
  56. break;
  57. }
  58. break;
  59. }
  60. break;
  61. case 'd': /* underline stuff */
  62. if ((n=get_next_char())>='A' && n <= 'O')
  63. standout++;
  64. else if (n == '@')
  65. standout = 0;
  66. break;
  67. default:
  68. get_next_char();
  69. break;
  70. }
  71. break;
  72. case 'i': /* back tab */
  73. if (x>0)
  74. x = (x-1) & ~07;
  75. break;
  76. case 'H': /* home cursor */
  77. case 'h':
  78. x = 0;
  79. y = 0;
  80. break;
  81. case 'L': /* insert blank line */
  82. scroll(y, ymax, y+1, y);
  83. break;
  84. case 'M': /* delete line */
  85. scroll(y+1, ymax+1, y, ymax);
  86. break;
  87. case 'J': /* clear to end of display */
  88. xtipple(Rpt(pt(0, y+1),
  89. pt(xmax+1, ymax+1)));
  90. /* flow */
  91. case 'K': /* clear to EOL */
  92. xtipple(Rpt(pt(x, y),
  93. pt(xmax+1, y+1)));
  94. break;
  95. case 'P': /* delete char */
  96. bitblt(&screen, pt(x, y),
  97. &screen, Rpt(pt(x+1, y),
  98. pt(xmax+1, y+1)),
  99. S);
  100. xtipple(Rpt(pt(xmax, y),
  101. pt(xmax+1, y+1)));
  102. break;
  103. case 'Q': /* enter insert mode */
  104. insmode++;
  105. break;
  106. case 'R': /* leave insert mode */
  107. insmode = 0;
  108. break;
  109. case 'S': /* roll up */
  110. scroll(1, ymax+1, 0, ymax);
  111. break;
  112. case 'T':
  113. scroll(0, ymax, 1, 0);
  114. break;
  115. case 'A': /* upline */
  116. case 't':
  117. if (y>0)
  118. y--;
  119. if (olines > 0)
  120. olines--;
  121. break;
  122. case 'B':
  123. case 'w':
  124. y++; /* downline */
  125. break;
  126. case 'C': /* right */
  127. case 'v':
  128. x++;
  129. break;
  130. case 'D': /* left */
  131. case 'u':
  132. x--;
  133. }
  134. break;
  135. case '\b': /* backspace */
  136. if(x > 0)
  137. --x;
  138. break;
  139. case '\n': /* linefeed */
  140. newline();
  141. standout = 0;
  142. if( ttystate[cs->raw].nlcr )
  143. x = 0;
  144. break;
  145. case '\r': /* carriage return */
  146. x = 0;
  147. standout = 0;
  148. if( ttystate[cs->raw].crnl )
  149. newline();
  150. break;
  151. default: /* ordinary char */
  152. n = 1;
  153. c = 0;
  154. while (!cs->raw && host_avail() && x+n<=xmax && n<BUFS
  155. && (c = get_next_char())>=' ' && c<'\177') {
  156. buf[n++] = c;
  157. c = 0;
  158. }
  159. buf[n] = 0;
  160. if (insmode) {
  161. bitblt(&screen, pt(x+n, y), &screen,
  162. Rpt(pt(x, y), pt(xmax-n+1, y+1)), S);
  163. }
  164. xtipple(Rpt(pt(x,y), pt(x+n, y+1)));
  165. string(&screen, pt(x, y), fnt, buf, DxorS);
  166. if (standout)
  167. rectf(&screen,
  168. Rpt(pt(x,y),pt(x+n,y+1)),
  169. DxorS);
  170. x += n;
  171. peekc = c;
  172. break;
  173. }
  174. }
  175. }