bug-bash
[Top][All Lists]
Advanced

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

Re: Prompt messed up if PS1 contains ANSI escape sequences


From: alex xmb ratchev
Subject: Re: Prompt messed up if PS1 contains ANSI escape sequences
Date: Thu, 7 Sep 2023 16:37:04 +0200

On Thu, Sep 7, 2023, 16:26 Andreas Kähäri <andreas.kahari@abc.se> wrote:

> On Thu, Sep 07, 2023 at 04:03:39PM +0200, Gioele Barabucci wrote:
> > On 07/09/23 15:50, Greg Wooledge wrote:
> > > On Thu, Sep 07, 2023 at 03:46:23PM +0200, Gioele Barabucci wrote:
> > > > On 07/09/23 15:00, alex xmb ratchev wrote:
> > > > > u have to \[ esc-seq \]
> > > > > eg inside \[ and \]
> > > > >
> > > > > PS1=$'\u\[\e[1m\]\h\[\e[0m- '
> > > > >
> > > > > should display hostname bold
> > > >
> > > > Thanks for the suggestion, but adding \] does not really fix the
> problem, it
> > > > just masks it in many cases (better than nothing).
> > >
> > > The \[ \] wrappings are required.  They're not "masking" the problem.
> > > Your prompt is literally set incorrectly without them.
> >
> > Agreed that \] is required. With "masking" I mean that the use of \]
> > prevents the problem I'm referring to from showing up easily. But the
> > problem is still there even when \] is used.
> >
> > The following snippet shows that, even with the final \], Bash produces
> the
> > same erroneous output and miscalculates the cursor position (it just
> needs a
> > longer prompt):
> >
> >     $ long_name="$(printf 'abcdef0123456789/%.0s' {0..20})"
> >     $ mkdir -p /tmp/$long_name
> >     $ cd /tmp/$long_name
> >     $ PS1=$'\n\[\e[1m\]\w\[\e[m\] \$ '
> >
> >     Now press the up arrow, then the down arrow)
> >
> > Regards,
> >
> > --
> > Gioele Barabucci
>
> I can't really reproduce the issue that you are seeing, but isn't the \n
> (the newline) also a non-printable character that should be wrapped in
> \[ \], since it has no width?
>

just from my past trying with multiline prompts , no , only esc seq
bash may parse \n there specially , for internal use .. displayment

-- 
> Andreas (Kusalananda) Kähäri
> Uppsala, Sweden
>
> .
>
>


reply via email to

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