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[];
#define NKEYS 32 /* max key definitions */
struct funckey {
char *name;
char *sequence;
};
extern struct funckey *fk;
extern struct funckey vt100fk[], vt220fk[], ansifk[], xtermfk[];
extern struct funckey *fk, *appfk;
extern struct funckey ansifk[], ansiappfk[], xtermfk[];
extern int x, y, xmax, ymax, olines;
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 *term;
struct funckey *fk;
struct funckey *fk, *appfk;
/* functions */
void initialize(int, char **);
@ -212,19 +212,17 @@ initialize(int argc, char **argv)
char *fontname, *p;
fontname = nil;
fk = ansifk;
term = "vt100";
fk = vt100fk;
blkbg = 0;
rflag = 0;
attr = defattr;
ARGBEGIN{
case '2':
term = "vt220";
fk = vt220fk;
break;
case 'a':
term = "ansi";
fk = ansifk;
break;
case 'b':
blkbg = 1; /* e.g., for linux colored output */
@ -521,17 +519,26 @@ canon(char *ep, Rune c)
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
sendfk(char *name)
{
int i;
static int fd;
for(i=0; fk[i].name; i++)
if(strcmp(name, fk[i].name)==0){
sendnchars(strlen(fk[i].sequence), fk[i].sequence);
return;
}
char *s = lookfk(appfk != nil ? appfk : fk, name);
if(s == nil && appfk != nil)
s = lookfk(fk, name);
if(s != nil)
sendnchars(strlen(s), s);
}
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
drawstring(Rune *str, int n)
{

View file

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