Commit Graph

163 Commits

Author SHA1 Message Date
Stephen Heumann
26efb6c33e Add support for moving forward/backward one word with OA-left/right on GNO and Ctrl/Alt/Command-left/right on VT100-style terminals.
The support for OA-left/right on GNO uses the OA2META ioctl option to map OA-x to ESC x.

VT100-type terminal emulators have significant variations in what modifier combinations they'll pass through and what escape sequences they produce. Hopefully at least one of them works on just about everything.
2014-12-14 18:49:10 -06:00
Stephen Heumann
8bc7d9fb31 Fix lineedit to process down arrow key properly.
This was broken by the change to using CRMOD mode, which actually does mapping on input as well as output. The fix is to set the terminal to "vt100 arrow" mode, which is an undocumented option that translates arrows to vt100-style escape sequences (also used by gsh).

(Note that the earlier patch actually makes us use CRMOD mode most of the time, not non-CRMOD mode as the summary erroneously says.)
2014-12-14 17:25:04 -06:00
Stephen Heumann
3887b30719 Fix bb_put_cr on non-GNO (it wasn't flushing stdout before printing the CR, leading to the prior character not appearing). 2014-12-14 14:21:25 -06:00
Stephen Heumann
55302cd56c Change lineedit so the terminal isn't kept in CRMOD mode most of the time.
This is important because CRMOD mode prevents text from backgrounded programs from being printed properly. It also leaves the terminal in an inappropriate state if hush crashes or is killed.

For the time being, we still switch briefly to CRMOD mode when we want to print just a CR.
2014-12-14 12:40:46 -06:00
Stephen Heumann
4f7d95d896 Fix problems with editing of commands that extend to multiple lines. 2014-12-13 22:21:38 -06:00
Stephen Heumann
2e0e5358c3 Change some stack-allocated arrays in libbb/lineedit.c to be dynamically allocated. 2014-11-20 18:34:52 -06:00
Stephen Heumann
97eb1defae Fix input handling so $ and # can be typed. This also fixes handling of ^C and ^D during line editing.
The issue with $ and # resulted from incompatible definitions of the CTRL macro between our code and the system headers.
2014-11-19 20:44:25 -06:00
Stephen Heumann
078f526df7 Fixes for terminal behavior on the GNO console 2014-11-19 12:52:05 -06:00
Stephen Heumann
2fd57a3bdc Add basic support for getting input escape sequences from termcap. 2014-11-12 23:25:01 -06:00
Stephen Heumann
5f6121c091 Add initial support for getting terminal information from termcap, instead of hard-coding vt100-style codes.
This currently only supports output, and still doesn't quite display correctly in some cases.
2014-11-11 20:58:06 -06:00
Stephen Heumann
d583686459 Disable functionality for printing the time in the shell's prompt. This required strftime(), which is missing in GNO 2.0.6.
It would have been possible to add a version of strftime(), but it didn't seem worth it for this little bit of functionality. It should also be possible to get similar functionality by invoking an external program like "date" in PS1.
2014-11-05 18:00:35 -06:00
Stephen Heumann
a3c32aaa73 Revise terminal control code to use ioctls supported by GNO instead of termios calls that aren't supported. 2014-11-04 19:53:40 -06:00
Stephen Heumann
9b98d32e66 Fix ORCA/C compatibility problems in libbb/lineedit.c. 2014-11-02 22:40:28 -06:00
Denys Vlasenko
79df481dc4 lineedit: fix trivial build failure
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-10 14:38:26 +01:00
Denys Vlasenko
1b9ac21166 lineedit: use unicode_strwidth instead of unicode_strlen
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-08-20 16:13:05 +02:00
Denys Vlasenko
e66a56de23 lineedit: fix multi-line PS1 handling: calculate PS1 length from last \n
function                                             old     new   delta
parse_and_put_prompt                                 755     774     +19

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-08-19 16:45:04 +02:00
Denys Vlasenko
7a18043a96 lineedit: improve Unicode handling (still buggy though)
function                                             old     new   delta
unicode_strlen                                         -      31     +31
read_line_input                                     3876    3879      +3
lineedit_read_key                                    255     246      -9
parse_and_put_prompt                                 785     755     -30
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/2 up/down: 34/-39)             Total: -5 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-08-19 16:44:05 +02:00
Flemming Madsen
d96ffda62e ash,hush: history builtin
function                                             old     new   delta
show_history                                           -      39     +39
builtin_history                                        -      16     +16
historycmd                                             -      13     +13
bltins1                                              312     324     +12
builtintab                                           336     344      +8
popstring                                            134     140      +6
hush_main                                           1048    1046      -2
ash_main                                            1398    1396      -2
size_from_HISTFILESIZE                                44      40      -4
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 3/3 up/down: 94/-8)              Total: 86 bytes

