peterh/liner

Cursor position calculation seems off when colored prompt is used

Closed this issue · 2 comments

The use case is to colorize the prompt. If the prompt-string input to line.Prompt() is colored, the tab completion moves the cursor much further. The tab works well with regular non-colored strings. I tried different ways to escape the strings but had not luck.

Operating System: Linux Centos
Terminal Emulator: ssh via Mac Terminal.

Here is the issue which is specific to readline/python:
http://wiki.hackzine.org/development/misc/readline-color-prompt.html

I tried escaping my string in the following ways:

// Colorize given string.
func green(s string) string {
// return "\x01\x1b[0;32m\x02" + s + "\x01\x1b[0m\x02"
// return "\001\033[1;32m\002" + s + "\001\033[0m\002"
// return "[1;32m" + s + "[0m"
}

None of the above ways helped.

Looks like there is an open pull-request #80 by @alvarolm to fix this issue. Please close this issue when that change is merged.

Sorry for the late reply.

That will never work in liner on Windows, because I don't want to write a VT102-to-Windows-Console library. Since liner is an opinionated cross-platform library, that will never work in liner. If you need colour, I recommend finding another command line input package. Sorry about that.