Ttyrec.js
a native implementation for encoding and decoding ttyrec files.
Usage
This implements a duplex / transform
stream v2 . Therefore only node v0.10.x is supported.
It also provides a few simple executable:
-
ttyrec
: records ttyrec file from the current terminal -
ttyplay
: plays ttyrec files -
ttytime
: shows the number of seconds is in the ttyrecord file -
ttyrec++
: similar to ttyrec but generator a json file -
See Ttyrec++
Installation
npm install ttyrec
Write recStream
var fs = ;var pty = ; var ttyrec = ;var ttyrecStream = ; var fileStream = fs; var _pty = pty;processstdin; _pty;ttyrecStream;
Read playStream
var fs = ; var ttyrec = ;var fileStream = fs; var ttyplayStream = ; // Play at half the speedttyplayStream; fileStream;ttyplayStream;
parseStream
var fs = ; var ttyrec = ;var fileStream = fs; var ttyparseStream = ; // No waiting = speed 0ttyparseStream; fileStream;ttyparseStream;
Encode
var ttyrec = ;var encoder = ttyrecencoder;var sec = 0;var usec = 10;var record = encoder
Decode (parseBuffer)
var ttyrec = ;var decoder = ttyrecdecoder;var results = decoder; // This returns an array of// [0] = records// [1] = rest of chunk not parsedvar records = result0;var record = records0;var rest = result1; var header = recordheader;consolevar packet = recordpacket; // Bufferconsole;
Limitations
- only handles buffer streams(non-encoded streams)
- only works versions v0.10.x (for v0.11 pty.js needs to be patched first)
Todo
- enhance the executables to mimic arguments from real ttyrec and ttyplay (almost, need peek + help)
- make v0.11 and v0.8 compatible
- handle special resizing escape codes for ttyrec
- browserify this code (almost, only process.hrtime does not exist in browser)
- help page