3 ms·
Show HN: Rewindtty – Record and replay terminal sessions as structured JSON
- debba 1y agoHi HN, I built rewindtty, a small tool in C that lets you record a terminal session and later replay it, using a simple JSON log format that includes: - timestamp - command (user input) - output (stdout) - stderr It works like this: - rewindtty record session.json # Runs a shell, records the session - rewindtty replay session.json # Replays it step by step Under the hood: - Uses fork() to manage the pseudo-terminal - Captures stdout/stderr with timestamps - Stores everything in structured JSON for easy analysis, replay or transformation Why I made this: I wanted a minimal tool to track terminal interactions — for debugging, documentation, and reproducibility — without relying on heavier tools or external formats. It’s still early, but the core works and I’d love feedback or suggestions. GitHub: https://github.com/debba/rewindtty https://github.com/debba/rewindtty
- sunscream89 1y agoYou have scratched a long persistent itch. Good work! And I love that you used c. Nothing against rust, or (ahem) “go”, but it’s good to see you doing something in c!
- debba 1y agoYeah, it’s just a side project for now, but I’m hoping to make it more solid over time. As for C, I wanted to challenge myself and step away from what I usually do — try something a bit different.
- happens 1y agoHow does it deal with escape sequences? Does it just record them verbatim?
- debba 1y agoIt records escape sequences verbatim during capture, then handles them intelligently during replay. Recording phase: All terminal output including ANSI escape codes, color sequences, and cursor movements are captured exactly as they appear - no processing or stripping occurs. Replay phase: - Decodes various escape formats (\u001b, \033, \x1b) back to actual escape characters - Filters out problematic terminal query sequences that could cause artifacts - Preserves visual escape sequences (colors, cursor positioning) for faithful reproduction So yes, escape sequences are recorded verbatim, but the replayer ntelligently processes them to recreate the original terminal experience while avoiding terminal corruption.
- happens 1y agoThat sounds like a good strategy! I've dabbled in writing task runner, and relaying logs with preserved colors and formatting without messing up the terminal and interleaving messages from different tasks is a huge hurdle. I wish there was a standard for telling processes "keep the colored and formatted output, but assume it will be read line by line"... It's possible to just let processes write into pty's and then parse the output, but then you pretty much have to implement an entire nested terminal emulator :-(
- loloquwowndueo 1y agoIs this ttyrec with json output?
- debba 1y agoyes exactly
- JdeBP 1y agoNo. Because checking some of the Debian patches accrued against ttyrec, and the source to rewindtty, it seems that rewindtty does not have some of the common programming mistakes that the author of ttyrec made a quarter of a century ago. * https://sources.debian.org/src/ttyrec/1.1.7.1-1/debian/patches/0012-Don-t-try-to-exec-char-1-if-SHELL-doesn-t-have-a-Clo.patch/ https://sources.debian.org/src/ttyrec/1.1.7.1-1/debian/patch... * https://github.com/debba/rewindtty/blob/develop/src/recorder.c#L167 https://github.com/debba/rewindtty/blob/develop/src/recorder... * https://github.com/mjording/ttyrec/blob/master/ttyrec.c#L328 https://github.com/mjording/ttyrec/blob/master/ttyrec.c#L328 rewindtty will error out if the SHELL environment variable's value does not have a directory prefix, but at least it won't outright crash. (-:
- JdeBP 1y agoBy the way, debba: execvp()/execlp() and _PATH_BSHELL out of <paths.h> as the fallback are the ways to go, here.
- debba 1y agoOuch sorry, I thought you meant 'it has the same features as ttyrec with JSON output.' Regarding the issue, I need to go into a bit more detail; if you like, feel free to make a PR on GitHub.
- debba 1y agosorry, in the last reply I told you 'yes, exactly'. I meant It has the same features as ttyrec with JSON output
- Waraqa 1y agoHave you made an online demo for the browser player? I guess it will have potential uses in tutorials
- debba 1y agoNot for now. That's a side project and it is really new and still a bit rough around the edges; it’s only a few days old. I’ll do it soon, meanwhile if you want to contribute you’re welcome :)
- reagle 1y agoOn github, I see an asciinema tag, but no explanation of the differences?
- debba 1y agoIt's not related to asciinema, it's a totally different project. Asciinema is a much more complex and structured project than mine; mine is the result of a few hours of free time—I was looking for a lighter solution.