shithub: riscv

Download patch

ref: f2b7f24e4e14099251dd0ed8e7e13d7ca466b0cf
parent: b58584b0578617f6cabcae6e51c6e3e0dc51fec1
author: cinap_lenrek <[email protected]>
date: Sat Apr 22 16:16:07 EDT 2017

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

--- a/sys/src/cmd/vt/cons.h
+++ b/sys/src/cmd/vt/cons.h
@@ -35,13 +35,12 @@
 };
 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;
--- a/sys/src/cmd/vt/main.c
+++ b/sys/src/cmd/vt/main.c
@@ -110,7 +110,7 @@
 char	*sendbufp = sendbuf;
 
 char *term;
-struct funckey *fk;
+struct funckey *fk, *appfk;
 
 /* functions */
 void	initialize(int, char **);
@@ -212,8 +212,8 @@
 	char *fontname, *p;
 
 	fontname = nil;
+	fk = ansifk;
 	term = "vt100";
-	fk = vt100fk;
 	blkbg = 0;
 	rflag = 0;
 	attr = defattr;
@@ -220,11 +220,9 @@
 	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,19 +519,28 @@
 	return(OTHER);
 }
 
-void
-sendfk(char *name)
+char*
+lookfk(struct funckey *fk, 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;
-		}
+	for(i=0; fk[i].name; i++){
+		if(strcmp(name, fk[i].name)==0)
+			return fk[i].sequence;
+	}
+	return nil;
 }
 
+void
+sendfk(char *name)
+{
+	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
 waitchar(void)
 {
@@ -1108,16 +1115,6 @@
 		else if(str[i] == '\n') fprint(fd,"^J\n");
 		else fprint(fd,"%c",str[i]);
 	}
-}
-
-void
-funckey(int key)
-{
-	if(key >= NKEYS)
-		return;
-	if(fk[key].name == 0)
-		return;
-	sendnchars(strlen(fk[key].sequence), fk[key].sequence);
 }
 
 void
--- a/sys/src/cmd/vt/vt.c
+++ b/sys/src/cmd/vt/vt.c
@@ -32,14 +32,7 @@
 
 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 @@
 	{ "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 @@
 	{ "F10",		"\033[21~", },
 	{ "F11",		"\033[23~", },
 	{ "F12",		"\033[24~", },
+	{ 0 },
 };
 
 char gmap[256] = {
@@ -433,6 +429,7 @@
 						}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 @@
 							default:
 								break;
 							case 1:	/* set cursor keys to send application function: ESC O A..D */
+								appfk = ansiappfk;
 								break;
 							case 2:	/* set ANSI */
 								break;