Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm sure someone here will know the answer for this off the top of their head so.. how does this work under the hood? How does it get to act as a sort of 'filter' for stdout?

I've recently seen a system that can 'record' your terminal session for replay on the Web - http://ascii.io/ - whose 'recorder' forks off a psuedo terminal for this (https://github.com/sickill/ascii.io-cli/blob/master/bin/asci...). Would something like Grc use a similar approach or is there another way?



I got this silly idea how to do it, I don't know if it works:

1. export your real $PATH to eg $REAL_PATH

2. clear $PATH (or set it to some dummy value)

3. Attach a wrapper script to command_not_found_handler, which would call the original command with REAL_PATH and pipes it to your filter (or colorizer or whatever).


This script inserts terminal escape sequences into text. These sequences are just text that the terminal interpret as color transitions.

Ascii.io transforms these terminal escape sequences into html/css, so Grc should work fine with it.


This script inserts terminal escape sequences into text.

I understand that part. But there's a screenshot where a "ping" is being done at a normal looking terminal and it just works without being explicitly piped through a program that does the above. What's the mechanism for piping all the terminal output through another process?


The initial grc command aliases commands like 'ping' to a modified command that processes the output[1].

[1] https://github.com/mxcl/homebrew/blob/7bbe7e9311ce95a141bf5f...


Ahh, aliases. Thanks :-) Makes sense. I was probably dreaming of a world where it'd pick up an IP address by regex in any terminal output.


Those are supplied if you source the aliases that ship with the Homebrew formula: https://github.com/mxcl/homebrew/blob/7bbe7e9311ce95a141bf5f...


I had an idea like this a while back, but as far as I know there is no shell support for it. Basically, you would install decorators in your current shell instance. The decorator could act as a filter for all stream io. Then you would not need any special commands or aliases, just configuration for how to highlight patterns.


To answer how programs like script (a little like ascii.io, but from decades ago and shipped with every Unix system), check out the manual page for forktty.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: