2

You supposedly can make some sort of low-tech replacement to screencasts of your terminal sessions with script(1):

DESCRIPTION

script makes a typescript of everything displayed on your terminal.  It
is useful for students who need a hardcopy  record  of  an  interactive
session  as  proof  of  an  assignment,  as  the typescript file can be
printed out later with lpr(1).

I now created a typescript file. But how do I make a readable pdf from it?

I used lp with the printer PDF from cups-pdf but the output is garbled. There are lots of m, 0; and 34;42 where should be blanks.

viuser
  • 2,614

3 Answers3

4

A utility that seems to work quite well with handling ansi escapes and input line editing from a typescript is ansi2html.sh which obviously generates html. You can either view this output in your browser and use its printing features, or, if you dont mind losing the colours, convert the html back to simple text with no escapes, eg with

ansi2html.sh <mytypescript | w3m -dump -T text/html >out.txt

You can then use enscript to print simple text files.

meuh
  • 51,383
  • I think https://github.com/theZiz/aha works better – viuser Jun 06 '16 at 01:31
  • I found aha didnt handle backspaces in the commands typed in to bash, for example, whereas ansi2html.sh did. So typing abc\b\b\bdef (where \b represents a backspace) showed as abcdef in the former, but def in the latter. – meuh Jun 06 '16 at 04:55
3

There's two choices:

  • replay the script (with pauses, even via XOFF/XON), and make screenshots which some tool may convert into PDF

  • strip the control sequences from the file, leaving a plain-text file that can be converted into PDF.

Generally I've done the latter; both have their pitfalls. When making screenshots, you may not get exactly the picture you wanted (though using scriptreplay, it's possible to slow things down to make it simpler to pause the screen). Filtering escape sequences works well enough for command-line applications such as "colorized ls", but poorly for screenshots of a text editor.

Further reading:

Thomas Dickey
  • 76,765
0

The counterpart of script(1) is scriptreplay(1):

DESCRIPTION
    This  program  replays  a typescript, using timing 
    information to ensure that output happens at the same 
    speed as it originally appeared when the script was recorded.

Also, scriptreplay provides option to speed up/slow down the replay.

Thus, you can't just print it. You could replay it and capture screenshots or make a movie.

Serge
  • 8,541
  • How do you know for sure, that one just can't print it? It even says it can be printed in the manpage. – viuser Jun 05 '16 at 05:38
  • Of course it can be printed as any text document with one exception: "Certain interactive commands, such as vi(1), create garbage in the typescript file. Script works best with commands that do not manipulate the screen, the results are meant to emulate a hardcopy terminal." (from the same man page). Did you use vi or alike? I meant exactly your case: you have such garbage in the script – Serge Jun 05 '16 at 05:49
  • Another thing that may produce 'garbage' is colored text output. – Serge Jun 05 '16 at 05:55