SUMMARY I have observed this behavior for a long time, I think in different terminals. Atm I am using KDE and Konsole, so I report it here first. STEPS TO REPRODUCE Open a terminal. Run `echo -n hello`. Use "Up" key to get the previous command. Use "Down" arrow key to get back to the empty prompt. Use "Up" again. EXPECTED RESULT After running `echo -n hello`: ``` ~ $ echo -n hello hello~ $ ``` After "Up" arrow key: ``` ~ $ echo -n hello hello~ $ echo -n hello ``` After "Down" arrow key: ``` ~ $ echo -n hello hello~ $ ``` After second "Up" arrow key: ``` ~ $ echo -n hello hello~ $ echo -n hello ``` OBSERVED RESULT (first two steps as in "Expected") After "Down" arrow key: ``` ~ $ echo -n hello hell ``` After second "Up" arrow key: ``` ~ $ echo -n hello hellecho -n hello ``` NOTES The behavior gets worse if the last command output was multiple lines long, or the command itself is multiple lines long. SOFTWARE/OS VERSIONS Operating System: Ubuntu 22.04 KDE Plasma Version: 5.24.7 KDE Frameworks Version: 5.92.0 Qt Version: 5.15.3 Kernel Version: 5.15.0-56-generic (64-bit) Graphics Platform: X11
Could also be a problem with bash or xterm.
This seems to be my own problem, caused by a PS1 setting in .bashrc. So, probably not a problem of Konsole. Sorry for the noise!
Actually no. After normalizing $PS1, I still see this problem occur. See also https://unix.stackexchange.com/questions/731987/terminal-history-up-down-broken-if-last-command-output-does-not-end-in-newline
That's just bash (actually readline) thinking that the prompt starts at the leftmost position of the current line, then when you press Down, just moving to position 5, and clearing to the end of line. When you press Down, bash sends the following to the terminal: \r\33[C\33[C\33[C\33[C\33[K That's a carriage return to move to the leftmost position of the current line, four (the length of the prompt) CUF (Cursor Forward) control sequences, and an EL (Erase in Line) control sequence, which with parameter 0 (default) clears from the current cursor position to the end of the line.
@ninjalj Thanks for the response in both places. I am not happy with this behavior of bash, but I don't really know where to take it from here. I don't know where I would file feature requests for bash. Perhaps I just need to find an alternative to bash.
Add '\[\e]133;L\a\]' at the start of PS1. This is a conditional newline, so it does nothing if the previous output ended in newline, and a newline if the last output did not end in newline.
> Add '\[\e]133;L\a\]' at the start of PS1. This is a conditional newline, so it does nothing if the previous output ended in newline, and a newline if the last output did not end in newline. This sounds great, but it does nothing for me.. ~ $ echo $PS1 \[\e]133;L\a\]\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;34m\]\w\[\033[00m\] \$ ~ $ echo -n hello hello~ $ ~ $ export PS1="\[\e]133;L\a\] \$" $ecoh^C $export PS1="\[\e]133;L\a\] \$ " $ echo -n hello hello $ The "hello" is still always on the same line. Btw, where could I look up these character sequences?
This person is asking for something similar, https://stackoverflow.com/questions/58626170/print-a-blank-line-in-bash-only-after-output
(In reply to donquixote from comment #7) > > Add '\[\e]133;L\a\]' at the start of PS1. This is a conditional newline, so it does nothing if the previous output ended in newline, and a newline if the last output did not end in newline. > > This sounds great, but it does nothing for me.. > > ~ $ echo $PS1 > \[\e]133;L\a\]\[\e]0;\u@\h: This escape sequence is only supported since 22.08 (In reply to donquixote from comment #8) > This person is asking for something similar, > https://stackoverflow.com/questions/58626170/print-a-blank-line-in-bash-only- > after-output It is a feature that is easy to add to konsole, but currently there is nothing that does this. There are some options to make finding command start easier (separating line, alternating background).