[Rd] buggy ANSI escape sequences in R prompt

Hugo Raguet hugo.raguet at centraliens.net
Tue Feb 7 09:59:19 CET 2017

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


PPS: I posted this question on [R] section of stack overflow


	[[alternative HTML version deleted]]

More information about the R-devel mailing list