Introduce FEATURE_EDITING_FANCY_KEYS, so that user can disable
less-known keys (e.g. Ctrl-B/E/F)
This commit is contained in:
parent
5592fac308
commit
00cdbd8fc2
@ -632,6 +632,7 @@ CONFIG_FEATURE_SH_IS_NONE=y
|
|||||||
# CONFIG_FEATURE_SH_EXTRA_QUIET is not set
|
# CONFIG_FEATURE_SH_EXTRA_QUIET is not set
|
||||||
# CONFIG_FEATURE_SH_STANDALONE_SHELL is not set
|
# CONFIG_FEATURE_SH_STANDALONE_SHELL is not set
|
||||||
# CONFIG_FEATURE_COMMAND_EDITING is not set
|
# CONFIG_FEATURE_COMMAND_EDITING is not set
|
||||||
|
# CONFIG_FEATURE_EDITING_FANCY_KEYS is not set
|
||||||
# CONFIG_FEATURE_COMMAND_EDITING_VI is not set
|
# CONFIG_FEATURE_COMMAND_EDITING_VI is not set
|
||||||
CONFIG_FEATURE_COMMAND_HISTORY=
|
CONFIG_FEATURE_COMMAND_HISTORY=
|
||||||
# CONFIG_FEATURE_COMMAND_SAVEHISTORY is not set
|
# CONFIG_FEATURE_COMMAND_SAVEHISTORY is not set
|
||||||
|
@ -247,6 +247,14 @@ config FEATURE_COMMAND_EDITING
|
|||||||
help
|
help
|
||||||
Enable command editing in shell.
|
Enable command editing in shell.
|
||||||
|
|
||||||
|
config FEATURE_EDITING_FANCY_KEYS
|
||||||
|
bool "Additional editing keys"
|
||||||
|
default n
|
||||||
|
depends on FEATURE_COMMAND_EDITING
|
||||||
|
help
|
||||||
|
Enable additonal editing keys (Ctrl-E, Ctrl-U etc).
|
||||||
|
Arrow keys, Home/End/Delete and Ctrl-W work even without this option.
|
||||||
|
|
||||||
config FEATURE_COMMAND_EDITING_VI
|
config FEATURE_COMMAND_EDITING_VI
|
||||||
bool "vi-style line editing commands"
|
bool "vi-style line editing commands"
|
||||||
default n
|
default n
|
||||||
|
@ -24,55 +24,10 @@
|
|||||||
|
|
||||||
Small bugs (simple effect):
|
Small bugs (simple effect):
|
||||||
- not true viewing if terminal size (x*y symbols) less
|
- not true viewing if terminal size (x*y symbols) less
|
||||||
size (prompt + editor`s line + 2 symbols)
|
size (prompt + editor's line + 2 symbols)
|
||||||
- not true viewing if length prompt less terminal width
|
- not true viewing if length prompt less terminal width
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
CONFIG_FEATURE_COMMAND_EDITING=y
|
|
||||||
# CONFIG_FEATURE_COMMAND_EDITING_VI is not set
|
|
||||||
CONFIG_FEATURE_COMMAND_HISTORY=15
|
|
||||||
# CONFIG_FEATURE_COMMAND_SAVEHISTORY is not set
|
|
||||||
# CONFIG_FEATURE_COMMAND_TAB_COMPLETION is not set
|
|
||||||
# CONFIG_FEATURE_COMMAND_USERNAME_COMPLETION is not set
|
|
||||||
# CONFIG_FEATURE_SH_FANCY_PROMPT is not set
|
|
||||||
Sizes with the above:
|
|
||||||
# size cmdedit.o
|
|
||||||
text data bss dec hex filename
|
|
||||||
2374 4 228 2606 a2e cmdedit.o
|
|
||||||
# nm --size-sort cmdedit.o
|
|
||||||
00000004 b cmdedit_prmt_len
|
|
||||||
00000004 b cmdedit_prompt
|
|
||||||
00000004 d cmdedit_termw
|
|
||||||
00000004 b cmdedit_x
|
|
||||||
00000004 b cmdedit_y
|
|
||||||
00000004 b command_ps
|
|
||||||
00000004 b cur_history
|
|
||||||
00000004 b cursor
|
|
||||||
00000004 b handlers_sets
|
|
||||||
00000004 b len
|
|
||||||
00000004 b n_history
|
|
||||||
00000004 b previous_SIGWINCH_handler
|
|
||||||
00000009 t beep
|
|
||||||
00000017 t goto_new_line
|
|
||||||
0000001a t input_end
|
|
||||||
0000001b t input_backspace
|
|
||||||
0000001e t input_forward
|
|
||||||
00000027 t get_next_history
|
|
||||||
00000036 t put_prompt
|
|
||||||
00000039 t redraw
|
|
||||||
0000003c b initial_settings
|
|
||||||
0000003c b new_settings
|
|
||||||
00000040 b history
|
|
||||||
00000047 t input_delete
|
|
||||||
0000004d t get_previous_history
|
|
||||||
00000059 t cmdedit_reset_term
|
|
||||||
0000006c t cmdedit_set_out_char
|
|
||||||
00000087 t input_backward
|
|
||||||
000000a1 t win_changed
|
|
||||||
0000053c T cmdedit_read_input
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include "busybox.h"
|
#include "busybox.h"
|
||||||
#include "cmdedit.h"
|
#include "cmdedit.h"
|
||||||
@ -969,7 +924,7 @@ void load_history(const char *fromfile)
|
|||||||
cur_history = n_history = hi;
|
cur_history = n_history = hi;
|
||||||
}
|
}
|
||||||
|
|
||||||
void save_history (const char *tofile)
|
void save_history(const char *tofile)
|
||||||
{
|
{
|
||||||
FILE *fp = fopen(tofile, "w");
|
FILE *fp = fopen(tofile, "w");
|
||||||
|
|
||||||
@ -1381,6 +1336,7 @@ int cmdedit_read_input(char *prompt, char command[BUFSIZ])
|
|||||||
goto_new_line();
|
goto_new_line();
|
||||||
break_out = 1;
|
break_out = 1;
|
||||||
break;
|
break;
|
||||||
|
#if ENABLE_FEATURE_EDITING_FANCY_KEYS
|
||||||
case CTRL('A'):
|
case CTRL('A'):
|
||||||
vi_case('0'|vbit:)
|
vi_case('0'|vbit:)
|
||||||
/* Control-a -- Beginning of line */
|
/* Control-a -- Beginning of line */
|
||||||
@ -1393,6 +1349,7 @@ int cmdedit_read_input(char *prompt, char command[BUFSIZ])
|
|||||||
/* Control-b -- Move back one character */
|
/* Control-b -- Move back one character */
|
||||||
input_backward(1);
|
input_backward(1);
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case CTRL('C'):
|
case CTRL('C'):
|
||||||
vi_case(CTRL('C')|vbit:)
|
vi_case(CTRL('C')|vbit:)
|
||||||
/* Control-c -- stop gathering input */
|
/* Control-c -- stop gathering input */
|
||||||
@ -1425,10 +1382,11 @@ int cmdedit_read_input(char *prompt, char command[BUFSIZ])
|
|||||||
break_out = len = -1;
|
break_out = len = -1;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
} else {
|
|
||||||
input_delete(0);
|
|
||||||
}
|
}
|
||||||
|
input_delete(0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
#if ENABLE_FEATURE_EDITING_FANCY_KEYS
|
||||||
case CTRL('E'):
|
case CTRL('E'):
|
||||||
vi_case('$'|vbit:)
|
vi_case('$'|vbit:)
|
||||||
/* Control-e -- End of line */
|
/* Control-e -- End of line */
|
||||||
@ -1440,16 +1398,21 @@ int cmdedit_read_input(char *prompt, char command[BUFSIZ])
|
|||||||
/* Control-f -- Move forward one character */
|
/* Control-f -- Move forward one character */
|
||||||
input_forward();
|
input_forward();
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
case '\b':
|
case '\b':
|
||||||
case '\x7f': /* DEL */
|
case '\x7f': /* DEL */
|
||||||
/* Control-h and DEL */
|
/* Control-h and DEL */
|
||||||
input_backspace();
|
input_backspace();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '\t':
|
case '\t':
|
||||||
#if ENABLE_FEATURE_COMMAND_TAB_COMPLETION
|
#if ENABLE_FEATURE_COMMAND_TAB_COMPLETION
|
||||||
input_tab(&lastWasTab);
|
input_tab(&lastWasTab);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
#if ENABLE_FEATURE_EDITING_FANCY_KEYS
|
||||||
case CTRL('K'):
|
case CTRL('K'):
|
||||||
/* Control-k -- clear to end of line */
|
/* Control-k -- clear to end of line */
|
||||||
command[cursor] = 0;
|
command[cursor] = 0;
|
||||||
@ -1462,6 +1425,8 @@ int cmdedit_read_input(char *prompt, char command[BUFSIZ])
|
|||||||
printf("\033[H");
|
printf("\033[H");
|
||||||
redraw(0, len - cursor);
|
redraw(0, len - cursor);
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if MAX_HISTORY > 0
|
#if MAX_HISTORY > 0
|
||||||
case CTRL('N'):
|
case CTRL('N'):
|
||||||
vi_case(CTRL('N')|vbit:)
|
vi_case(CTRL('N')|vbit:)
|
||||||
@ -1482,6 +1447,8 @@ int cmdedit_read_input(char *prompt, char command[BUFSIZ])
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ENABLE_FEATURE_EDITING_FANCY_KEYS
|
||||||
case CTRL('U'):
|
case CTRL('U'):
|
||||||
vi_case(CTRL('U')|vbit:)
|
vi_case(CTRL('U')|vbit:)
|
||||||
/* Control-U -- Clear line before cursor */
|
/* Control-U -- Clear line before cursor */
|
||||||
@ -1490,14 +1457,16 @@ int cmdedit_read_input(char *prompt, char command[BUFSIZ])
|
|||||||
redraw(cmdedit_y, len -= cursor);
|
redraw(cmdedit_y, len -= cursor);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case CTRL('W'):
|
case CTRL('W'):
|
||||||
vi_case(CTRL('W')|vbit:)
|
vi_case(CTRL('W')|vbit:)
|
||||||
/* Control-W -- Remove the last word */
|
/* Control-W -- Remove the last word */
|
||||||
while (cursor > 0 && isspace(command[cursor-1]))
|
while (cursor > 0 && isspace(command[cursor-1]))
|
||||||
input_backspace();
|
input_backspace();
|
||||||
while (cursor > 0 &&!isspace(command[cursor-1]))
|
while (cursor > 0 && !isspace(command[cursor-1]))
|
||||||
input_backspace();
|
input_backspace();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#if ENABLE_FEATURE_COMMAND_EDITING_VI
|
#if ENABLE_FEATURE_COMMAND_EDITING_VI
|
||||||
case 'i'|vbit:
|
case 'i'|vbit:
|
||||||
vi_cmdmode = 0;
|
vi_cmdmode = 0;
|
||||||
@ -1655,6 +1624,7 @@ int cmdedit_read_input(char *prompt, char command[BUFSIZ])
|
|||||||
if (dummy != '~')
|
if (dummy != '~')
|
||||||
c = '\0';
|
c = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
#if ENABLE_FEATURE_COMMAND_TAB_COMPLETION
|
#if ENABLE_FEATURE_COMMAND_TAB_COMPLETION
|
||||||
case '\t': /* Alt-Tab */
|
case '\t': /* Alt-Tab */
|
||||||
@ -1705,7 +1675,7 @@ int cmdedit_read_input(char *prompt, char command[BUFSIZ])
|
|||||||
input_end();
|
input_end();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
c = 0;
|
c = '\0';
|
||||||
beep();
|
beep();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1722,36 +1692,33 @@ int cmdedit_read_input(char *prompt, char command[BUFSIZ])
|
|||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
|
||||||
#if ENABLE_FEATURE_COMMAND_EDITING_VI
|
#if ENABLE_FEATURE_COMMAND_EDITING_VI
|
||||||
if (vi_cmdmode) /* don't self-insert */
|
if (vi_cmdmode) /* Don't self-insert */
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
if (!Isprint(c)) /* Skip non-printable characters */
|
if (!Isprint(c)) /* Skip non-printable characters */
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
if (len >= (BUFSIZ - 2)) /* Need to leave space for enter */
|
if (len >= (BUFSIZ - 2)) /* Need to leave space for enter */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
len++;
|
len++;
|
||||||
|
|
||||||
if (cursor == (len - 1)) { /* Append if at the end of the line */
|
if (cursor == (len - 1)) { /* Append if at the end of the line */
|
||||||
*(command + cursor) = c;
|
command[cursor] = c;
|
||||||
*(command + cursor + 1) = 0;
|
command[cursor+1] = '\0';
|
||||||
cmdedit_set_out_char(' ');
|
cmdedit_set_out_char(' ');
|
||||||
} else { /* Insert otherwise */
|
} else { /* Insert otherwise */
|
||||||
int sc = cursor;
|
int sc = cursor;
|
||||||
|
|
||||||
memmove(command + sc + 1, command + sc, len - sc);
|
memmove(command + sc + 1, command + sc, len - sc);
|
||||||
*(command + sc) = c;
|
command[sc] = c;
|
||||||
sc++;
|
sc++;
|
||||||
/* rewrite from cursor */
|
/* rewrite from cursor */
|
||||||
input_end();
|
input_end();
|
||||||
/* to prev x pos + 1 */
|
/* to prev x pos + 1 */
|
||||||
input_backward(cursor - sc);
|
input_backward(cursor - sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (break_out) /* Enter is the command terminator, no more input. */
|
if (break_out) /* Enter is the command terminator, no more input. */
|
||||||
|
Loading…
Reference in New Issue
Block a user