stephencelis/ghi — pull request #150 by LFDM (2014-02-19 12:47:39+00:00)
Title: Syntax highlighting

Quick and easy way to highlight code in issues!

I set up an exemplary repo with an issue, where you can see its effects: https://github.com/LFDM/ghi_test

This is done through python's `pygments`, which is exposed to ruby through the gem `pygments.rb`. The current implementation tries to load it lazily and if a user hasn't installed it nothing happens: Issues are displayed the way it is done without this PR.

A user can configure the style used to do the highlighting through the env var `GHI_HIGHLIGHT_STYLE`. If the style requested is invalid, it falls back to the old behavior.

Inline code blocks are highlighted as well.

If you are interested in merging this, there are a couple of open questions:
- The `pygments.rb` gem could be added to the `gemspec` as a dependency. There's one caveat involved: It's not compatible with jruby - I imagine user's of ghi don't run it through jruby anyway, which would be far too slow...
- We could just rely on the user to install it themselves and add a note to the README
- The method currently only fires when the user's terminal supports 256 colors. Pygments works with less colors as well - personally I think the colorset for a 16 color terminal is too hard to read and doesn't add much to the experience.
- I don't output the code block fencing (the backticks) as of now - they could be left in if you want. Code blocks are currently surrounded by simple dashes, which is not too pretty and can be easily replaced.
- Inline code blocks also strip their backticks, current style used is `inverse` - that too can be debated.

Type `ghi show 1 -- LFDM/ghi_test` and see it for yourself :)