[ESS] ANSI escape sequences in ESS

Richard M. Heiberger rmh at temple.edu
Thu May 14 21:03:52 CEST 2015


I tried this in Windows

> library(memoise, lib.loc="C:/Users/rmh/Documents/R/win-library/3.2/")
> library(crayon, lib.loc="C:/Users/rmh/Documents/R/win-library/3.2/")
> (red("abcd\n"))
[1] "abcd\n"
> Sys.getenv("SHELL")
[1] "c:/cygwin/bin/bash.exe"
> Sys.setenv("TERM"="xterm-256color")
> (red("abcd\n"))
[1] "abcd\n"
> has_color()
[1] FALSE
## I redefined has_color by ess-developing the crayon package
> has_color()
[1] TRUE
> (red("abcd\n"))
[1] "\033[31mabcd\n\033[39m"
> Sys.setenv(COLORTERM = "emacs")
> (red("abcd\n"))
[1] "\033[31mabcd\n\033[39m"
> find("has_color")
[1] "package:crayon"
>

As you see, the ansi codes are produced and then displayed in octal on
the screen.

I found this, which is old, and it says emacs for windows didn't
support color then
http://osdir.com/ml/help-emacs-windows-gnu/2011-05/msg00023.html

Further searching didn't come up immediately with anything useful.

