Outputs code highlighted for a color terminal.
Note: This encoder is in beta. It currently doesn’t use the Styles.
Alias: term
By Rob Aldred (robaldred.co.uk)
Based on idea by Nathan Weizenbaum (nex-3.com)
MIT License (www.opensource.org/licenses/mit-license.php)
# File lib/coderay/encoders/terminal.rb, line 126 def begin_group kind @opened << kind @out << open_token(kind) end
# File lib/coderay/encoders/terminal.rb, line 132 def end_group kind if @opened.empty? # nothing to close else @opened.pop @out << ansi_clear @out << open_token(@opened.last) end end
# File lib/coderay/encoders/terminal.rb, line 142 def end_line kind if @opened.empty? # nothing to close else @opened.pop # whole lines to be highlighted, # eg. added/modified/deleted lines in a diff @out << "\t" * 100 + ansi_clear @out << open_token(@opened.last) end end
# File lib/coderay/encoders/terminal.rb, line 106 def text_token text, kind if color = (@subcolors || TOKEN_COLORS)[kind] if Hash === color if color[:self] color = color[:self] else @out << text return end end @out << ansi_colorize(color) @out << text.gsub("\n", ansi_clear + "\n" + ansi_colorize(color)) @out << ansi_clear @out << ansi_colorize(@subcolors[:self]) if @subcolors && @subcolors[:self] else @out << text end end
# File lib/coderay/encoders/terminal.rb, line 98 def setup(options) super @opened = [] @subcolors = nil end