summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2020-09-20 14:40:45 +0000
committermillert <millert@openbsd.org>2020-09-20 14:40:45 +0000
commit2e824dbddfdb1c05ae1d835de7a365c9c1ca94b3 (patch)
tree8fcc6e83575a6a6b838ec1562fe071fdd734adc8 /bin
parentSet `if_snd' queue maximum length to 1. This enforces calls of (diff)
downloadwireguard-openbsd-2e824dbddfdb1c05ae1d835de7a365c9c1ca94b3.tar.xz
wireguard-openbsd-2e824dbddfdb1c05ae1d835de7a365c9c1ca94b3.zip
Clear screen before redrawing the line with ^L, also in input mode.
This is similar to the emacs mode clear-screen command. Unlike bash, but like zsh, ^L also works in input mode, not just command mode. OK kn@ tb@
Diffstat (limited to 'bin')
-rw-r--r--bin/ksh/ksh.115
-rw-r--r--bin/ksh/vi.c76
2 files changed, 62 insertions, 29 deletions
diff --git a/bin/ksh/ksh.1 b/bin/ksh/ksh.1
index a91ab51e63b..818e5e9f5e9 100644
--- a/bin/ksh/ksh.1
+++ b/bin/ksh/ksh.1
@@ -1,8 +1,8 @@
-.\" $OpenBSD: ksh.1,v 1.209 2020/07/07 10:33:58 jca Exp $
+.\" $OpenBSD: ksh.1,v 1.210 2020/09/20 14:40:45 millert Exp $
.\"
.\" Public Domain
.\"
-.Dd $Mdocdate: July 7 2020 $
+.Dd $Mdocdate: September 20 2020 $
.Dt KSH 1
.Os
.Sh NAME
@@ -5053,6 +5053,13 @@ Erases previous character.
.It ^J | ^M
End of line.
The current line is read, parsed, and executed by the shell.
+.It ^L
+Clear the screen (if possible) and redraw the current line.
+See the
+.Em clear-screen
+command in
+.Sx Emacs editing mode
+for more information.
.It ^V
Literal next.
The next character typed is not treated specially (can be used
@@ -5510,7 +5517,9 @@ Miscellaneous vi commands
.Bl -tag -width Ds
.It ^J and ^M
The current line is read, parsed, and executed by the shell.
-.It ^L and ^R
+.It ^L
+Clear the screen (if possible) and redraw the current line.
+.It ^R
Redraw the current line.
.It Xo
.Oo Ar n Oc Ns \&.
diff --git a/bin/ksh/vi.c b/bin/ksh/vi.c
index 12202d5c3d3..53be5a76d50 100644
--- a/bin/ksh/vi.c
+++ b/bin/ksh/vi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vi.c,v 1.56 2018/03/15 16:51:29 anton Exp $ */
+/* $OpenBSD: vi.c,v 1.57 2020/09/20 14:40:45 millert Exp $ */
/*
* vi command editing
@@ -14,12 +14,14 @@
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
+#ifndef SMALL
+# include <term.h>
+# include <curses.h>
+#endif
#include "sh.h"
#include "edit.h"
-#define CTRL(c) (c & 0x1f)
-
struct edstate {
char *cbuf; /* main buffer to build the command line */
int cbufsize; /* number of bytes allocated for cbuf */
@@ -52,8 +54,9 @@ static int Backword(int);
static int Endword(int);
static int grabhist(int, int);
static int grabsearch(int, int, int, char *);
+static void do_clear_screen(void);
static void redraw_line(int);
-static void refresh(int);
+static void refresh_line(int);
static int outofwin(void);
static void rewindow(void);
static int newcol(int, int);
@@ -271,9 +274,9 @@ vi_hook(int ch)
case 0:
if (state == VLIT) {
es->cursor--;
- refresh(0);
+ refresh_line(0);
} else
- refresh(insert != 0);
+ refresh_line(insert != 0);
break;
case 1:
return 1;
@@ -298,7 +301,7 @@ vi_hook(int ch)
return -1;
} else if (putbuf("?", 1, 0) != 0)
return -1;
- refresh(0);
+ refresh_line(0);
}
}
}
@@ -310,7 +313,7 @@ vi_hook(int ch)
vi_error();
} else
es->cbuf[es->cursor++] = ch;
- refresh(1);
+ refresh_line(1);
state = VNORMAL;
break;
@@ -375,7 +378,7 @@ vi_hook(int ch)
if (!srchpat[0]) {
vi_error();
state = VNORMAL;
- refresh(0);
+ refresh_line(0);
return 0;
}
} else {
@@ -392,17 +395,17 @@ vi_hook(int ch)
} while (srchlen > 0 &&
isu8cont(locpat[srchlen]));
es->cursor = es->linelen;
- refresh(0);
+ refresh_line(0);
return 0;
}
restore_cbuf();
state = VNORMAL;
- refresh(0);
+ refresh_line(0);
} else if (ch == edchars.kill) {
srchlen = 0;
es->linelen = 1;
es->cursor = 1;
- refresh(0);
+ refresh_line(0);
return 0;
} else if (ch == edchars.werase) {
struct edstate new_es, *save_es;
@@ -421,7 +424,7 @@ vi_hook(int ch)
es->linelen -= char_len((unsigned char)locpat[i]);
srchlen = n;
es->cursor = es->linelen;
- refresh(0);
+ refresh_line(0);
return 0;
} else {
if (srchlen == SRCHLEN - 1)
@@ -446,7 +449,7 @@ vi_hook(int ch)
es->cbuf[es->linelen++] = ch;
}
es->cursor = es->linelen;
- refresh(0);
+ refresh_line(0);
}
return 0;
}
@@ -459,15 +462,15 @@ vi_hook(int ch)
switch (vi_cmd(argc1, curcmd)) {
case -1:
vi_error();
- refresh(0);
+ refresh_line(0);
break;
case 0:
if (insert != 0)
inslen = 0;
- refresh(insert != 0);
+ refresh_line(insert != 0);
break;
case 1:
- refresh(0);
+ refresh_line(0);
return 1;
case 2:
/* back from a 'v' command - don't redraw the screen */
@@ -482,7 +485,7 @@ vi_hook(int ch)
switch (vi_cmd(lastac, lastcmd)) {
case -1:
vi_error();
- refresh(0);
+ refresh_line(0);
break;
case 0:
if (insert != 0) {
@@ -495,10 +498,10 @@ vi_hook(int ch)
vi_error();
}
}
- refresh(0);
+ refresh_line(0);
break;
case 1:
- refresh(0);
+ refresh_line(0);
return 1;
case 2:
/* back from a 'v' command - can't happen */
@@ -651,6 +654,10 @@ vi_insert(int ch)
print_expansions(es);
break;
+ case CTRL('l'):
+ do_clear_screen();
+ break;
+
case CTRL('i'):
if (Flag(FVITABCOMPLETE)) {
complete_word(0, 0);
@@ -708,6 +715,9 @@ vi_cmd(int argcnt, const char *cmd)
switch (*cmd) {
case CTRL('l'):
+ do_clear_screen();
+ break;
+
case CTRL('r'):
redraw_line(1);
break;
@@ -1028,7 +1038,7 @@ vi_cmd(int argcnt, const char *cmd)
c1, srchpat)) < 0) {
if (c3) {
restore_cbuf();
- refresh(0);
+ refresh_line(0);
}
return -1;
} else {
@@ -1717,10 +1727,24 @@ grabsearch(int save, int start, int fwd, char *pat)
}
static void
-redraw_line(int newline)
+do_clear_screen(void)
+{
+ int neednl = 1;
+
+#ifndef SMALL
+ if (cur_term != NULL && clear_screen != NULL) {
+ if (tputs(clear_screen, 1, x_putc) != ERR)
+ neednl = 0;
+ }
+#endif
+ redraw_line(neednl);
+}
+
+static void
+redraw_line(int neednl)
{
(void) memset(wbuf[win], ' ', wbuf_len);
- if (newline) {
+ if (neednl) {
x_putc('\r');
x_putc('\n');
}
@@ -1730,7 +1754,7 @@ redraw_line(int newline)
}
static void
-refresh(int leftside)
+refresh_line(int leftside)
{
if (outofwin())
rewindow();
@@ -2033,7 +2057,7 @@ expand_word(int command)
modified = 1; hnum = hlast;
insert = INSERT;
lastac = 0;
- refresh(0);
+ refresh_line(0);
return rval;
}
@@ -2137,7 +2161,7 @@ complete_word(int command, int count)
modified = 1; hnum = hlast;
insert = INSERT;
lastac = 0; /* prevent this from being redone... */
- refresh(0);
+ refresh_line(0);
return rval;
}