Skip to content

Commit

Permalink
Use "kb" termcap to determine bytes of ESC-backspace command.
Browse files Browse the repository at this point in the history
Add lesskey support for some missing special keys.
  • Loading branch information
gwsw committed Jul 12, 2021
1 parent bf7c8ce commit ccb3f80
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
1 change: 1 addition & 0 deletions cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,5 @@
#define SK_F1 14
#define SK_BACKTAB 15
#define SK_CTL_BACKSPACE 16
#define SK_BACKSPACE 17
#define SK_CONTROL_K 40
2 changes: 1 addition & 1 deletion decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ static unsigned char edittable[] =
ESC,SK(SK_DELETE),0, EC_W_DELETE, /* ESC DELETE */
SK(SK_CTL_DELETE),0, EC_W_DELETE, /* CTRL-DELETE */
SK(SK_CTL_BACKSPACE),0, EC_W_BACKSPACE, /* CTRL-BACKSPACE */
ESC,'\b',0, EC_W_BACKSPACE, /* ESC BACKSPACE */
ESC,SK(SK_BACKSPACE),0, EC_W_BACKSPACE, /* ESC BACKSPACE */
ESC,'0',0, EC_HOME, /* ESC 0 */
SK(SK_HOME),0, EC_HOME, /* HOME */
ESC,'$',0, EC_END, /* ESC $ */
Expand Down
12 changes: 12 additions & 0 deletions lesskey.nro.VER
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ DOWN ARROW
RIGHT ARROW
.IP \ekl
LEFT ARROW
.IP \ek>
ctrl-RIGHT ARROW
.IP \ek<
ctrl-LEFT ARROW
.IP \ekU
PAGE UP
.IP \ekD
Expand All @@ -94,6 +98,14 @@ HOME
END
.IP \ekx
DELETE
.IP \ekX
ctrl-DELETE
.IP \eki
INSERT
.IP \ekt
BACKTAB
.IP \ek1
F1
.PP
A backslash followed by any other character indicates that character is
to be taken literally.
Expand Down
17 changes: 12 additions & 5 deletions lesskey_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,22 @@ tstr(pp, xlate)
{
switch (*++p)
{
case 'u': ch = SK_UP_ARROW; break;
case 'b': ch = SK_BACKSPACE; break;
case 'd': ch = SK_DOWN_ARROW; break;
case 'r': ch = SK_RIGHT_ARROW; break;
case 'l': ch = SK_LEFT_ARROW; break;
case 'U': ch = SK_PAGE_UP; break;
case 'D': ch = SK_PAGE_DOWN; break;
case 'h': ch = SK_HOME; break;
case 'e': ch = SK_END; break;
case 'h': ch = SK_HOME; break;
case 'i': ch = SK_INSERT; break;
case 'l': ch = SK_LEFT_ARROW; break;
case 'r': ch = SK_RIGHT_ARROW; break;
case 't': ch = SK_BACKTAB; break;
case 'u': ch = SK_UP_ARROW; break;
case 'U': ch = SK_PAGE_UP; break;
case 'x': ch = SK_DELETE; break;
case 'X': ch = SK_CTL_DELETE; break;
case '1': ch = SK_F1; break;
case '<': ch = SK_CTL_LEFT_ARROW; break;
case '>': ch = SK_CTL_RIGHT_ARROW; break;
default: { char buf[2]; buf[0] = *p; buf[1] = '\0';
parse_error("illegal escape sequence \\k", buf);
*pp = p+1;
Expand Down
13 changes: 13 additions & 0 deletions screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,7 @@ special_key_str(key)
static char k_delete[] = { '\340', PCK_DELETE, 0 };
static char k_ctl_delete[] = { '\340', PCK_CTL_DELETE, 0 };
static char k_ctl_backspace[] = { '\177', 0 };
static char k_backspace[] = { '\b', 0 };
static char k_home[] = { '\340', PCK_HOME, 0 };
static char k_end[] = { '\340', PCK_END, 0 };
static char k_up[] = { '\340', PCK_UP, 0 };
Expand Down Expand Up @@ -1029,6 +1030,9 @@ special_key_str(key)
case SK_CTL_DELETE:
s = k_ctl_delete;
break;
case SK_BACKSPACE:
s = k_backspace;
break;
case SK_F1:
s = k_f1;
break;
Expand Down Expand Up @@ -1069,6 +1073,15 @@ special_key_str(key)
s = tbuf;
}
break;
case SK_BACKSPACE:
s = ltgetstr("kb", &sp);
if (s == NULL)
{
tbuf[0] = '\b';
tbuf[1] = '\0';
s = tbuf;
}
break;
#endif
case SK_CONTROL_K:
tbuf[0] = CONTROL('K');
Expand Down

0 comments on commit ccb3f80

Please sign in to comment.