Home ^[ escape in shell prompt

# ^[ escape in shell prompt

user1048
1#
user1048 Published in May 26, 2018, 9:36 pm

### Problem

I am writing an application in rust (for fun) that allows me to use DSL to pretty-print git repository stats into my bash shell prompt.

However, I am having an issue with the library I use to format text in the terminal. It uses an escape I haven't seen before, ^[, in the output. It seems to affect the line wrapping such that the text wraps onto the same line before the end of the terminal.

You can see here a demonstration in gnome shell and in hyper.

### Replication

Create a file shell.txt with the following contents:

^[[1;32m\u^[[0m^[[32m@\h^[[0m:^[[1;34m\w^[[0m


Set your prompt command to be the following:

__set_prompt() {
PS1="\$(cat shell.txt)"
}
PROMPT_COMMAND=__set_prompt


### Question

What is the ^[ escape?

Is there a simple fix to get my shell to recognize the line width-properly?

bash --version 4.4.12(1)-release

 You need to login account before you can post.
Processed in 0.304997 second(s) , Gzip On .