[Rd] buggy ANSI escape sequences in R prompt

Gábor Csárdi csardi.gabor at gmail.com
Tue Feb 7 14:44:35 CET 2017


I guess that R does not know about ANSI sequences, and it calculates the
width of the prompt including the characters in the sequences. You cannot
do much about this, except maybe use a prompt that has two lines. You can
put the colored text and whatever you like in the first line, and the
second line can be non-ANSI.

Note that this works in the terminal, but does not work in RStudio. RStudio
does not support multi-line prompt currently.

Maybe this is also interesting for you, if you want a dynamic R prompt:
https://github.com/gaborcsardi/prompt#readme (Self-ad, sorry.)

Gabor

On Tue, Feb 7, 2017 at 8:59 AM, Hugo Raguet <hugo.raguet at centraliens.net>
wrote:

> When R is run interactively in a terminal which supports colors, it is
> possible to use ANSI escape sequences in order to put colors in the prompt,
> such as
>
> options(prompt = "\033[0;31mThis is red\033[0m> ")
>
> Unfortunately, something goes wrong because for long command lines, the
> line continuation override the prompt instead of being written in the next
> line. The problem gets worse when using several colors, because somehow
> each escape sequence "takes up some space" in the command line, *up to the
> point that the end of the prompt might overwrite the beginning*. On my
> configuration this happens with for instance
>
> options(prompt = paste("\033[0;31m With \033[0;32m multiple",
>                    "\033[0;33m colors \033[0;34m this",
>                    "\033[0;35m gets \033[0;36m really",
>                    "\033[0;37m wrong! \033[0m"))
>
> Why is it so? Is there a workaround?
>
> PS: This rather old post seems related
>
> http://r.789695.n4.nabble.com/Xterm-escape-sequences-in-
> Prompt-td906375.html
>
> PPS: I posted this question on [R] section of stack overflow
>
> http://stackoverflow.com/questions/42072092/buggy-ansi-
> escape-sequences-in-r-prompt
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

	[[alternative HTML version deleted]]



More information about the R-devel mailing list