Signed-off-by: Flemming Madsen <busybox@themadsens.dk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-04-07 18:47:24 +02:00
Denys Vlasenko
8172d054db lineedit: \W on "/bin" should show "bin", not "/bin"
function                                             old     new   delta
parse_and_put_prompt                                 793     785      -8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-03-29 13:21:53 +01:00
Denys Vlasenko
1d14569a66 lineedit: implement \T \t \A \@ prompts escapes, fix \W escape, drop \!
function                                             old     new   delta
parse_and_put_prompt                                 742     793     +51
read_line_input                                     3836    3826     -10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-03-29 13:10:23 +01:00
Denys Vlasenko
6c852bfcad lineedit: add handling of \H in prompt
Based on the patch by Arnaud Rébillout <rebillout@syscom.ch>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-03-28 13:20:12 +01:00
Shawn J. Goff
46031da862 lineedit: initialize delptr
In vi mode, the 'p' and 'P' commands caused a segfault when nothing had
been put in the buffer yet because the delptr was not initialized.

Signed-off-by: Shawn J. Goff <shawn7400@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-02-27 18:30:05 +01:00
Denys Vlasenko
b2320370be lineedit: in !EDITING config, return -1 on fgets error
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-09-27 16:03:49 +02:00
Cliff Frey
4919565c15 lineedit: fix Alt-D when cursor==0
Signed-off-by: Cliff Frey <cliff@meraki.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-08-07 17:59:40 +02:00
Dennis Groenen
deee356a62 lineedit: histfile can get emptied when CONFIG_FEATURE_EDITING_SAVE_ON_EXIT=y
When CONFIG_FEATURE_EDITING_SAVE_ON_EXIT is set to y, the histfile
will get cleared if the total amount of history lines is less than MAX_HISTORY.
Only if the histfile is not empty _and_ the amount of lines currently
in memory are equal to or greater than MAX_HISTORY, history saving will
work as expected with this feature enabled.

Output from defconfig + CONFIG_FEATURE_EDITING_SAVE_ON_EXIT=y:
$ echo "foo" > ~/.ash_history
$ ./busybox ash
~/busybox/a $ echo "bar" > /dev/null
~/busybox/a $ exit
$ cat ~/.ash_history
$

Output with the patch applied and same config as above:
$ echo "foo" > ~/.ash_history
$ ./busybox ash
~/busybox/b $ echo "bar" > /dev/null
~/busybox/b $ exit
$ cat ~/.ash_history
foo
echo "bar" > /dev/null
exit
$

Signed-off-by: Dennis Groenen <tj.groenen at gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-04-26 11:19:38 +02:00
Denys Vlasenko
56443cdbdd whitespace fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-04-20 15:07:22 +02:00
Denys Vlasenko
7ce209b9d4 shell_builtin_read: set cc[VMIN] to 1; lineedit: don't clear c_cc[VINTR]
First change fixes "read -n NUM". Apparently poll() won't report
data availability if cc[VMIN] > 1 until there are at least cc[VMIN] bytes.

