Page MenuHomePhabricator

Support ANSI escaped color sequences in Paste
Open, NormalPublic

Description

Say I have a script or program which outputs ANSI colorized text to the terminal, and I make a paste of that text using arc paste. If I dump the paste to my terminal using cat-pastebin Pxxxxxx, the output is colorized just like the original, so it seems that the paste contains all the escaped color sequences. Often I'll put the paste link into a task and view the output using diffusion though, and the color sequences are not interpreted in diffusion.

Instead the output looks e.g. like this:
[01;34m[14:41:40] ================================================================================
[14:41:40] Executing (in order):
[14:41:40] ================================================================================

Here the initial [01;34m codes the following text blue, and the trailing [00m codes following text black.

What would it take to make diffusion interpret these sequences correctly to color code the output?

Event Timeline

alex.n.james renamed this task from [feature request] Support ANSI escaped color sequences in arc paste and diffusion to [feature request] Support ANSI escaped color sequences in diffusion.
alex.n.james raised the priority of this task from to Needs Triage.
alex.n.james updated the task description. (Show Details)
alex.n.james added a project: Diffusion.
alex.n.james added a subscriber: alex.n.james.

To clarify, you're checking files which contain ANSI color sequences into a repository, and then viewing them in the repository browser in Diffusion?

Do these files have identifying suffixes, or are they just called things like "log"?

epriestley renamed this task from [feature request] Support ANSI escaped color sequences in diffusion to Support ANSI escaped color sequences in diffusion.Mar 3 2015, 11:50 PM

Sorry, maybe this isn't a diffusion issue. The issue is with whatever the
URL takes you to which results from arc paste.

epriestley renamed this task from Support ANSI escaped color sequences in diffusion to Support ANSI escaped color sequences in Paste.Mar 4 2015, 3:04 AM
epriestley triaged this task as Normal priority.
epriestley edited projects, added Paste; removed Diffusion.

Cool, that makes sense. I think the way forward here is:

  • Write an "ANSI console output" syntax highlighter, which converts text input with ANSI sequences into HTML. This will be slightly unusual in that it will mutate the input (other highlighters generally preserve the input faithfully) but there's no technical reason this isn't workable (except that it may need to emit hidden placeholder characters to replace the ANSI escape sequences, so character-by-character diff algorithms can operate on it correctly).
  • Have the language detector infer ANSI if input contains ANSI escape sequences and doesn't match other detectors.

ANSI highlighter will also probably be useful with harbormaster builds.