- syntax highlighting is nice
- wouldn’t it be nice to copy /paste it
The main problem is many terminals don’t for no especially good reason allow copy/paste of formatted text. There are three tools which help:
- xclip -t text/html this eats standard input and allows pasting of it as HTML, so it can include formatting and color and so on. By default, xclip does plain text, so you have to specify that it’s HTML.
- aha this takes ANSI formatted text (i.e. the formatting scheme used by terminals and turns it into HTML).
- unbuffer many tools will only write color output to a terminal, not a pipe. Through the magic of PTYs (pseudoterminals) this program fools other programs into thinking they’re running on a terminal when they’re not.
Now all you have to do is pipe them together. So, take a silly C++ program like this:
And compile it like this:
unbuffer g++-7 error.cc -std=c++1z | aha | xclip -t text/html
Then a simple paste into a box which accepts HTML (e.g. email, etc) gives:
error.cc:2:6: error: variable or field 'silly' declared void void silly; ^~~~~