Closed tgbugs closed 11 months ago
Thanks for the report. I wrongly assumed that was one of the many comint
things that were for use by things like M-x shell
. I didn't realize people would do that from Racket output.
comint
did this by calling ansi-color-process-output
on all output before inserting into the buffer.
I could pretty simply revive that same indiscriminate behavior, where an escape affects everything in the buffer.
But:
A main motivation for the new REPL is to use structured output. (Typically, many kinds of output get dumped into the same text stream; then you (try to) recover them via regexps. Whereas with the new REPL, the back end preserves the output structure for the front end REPL.)
And so what I'd want to do is revive this more smartly -- to have the escapes affect only portions of the REPL that are stdout or stderr. For example a "blue" escape should affect the color subsequent stdout/sterr output regions in the buffer -- but not other regions, like error messages, prompts, values, file locations, etc.
Doing this would be more work, but not terribly difficult, from a quick glance at ansi-color-apply-on-region
. (I think I can use its ansi-color-context-region
state variable to preserve the codes state, but change the position marker to be the next stdout/stderr region. Or something like that.)
I'll take a look.
From a quick experiment, that seems to work well.
Something like:
> (display "\033[30;47mblah blah blah")
blah blah blah
> (display "foo")
foo
Causes the "blah blah blah" and "foo" regions to be colored -- but not the following prompt and new input. Just as I want and would expect, in the new REPL.
Also I reset any escape code start upon the next racket-run
, which IIUC is correct.
Whereas with M-x shell
and running racket
there, everything is colored, even the prompt and input. And the escape code state is stuck in the buffer until an explicit reset. Which I don't want. (And IIRC is how the old REPL would have done all this.)
So, after sleeping on it and reviewing, I might have a commit to merge tomorrow.
But one thing that confuses me:
Your example using system
and tput
works for me running Racket in Gnome terminal, outside Emacs.
But it does not give me any blue color in Emacs. Not in M-x shell
. Not in my just-updated Racket REPL.
I don't see blue and I don't see any raw codes.
It seems like maybe tput
isn't emitting the escape codes for me running something via Emacs?
I am pretty ignorant about escape codes and terminals. Is this because when the emacs process is running racket, tput
doesn't see it as a certain kind of terminal?? (For me. But presumably you have it configured differently?)
Oh maybe it's because TERM
env var for me is xterm-256color
in Gnome terminal but dumb
in Emacs?
Presumably if someone like you has set TERM
as you want for Emacs, then when I launch the racket
process from Emacs it will inherit that, and doing (system " ... tput ... ")
will do what you want?
In an M-x shell
buffer, tput
setaf
works when I use -T xterm-256color
("don't look at TERM, just produce SGR escapes"):
$ echo $(tput -T xterm-256color setaf 4)should be blue$(tput -T xterm-256color setaf 0)
should be blue
$ racket
Welcome to Racket v8.10.0.3 [cs].
> (require racket/system)
> (system "echo $(tput -T xterm-256color setaf 4)should be blue$(tput -T xterm-256color setaf 0)")
should be blue
#t
I just pushed a commit (not yet merged to the main branch) that handles SGR escapes to colorize. By default; it can also be configured to show them raw or filter them with no colorizing.
p.s. Although I don't understand exactly how/when tput
emits SGR escapes or not, in Emacs generally, I think that's a general Emacs configuration question.
If you have any tips in this regard I'd be happy to add them to the docs for racket-repl-mode
(but AFAICT it's not something racket-repl-mode
can or should solve?).
I went ahead and merged this. I think the TL;DR is, if you have things configured in such a way that tput
emits SGR escapes when run from Emacs, and you see colors in e.g. shell-mode
(which uses comint-mode
)... then you should now see colors in racket-repl-mode
.
If not, or if you have any other questions or comments of course please let me know.
Before the changes to repl-mode in 25224889d20b37bfd0d315a656542bb4fe8c2076 ansi escape codes were processed correctly. After the changes they are no longer processed correctly. Is there some way to get this working again?
Steps to reproduce: In the repl run
The output should be blue as it was in the comint version of the repl and as it would be if running racket from the command line.
The actual result in some cases contains raw escape charachters, possibly when logging to stderr instead of stdout?
Package
System values
Buffer values
Racket Mode values
Minor modes
Disabled minor modes