4

Context

Have some transcript files from terminal interaction, obtained using traditional Unix command "script".

Those transcripts contain lots of control character (like backspace when editing shell commands), and lots of color code sequences as result of running various commands. Occasionally, even colorful full-terminal (ncurses-based) applications like "emacs -nw" or "aptitude" were run.

At program runtime, TERM environment variable was set as "xterm".

Need 1: read (more or less solved)

I need to read those files again and sometimes copy-paste some small parts.

The trouble is : while one color change here and there is not so much of a problem, their actual density makes the output barely readable. Worse, edited command lines (with cursor jumps and edited words) are completely unreadable.

"Okay" solution

Browse through files using e.g. "less -r". Paging forward in the same terminal setup reproduces the various color and character style.

But many other features come out more or less broken, e.g. search backwards produces jumbled terminal output, often have to pres "Ctrl-L" to clean thing up.

Need 2: editing

My preferred editor is emacs. Some people have had a similar situation when running the shell inside emacs, e.g. Something wrong with Emacs shell.

Here is not the same situation. Examples of differences: here we don't have to run an actual shell, but we need to move cursor freely like in usual editing.

Editing here means easily open such a transcript file in editor and then:

  • at all times through editing, see character changes (color, attributes) as conveyed by the terminal codes
  • (optional) some character that are neighbour on the terminal grid but are separated in file by some control characters would have a visual hint about this
  • ability to insert some text,
  • delete sections,
  • use all editor features like search/replace etc.
  • copy & paste to & from file (including to external programs, which would receive just plain text)
  • in my wildest dreams, some kind of "flatten" action, like select a sequence with a heavily edited command line and replace it with a simple series of characters as if it was typed in one run. "Visual hints" mentioned above would disappear.
Community
  • 1
  • 1
Stéphane Gourichon
  • 6,493
  • 4
  • 37
  • 48
  • I tried http://www.emacswiki.org/emacs/AnsiColor and http://www.emacswiki.org/emacs/TtyFormat but could not get satisfaction. – Stéphane Gourichon Mar 13 '13 at 22:22
  • Could you link to an example file, please? – Thomas Mar 14 '13 at 01:16
  • 1
    Sure. Actual files contain private business data so I've crafted a sample available on http://gourichon.org/2013/ansi-coloured-file-editing/file_with_ansi_colors.txt . It shows: color bash prompt with system info, color ls, emacs -nw, aptitude, and an example of edited command line. As a workaround for the last case I have a PROMPT_COMMAND that repeats command line before running (see line with "1285"). Regards. – Stéphane Gourichon Mar 14 '13 at 10:31
  • 1
    I find that "less -R" works better than "less -r". – Zaq May 24 '13 at 03:23
  • 1
    apparently, none of the usual text screencasting tools (ttyrec, shelr, IPBT etc.) have this feature, but anyhow they require input with timestamps, which `script` output usually doesn't have. [IPBT](http://www.chiark.greenend.org.uk/~sgtatham/ipbt/) is likely the closest starting point to an editor. – sendmoreinfo May 09 '16 at 17:50

1 Answers1

1

Type Alt-: to evaluate something in the minibuffer. Evaluate (ansi-color-apply-on-region (point-min) (point-max)) and it will convert ansi color codes to be font colors.

Eric Ihli
  • 1,722
  • 18
  • 30