on ^C (INTR, QUIT edchars), shove input line into history

This commit is contained in:
tg 2017-04-21 19:08:18 +00:00
parent 74bd8b61a3
commit 36ea8e6171
2 changed files with 35 additions and 19 deletions

46
edit.c
View File

@ -28,7 +28,7 @@
#ifndef MKSH_NO_CMDLINE_EDITING
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.321 2017/04/12 16:46:20 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.322 2017/04/21 19:08:17 tg Exp $");
/*
* in later versions we might use libtermcap for this, but since external
@ -76,7 +76,7 @@ static int modified; /* buffer has been "modified" */
static char *holdbufp; /* place to hold last edit buffer */
/* 0=dumb 1=tmux (for now) */
static bool x_term_mode;
static uint8_t x_term_mode;
static void x_adjust(void);
static int x_getc(void);
@ -97,6 +97,7 @@ static void x_init_prompt(bool);
#if !MKSH_S_NOVI
static int x_vi(char *);
#endif
static void x_intr(int, int) MKSH_A_NORETURN;
#define x_flush() shf_flush(shl_out)
#if defined(MKSH_SMALL) && !defined(MKSH_SMALL_BUT_FAST)
@ -991,6 +992,7 @@ static void x_bs3(char **);
static int x_size2(char *, char **);
static void x_zots(char *);
static void x_zotc3(char **);
static void x_vi_zotc(int);
static void x_load_hist(char **);
static int x_search(char *, int, int);
#ifndef MKSH_SMALL
@ -1299,9 +1301,7 @@ x_emacs(char *buf)
return (i);
case KINTR:
/* special case for interrupt */
trapsig(SIGINT);
x_mode(false);
unwind(LSHELL);
x_intr(SIGINT, c);
}
/* ad-hoc hack for fixing the cursor position */
x_goto(xcp);
@ -2313,14 +2313,28 @@ x_meta_yank(int c MKSH_A_UNUSED)
return (KSTD);
}
static int
x_abort(int c MKSH_A_UNUSED)
/* fake receiving an interrupt */
static void
x_intr(int signo, int c)
{
/* x_zotc(c); */
x_vi_zotc(c);
*xep = '\0';
strip_nuls(xbuf, xep - xbuf);
if (*xbuf)
histsave(&source->line, xbuf, HIST_STORE, true);
xlp = xep = xcp = xbp = xbuf;
xlp_valid = true;
*xcp = 0;
x_modified();
x_flush();
trapsig(signo);
x_mode(false);
unwind(LSHELL);
}
static int
x_abort(int c MKSH_A_UNUSED)
{
return (KINTR);
}
@ -3396,7 +3410,6 @@ static int complete_word(int, int);
static int print_expansions(struct edstate *, int);
#define char_len(c) ((ISCTRL((unsigned char)c) && \
/* but not C1 */ (unsigned char)c < 0x80) ? 2 : 1)
static void x_vi_zotc(int);
static void vi_error(void);
static void vi_macro_reset(void);
static int x_vi_putbuf(const char *, size_t);
@ -3587,13 +3600,14 @@ x_vi(char *buf)
if (state != VLIT) {
if (isched(c, edchars.intr) ||
isched(c, edchars.quit)) {
/* shove input buffer away */
xbuf = ebuf.cbuf;
xep = xbuf;
if (ebuf.linelen > 0)
xep += ebuf.linelen;
/* pretend we got an interrupt */
x_vi_zotc(c);
x_flush();
trapsig(isched(c, edchars.intr) ?
SIGINT : SIGQUIT);
x_mode(false);
unwind(LSHELL);
x_intr(isched(c, edchars.intr) ?
SIGINT : SIGQUIT, c);
} else if (isched(c, edchars.eof) &&
state != VVERSION) {
if (vs->linelen == 0) {
@ -5460,6 +5474,7 @@ print_expansions(struct edstate *est, int cmd MKSH_A_UNUSED)
redraw_line(false);
return (0);
}
#endif /* !MKSH_S_NOVI */
/* Similar to x_zotc(emacs.c), but no tab weirdness */
static void
@ -5472,6 +5487,7 @@ x_vi_zotc(int c)
x_putc(c);
}
#if !MKSH_S_NOVI
static void
vi_error(void)
{

8
mksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.443 2017/04/20 20:50:12 tg Exp $
.\" $MirOS: src/bin/mksh/mksh.1,v 1.444 2017/04/21 19:08:18 tg Exp $
.\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $
.\"-
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
@ -76,7 +76,7 @@
.\" with -mandoc, it might implement .Mx itself, but we want to
.\" use our own definition. And .Dd must come *first*, always.
.\"
.Dd $Mdocdate: April 20 2017 $
.Dd $Mdocdate: April 21 2017 $
.\"
.\" Check which macro package we use, and do other -mdoc setup.
.\"
@ -5537,7 +5537,7 @@ Emacs key bindings:
.No INTR Pq \*(haC ,
.No \*(haG
.Xc
Abort the current command, empty the line buffer and
Abort the current command, save it to the history, empty the line buffer and
set the exit state to interrupted.
.It auto\-insert: Op Ar n
Simply causes the character to appear as literal input.
@ -6434,7 +6434,7 @@ Undo all changes that have been made to the current line.
They move as expected, both in insert and command mode.
.It Ar intr No and Ar quit
The interrupt and quit terminal characters cause the current line to be
deleted and a new prompt to be printed.
removed to the history and a new prompt to be printed.
.El
.Sh FILES
.Bl -tag -width XetcXsuid_profile -compact