bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multiline editing breaks if the previous output doesn't end in newli


From: Koichi Murase
Subject: Re: Multiline editing breaks if the previous output doesn't end in newline
Date: Sat, 29 Oct 2022 16:19:57 +0900

2022年10月29日(土) 15:44 Albert Vaca Cintora <albertvaka@gmail.com>:
> On Sat, Oct 29, 2022 at 7:28 AM Koichi Murase <myoga.murase@gmail.com> wrote:
> > shopt -s checkwinsize
> > { ! type -t tput || tput xenl || tput xn; } &>/dev/null; 
> > _prompt_xenl_offset=$?
> > _prompt_newline() { (:); printf '\e[m%-*s\r\e[K'
> > "$((COLUMNS-_prompt_xenl_offset))" '[EOF]'; }
> > PROMPT_COMMAND+=(_prompt_newline)
>
> It would be great if this got fixed in bash itself, but in the
> meantime this workaround will help, thanks :)
>
> I've noted that it creates some artifacts when you resize the terminal
> after a command that ends without a newline, though.

Isn't that the same for zsh and fish?

> Would you mind explaining the code a bit? Eg: why is  "(:);" in there,

To make Bash update COLUMNS. The manual (see below) says `external
command', but a subshell () works as well.

>From Bash Reference Manual
<https://www.gnu.org/software/bash/manual/bash.html#The-Shopt-Builtin>:
> checkwinsize
>
> If set, Bash checks the window size after each external (non-builtin)
> command and, if necessary, updates the values of LINES and COLUMNS.
> This option is enabled by default.

> or why do we need $_prompt_xenl_offset ?

Because the behavior depends on the terminal capability
"eat_newline_glitch" ("xenl" in terminfo name / "xn" in termcap name).
In a terminal without "eat_newline_glitch", when there are as many
characters in the line as the columns, the cursor automatically moves
to the next line:

$ printf '%*s\rY' "$COLUMNS" X
|  ... X|
|Y      |

But in a terminal with "eat_newline_glitch", the cursor stays at the
last column with an intermediate state:

$ printf '%*s\rY' "$COLUMNS" X
|Y ... X|

VT and XTerm behave in the latter way, and the recent terminals
emulate VT/XTerm, but some terminals/consoles behave in the former
way. To support both types of terminals, one needs to adjust the
number of characters in the line. If you only use the VT terminal
emulators, you can just drop the processing related to
"_prompt_xenl_offset" and just write it like

PROMPT_COMMAND+=('(:); printf "\e[m%-${COLUMNS}s\r\e[K" "[EOF]"')



reply via email to

[Prev in Thread] Current Thread [Next in Thread]