Bug 678578

Summary: Cursor position when completing and using a prompt with colour escape characters is wrong
Product: [Fedora] Fedora Reporter: Enrique <cquike>
Component: zshAssignee: James Antill <james.antill>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 13CC: james.antill
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-02-18 15:03:32 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Enrique 2011-02-18 14:08:39 UTC
Description of problem:

 I am using a prompt with some colour characters, like:

PROMPT=$'\e[0;32muser@host:\e[0;34m%/+ \e[0m'

which uses escape sequences to display green and blue colours.
However, if I press tab to complete files, the cursor position is moved to the right, like:

user@host:/tmp+ ls file           ls file
file1  file2
 
 The first "ls file" is what I typed, while the second one appears when I press tab. It seems that the sequence characters are also counted to place the cursor after completion.
 Related to that is the breaking of long lines before one reaches the rightmost end of the terminal. That makes also very annoying to recover commands from the history longer than the terminal width.


How reproducible:
 
 Always

Comment 1 James Antill 2011-02-18 15:03:32 UTC
1. Don't use \e directly, use %F{red} and %K{blue} etc.

2. Use %{\e[0;32m%}blah ... which tells the prompt that the characters are zero width (also see the docs. for %G.

Comment 2 Enrique 2011-02-19 18:18:28 UTC
 Option 2. worked perfectly. It is a pleasure to see a promptly and accurate response.
 Thank you!