shithub: riscv

Download patch

ref: 2e1ac96d3f6ff85ccac1681631d09d60953cf8a6
parent: 800170c6559b633c92d742d2950ecd1ce5ffb961
author: Michael Forney <mforney@mforney.org>
date: Tue Oct 4 13:34:50 EDT 2022

vt: fix home/end sequences in xterm mode

According to the ncurses terminfo database, we have

$ for k in khome kend; do printf '%s:\t' "$k"; TERM=xterm tput $k | od -An -tc; done
khome:	033   O   H
kend:	033   O   F
$

This differs from vt220fk, so add a new xtermfk table with the proper
sequences.

--- a/sys/src/cmd/vt/cons.h
+++ b/sys/src/cmd/vt/cons.h
@@ -39,7 +39,7 @@
 	char	*sequence;
 };
 extern struct funckey *fk, *appfk;
-extern struct funckey ansifk[], ansiappfk[], vt220fk[];
+extern struct funckey ansifk[], ansiappfk[], vt220fk[], 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
@@ -286,7 +286,7 @@
 			sysfatal("could not create log file: %s: %r", p);
 		break;
 	case 'x':
-		fk = vt220fk;
+		fk = xtermfk;
 		term = "xterm";
 		break;
 	case 'r':
--- a/sys/src/cmd/vt/vt.c
+++ b/sys/src/cmd/vt/vt.c
@@ -91,6 +91,35 @@
 	{ 0 },
 };
 
+struct funckey xtermfk[] = {
+	{ "insert",		"\033[2~", },
+	{ "delete",		"\033[3~", },
+	{ "home",		"\033OH", },
+	{ "end",		"\033OF", },
+	{ "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", },
+	{ "F4",			"\033OS", },
+	{ "F5",			"\033[15~", },
+	{ "F6",			"\033[17~", },
+	{ "F7",			"\033[18~", },
+	{ "F8",			"\033[19~", },
+	{ "F9",			"\033[20~", },
+	{ "F10",		"\033[21~", },
+	{ "F11",		"\033[23~", },
+	{ "F12",		"\033[24~", },
+
+	{ 0 },
+};
+
 char gmap[256] = {
 	['_']	' ',	/* blank */
 	['\\']	'*',	/* diamond */