On Thu, May 14, 2015 at 2:05 PM, Martin Maechler
<maechler at stat.math.ethz.ch> wrote:
> The solution is quite easy.  At least on that one of my computers where
> crayon did not work:
>
> You just need to make sure the   has_color()  function (from the
> crayon package) returns TRUE.
> On  a  non-Windows platform,
> the following should work
>
> Sys.setenv(COLORTERM = "emacs")
>
> After that,
>     example(green)
> works for me also on my new Fedora 21 - Notebook  where things did not
> work out of the box.
> It seems  Ubuntu does set COLORTERM at least in some cases, and that's
> why things worked there automatically.
>
> We could add the above line to the the initial R commands that ESS
> "sends for us" on startup.
> This will not help for the crayon package as its  has_color()  will
> currently always return FALSE  on Windows.
> (and maybe the crayon author knows more than I do, and is sure that
> these ANSI sequence will never work in emacs ESS in any incantation on
> Windows ?)
>
> Martin
>
> Martin
>
> On Tue, May 12, 2015 at 8:13 AM, Martin Maechler
> <maechler at stat.math.ethz.ch> wrote:
>> On Tue, May 12, 2015 at 12:40 AM, Vitalie Spinu <spinuvit at gmail.com> wrote:
>>>
>>>
>>> Don't you have TERM=dumb in process-environment list?
>>>
>>> What's the value of Sys.getenv("TERM") for you?
>>
>> Yes, I do have both   TERM=dumb  set... I have some non-default comint
>> settings.. Probably one of those must help....
>> ...
>> actually "no":
>>
>> emacs24 -Q
>>
>> manually    M-x load-file ...../ess/lisp/ess-site.el
>>                    M-x R
>> and it works ...
>>
>> for me.
>>
>>
>>
>>>
>>>  >>> Martin Maechler on Mon, 11 May 2015 23:02:05 +0200 wrote:
>>>
>>>  > Interestingly, this *works* extremely nicely for me,  using emacs
>>>  > 23.4.1 (still the default on ubuntu 14.03 LTS).
>>>  > I attach an emacs window screen shot, which at least Vitalie and Tamas will get.
>>>
>>>  > (R 3.2.0 patched, "current";  emacs 15.09-devel "current")
>>>
>>>  > Martin
>>>
>>>  > On Mon, May 11, 2015 at 1:23 AM, Vitalie Spinu <spinuvit at gmail.com> wrote:
>>>  >>
>>>  >> We are not even getting those delimiters because TERM var is "dumb" by
>>>  >> default. You can either:
>>>  >>
>>>  >> Sys.setenv(TERM = "xterm-256color")
>>>  >>
>>>  >> directly in R, or prepend that to process-environment in emacs.
>>>  >>
>>>  >> Vitalie
>>>  >>
>>>  >>
>>>  >> >>> Tamas Papp on Sun, 10 May 2015 17:28:49 +0200 wrote:
>>>  >>
>>>  >> > On Fri, May 08 2015, Vitalie Spinu <spinuvit at gmail.com> wrote:
>>>  >>
>>>  >> >> >>> Tamas Papp on Fri, 08 May 2015 13:23:54 +0200 wrote:
>>>  >> >>
>>>  >> >> > Hi,
>>>  >> >> > I saw some R packages that implement ANSI escapes in R and Julia, eg
>>>  >> >> > https://github.com/gaborcsardi/crayon . But when I tried this in ESS/R,
>>>  >> >> > the output was unchanged, in Julia I saw the escapes.
>>>  >> >>
>>>  >> >> There is ansi-color-process-output in comint-output-filter-functions so
>>>  >> >> it should work in principle. But, as R is not producing any of shush, it
>>>  >> >> was never tested.
>>>  >> >>
>>>  >> >> If you give a small reproducible example that works in terminal but not
>>>  >> >> in ESS, I might have a look at it.
>>>  >>
>>>  >> > Hi Vitalie,
>>>  >>
>>>  >> > This works in the terminal, but not in Emacs/ESS (versions below):
>>>  >>
>>>  >> > install.packages("crayon")
>>>  >> > library(crayon)
>>>  >> > cat(green("test\n"))
>>>  >>
>>>  >> > Should print "test" in green.
>>>  >>
>>>  >> > Thanks for looking into this.
>>>  >>
>>>  >> > Best,
>>>  >>
>>>  >> > Tamas
>>>  >>
>>>  >> > PS.: Versions:
>>>  >>
>>>  >> > GNU Emacs 24.4.1 (x86_64-pc-linux-gnu, GTK+ Version 3.14.5) of
>>>  >> > 2015-03-07 on trouble, modified by Debian
>>>  >>
>>>  >> > ess-version: 15.09-devel [elpa: 20150423.923] (loaded from /home/tamas/.emacs.d/elpa/ess-20150423.923/)
>>>  >>
>>>  >> > R version:
>>>  >> >                _
>>>  >> > platform       x86_64-pc-linux-gnu
>>>  >> > arch           x86_64
>>>  >> > os             linux-gnu
>>>  >> > system         x86_64, linux-gnu
>>>  >> > status
>>>  >> > major          3
>>>  >> > minor          2.0
>>>  >> > year           2015
>>>  >> > month          04
>>>  >> > day            16
>>>  >> > svn rev        68180
>>>  >> > language       R
>>>  >> > version.string R version 3.2.0 (2015-04-16)
>>>  >> > nickname       Full of Ingredients
>>>  >>
>>>  >> > Crayon: 2015-04-09 00:30:34
>>>  >>
>>>  >> ______________________________________________
>>>  >> ESS-help at r-project.org mailing list
>>>  >> https://stat.ethz.ch/mailman/listinfo/ess-help>
>>>
>>>
>>>
>>
>>>
>>>
>>>  >>> Martin Maechler on Mon, 11 May 2015 23:02:05 +0200 wrote:
>>>
>>>  > Interestingly, this *works* extremely nicely for me,  using emacs
>>>  > 23.4.1 (still the default on ubuntu 14.03 LTS).
>>>  > I attach an emacs window screen shot, which at least Vitalie and Tamas will get.
>>>
>>>  > (R 3.2.0 patched, "current";  emacs 15.09-devel "current")
>>>
>>>  > Martin
>>>
>>>  > On Mon, May 11, 2015 at 1:23 AM, Vitalie Spinu <spinuvit at gmail.com> wrote:
>>>  >>
>>>  >> We are not even getting those delimiters because TERM var is "dumb" by
>>>  >> default. You can either:
>>>  >>
>>>  >> Sys.setenv(TERM = "xterm-256color")
>>>  >>
>>>  >> directly in R, or prepend that to process-environment in emacs.
>>>  >>
>>>  >> Vitalie
>>>  >>
>>>  >>
>>>  >> >>> Tamas Papp on Sun, 10 May 2015 17:28:49 +0200 wrote:
>>>  >>
>>>  >> > On Fri, May 08 2015, Vitalie Spinu <spinuvit at gmail.com> wrote:
>>>  >>
>>>  >> >> >>> Tamas Papp on Fri, 08 May 2015 13:23:54 +0200 wrote:
>>>  >> >>
>>>  >> >> > Hi,
>>>  >> >> > I saw some R packages that implement ANSI escapes in R and Julia, eg
>>>  >> >> > https://github.com/gaborcsardi/crayon . But when I tried this in ESS/R,
>>>  >> >> > the output was unchanged, in Julia I saw the escapes.
>>>  >> >>
>>>  >> >> There is ansi-color-process-output in comint-output-filter-functions so
>>>  >> >> it should work in principle. But, as R is not producing any of shush, it
>>>  >> >> was never tested.
>>>  >> >>
>>>  >> >> If you give a small reproducible example that works in terminal but not
>>>  >> >> in ESS, I might have a look at it.
>>>  >>
>>>  >> > Hi Vitalie,
>>>  >>
>>>  >> > This works in the terminal, but not in Emacs/ESS (versions below):
>>>  >>
>>>  >> > install.packages("crayon")
>>>  >> > library(crayon)
>>>  >> > cat(green("test\n"))
>>>  >>
>>>  >> > Should print "test" in green.
>>>  >>
>>>  >> > Thanks for looking into this.
>>>  >>
>>>  >> > Best,
>>>  >>
>>>  >> > Tamas
>>>  >>
>>>  >> > PS.: Versions:
>>>  >>
>>>  >> > GNU Emacs 24.4.1 (x86_64-pc-linux-gnu, GTK+ Version 3.14.5) of
>>>  >> > 2015-03-07 on trouble, modified by Debian
>>>  >>
>>>  >> > ess-version: 15.09-devel [elpa: 20150423.923] (loaded from /home/tamas/.emacs.d/elpa/ess-20150423.923/)
>>>  >>
>>>  >> > R version:
>>>  >> >                _
>>>  >> > platform       x86_64-pc-linux-gnu
>>>  >> > arch           x86_64
>>>  >> > os             linux-gnu
>>>  >> > system         x86_64, linux-gnu
>>>  >> > status
>>>  >> > major          3
>>>  >> > minor          2.0
>>>  >> > year           2015
>>>  >> > month          04
>>>  >> > day            16
>>>  >> > svn rev        68180
>>>  >> > language       R
>>>  >> > version.string R version 3.2.0 (2015-04-16)
>>>  >> > nickname       Full of Ingredients
>>>  >>
>>>  >> > Crayon: 2015-04-09 00:30:34
>>>  >>
>>>  >> ______________________________________________
>>>  >> ESS-help at r-project.org mailing list
>>>  >> https://stat.ethz.ch/mailman/listinfo/ess-help>
>>>
>>>
>>>
>
> ______________________________________________
> ESS-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/ess-help



More information about the ESS-help mailing list