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 156 def begin_group kind @opened << kind @out << open_token(kind) end
# File lib/coderay/encoders/terminal.rb, line 162 def end_group kind if @opened.pop @color_scopes.pop @out << "\e[0m" if outer_color = @color_scopes.last[:self] @out << outer_color end end end
# File lib/coderay/encoders/terminal.rb, line 172 def end_line kind @out << (@line_filler ||= "\t" * 100) end_group kind end
# File lib/coderay/encoders/terminal.rb, line 141 def text_token text, kind if color = @color_scopes.last[kind] color = color[:self] if color.is_a? Hash @out << color @out << (text.index("\n") ? text.gsub("\n", "\e[0m\n" + color) : text) @out << "\e[0m" if outer_color = @color_scopes.last[:self] @out << outer_color end else @out << text end end
Generated with the Darkfish Rdoc Generator 2.