function                                             old     new   delta
read_line_input                                     3885    3877      -8
shell_builtin_read                                  1097    1087     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-18)             Total: -18 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-01-15 22:58:06 +01:00
Denys Vlasenko
c0cae52662 lineedit: fix build failure
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-11-04 01:09:09 +01:00
Denys Vlasenko
9ce09bc9cb lineedit: add support for M-b, M-f, M-d, M-Backspace
function                                             old     new   delta
ctrl_left                                              -      96     +96
ctrl_right                                             -      76     +76
static.esccmds                                        81      93     +12
read_line_input                                     3876    3885      +9
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 2/0 up/down: 193/0)             Total: 193 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-11-03 13:28:22 +01:00
Denys Vlasenko
e45af7ad17 lineedit: remove SAVE_HISTORY bit, ->hist_file can be used as indicator
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-09-04 16:15:24 +02:00
Denys Vlasenko
bede215cf1 lineedit: add support for history saving on exit
Based on the patch by Dennis Groenen <tj.groenen@gmail.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-09-04 16:12:33 +02:00
Denys Vlasenko
4840ae8a06 lineedit: fix atomic replace of history file; hush: fix $HISTFILE handling
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-09-04 15:28:03 +02:00
Denys Vlasenko
a669eca3a2 libbb/lineedit: implement optional Ctrl-R history search
function                                             old     new   delta
read_line_input                                     3433    3957    +524
load_string                                           77      90     +13
input_tab                                           1086    1069     -17
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 537/-17)           Total: 520 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-07-11 07:36:59 +02:00
Alexey Fomenko
232ebaa568 lineedit: fix rare SEGV; mark a few FIXMEs
Signed-off-by: Alexey Fomenko <ext-alexey.fomenko@nokia.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-05-20 04:26:29 +02:00
Denys Vlasenko
e3d8d077b7 small fix for HISTFILESIZE
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-03-31 14:39:38 +02:00
Denys Vlasenko
2c4de5b045 ash,hush: optional support for $HISTFILESIZE.
Based on patch from Alexey Fomenko (ext-alexey.fomenko AT nokia.com)

function                                             old     new   delta
size_from_HISTFILESIZE                                 -      44     +44
hush_main                                            998    1025     +27
ash_main                                            1348    1374     +26
read_line_input                                     3361    3372     +11
new_line_input_t                                      17      24      +7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-03-31 13:16:52 +02:00
Denys Vlasenko
353680aa46 lineedit: fixes for CONFIG_UNICODE_USING_LOCALE=y
function                                             old     new   delta
load_string                                           45      91     +46
save_string                                           40      82     +42
reinit_unicode                                        34      61     +27
BB_PUTCHAR                                            97     120     +23
init_unicode                                          17      37     +20
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/0 up/down: 158/0)             Total: 158 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-03-27 01:18:07 +01:00
Denys Vlasenko
66c5b12dbf ash: fix TMOUT not restoring tty attributes
function                                             old     new   delta
pgetc                                                420     500     +80
readtoken1                                          3202    3239     +37
read_line_input                                     3316    3337     +21
udhcpc_main                                         2610    2630     +20
file_get                                             266     272      +6
expandarg                                            958     963      +5
localcmd                                             257     259      +2
addLines                                              85      87      +2
read_line                                             94      95      +1
ed_main                                             2540    2541      +1
timed_out                                              1       -      -1
lineedit_read_key                                    256     255      -1
alrm_sighandler                                       44       -     -44
cmdloop                                              539     434    -105
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 10/2 up/down: 175/-151)          Total: 24 bytes
   text    data     bss     dec     hex filename
 887379     936   17200  905515   dd12b busybox_old
 887411     936   17192  905539   dd143 busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-02-08 05:07:02 +01:00
