You are not logged in.

#1 2010-05-19 12:31:31

d_d
Member
Registered: 2009-11-18
Posts: 12

[SOLVED]Bash/Readline: line garbled when using up, down, home, end

Ok, This is driving me crazy at the moment.

The home and end keys are being recognised, and jump to the right location in the string, but the visual display is messed up. When I press <home> after a long line, the cursor now jumps to the middle of the command. Similarly with <end>. The actual cursor seems to get out of sync with the visual cursor, and it is driving me crazy!

For example: cursor shown as []

>a-very-long --command --with --args[]
#Press <home>
>a-very-long --[c]ommand --with --args
#Press <end>
>a-very-long --command --with --args                []

Similarly, using <up> to move through your history garbles your line:

>once-again --some --long --command
...output...
>cat foo.txt
...output...
#Press <up> twice to get to previous command:
>once-again --scat foo.txt

Does anyone know what is causing this? Is there a way to fix it?

Last edited by d_d (2010-05-19 12:54:33)

Offline

#2 2010-05-19 12:50:24

hbekel
Member
Registered: 2008-10-04
Posts: 311

Re: [SOLVED]Bash/Readline: line garbled when using up, down, home, end

This sounds like a bad PS1. If you use color escape sequences in your prompt, you'll have to enclose them in \[ and \] so that bash can calculate the proper prompt length. In fact this applies to all non-printable characters in your prompt.

For example, my PS1 looks like this:

PS1="\[\033[0;36m\]\w\$> \[\033[0m\]"

Your second problem is probably due to the same issue.

Last edited by hbekel (2010-05-19 12:51:03)

Offline

#3 2010-05-19 12:54:12

d_d
Member
Registered: 2009-11-18
Posts: 12

Re: [SOLVED]Bash/Readline: line garbled when using up, down, home, end

Thanks hbekel! That was it.

Offline

Board footer

Powered by FluxBB