mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-14 10:09:48 +00:00
Allow excessive backspacing to correctly abort an input (most significantly
a search string input).
This commit is contained in:
parent
9a49dca0b1
commit
db0d7f4131
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=55102
@ -99,8 +99,10 @@ biggetinputhack()
|
||||
/*
|
||||
* Read a line of input from the terminal. Reads at most bufsiz - 1 characters
|
||||
* and places them in buffer buf. They are NUL-terminated. Prints the
|
||||
* temporary prompt prompt.
|
||||
* temporary prompt prompt. Returns true if the user aborted the input and
|
||||
* returns false otherwise.
|
||||
*/
|
||||
int
|
||||
getinput(prompt, buf, bufsiz)
|
||||
const char *prompt;
|
||||
char *buf;
|
||||
@ -117,18 +119,18 @@ getinput(prompt, buf, bufsiz)
|
||||
c = getcc();
|
||||
if (c == '\n') {
|
||||
*bufcur = '\0';
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
if (c == READ_INTR ||
|
||||
cmd_char(c, buf, &bufcur, buf + bufsiz - 1)) {
|
||||
/* input cancelled */
|
||||
if (bufsiz) *buf = '\0';
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
if (biggetinputhack_f) {
|
||||
biggetinputhack_f = 0;
|
||||
*bufcur = '\0';
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -916,7 +916,8 @@ cusercom(cident, args)
|
||||
char buf[125]; /* XXX should avoid static buffer... */
|
||||
|
||||
ENDPARSE;
|
||||
getinput("Command: ", buf, sizeof(buf));
|
||||
if (getinput("Command: ", buf, sizeof(buf)))
|
||||
return args; /* abort the command */
|
||||
if (command(buf))
|
||||
return NULL;
|
||||
|
||||
@ -1192,7 +1193,10 @@ caskfile(cident, args)
|
||||
char buf[MAXPATHLEN + 1];
|
||||
|
||||
ENDPARSE;
|
||||
getinput("Examine: ", buf, sizeof(buf));
|
||||
if (getinput("Examine: ", buf, sizeof(buf)))
|
||||
return args; /* abort */
|
||||
/* Abort is different from a "" answer in that "" causes the current
|
||||
* file to be re-opened. */
|
||||
/* XXX should modify this() or edit() to handle lists of file, ie.
|
||||
* the type of lists that I get if I try to glob("*") */
|
||||
(void)edit(glob(buf));
|
||||
@ -1297,6 +1301,7 @@ csearch(cident, args)
|
||||
enum { FORW=0, BACK=1 } direction;
|
||||
static enum { NOINVERT=0, INVERT=1 } sense;
|
||||
long N;
|
||||
int abrt;
|
||||
|
||||
ARGTOG(direction, 6, "forw", "back", "forward", "backward",
|
||||
"forwards", "backwards");
|
||||
@ -1313,25 +1318,25 @@ csearch(cident, args)
|
||||
case MAGICASKSEARCH:
|
||||
biggetinputhack(); /* It's magic, boys */
|
||||
if (direction == FORW)
|
||||
getinput("Search: /", buf, 2);
|
||||
abrt = getinput("Search: /", buf, 2);
|
||||
else
|
||||
getinput("Search: ?", buf, 2);
|
||||
abrt = getinput("Search: ?", buf, 2);
|
||||
switch (*buf) {
|
||||
case '!':
|
||||
/* Magic */
|
||||
if (direction == FORW)
|
||||
getinput("Search: !/", buf, sizeof(buf));
|
||||
abrt = getinput("Search: !/", buf, sizeof(buf));
|
||||
else
|
||||
getinput("Search: !?", buf, sizeof(buf));
|
||||
abrt = getinput("Search: !?", buf, sizeof(buf));
|
||||
sense = INVERT;
|
||||
break;
|
||||
default:
|
||||
/* No magic */
|
||||
ungetcc(*buf);
|
||||
if (direction == FORW)
|
||||
getinput("Search: /", buf, sizeof(buf));
|
||||
abrt = getinput("Search: /", buf, sizeof(buf));
|
||||
else
|
||||
getinput("Search: ?", buf, sizeof(buf));
|
||||
abrt = getinput("Search: ?", buf, sizeof(buf));
|
||||
case '\0':
|
||||
sense = NOINVERT;
|
||||
break;
|
||||
@ -1345,6 +1350,9 @@ csearch(cident, args)
|
||||
break;
|
||||
}
|
||||
|
||||
if (abrt)
|
||||
return args;
|
||||
|
||||
if (cident == SEARCH || cident == MAGICASKSEARCH) {
|
||||
settog("_ls_direction", direction, 2, "forw", "back");
|
||||
settog("_ls_sense", sense, 2, "noinvert", "invert");
|
||||
|
Loading…
Reference in New Issue
Block a user