From hugo.raguet at centraliens.net  Tue Feb  7 09:59:19 2017
From: hugo.raguet at centraliens.net (Hugo Raguet)
Date: Tue, 7 Feb 2017 09:59:19 +0100
Subject: [Rd] buggy ANSI escape sequences in R prompt
Message-ID: <CAB4ZKxM1WqQ+qbWb9p7GBNPLs2Fbiu6PBHPVnhajmtQDW_6ZBg@mail.gmail.com>

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]]



[Rd] buggy ANSI escape sequences in R prompt
Hugo Raguet