home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume1 / 8707 / 6 < prev    next >
Encoding:
Internet Message Format  |  1990-07-13  |  11.6 KB

  1. From: jimp@cognos.UUCP (Jim Patterson)
  2. Newsgroups: comp.sources.misc
  3. Subject: JOVE support for VT200-type function keys
  4. Message-ID: <2788@ncoast.UUCP>
  5. Date: 4 Jul 87 20:28:03 GMT
  6. Sender: allbery@ncoast.UUCP
  7. Organization: Cognos Incorporated, Ottawa, Canada
  8. Lines: 448
  9. Approved: allbery@ncoast.UUCP
  10. X-Archive: comp.sources.misc/8707/6
  11.  
  12. I've put together a series of differences we've applied to JOVE
  13. since we got it from USENET.  Basically these changes fall into
  14. two categories:
  15.  
  16.   Support for ANSI function keys (VT200-style).  The existing support
  17. wasn't able to handle function keys with numeric parameters.  This is
  18. now possible, though not quite as general as the rest of the
  19. key-mapping.  Incidently, Dasher terminals that have an ANSI mode and
  20. SUN workstations can make use of the same logic.
  21.  
  22. To enable the ANSI function key support, you need to bind the ANSI
  23. function code initiator to the function ansi-codes.  This is a special
  24. prefix which existed in the original version of jove that we got
  25. (4.6.1.4), but which we have extended somewhat.  The following bindings
  26. work for most ANSI-style terminals
  27.  
  28.     bind-to-key ansi-codes ^[[
  29.     bind-to-key ansi-codes ^[O
  30.  
  31. If you are running a terminal which transmits 8-bit controls, then set the
  32. environment variable METAKEY and define the following bindings instead.
  33.  
  34.     bind-to-key ansi-codes ^[^[
  35.     bind-to-key ansi-codes ^[^O
  36.  
  37.   We have included a few bug-fixes.  Some of these are for support of
  38. different terminals; for example, Dashers don't have a conventional
  39. line-feed (it acts as a newline), so we've added a DN termcap function
  40. that can be set to the proper value.  A similar problem occured
  41. because the backspace sequence wasn't being used properly.
  42.  
  43. You may or may not want the change put into jove.c to put out
  44. visual-end a little later.  I found this useful in dealing with
  45. a terminal which supports multiple windows.  
  46.  
  47. Here are a few things that we haven't done, but should.
  48.     
  49.     Put function keys into their own section of the keymaps.  At present
  50.     they share the keymap with other keys, and so have been restricted to
  51.     the miscmap.  This prevents the use of any prefix character with
  52.     a function key (but a function key can be a prefix character). This
  53.     isn't a really big problem because there are generally a liberal number
  54.     of function keys, but it would be nice to be able to define ESC <left>
  55.     and so on.
  56.     
  57.     Provide some sort of terminal specific translation of function key
  58.     names, so that describe-key prints function keys as FIND, F12, etc.
  59.     instead of ESC [ 1 ~ and ESC [ 2 4 ~.
  60.     
  61.     Update the documentation to describe Ansi-codes and how to bind 
  62.     ansi function keys.
  63.  
  64. The following file gives default bindings for a vt200-series terminal.
  65. ============================================= New file: vt200.joverc
  66. bind-to-key ansi-codes ^[[
  67. bind-to-key ansi-codes ^[O
  68. bind-to-key ansi-codes ^[^[
  69. bind-to-key ansi-codes ^[^O
  70. bind-to-key search-forward ^[[1~
  71. bind-to-key yank ^[[2~
  72. bind-to-key kill-region ^[[3~
  73. bind-to-key set-mark ^[[4~
  74. bind-to-key previous-page ^[[5~
  75. bind-to-key next-page ^[[6~
  76. bind-to-key describe-key [28~
  77. bind-to-key execute-named-command [29~
  78. ============================================ End of vt200.joverc
  79. The following are all context diffs.  They work with patch on our system
  80. (SUN running BSD 4.2 Unix).
  81.  
  82. *** extend.c        Mon Jun 22 14:44:20 1987
  83. --- extend.c        Mon Jun 22 14:44:21 1987
  84. ***************
  85. *** 20,25 ****
  86. --- 20,27 ----
  87.   extern int    getch(),
  88.           getchar();
  89.   
  90. + #define DASHER_MAP(x) (((x) % 100) + ((x) / 100) * 32)
  91.   /* Auto execute code */
  92.   
  93.   #define NEXECS    20
  94. ***************
  95. *** 99,107 ****
  96. --- 101,135 ----
  97.       BindSomething(findmac);
  98.   }
  99.   
  100. + /*
  101. + * AnsiKey : return 'key' value for an ANSI-style function 
  102. + * sequence.  This is the value of the numeric operand for
  103. + * extended-type functions, or the next character for others.
  104. + */
  105. + int AnsiKey() {
  106. +     int c;
  107. +     int num1 = 0;
  108. +     c = addgetc();
  109. +     while (isdigit(c)) {
  110. +         num1 = num1*10 + (c - '0');
  111. +         c = addgetc();
  112. +     }
  113. +     while (c == ';' || isdigit(c))
  114. +         c = addgetc();
  115. +     /* Map Dasher functions into 128-byte space */
  116. +     if (c == 'z')
  117. +         num1 = DASHER_MAP(num1);
  118. +     if (c == '~' || c == 'z')
  119. +         return num1;
  120. +       else return c; 
  121. + }
  122.   extern int    EscPrefix(),
  123.           CtlxPrefix(),
  124.           MiscPrefix();
  125. + extern int      AnsiCodes();
  126.   
  127.   data_obj **
  128.   IsPrefix(cp)
  129. ***************
  130. *** 121,126 ****
  131. --- 149,168 ----
  132.       return 0;
  133.   }
  134.   
  135. + data_obj **
  136. + IsAnsiCode(cp)
  137. + data_obj    *cp;
  138. + {
  139. +        int (*proc)();
  140. +     if (cp == 0 || (cp->Type & TYPEMASK) != FUNCTION)
  141. +          return 0;
  142. +     proc = ((struct cmd *) cp)->c_proc;
  143. +     if (proc == AnsiCodes)
  144. +         return miscmap;
  145. +     return 0;
  146. + }
  147.   unbind_aux(c)
  148.   {
  149.       if (c == CR || c == LF)
  150. ***************
  151. *** 132,137 ****
  152. --- 174,180 ----
  153.   UnbindC()
  154.   {
  155.       char    *keys;
  156. +         int     lastKey;
  157.       data_obj    **map = mainmap;
  158.   
  159.       keys = do_ask("\r\n\01\02\03\04\05\06\010\011\013\014\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037", unbind_aux, (char *) 0, ProcFmt);
  160. ***************
  161. *** 142,152 ****
  162.               break;
  163.           if ((map = IsPrefix(map[*keys])) == 0)
  164.               break;
  165. !         keys++;
  166.       }
  167.       if (keys[1] != 0)
  168.           complain("That's not a legitimate key sequence.");
  169. !     map[keys[0]] = 0;
  170.   }
  171.           
  172.   addgetc()
  173. --- 185,211 ----
  174.               break;
  175.           if ((map = IsPrefix(map[*keys])) == 0)
  176.               break;
  177. !                 if (IsAnsiCode(map[*keys])) {
  178. !                     map = miscmap;
  179. !                     lastKey = 0;
  180. !                     ++keys;
  181. !                     while (*keys != '\0' && isdigit(*keys)) {
  182. !                        lastKey = lastKey * 10 + (*keys - '0');
  183. !                        ++keys;
  184.               }
  185. +                     if (*keys != 'z' && *keys != '~')
  186. +                         lastKey = *keys;
  187. +                     /* Map Dasher functions into 128-byte space */
  188. +                     if (*keys == 'z')
  189. +                         lastKey = DASHER_MAP(lastKey);
  190. +                     break;
  191. +         }
  192. +                      
  193. +         lastKey = *++keys;
  194. +      }
  195.       if (keys[1] != 0)
  196.           complain("That's not a legitimate key sequence.");
  197. !     map[lastKey] = 0;
  198.   }
  199.           
  200.   addgetc()
  201. ***************
  202. *** 193,198 ****
  203. --- 252,259 ----
  204.       } else {
  205.           if (nextmap = IsPrefix(map[c]))
  206.               BindWMap(nextmap, c, cmd);
  207. +         else if (IsAnsiCode(map[c]))
  208. +             miscmap[AnsiKey()] = cmd;
  209.           else
  210.               map[c] = cmd;
  211.       }
  212. ***************
  213. *** 215,220 ****
  214. --- 276,282 ----
  215.   
  216.   DescWMap(map, key)
  217.   data_obj    **map;
  218. + int             key;
  219.   {
  220.       data_obj    *cp = map[key],
  221.               **prefp;
  222. ***************
  223. *** 223,228 ****
  224. --- 285,292 ----
  225.           add_mess("is unbound.");
  226.       else if (prefp = IsPrefix(cp))
  227.           DescWMap(prefp, addgetc());
  228. +         else if (IsAnsiCode(cp))
  229. +             DescWMap(miscmap, AnsiKey());
  230.       else
  231.           add_mess("is bound to %s.", cp->Name);
  232.   }
  233. ***************
  234. *** 519,524 ****
  235. --- 583,589 ----
  236.   {
  237.       struct variable    *vp;
  238.       char    prbuf[256];
  239.   
  240.       if ((vp = (struct variable *) findvar(ProcFmt)) == 0)
  241.           return;
  242. *** jove.c    Mon Jun 22 14:45:33 1987
  243. --- jove.c    Mon Jun 22 14:45:34 1987
  244. ***************
  245. *** 342,353 ****
  246.   {
  247.       ttyset(OFF);
  248.       putpad(KE, 1);
  249. -     putpad(VE, 1);
  250.       putpad(TE, 1);
  251.   #ifdef ID_CHAR
  252.       INSmode(0);
  253.   #endif
  254.       Placur(ILI, 0);
  255.       printf("%s", mesg);
  256.       putpad(CE, 1);
  257.       flusho();
  258. --- 342,353 ----
  259.   {
  260.       ttyset(OFF);
  261.       putpad(KE, 1);
  262.       putpad(TE, 1);
  263.   #ifdef ID_CHAR
  264.       INSmode(0);
  265.   #endif
  266.       Placur(ILI, 0);
  267. +     putpad(VE, 1);    /* Relocated, for better visual support */
  268.       printf("%s", mesg);
  269.       putpad(CE, 1);
  270.       flusho();
  271. *** misc.c    Mon Jun 22 14:46:13 1987
  272. --- misc.c    Mon Jun 22 14:46:14 1987
  273. ***************
  274. *** 439,444 ****
  275. --- 439,446 ----
  276.       int    num2;
  277.       static char *unsupported = "[Unsupported ANSI code received]";
  278.   
  279. +     register data_obj    *cp;
  280.       while (isdigit(c = getch()))
  281.           num1 = (num1*10) + (c - '0');
  282.   
  283. ***************
  284. *** 478,486 ****
  285.               ClAndRedraw();
  286.               break;
  287.           }
  288.           /* FALL THROUGH */
  289.       default:
  290. !         complain(unsupported);
  291.       }
  292.   }
  293.   #endif ANSICODES
  294. --- 480,507 ----
  295.               ClAndRedraw();
  296.               break;
  297.           }
  298. +                 break;
  299. +         case 'z':    /* DASHER (ANSI) Function */
  300. +                 num1 = (num1 % 100) + (num1 / 100) * 32;
  301.           /* FALL THROUGH */
  302. +         case '~':    /* VT220 function */
  303. +         cp = miscmap[num1 % (sizeof(miscmap) / sizeof(miscmap[0]))];
  304. +         if (cp == 0) {
  305. +             s_mess("[%sunbound]", key_strokes);
  306. +             rbell();
  307. +         } else
  308. +             ExecCmd(cp);
  309. +                 break;
  310.       default:
  311. !         cp = miscmap[c];
  312. !         if (cp == 0) {
  313. !             s_mess("[%sunbound]", key_strokes);
  314. !             rbell();
  315. !         } else
  316. !             ExecCmd(cp);
  317. !                 break;
  318.       }
  319.   }
  320.   #endif ANSICODES
  321. *** screen.c    Mon Jun 22 14:47:16 1987
  322. --- screen.c    Mon Jun 22 14:47:17 1987
  323. ***************
  324. *** 144,149 ****
  325.           if (i_line != CapLine || i_col != CapCol)
  326.               Placur(i_line, i_col);
  327. !         if (UL && (c & 0177) == '_' && (*cursor & 0177) != ' ')
  328. !             putstr(" \b");        /* Erase so '_' looks right. */
  329.           *cursor++ = c;
  330.           putchar(c & 0177);
  331. --- 144,154 ----
  332.           if (i_line != CapLine || i_col != CapCol)
  333.               Placur(i_line, i_col);
  334. !         if (UL && (c & 0177) == '_' && (*cursor & 0177) != ' ') {
  335. !             putstr(" ");        /* Erase so '_' looks right. */
  336. !             if (BC)
  337. !                 putpad(BC, 1);
  338. !             else
  339. !                 putchar('\b');
  340. !               }
  341.           *cursor++ = c;
  342.           putchar(c & 0177);
  343. ***************
  344. *** 533,537 ****
  345.   
  346.       while (--nlines >= 0)
  347. !         putchar('\n');
  348.       CapLine = destline;
  349.   }
  350. --- 538,542 ----
  351.   
  352.       while (--nlines >= 0)
  353. !         putpad(DN, 1);
  354.       CapLine = destline;
  355.   }
  356. *** term.c    Mon Jun 22 14:47:50 1987
  357. --- term.c    Mon Jun 22 14:47:50 1987
  358. ***************
  359. *** 20,25 ****
  360. --- 20,26 ----
  361.   /* Termcap definitions */
  362.   
  363.   char    *UP,
  364. +     *DN,
  365.       *CS,
  366.       *SO,
  367.       *SE,
  368. ***************
  369. *** 80,101 ****
  370.   
  371.   /* The ordering of ts and meas must agree !! */
  372.   #ifdef LSRHS
  373. ! static char    *ts="vsvealdlspcssosecmclcehoupbcicimdceillsfsrvbksketiteALDLICDCrsrepcip";
  374.   static char    **meas[] = {
  375.       &VS, &VE, &AL, &DL, &SP, &CS, &SO, &SE,
  376.       &CM, &CL, &CE, &HO, &UP, &BC, &IC, &IM,
  377.       &DC, &EI, &LL, &SF, &SR, &VB, &KS, &KE,
  378.       &TI, &TE, &M_AL, &M_DL, &M_IC, &M_DC,
  379. !     &RS, &RE, &lPC, &IP, 0
  380.   };
  381.   #else
  382. ! static char    *ts="vsvealdlspcssosecmclcehoupbcicimdceillsfsrvbksketiteALDLICDCpcip";
  383.   static char    **meas[] = {
  384.       &VS, &VE, &AL, &DL, &SP, &CS, &SO, &SE,
  385.       &CM, &CL, &CE, &HO, &UP, &BC, &IC, &IM,
  386.       &DC, &EI, &LL, &SF, &SR, &VB, &KS, &KE,
  387.       &TI, &TE, &M_AL, &M_DL, &M_IC, &M_DC,
  388. !     &lPC, &IP, 0
  389.   };
  390.   #endif
  391.   
  392. --- 81,102 ----
  393.   
  394.   /* The ordering of ts and meas must agree !! */
  395.   #ifdef LSRHS
  396. ! static char    *ts="vsvealdlspcssosecmclcehoupbcicimdceillsfsrvbksketiteALDLICDCrsrepcipdo";
  397.   static char    **meas[] = {
  398.       &VS, &VE, &AL, &DL, &SP, &CS, &SO, &SE,
  399.       &CM, &CL, &CE, &HO, &UP, &BC, &IC, &IM,
  400.       &DC, &EI, &LL, &SF, &SR, &VB, &KS, &KE,
  401.       &TI, &TE, &M_AL, &M_DL, &M_IC, &M_DC,
  402. !     &RS, &RE, &lPC, &IP, &DN, 0
  403.   };
  404.   #else
  405. ! static char    *ts="vsvealdlspcssosecmclcehoupbcicimdceillsfsrvbksketiteALDLICDCpcipdo";
  406.   static char    **meas[] = {
  407.       &VS, &VE, &AL, &DL, &SP, &CS, &SO, &SE,
  408.       &CM, &CL, &CE, &HO, &UP, &BC, &IC, &IM,
  409.       &DC, &EI, &LL, &SF, &SR, &VB, &KS, &KE,
  410.       &TI, &TE, &M_AL, &M_DL, &M_IC, &M_DC,
  411. !     &lPC, &IP, &DN, 0
  412.   };
  413.   #endif
  414.   
  415. ***************
  416. *** 154,159 ****
  417. --- 155,163 ----
  418.           *(meas[i]) = (char *) tgetstr(ts, &termp);
  419.           ts += 2;
  420.       }
  421. +     
  422. +     if (!DN)
  423. +         DN = "\n";
  424.       if (lPC)
  425.           PC = *lPC;
  426.       if (XS)
  427. ***************
  428. *** 190,193 ****
  429.       if (CanScroll = ((AL && DL) || CS))
  430.           IDline_setup(termname);
  431.   }
  432. --- 194,196 ----
  433. *** termcap.h        Mon Jun 22 14:47:57 1987
  434. --- termcap.h    Mon Jun 22 14:47:57 1987
  435. ***************
  436. *** 9,14 ****
  437. --- 9,15 ----
  438.   
  439.   extern char
  440.       *UP,    /* Scroll reverse, or up */
  441. +     *DN,    /* down */
  442.       *CS,    /* If on vt100 */
  443.       *SO,    /* Start standout */
  444.       *SE,    /* End standout */
  445. -- 
  446.  
  447. Jim Patterson          decvax!utzoo!dciem!nrcaer!cognos!jimp
  448. Cognos Incorporated    
  449.