Screen Corruption when browsing Command History with Custom Prompt
From: root To: bug-bash@gnu.org,[EMAIL PROTECTED] Subject: Screen Corruption when browsing Command History with Custom Prompt Configuration Information [Automatically generated, do not change]: Machine: i486 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i486' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-pc-linux-gnu' -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I../bash -I../bash/include -I../bash/lib -g -O2 -Wall uname output: Linux Ashley-Ubuntu 2.6.24-19-generic #1 SMP Wed Aug 20 22:56:21 UTC 2008 i686 GNU/Linux Machine Type: i486-pc-linux-gnu Bash Version: 3.2 Patch Level: 39 Release Status: release Description: I'm using a custom prompt using ~/.bashrc, given below: PS1="\n\e[0;31m\u: \w\n# \e[m" When I browse the command history using the up/down arrow buttons, some of the first few characters get stuck to the prompt. However, if I move the cursor until it reaches the position just after these characters, I can type-in the command I want and it works - even though someone who sees the screen later will wonder how it did work. For example, this is how my bash screen looks after I've run the ls command: root: /home/ash # gedls Desktop Documents Examples Music My Games Pictures Public Templates Videos root: /home/ash # It looks as if I've run a command 'gedls', whereas the first three characters are left-overs from the 'gedit' command I ran just before it. The output is exactly what I expect, but I can't seem to delete the 'ged' from the prompt. Repeat-By: Set a custom prompt using the PS1 variable as follows: PS1="\n\e[0;31m\u: \w\n# \e[m" Then, browse command history using up/down keys. The issue appears when the newline (\n) characters and the coloring sequences (\e[0;31m, \e[m) are used together in the prompt.
Re: Screen Corruption when browsing Command History with Custom Prompt
The escape sequence for adding colors are an exception - If you add backslashes to those brackets, it won't (and doesn't) work as expected. I tried what you said : Set PS1 = "\n\e\[0;31m\u: \w\n# \e\[m" The resulting prompt did, still, exhibit the corruption explained in my bug report, and the prompt appeared as follows: 0;31mroot: /home/ash # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * It seems I shouldn't have used the \e character.. The default Ubuntu .bashrc has another way of doing it, which I tried to learn from. And it seems it works! Here is my working sequence (and no screen corruption!) PS1="\n\[\033[0;31m\]\u: \w\n# \[\033[00m\]" Note that not all square brackets are preceded with backslashes! Thanks for replying anyway. I was only trying to copy-paste from the web, but overlooked the example that was already in the default .bashrc !! Sorry for the trouble.. -- Regards, Ashley. On Tue, Sep 9, 2008 at 11:49 PM, Chet Ramey <[EMAIL PROTECTED]> wrote: > Ashley Wilson wrote: > >> Repeat-By: >> >>Set a custom prompt using the PS1 variable as follows: >> >>PS1="\n\e[0;31m\u: \w\n# \e[m" >> >>Then, browse command history using up/down keys. > > As the documentation states, you need to bracket sequences of non-printing > characters in prompt strings with the \[ and \] escape sequences. > > Chet > >
Re: Screen Corruption when browsing Command History with Custom Prompt
No, Wait! That's not the issue!! This works just fine: PS1="\n\[\e[0;32m\]\u: \w\n# \[\e[m\]" So, all I had to do was to add '\[' before and '\]' after the coloring sequence to fix everything! -- Regards, Ashley. On Wed, Sep 10, 2008 at 12:51 AM, Ashley Wilson <[EMAIL PROTECTED]> wrote: > The escape sequence for adding colors are an exception - If you add > backslashes to those brackets, it won't (and doesn't) work as > expected. > > I tried what you said : Set > > PS1 = "\n\e\[0;31m\u: \w\n# \e\[m" > > The resulting prompt did, still, exhibit the corruption explained in > my bug report, and the prompt appeared as follows: > >0;31mroot: /home/ash > # > > * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * > * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * > * * * * * > > It seems I shouldn't have used the \e character.. The default Ubuntu > .bashrc has another way of doing it, which I tried to learn from. And > it seems it works! Here is my working sequence (and no screen > corruption!) > > PS1="\n\[\033[0;31m\]\u: \w\n# \[\033[00m\]" > > Note that not all square brackets are preceded with backslashes! > > Thanks for replying anyway. I was only trying to copy-paste from the > web, but overlooked the example that was already in the default > .bashrc !! > > Sorry for the trouble.. > > -- > Regards, > Ashley. > > > On Tue, Sep 9, 2008 at 11:49 PM, Chet Ramey <[EMAIL PROTECTED]> wrote: >> Ashley Wilson wrote: >> >>> Repeat-By: >>> >>>Set a custom prompt using the PS1 variable as follows: >>> >>>PS1="\n\e[0;31m\u: \w\n# \e[m" >>> >>>Then, browse command history using up/down keys. >> >> As the documentation states, you need to bracket sequences of non-printing >> characters in prompt strings with the \[ and \] escape sequences. >> >> Chet >> >> >
Re: Screen Corruption when browsing Command History with Custom Prompt
On Wed, Sep 10, 2008 at 3:02 AM, Matthew Woehlke <[EMAIL PROTECTED]> wrote: > Ashley Wilson wrote: >> >> No, Wait! That's not the issue!! This works just fine: >> >> PS1="\n\[\e[0;32m\]\u: \w\n# \[\e[m\]" >> >> So, all I had to do was to add '\[' before and '\]' after the coloring >> sequence to fix everything! > > Of course it works; this is exactly what Chet was trying to tell you. > > -- > Matthew > ENOCOFFEE: operator suffering from lack of sleep and/or early-morning-itis > Yes, I realize that now. Thanks Mathew, Chet. -- Regards, Ashley.