vt: handle application/normal mode (really fixes cursor keys)

This commit is contained in:
cinap_lenrek 2017-04-22 20:16:07 +02:00
parent b58584b057
commit f2b7f24e4e
3 changed files with 37 additions and 43 deletions

View file

@ -35,13 +35,12 @@ struct ttystate {
}; };
extern struct ttystate ttystate[]; extern struct ttystate ttystate[];
#define NKEYS 32 /* max key definitions */
struct funckey { struct funckey {
char *name; char *name;
char *sequence; char *sequence;
}; };
extern struct funckey *fk; extern struct funckey *fk, *appfk;
extern struct funckey vt100fk[], vt220fk[], ansifk[], xtermfk[]; extern struct funckey ansifk[], ansiappfk[], xtermfk[];
extern int x, y, xmax, ymax, olines; extern int x, y, xmax, ymax, olines;
extern int peekc, attribute; extern int peekc, attribute;

View file

@ -110,7 +110,7 @@ char sendbuf[BSIZE]; /* hope you can't type ahead more than BSIZE chars */
char *sendbufp = sendbuf; char *sendbufp = sendbuf;
char *term; char *term;
struct funckey *fk; struct funckey *fk, *appfk;
/* functions */ /* functions */
void initialize(int, char **); void initialize(int, char **);
@ -212,19 +212,17 @@ initialize(int argc, char **argv)
char *fontname, *p; char *fontname, *p;
fontname = nil; fontname = nil;
fk = ansifk;
term = "vt100"; term = "vt100";
fk = vt100fk;
blkbg = 0; blkbg = 0;
rflag = 0; rflag = 0;
attr = defattr; attr = defattr;
ARGBEGIN{ ARGBEGIN{
case '2': case '2':
term = "vt220"; term = "vt220";
fk = vt220fk;
break; break;
case 'a': case 'a':
term = "ansi"; term = "ansi";
fk = ansifk;
break; break;
case 'b': case 'b':
blkbg = 1; /* e.g., for linux colored output */ blkbg = 1; /* e.g., for linux colored output */
@ -521,17 +519,26 @@ canon(char *ep, Rune c)
return(OTHER); return(OTHER);
} }
char*
lookfk(struct funckey *fk, char *name)
{
int i;
for(i=0; fk[i].name; i++){
if(strcmp(name, fk[i].name)==0)
return fk[i].sequence;
}
return nil;
}
void void
sendfk(char *name) sendfk(char *name)
{ {
int i; char *s = lookfk(appfk != nil ? appfk : fk, name);
static int fd; if(s == nil && appfk != nil)
s = lookfk(fk, name);
for(i=0; fk[i].name; i++) if(s != nil)
if(strcmp(name, fk[i].name)==0){ sendnchars(strlen(s), s);
sendnchars(strlen(fk[i].sequence), fk[i].sequence);
return;
}
} }
int int
@ -1110,16 +1117,6 @@ escapedump(int fd,uchar *str,int len)
} }
} }
void
funckey(int key)
{
if(key >= NKEYS)
return;
if(fk[key].name == 0)
return;
sendnchars(strlen(fk[key].sequence), fk[key].sequence);
}
void void
drawstring(Rune *str, int n) drawstring(Rune *str, int n)
{ {

View file

@ -32,14 +32,7 @@ int originrelative = 0;
int tabcol[200]; int tabcol[200];
struct funckey vt100fk[NKEYS] = { struct funckey ansifk[] = {
{ "up key", "\033OA", },
{ "down key", "\033OB", },
{ "left key", "\033OD", },
{ "right key", "\033OC", },
};
struct funckey ansifk[NKEYS] = {
{ "up key", "\033[A", }, { "up key", "\033[A", },
{ "down key", "\033[B", }, { "down key", "\033[B", },
{ "left key", "\033[D", }, { "left key", "\033[D", },
@ -56,22 +49,24 @@ struct funckey ansifk[NKEYS] = {
{ "F10", "\033OY", }, { "F10", "\033OY", },
{ "F11", "\033OZ", }, { "F11", "\033OZ", },
{ "F12", "\033O1", }, { "F12", "\033O1", },
{ 0 },
}; };
struct funckey vt220fk[NKEYS] = { struct funckey ansiappfk[] = {
{ "up key", "\033[A", },
{ "down key", "\033[B", },
{ "left key", "\033[D", },
{ "right key", "\033[C", },
};
struct funckey xtermfk[NKEYS] = {
{ "page up", "\033[5~", },
{ "page down", "\033[6~", },
{ "up key", "\033OA", }, { "up key", "\033OA", },
{ "down key", "\033OB", }, { "down key", "\033OB", },
{ "left key", "\033OD", }, { "left key", "\033OD", },
{ "right key", "\033OC", }, { "right key", "\033OC", },
{ 0 },
};
struct funckey xtermfk[] = {
{ "page up", "\033[5~", },
{ "page down", "\033[6~", },
{ "up key", "\033[A", },
{ "down key", "\033[B", },
{ "left key", "\033[D", },
{ "right key", "\033[C", },
{ "F1", "\033OP", }, { "F1", "\033OP", },
{ "F2", "\033OQ", }, { "F2", "\033OQ", },
{ "F3", "\033OR", }, { "F3", "\033OR", },
@ -84,6 +79,7 @@ struct funckey xtermfk[NKEYS] = {
{ "F10", "\033[21~", }, { "F10", "\033[21~", },
{ "F11", "\033[23~", }, { "F11", "\033[23~", },
{ "F12", "\033[24~", }, { "F12", "\033[24~", },
{ 0 },
}; };
char gmap[256] = { char gmap[256] = {
@ -433,6 +429,7 @@ emulate(void)
}else while(--noperand > 0){ }else while(--noperand > 0){
switch(operand[noperand]){ switch(operand[noperand]){
case 1: /* set cursor keys to send ANSI functions: ESC [ A..D */ case 1: /* set cursor keys to send ANSI functions: ESC [ A..D */
appfk = nil;
break; break;
case 2: /* set VT52 mode (not implemented) */ case 2: /* set VT52 mode (not implemented) */
break; break;
@ -486,6 +483,7 @@ emulate(void)
default: default:
break; break;
case 1: /* set cursor keys to send application function: ESC O A..D */ case 1: /* set cursor keys to send application function: ESC O A..D */
appfk = ansiappfk;
break; break;
case 2: /* set ANSI */ case 2: /* set ANSI */
break; break;