You are not logged in.

#1 2010-06-26 17:41:35

ssri
Member
Registered: 2010-02-16
Posts: 216

[SOLVED]Bash cli input truncated after customizing prompt with colors

Here is my customized prompt (two lines) in ~/.bashrc (colors defined):

PS1="${CYAN}┌─${NC}\u@\h ${LIGHTBLUE}\w${NC}\n${CYAN}└─{${NC}\@${CYAN}}──${LIGHTCYAN}>${NC} "

It looks like this:

┌─ssri@host ~/Projects/cairo-dock
└─{10:26 AM}──>

Now, when I have a long entry (removing multiple packages, ie pacman removal of cairo-dock-bzr & cairo-dock-plugins-bzr), the input entry does not extend to the edge of my konsole window (80x33).  Insteads it stops halfway and continues onto the second line.  Since this prompt takes up two lines, the second line portion of the prompt is now overrunned and the entry is considerably garbled:

┌─ssri@host ~/Projects/cairo-dock
-plugins-bzr ─> pacman -R cairo-dock-bzr cairo-dock-

I'm wondering how I can extend keyboard entries towards 80 columns(?) and allow extended entries to continue onto a third line (rather than the second).

Thanks

Last edited by ssri (2010-06-26 21:03:27)

Offline

#2 2010-06-26 18:03:16

Vain
Member
Registered: 2008-10-19
Posts: 179
Website

Re: [SOLVED]Bash cli input truncated after customizing prompt with colors

How do you define your colors? You're supposed to put "\[" and "\]" around the escape sequences:

C_RESET='\[\033[00m\]'
C_BOLD='\[\033[01m\]'
C_UNDERLINED='\[\033[04m\]'
...

This way, the shell knows that these sequences are non-printable characters. If you omit the additional braces, the shell thinks that your escape sequences are actually printed -- which results in "too short" lines.

Offline

#3 2010-06-26 18:17:56

ssri
Member
Registered: 2010-02-16
Posts: 216

Re: [SOLVED]Bash cli input truncated after customizing prompt with colors

I didn't have "\]" from before

BEFORE

BLACK='\e[0;30m'
BLUE='\e[0;34m'
GREEN='\e[0;32m'
CYAN='\e[0;36m'
RED='\e[0;31m'
PURPLE='\e[0;35m'
BROWN='\e[0;33m'
LIGHTGRAY='\e[0;37m'
DARKGRAY='\e[1;30m'
LIGHTBLUE='\e[1;34m'
LIGHTGREEN='\e[1;32m'
LIGHTCYAN='\e[1;36m'
LIGHTRED='\e[1;31m'
LIGHTPURPLE='\e[1;35m'
YELLOW='\e[1;33m'
WHITE='\e[1;37m'
NC='\e[0m'              # No Color

AFTER

BLACK='\e[0;30m\]'
BLUE='\e[0;34m\]'
GREEN='\e[0;32m\]'
CYAN='\e[0;36m\]'
RED='\e[0;31m\]'
PURPLE='\e[0;35m\]'
BROWN='\e[0;33m\]'
LIGHTGRAY='\e[0;37m\]'
DARKGRAY='\e[1;30m\]'
LIGHTBLUE='\e[1;34m\]'
LIGHTGREEN='\e[1;32m\]'
LIGHTCYAN='\e[1;36m\]'
LIGHTRED='\e[1;31m\]'
LIGHTPURPLE='\e[1;35m\]'
YELLOW='\e[1;33m\]'
WHITE='\e[1;37m\]'
NC='\e[0m\]'              # No Color

RESULT = entries are still truncated

Last edited by ssri (2010-06-26 18:18:43)

Offline

#4 2010-06-26 18:19:47

jac
Member
From: /home/jac
Registered: 2009-05-19
Posts: 431
Website

Re: [SOLVED]Bash cli input truncated after customizing prompt with colors

I'm pretty sure you need the '\[' before the colors too, as in Vain's example and the wiki an color bash prompts

Offline

#5 2010-06-26 19:13:33

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: [SOLVED]Bash cli input truncated after customizing prompt with colors

From  the bash manpage:

              \[     begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
              \]     end a sequence of non-printing characters

Color codes are terminal control sequences.


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Offline

#6 2010-06-26 21:03:06

ssri
Member
Registered: 2010-02-16
Posts: 216

Re: [SOLVED]Bash cli input truncated after customizing prompt with colors

jac wrote:

I'm pretty sure you need the '\[' before the colors too, as in Vain's example and the wiki an color bash prompts

Yup, that did it, thanks guys! big_smile

Offline

Board footer

Powered by FluxBB