Class: CodeRay::Encoders::Terminal

### Home Classes Methods

### In Files

- lib/coderay/encoders/terminal.rb

### Parent

CodeRay::Encoders::Encoder

### Methods

- #begin_group
- #begin_line
- #end_group
- #end_line
- #setup
- #text_token

### Class/Module Index

Quicksearch

- CodeRay
- CodeRay::Duo
- CodeRay::Encoders
- CodeRay::Encoders::CommentFilter
- CodeRay::Encoders::Count
- CodeRay::Encoders::Debug
- CodeRay::Encoders::DebugLint
- CodeRay::Encoders::Div
- CodeRay::Encoders::Encoder
- CodeRay::Encoders::Filter
- CodeRay::Encoders::HTML
- CodeRay::Encoders::HTML::Output
- CodeRay::Encoders::JSON
- CodeRay::Encoders::LinesOfCode
- CodeRay::Encoders::Lint
- CodeRay::Encoders::Null
- CodeRay::Encoders::Page
- CodeRay::Encoders::Span
- CodeRay::Encoders::Statistic
- CodeRay::Encoders::Terminal
- CodeRay::Encoders::Text
- CodeRay::Encoders::TokenKindFilter
- CodeRay::Encoders::XML
- CodeRay::Encoders::YAML
- CodeRay::FileType
- CodeRay::ForRedCloth
- CodeRay::Plugin
- CodeRay::PluginHost
- CodeRay::Scanners
- CodeRay::Scanners::C
- CodeRay::Scanners::CPlusPlus
- CodeRay::Scanners::CSS
- CodeRay::Scanners::Clojure
- CodeRay::Scanners::Debug
- CodeRay::Scanners::Delphi
- CodeRay::Scanners::Diff
- CodeRay::Scanners::ERB
- CodeRay::Scanners::Go
- CodeRay::Scanners::Groovy
- CodeRay::Scanners::HAML
- CodeRay::Scanners::HTML
- CodeRay::Scanners::JSON
- CodeRay::Scanners::Java
- CodeRay::Scanners::JavaScript
- CodeRay::Scanners::Python
- CodeRay::Scanners::Raydebug
- CodeRay::Scanners::Ruby
- CodeRay::Scanners::SQL
- CodeRay::Scanners::Sass
- CodeRay::Scanners::Scanner
- CodeRay::Scanners::Taskpaper
- CodeRay::Scanners::Text
- CodeRay::Scanners::XML
- CodeRay::Scanners::YAML
- CodeRay::Styles
- CodeRay::Styles::Alpha
- CodeRay::Styles::Style
- CodeRay::Tokens
- CodeRay::TokensProxy
- CodeRay::WordList
- CodeRay::WordList::CaseIgnoring

No matching classes.

# CodeRay::Encoders::Terminal

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)

### Constants

TOKEN_COLORS

### Public Instance Methods

begin_group(kind) click to toggle source

    # File lib/coderay/encoders/terminal.rb, line 156
    def begin_group kind
      @opened << kind
      @out << open_token(kind)
    end

Also aliased as: begin_line
begin_line(kind) click to toggle source
Alias for: begin_group
end_group(kind) click to toggle source

    # 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

end_line(kind) click to toggle source

    # File lib/coderay/encoders/terminal.rb, line 172
    def end_line kind
      @out << (@line_filler ||= "\t" * 100)
      end_group kind
    end

text_token(text, kind) click to toggle source

    # 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

### Protected Instance Methods

setup(options) click to toggle source

    # File lib/coderay/encoders/terminal.rb, line 133
    def setup(options)
      super
      @opened = []
      @color_scopes = [TOKEN_COLORS]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.