Mike Shal
f3763033e4 lineedit: fix tab-completion of filenames with spaces
Using ash in busybox git version dea28e1e, tab completion doesn't seem
to work properly for filenames that have special characters (such as
spaces) in them. For example, with filenames "foo bar" and "foo zap",
typing "ls fo<TAB>" correctly expands to "ls foo\ ", but then
continuing to type "b<TAB>" will produce "ls foo\ bbar", which is not
correct (the 'b' is duplicated).

Signed-off-by: Mike Shal <marfey@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-11-22 03:49:18 +01:00
Wolfram Sang
2e9aeae4db lineedit: create history files with mode 0600
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-11-15 02:58:28 +01:00
Marek Polacek
7b18107384 *: use _exit() in sighandlers; showkey: do not use exit-thru-sighandler
While at it, make ESC sequences more readable; and removed check for
isatty(stdin) in reset. Code shrink:

   text    data     bss     dec     hex filename
 884771     936   17216  902923   dc70b busybox_old
 884723     936   17216  902875   dc6db busybox_unstripped

Signed-off-by: Marek Polacek <mmpolacek@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-10-28 21:34:56 +02:00
Denys Vlasenko
d55f599440 lineedit: do not hang on error, but return error indicator.
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2010-09-07 18:40:53 +02:00
Denys Vlasenko
3926363214 lineedit: on tab completion, show filenames obly in all cases (bash compat)
function                                             old     new   delta
complete_cmd_dir_file                                731     730      -1

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2010-09-03 14:11:08 +02:00
Denys Vlasenko
76939e7b72 lineedit: allocate matchBuf only temporarily: saves MAX_LINELEN bytes
function                                             old     new   delta
input_tab                                           1027    1041     +14
build_match_prefix                                   590     562     -28
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 14/-28)            Total: -14 bytes

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2010-09-03 14:09:24 +02:00
Denys Vlasenko
ba0e103a66 lineedit: de-indent large block in input_tab. No logic changes.
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2010-09-03 14:08:24 +02:00
Denys Vlasenko
a46e16ef52 lineedit: rename tmp -> chosen_match; small code shrink
function                                             old     new   delta
input_tab                                           1016    1012      -4

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2010-09-03 13:05:51 +02:00
Denys Vlasenko
9b56bf5416 lineedit: stop using permanent int_buf[] (16k!): allocate it
Now it is allocated temporarily only for the duretion of prefix generation,
and also we only allocate the needed size, not maximally possible.

function                                             old     new   delta
build_match_prefix                                   579     590     +11
remove_chunk                                          43      28     -15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 11/-15)             Total: -4 bytes

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2010-09-03 13:02:47 +02:00
Denys Vlasenko
81254ed387 lineedit: remove pos_buf[] array (up to 16k!); fix compat bugs
pos_buf is a strange hack, easy to do without it.
This also allows lines >32k long to be handled.
Also simplified match prefix generations and made behavior more like bash.

function                                             old     new   delta
remove_chunk                                           -      43     +43
collapse_pos                                          79       -     -79
build_match_prefix                                   804     579    -225
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/1 up/down: 43/-304)          Total: -261 bytes

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2010-09-03 12:59:15 +02:00
Denys Vlasenko
3c460b005c lineedit: return prefix len from tab completion helpers
This kills horrific logic which deletes and re-adds prefix (!)

function                                             old     new   delta
complete_cmd_dir_file                                705     731     +26
complete_username                                    121     124      +3
input_tab                                           1041    1016     -25
build_match_prefix                                   838     804     -34
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 29/-59)            Total: -30 bytes

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2010-09-03 12:56:36 +02:00
Denys Vlasenko
2679e3c8cc lineedit: clean up tab completion code (variable reuse, comments)
Noted bugs in behavior.
Added debugging machinery.
Decoupled variables reused for unrelated purposes: apparently,
when not forced to use liveness analysis, gcc fares better.

function                                             old     new   delta
complete_cmd_dir_file                                699     705      +6
collapse_pos                                          75      79      +4
build_match_prefix                                   892     838     -54
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 10/-54)            Total: -44 bytes

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2010-09-03 12:53:15 +02:00