mossymountain
mossymountain

Reputation: 183

How to dump GNU screen scrollback buffer while preserving ANSI control sequences?

In a screen session, its scrollback buffer can be saved to file by entering ^A:hardcopy -h /path/to/filename. However, this strips all ANSI control sequences from the output.

I want something like less -R but for saving the scrollback buffer.

example script to produce coloured text:

#!/bin/bash
# both times, the word 'red' is printed in bright red text.
printf 'example \x1b[1;31mred\x1b[m output\n' |tee example.log
cat example.log

you can also view the file with less -R example.log

Upvotes: 3

Views: 861

Answers (1)

KT.
KT.

Reputation: 11430

When the terminal consumes ANSI sequences, it does not store them in memory verbatim, but instead converts to display attributes of the individual characters on screen. hardcopy, apparently, was not designed to output those attributes.

You might get what you need if you enable logging, however. See this answer, for example.

Upvotes: 1

Related Questions