Hello, I have been working on a prompt that I would like to be compatible with busybox. It is a 2-line prompt, the source is here: https://github.com/rkitover/sh-prompt-simple/ It does mostly work, except that when I use file/directory completion, pressing tab deletes the line above the prompt. I have recorded a video to demonstrate this: https://1drv.ms/v/s!AuXve-AbNCkVgdhRmSYz8iwQusZDfQ?e=qCMjy4
Can you specify the value of PS1 which does not work for you?
Yes, it's in my project that I linked here: https://raw.githubusercontent.com/rkitover/sh-prompt-simple/master/prompt.sh Just do: . ./prompt.sh I don't know what specifically in my prompt causes the bug, and I can't paste it here because it has ANSI color codes.
"Please run my obscure 210-line shell script on your system. I promise, nothing untoward will happen". Er. How about "no"? Add echo "$PS1" | hexdump -vC in a relevant part of your script, run it, and post the value of PS1.
The prompt has embedded function calls to functions in that script. Here you go: 00000000 60 5f 53 50 53 5f 63 6d 64 5f 73 74 61 74 75 73 |`_SPS_cmd_status| 00000010 60 20 60 5f 53 50 53 5f 65 6e 76 60 20 60 5f 53 |` `_SPS_env` `_S| 00000020 50 53 5f 63 77 64 60 20 60 5f 53 50 53 5f 67 69 |PS_cwd` `_SPS_gi| 00000030 74 5f 62 61 72 60 0a 1b 5b 33 38 3b 32 3b 31 34 |t_bar`..[38;2;14| 00000040 30 3b 32 30 36 3b 32 35 30 6d 72 6b 69 74 6f 76 |0;206;250mrkitov| 00000050 65 72 1b 5b 31 3b 39 37 6d 40 1b 5b 30 6d 1b 5b |er.[1;97m@.[0m.[| 00000060 33 38 3b 32 3b 31 34 30 3b 32 30 36 3b 32 35 30 |38;2;140;206;250| 00000070 6d 63 6f 6d 70 6c 79 20 1b 5b 33 38 3b 32 3b 32 |mcomply .[38;2;2| 00000080 32 30 3b 32 30 3b 36 30 6d 3e 1b 5b 30 6d 20 0a |20;20;60m>.[0m .| 00000090
Here is the prompt with all of the functions expanded once, it still exhibits the same behavior: 00000000 1b 5b 30 3b 33 32 6d 76 20 1b 5b 30 3b 39 35 6d |.[0;32mv .[0;95m| 00000010 53 55 53 45 20 1b 5b 33 33 6d 7e 20 0a 1b 5b 33 |SUSE .[33m~ ..[3| 00000020 38 3b 32 3b 31 34 30 3b 32 30 36 3b 32 35 30 6d |8;2;140;206;250m| 00000030 72 6b 69 74 6f 76 65 72 1b 5b 31 3b 39 37 6d 40 |rkitover.[1;97m@| 00000040 1b 5b 30 6d 1b 5b 33 38 3b 32 3b 31 34 30 3b 32 |.[0m.[38;2;140;2| 00000050 30 36 3b 32 35 30 6d 63 6f 6d 70 6c 79 20 1b 5b |06;250mcomply .[| 00000060 33 38 3b 32 3b 32 32 30 3b 32 30 3b 36 30 6d 3e |38;2;220;20;60m>| 00000070 1b 5b 30 6d 20 0a |.[0m .|00000076
Tried to reproduce with this: e=`printf '\033'` n=$'\n' PS1="$e[0;32m""v ""$e[0;95m""SUSE ""$e[33m""~ ""$n$e[38;2;140;206;250m""rkitover""$e[1;97m""@""$e[0m$e[38;2;140;206;250m""comply ""$e[38;2;220;20;60m"">""$e[0m " but it works for me: completions do not "eat" previous screen row. What is your version of busybox? Please attach your .config.
Same result for me with your code. BusyBox v1.34.1 () multi-call binary. This is from OpenSUSE Tumbleweed, the package is: busybox-1.34.1-2.1.x86_64 This is the config they use: https://build.opensuse.org/package/view_file/Base:System/busybox/busybox.config?expand=1
lineedit.c: * lineedit does not know that the terminal escape sequences do not * take up space on the screen. The redisplay code assumes, unless * told otherwise, that each character in the prompt is a printable * character that takes up one character position on the screen. * You need to tell lineedit that some sequences of characters * in the prompt take up no screen space. Compatibly with readline, * use the \[ escape to begin a sequence of non-printing characters, * and the \] escape to signal the end of such a sequence. Example: * * PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] ' Your PS1 has no such annotations and this what makes line editing code to incorrectly conclude that line has wrapped when it did not. The very same PS1 also misbehaves in bash. (This depends on terminal width, this is why it did not happen to me in a wider terminal). This PS1 would work: PS1="\[$e[0;32m\]""v ""\[$e[0;95m\]""SUSE ""\[$e[33m\]""~ ""\n\[$e[38;2;140;206;250m\]""rkitover""\[$e[1;97m\]""@""\[$e[0m$e[38;2;140;206;250m\]""comply ""\[$e[38;2;220;20;60m\]"">""\[$e[0m\] " ...but their .config has this: # CONFIG_FEATURE_EDITING_FANCY_PROMPT is not set which disables the \[ \] feature (and all other useful magic for PS1, such as \u \w). It needs to be enabled...
In bash I use the \001 and \002 escape sequences for this, so my prompt works there. Do the \[ and \] sequences map to a character? How can I detect busybox ash as opposed to ksh or something like that? I will get the suse package fixed.
bash supports \[ \] too.