I’ve been working on a side project to make a source display widget for the aggregate.org SC’11 exhibit, and it is surprisingly problematic. The goals for the program are as follows:
- Take a directory of source files as input
- Automatically perform appropriate syntax highlighting on the source files.
- Display (On a dark background – intended use is a floating projection display) all the source files consecutively.
- Scroll automatically through the output in a pleasing, readable way.
- Be capable of repeating this action unattended indefinitely.
My first attempt was a simple program in Vala with GTK3 and GTKSourceView (source). It went together quickly, fits in around 150 lines, and is rather modern looking, but has several deal-breakers.
- It advances using textiters, which creates a kind of jumpy output.
- Related – there is no support for smooth scrolling in GTKSourceView that I can find.
- It is surprisingly difficult to theme to light text on a dark background.
- GTK file_chooser objects don’t really have any concept of “all files in directory,” which makes automatically transitioning between files supremely clumsy (posted code doesn’t try).
On the plus side, it is standalone once built, and has a nice button to start/stop scrolling, so it is easy to pause and talk about a piece of code in place.
Then I had the idea that there was also the classical unix solution: I made a 25-line bash script that uses source-highlight, less, and xdotool to make it happen in a terminal (source). This has several advantages, including easy file globbing, and the ability to hijack the terminal’s display customization features (light-on-dark, size, etc.). It also has serious problems:
- Extremely non-interactive. Once started, it just runs, and because it spawns background processes, it is genuinely difficult to kill.
- Depends on several random external programs.
- VERY jumpy scrolling. Either line-at-a-time or half-page at a time.
- Modern terminals don’t seem to have any reasonable mechanism for scroll-rate limiting.
The quick and dirty solution is, as usual, better than the nice one, but it is clearly still not what I was hoping for.
We’ve also considered prepossessing the sources with source-highlight set to emit HTML (and a little regex-foo), then hijiacking a full-screen browser for output, but all the auto-scroll plugins for browsers seem to be broken, file transitions will be complicated, and programatically simulating input to cause smooth scrolling in the browser is touchy.
I generally view smooth-scrolling as a non-feature, so the situation of trying to cause it is sort of jarring, but it is surprising and irritating that there is no ready support for it in display programs or libraries. The Bash scrips are probably adequate, but I’d love to hear of a way to do this right.