Outputs code highlighted for a color terminal.

Note: This encoder is in beta. It currently doesn’t use the Styles.

Alias: term

Authors & License

By Rob Aldred (robaldred.co.uk)

Based on idea by Nathan Weizenbaum (nex-3.com)

MIT License (www.opensource.org/licenses/mit-license.php)

Methods
Constants
TOKEN_COLORS = { :annotation => '35', :attribute_name => '33', :attribute_value => '31', :binary => '1;35', :char => { :self => '36', :delimiter => '34'
Public Instance methods
begin_group(kind)
--- This method is also aliased as begin_line ---
# File lib/coderay/encoders/terminal.rb, line 126
      def begin_group kind
        @opened << kind
        @out << open_token(kind)
      end
begin_line(kind)

Alias for begin_group

end_group(kind)
# 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
end_line(kind)
# 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
text_token(text, kind)
# 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