aboutsummaryrefslogtreecommitdiff
path: root/libbb/lineedit.c
AgeCommit message (Collapse)Author
2018-04-06hush: fix "unset PS1/PS2", and put them into initial variable setDenys Vlasenko
"unset PS1/PS2" causes prompts to be empty strings function old new delta hush_main 1031 1089 +58 goto_new_line 27 33 +6 fgetc_interactive 244 245 +1 unset_local_var 155 149 -6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/1 up/down: 65/-6) Total: 59 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-25lineedit: allow window size tracking to be disabledRon Yorston
function old new delta lineedit_read_key 269 261 -8 win_changed 47 - -47 read_line_input 3884 3821 -63 cmdedit_setwidth 63 - -63 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 0/2 up/down: 0/-181) Total: -181 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-12-31randomconfig fixesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-11-08lineedit: get terminal width before printing promptDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-11-08lineedit: do not tab-complete any strings which have control charactersDenys Vlasenko
function old new delta add_match 41 68 +27 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-10-12lineedit: improve multiline PS1 - redraw using last PS1 line. Closes 10381Avi Halachmi
This patch only affects prompts with newlines. We redraw the prompt [+ input] occasionally, e.g. during tab completion, history browsing or search, etc, and we expect it to align with prior redraws, such that the visible effect is that only the input changes. With multi-line PS1, redraw always printed the prompt some lines below the old one, which resulted in terminal scroll during every redraw. Now we only redraw the last PS1 line, so vertical alignment is easier to manage (we already calculated it using only the last line, but re-drew all lines - that was the culprit), which fixes those extra scrolls. Notes: - We now use the full prompt for the initial draw, after clear-screen (^L), and after tab-completion choices are displayed. Everything else now redraws using the last/sole prompt line. - During terminal resize we now only redraw the last[/sole] prompt line, which is arguably better because it's hard to do right (and we never did). - Good side effect for reverse-i-search: its prompt now replaces only the last line of the original prompt - like other shells do. function old new delta put_prompt_custom - 66 +66 draw_custom - 66 +66 parse_and_put_prompt 766 806 +40 read_line_input 3867 3884 +17 input_tab 1069 1076 +7 cmdedit_setwidth 61 63 +2 redraw 59 47 -12 put_prompt 46 - -46 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 4/1 up/down: 198/-58) Total: 140 bytes Signed-off-by: Avi Halachmi <avihpit@yahoo.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-09-15less,microcom,lineedit: use common routine to set raw termiosDenys Vlasenko
function old new delta get_termios_and_make_raw - 139 +139 xget1 39 8 -31 read_line_input 3912 3867 -45 less_main 2525 2471 -54 set_termios_to_raw 116 36 -80 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/4 up/down: 139/-210) Total: -71 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-09-13*: use ESC define instead of "\033"; use ESC[m instead of ESC[0mDenys Vlasenko
text data bss dec hex filename 922535 481 6832 929848 e3038 busybox_old 922534 481 6832 929847 e3037 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-02line editing: make read_line_input() not take timeout paramDenys Vlasenko
It's almost always -1. function old new delta read_line_input 3902 3912 +10 new_line_input_t 24 31 +7 pgetc 583 585 +2 save_command_ps_at_cur_history 80 78 -2 read_line 76 74 -2 fgetc_interactive 246 244 -2 addLines 84 82 -2 doCommands 2226 2222 -4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/5 up/down: 19/-12) Total: 7 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-29shell: make standalone shell tab-complete "busybox"Denys Vlasenko
function old new delta busybox_main - 624 +624 packed_usage 31758 31777 +19 applet_names 2638 2646 +8 applet_main 1528 1532 +4 applet_install_loc 191 192 +1 run_applet_and_exit 681 78 -603 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 4/1 up/down: 656/-603) Total: 53 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-11libbb: consolidate the code to set termios unbuffered modeDenys Vlasenko
function old new delta set_termios_to_raw - 116 +116 count_lines 72 74 +2 powertop_main 1458 1430 -28 top_main 943 914 -29 more_main 759 714 -45 fsck_minix_main 2969 2921 -48 conspy_main 1197 1135 -62 rawmode 99 36 -63 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/6 up/down: 118/-275) Total: -157 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-28lineedit: simplify code a bitDenys Vlasenko
function old new delta lineedit_read_key 155 162 +7 put_prompt 51 46 -5 read_line_input 3722 3715 -7 cmdedit_setwidth 81 50 -31 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/3 up/down: 7/-43) Total: -36 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-27lineedit: fix two bugs in SIGWINCH signal handlingDenys Vlasenko
(1) restore entire sigaction, not only signal handler function (2) do not use stdio when not sure WINCH did not interrupt a printf() or such. function old new delta cmdedit_setwidth - 81 +81 read_line_input 3682 3722 +40 lineedit_read_key 138 155 +17 put_prompt 55 51 -4 win_changed 93 47 -46 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/2 up/down: 138/-50) Total: 88 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-25ash,hush: make ^C in interactive mode visually much closer to bash behaviorDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-24lineedit: fix handling of repeating Alt-b, Alt-f, Alt-d, Alt-BackspaceRostislav Skudnov
These key combinations should repeat correctly when the keys are pressed and held. Before this change, they do this erratically - many repeats are "eaten" because they are treated as unrecognized ESC seqs: ESC 0x7f is treated by Alt+baskspace, but ESC 0x7f ESC 0x7f ESC 0x7f is unrecognized. Escape sequences corresponding to these key combinations are moved from read_line_input to lineedit_read_key. Also, these key sequences are now enabled regardless of whether FEATURE_EDITING_VI is set, since Vim does not actually support these key combinations, but they are present in readline library. function old new delta static.esccmds 93 103 +10 read_line_input 3737 3687 -50 Signed-off-by: Rostislav Skudnov <rostislav@tuxera.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-24lineedit: fix completion with applet names. closes 9361Denys Vlasenko
Patch by Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-14lineedit: trivial codeshrink for vi-modeNatanael Copa
Introduce and use BB_isalnum_or_underscore(). function old new delta BB_isalnum_or_underscore - 43 +43 vi_word_motion 162 150 -12 vi_end_motion 163 145 -18 vi_back_motion 198 179 -19 BB_isalnum 39 - -39 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 0/3 up/down: 43/-88) Total: -45 bytes Signed-off-by: Natanael Copa <ncopa@alpinelinux.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-15Rewrite iteration through applet names to save a few bytesRon Yorston
function old new delta run_applet_and_exit 758 755 -3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-3) Total: -3 bytes In standalone shell mode the saving increases to 17 bytes. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-30lineedit: search applets as well as PATH for tab completionRon Yorston
In standalone shell mode search the applet table as well as PATH when tab completing a command. Use a stupid linear search: we're also about to read all the directories on PATH so efficiency isn't a big concern. function old new delta add_match - 53 +53 complete_cmd_dir_file 687 724 +37 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/0 up/down: 90/0) Total: 90 bytes Signed-off-by: Ron Yorston <rmy@frippery.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-12libbb: introduce and use is_prefixed_with()Denys Vlasenko
function old new delta is_prefixed_with - 18 +18 complete_username 78 77 -1 man_main 737 735 -2 fsck_device 429 427 -2 unpack_ar_archive 80 76 -4 strip_unsafe_prefix 105 101 -4 singlemount 1054 1050 -4 rtc_adjtime_is_utc 90 86 -4 resolve_mount_spec 88 84 -4 parse_one_line 1029 1025 -4 parse_conf 1460 1456 -4 may_wakeup 83 79 -4 loadkmap_main 219 215 -4 get_irqs_from_stat 103 99 -4 get_header_cpio 913 909 -4 findfs_main 79 75 -4 fbsplash_main 1230 1226 -4 load_crontab 776 771 -5 expand_vars_to_list 1151 1146 -5 date_main 881 876 -5 skip_dev_pfx 30 24 -6 make_device 2199 2193 -6 complete_cmd_dir_file 773 767 -6 run_applet_and_exit 715 708 -7 uudecode_main 321 313 -8 pwdx_main 197 189 -8 execute 568 560 -8 i2cdetect_main 1186 1176 -10 procps_scan 1242 1230 -12 procps_read_smaps 1017 1005 -12 process_module 746 734 -12 patch_main 1903 1891 -12 nfsmount 3572 3560 -12 stack_machine 126 112 -14 process_timer_stats 449 435 -14 match_fstype 111 97 -14 do_ipaddr 1344 1330 -14 open_list_and_close 359 343 -16 get_header_tar 1795 1779 -16 prepend_new_eth_table 340 323 -17 fsck_main 1811 1794 -17 find_iface_state 56 38 -18 dnsd_main 1321 1303 -18 base_device 179 158 -21 find_keyword 104 82 -22 handle_incoming_and_exit 2785 2762 -23 parse_and_put_prompt 774 746 -28 modinfo 347 317 -30 find_action 204 171 -33 update_passwd 1470 1436 -34 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/49 up/down: 18/-540) Total: -522 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-07libpwdgrp: use getpwent() instead of getpwent_r()Denys Vlasenko
function old new delta massage_data_for_non_r_func - 90 +90 bb_internal_getpwent - 69 +69 getXXnam_r 94 162 +68 fill_bounds 131 128 -3 deluser_main 355 310 -45 complete_username 123 78 -45 getXXnam 163 90 -73 massage_data_for_r_func 103 - -103 bb_internal_getpwent_r 121 - -121 ------------------------------------------------------------------------------ (add/remove: 2/2 grow/shrink: 1/5 up/down: 227/-407) Total: -163 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-15lineedit: don't block when looking for escape sequence in vi-modeRon Yorston
In vi-mode lineedit tries to detect some escape sequences. After the ESC it reads the next character to check for certain values. This read should have a timeout or a user-entered ESC to switch to command mode doesn't properly handle the next character. Signed-off-by: Ron Yorston <rmy@tigress.co.uk> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-10lineedit: don't fall back to simple line input if tty is in raw modeDenys Vlasenko
Testcase: shell command input after python ^Z should still work Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-10lineedit: fix trivial build failureDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-08-20lineedit: use unicode_strwidth instead of unicode_strlenDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-08-19lineedit: fix multi-line PS1 handling: calculate PS1 length from last \nDenys Vlasenko
function old new delta parse_and_put_prompt 755 774 +19 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-08-19lineedit: improve Unicode handling (still buggy though)Denys Vlasenko
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-04-07ash,hush: history builtinFlemming Madsen
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-03-29lineedit: \W on "/bin" should show "bin", not "/bin"Denys Vlasenko
function old new delta parse_and_put_prompt 793 785 -8 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-03-29lineedit: implement \T \t \A \@ prompts escapes, fix \W escape, drop \!Denys Vlasenko
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-28lineedit: add handling of \H in promptDenys Vlasenko
Based on the patch by Arnaud RĂ©billout <rebillout@syscom.ch> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-02-27lineedit: initialize delptrShawn J. Goff
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>
2012-09-27lineedit: in !EDITING config, return -1 on fgets errorDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-08-07lineedit: fix Alt-D when cursor==0Cliff Frey
Signed-off-by: Cliff Frey <cliff@meraki.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-04-26lineedit: histfile can get emptied when CONFIG_FEATURE_EDITING_SAVE_ON_EXIT=yDennis Groenen
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-20whitespace fixesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-01-15shell_builtin_read: set cc[VMIN] to 1; lineedit: don't clear c_cc[VINTR]Denys Vlasenko
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>
2011-11-04lineedit: fix build failureDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-11-03lineedit: add support for M-b, M-f, M-d, M-BackspaceDenys Vlasenko
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-09-04lineedit: remove SAVE_HISTORY bit, ->hist_file can be used as indicatorDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-09-04lineedit: add support for history saving on exitDenys Vlasenko
Based on the patch by Dennis Groenen <tj.groenen@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-09-04lineedit: fix atomic replace of history file; hush: fix $HISTFILE handlingDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-07-11libbb/lineedit: implement optional Ctrl-R history searchDenys Vlasenko
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-05-20lineedit: fix rare SEGV; mark a few FIXMEsAlexey Fomenko
Signed-off-by: Alexey Fomenko <ext-alexey.fomenko@nokia.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-03-31small fix for HISTFILESIZEDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-03-31ash,hush: optional support for $HISTFILESIZE.Denys Vlasenko
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-27lineedit: fixes for CONFIG_UNICODE_USING_LOCALE=yDenys Vlasenko
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-02-08ash: fix TMOUT not restoring tty attributesDenys Vlasenko
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>
2010-11-22lineedit: fix tab-completion of filenames with spacesMike Shal
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-15lineedit: create history files with mode 0600Wolfram Sang
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>