diff options
Diffstat (limited to 'lib/coderay')
| -rw-r--r-- | lib/coderay/encoders/terminal.rb | 179 | ||||
| -rw-r--r-- | lib/coderay/styles/alpha.rb | 29 | ||||
| -rwxr-xr-x | lib/coderay/token_kinds.rb | 136 | 
3 files changed, 181 insertions, 163 deletions
| diff --git a/lib/coderay/encoders/terminal.rb b/lib/coderay/encoders/terminal.rb index 9894b91..c7ae014 100644 --- a/lib/coderay/encoders/terminal.rb +++ b/lib/coderay/encoders/terminal.rb @@ -19,105 +19,135 @@ module CodeRay        register_for :terminal        TOKEN_COLORS = { -        :annotation => "\e[35m", -        :attribute_name => "\e[33m", +        :debug => "\e[1;37;44m", +         +        :annotation => "\e[34m", +        :attribute_name => "\e[35m",          :attribute_value => "\e[31m", -        :binary => "\e[1;35m", +        :binary => { +          :self => "\e[31m", +          :char => "\e[1;31m", +          :delimiter => "\e[1;31m", +        },          :char => { -          :self => "\e[36m", :delimiter => "\e[1;34m" +          :self => "\e[35m", +          :delimiter => "\e[1;35m"          }, -        :class => "\e[1;35m", +        :class => "\e[1;35;4m",          :class_variable => "\e[36m",          :color => "\e[32m", -        :comment => "\e[37m", -        :complex => "\e[1;34m", -        :constant => "\e[1;34m\e[4m", -        :decoration => "\e[35m", -        :definition => "\e[1;32m", -        :directive => "\e[32m\e[4m", -        :doc => "\e[46m", -        :doctype => "\e[1;30m", -        :docstring => "\e[31m\e[4m", -        :entity => "\e[33m", -        :error => "\e[1;33m\e[41m", +        :comment => { +          :self => "\e[1;30m", +          :char => "\e[37m", +          :delimiter => "\e[37m", +        }, +        :constant => "\e[1;34;4m", +        :decorator => "\e[35m", +        :definition => "\e[1;33m", +        :directive => "\e[33m", +        :docstring => "\e[31m", +        :doctype => "\e[1;34m", +        :done => "\e[1;30;2m", +        :entity => "\e[31m", +        :error => "\e[1;37;41m",          :exception => "\e[1;31m",          :float => "\e[1;35m",          :function => "\e[1;34m", -        :global_variable => "\e[42m", +        :global_variable => "\e[1;32m",          :hex => "\e[1;36m", -        :include => "\e[33m", +        :id => "\e[1;34m", +        :include => "\e[31m",          :integer => "\e[1;34m", -        :key => "\e[35m", -        :label => "\e[1;15m", +        :imaginary => "\e[1;34m", +        :important => "\e[1;31m", +        :key => { +          :self => "\e[35m", +          :char => "\e[1;35m", +          :delimiter => "\e[1;35m", +        }, +        :keyword => "\e[32m", +        :label => "\e[1;33m",          :local_variable => "\e[33m", -        :octal => "\e[1;35m", -        :operator_name => "\e[1;29m", +        :namespace => "\e[1;35m", +        :octal => "\e[1;34m", +        :predefined => "\e[36m",          :predefined_constant => "\e[1;36m", -        :predefined_type => "\e[1;30m", -        :predefined => "\e[4m\e[1;34m", -        :preprocessor => "\e[36m", +        :predefined_type => "\e[1;32m", +        :preprocessor => "\e[1;36m",          :pseudo_class => "\e[1;34m",          :regexp => { -          :self => "\e[31m", -          :content => "\e[31m", -          :delimiter => "\e[1;29m", +          :self => "\e[35m", +          :delimiter => "\e[1;35m",            :modifier => "\e[35m", +          :char => "\e[1;35m",          }, -        :reserved => "\e[1;31m", +        :reserved => "\e[32m",          :shell => { -          :self => "\e[42m", -          :content => "\e[1;29m", -          :delimiter => "\e[37m", +          :self => "\e[33m", +          :char => "\e[1;33m", +          :delimiter => "\e[1;33m", +          :escape => "\e[1;33m",          },          :string => { -          :self => "\e[32m", -          :modifier => "\e[1;32m", -          :escape => "\e[1;36m", -          :delimiter => "\e[1;32m", -          :char => "\e[1;36m", +          :self => "\e[31m", +          :modifier => "\e[1;31m", +          :char => "\e[1;35m", +          :delimiter => "\e[1;31m", +          :escape => "\e[1;31m", +        }, +        :symbol => { +          :self => "\e[33m", +          :delimiter => "\e[1;33m",          }, -        :symbol => "\e[1;32m", -        :tag => "\e[1;34m", +        :tag => "\e[32m",          :type => "\e[1;34m",          :value => "\e[36m", -        :variable => "\e[1;34m", +        :variable => "\e[34m", -        :insert => "\e[42m", -        :delete => "\e[41m", -        :change => "\e[44m", -        :head => "\e[45m" +        :insert => { +          :self => "\e[42m", +          :insert => "\e[1;32;42m", +          :eyecatcher => "\e[102m", +        }, +        :delete => { +          :self => "\e[41m", +          :delete => "\e[1;31;41m", +          :eyecatcher => "\e[101m", +        }, +        :change => { +          :self => "\e[44m", +          :change => "\e[37;44m", +        }, +        :head => { +          :self => "\e[45m", +          :filename => "\e[37;45m" +        },        } +              TOKEN_COLORS[:keyword] = TOKEN_COLORS[:reserved]        TOKEN_COLORS[:method] = TOKEN_COLORS[:function] -      TOKEN_COLORS[:imaginary] = TOKEN_COLORS[:complex] -      TOKEN_COLORS[:begin_group] = TOKEN_COLORS[:end_group] = -        TOKEN_COLORS[:escape] = TOKEN_COLORS[:delimiter] +      TOKEN_COLORS[:escape] = TOKEN_COLORS[:delimiter]      protected        def setup(options)          super          @opened = [] -        @subcolors = nil +        @color_scopes = [TOKEN_COLORS]        end      public        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 +        if color = @color_scopes.last[kind] +          color = color[:self] if color.is_a? Hash            @out << color -          @out << text.gsub("\n", "\e[0m\n" + color) +          @out << (text.index("\n") ? text.gsub("\n", "\e[0m\n" + color) : text)            @out << "\e[0m" -          @out << @subcolors[:self] if @subcolors +          if outer_color = @color_scopes.last[:self] +            @out << outer_color +          end          else            @out << text          end @@ -130,40 +160,33 @@ module CodeRay        alias begin_line begin_group        def end_group kind -        if @opened.empty? -          # nothing to close -        else -          @opened.pop +        if @opened.pop +          @color_scopes.pop            @out << "\e[0m" -          @out << open_token(@opened.last) +          if outer_color = @color_scopes.last[:self] +            @out << outer_color +          end          end        end        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 << (@line_filler ||= "\t" * 100 + "\e[0m") -          @out << open_token(@opened.last) -        end +        @out << (@line_filler ||= "\t" * 100) +        end_group kind        end      private        def open_token kind -        if color = TOKEN_COLORS[kind] -          if Hash === color -            @subcolors = color +        if color = @color_scopes.last[kind] +          if color.is_a? Hash +            @color_scopes << color              color[:self]            else -            @subcolors = {} +            @color_scopes << @color_scopes.last              color            end          else -          @subcolors = nil +          @color_scopes << @color_scopes.last            ''          end        end diff --git a/lib/coderay/styles/alpha.rb b/lib/coderay/styles/alpha.rb index 2ad088a..9a94091 100644 --- a/lib/coderay/styles/alpha.rb +++ b/lib/coderay/styles/alpha.rb @@ -57,26 +57,25 @@ table.CodeRay td { padding: 2px 4px; vertical-align: top; }  .attribute-name { color:#b48 }  .attribute-value { color:#700 }  .binary { color:#549 } -.binary .delimiter { color:#325 }  .binary .char { color:#325 } +.binary .delimiter { color:#325 } +.char { color:#D20 }  .char .content { color:#D20 }  .char .delimiter { color:#710 } -.char { color:#D20 }  .class { color:#B06; font-weight:bold }  .class-variable { color:#369 }  .color { color:#0A0 }  .comment { color:#777 }  .comment .char { color:#444 }  .comment .delimiter { color:#444 } -.complex { color:#A08 }  .constant { color:#036; font-weight:bold }  .decorator { color:#B0B }  .definition { color:#099; font-weight:bold }  .delimiter { color:black }  .directive { color:#088; font-weight:bold } -.doc { color:#970 } -.doc-string { color:#D42; font-weight:bold } +.docstring { color:#D42; }  .doctype { color:#34b } +.done { text-decoration: line-through; color: gray }  .entity { color:#800; font-weight:bold }  .error { color:#F00; background-color:#FAA }  .escape  { color:#666 } @@ -87,16 +86,16 @@ table.CodeRay td { padding: 2px 4px; vertical-align: top; }  .global-variable { color:#d70 }  .hex { color:#02b }  .id  { color:#33D; font-weight:bold } -.imaginary { color:#f00 }  .include { color:#B44; font-weight:bold }  .inline { background-color: hsla(0,0%,0%,0.07); color: black }  .inline-delimiter { font-weight: bold; color: #666 }  .instance-variable { color:#33B }  .integer  { color:#00D } +.imaginary { color:#f00 }  .important { color:#D00 } +.key { color: #606 }  .key .char { color: #60f }  .key .delimiter { color: #404 } -.key { color: #606 }  .keyword { color:#080; font-weight:bold }  .label { color:#970; font-weight:bold }  .local-variable { color:#963 } @@ -108,30 +107,30 @@ table.CodeRay td { padding: 2px 4px; vertical-align: top; }  .predefined-type { color:#0a5; font-weight:bold }  .preprocessor { color:#579 }  .pseudo-class { color:#00C; font-weight:bold } +.regexp { background-color:hsla(300,100%,50%,0.06); }  .regexp .content { color:#808 }  .regexp .delimiter { color:#404 }  .regexp .modifier { color:#C2C } -.regexp { background-color:hsla(300,100%,50%,0.06); }  .reserved { color:#080; font-weight:bold } +.shell { background-color:hsla(120,100%,50%,0.06); }  .shell .content { color:#2B2 }  .shell .delimiter { color:#161 } -.shell { background-color:hsla(120,100%,50%,0.06); } +.string { background-color:hsla(0,100%,50%,0.05); }  .string .char { color: #b0b }  .string .content { color: #D20 }  .string .delimiter { color: #710 }  .string .modifier { color: #E40 } -.string { background-color:hsla(0,100%,50%,0.05); } +.symbol { color:#A60 }  .symbol .content { color:#A60 }  .symbol .delimiter { color:#630 } -.symbol { color:#A60 }  .tag { color:#070 }  .type { color:#339; font-weight:bold } -.value { color: #088; } -.variable  { color:#037 } +.value { color: #088 } +.variable { color:#037 }  .insert { background: hsla(120,100%,50%,0.12) }  .delete { background: hsla(0,100%,50%,0.12) } -.change { color: #bbf; background: #007; } +.change { color: #bbf; background: #007 }  .head { color: #f8f; background: #505 }  .head .filename { color: white; } @@ -142,8 +141,6 @@ table.CodeRay td { padding: 2px 4px; vertical-align: top; }  .delete .delete { color: #c00; background:transparent; font-weight:bold }  .change .change { color: #88f }  .head .head { color: #f4f } - -.done { text-decoration: line-through; color: gray }      TOKENS    end diff --git a/lib/coderay/token_kinds.rb b/lib/coderay/token_kinds.rb index de3a0d0..42ea427 100755 --- a/lib/coderay/token_kinds.rb +++ b/lib/coderay/token_kinds.rb @@ -10,79 +10,77 @@ module CodeRay    TokenKinds.compare_by_identity if TokenKinds.respond_to? :compare_by_identity    TokenKinds.update(  # :nodoc: -    :annotation          => 'annotation', -    :attribute_name      => 'attribute-name', -    :attribute_value     => 'attribute-value', -    :binary              => 'bin', -    :char                => 'char', -    :class               => 'class', -    :class_variable      => 'class-variable', -    :color               => 'color', -    :comment             => 'comment', -    :complex             => 'complex', -    :constant            => 'constant', -    :content             => 'content', -    :debug               => 'debug', -    :decorator           => 'decorator', -    :definition          => 'definition', -    :delimiter           => 'delimiter', -    :directive           => 'directive', -    :doc                 => 'doc', -    :doctype             => 'doctype', -    :docstring           => 'doc-string', -    :done                => 'done', -    :entity              => 'entity', -    :error               => 'error', -    :escape              => 'escape', -    :exception           => 'exception', -    :filename            => 'filename', -    :float               => 'float', -    :function            => 'function', -    :global_variable     => 'global-variable', -    :hex                 => 'hex', -    :id                  => 'id', -    :imaginary           => 'imaginary', -    :important           => 'important', -    :include             => 'include', -    :inline              => 'inline', -    :inline_delimiter    => 'inline-delimiter', -    :instance_variable   => 'instance-variable', -    :integer             => 'integer', -    :key                 => 'key', -    :keyword             => 'keyword', -    :label               => 'label', -    :local_variable      => 'local-variable', -    :modifier            => 'modifier', -    :namespace           => 'namespace', -    :octal               => 'octal', -    :predefined          => 'predefined', -    :predefined_constant => 'predefined-constant', -    :predefined_type     => 'predefined-type', -    :preprocessor        => 'preprocessor', -    :pseudo_class        => 'pseudo-class', -    :regexp              => 'regexp', -    :reserved            => 'reserved', -    :shell               => 'shell', -    :string              => 'string', -    :symbol              => 'symbol', -    :tag                 => 'tag', -    :type                => 'type', -    :value               => 'value', -    :variable            => 'variable', +    :debug               => 'debug',              # highlight for debugging (white on blue background) -    :change              => 'change', -    :delete              => 'delete', -    :head                => 'head', -    :insert              => 'insert', +    :annotation          => 'annotation',         # Groovy, Java +    :attribute_name      => 'attribute-name',     # HTML, CSS +    :attribute_value     => 'attribute-value',    # HTML +    :binary              => 'binary',             # Python, Ruby +    :char                => 'char',               # most scanners, also inside of strings +    :class               => 'class',              # lots of scanners, for different purposes also in CSS +    :class_variable      => 'class-variable',     # Ruby, YAML +    :color               => 'color',              # CSS +    :comment             => 'comment',            # most scanners +    :constant            => 'constant',           # PHP, Ruby +    :content             => 'content',            # inside of strings, most scanners +    :decorator           => 'decorator',          # Python +    :definition          => 'definition',         # CSS +    :delimiter           => 'delimiter',          # inside strings, comments and other types +    :directive           => 'directive',          # lots of scanners +    :doctype             => 'doctype',            # Goorvy, HTML, Ruby, YAML +    :docstring           => 'docstring',          # Python +    :done                => 'done',               # Taskpaper +    :entity              => 'entity',             # HTML +    :error               => 'error',              # invalid token, most scanners +    :escape              => 'escape',             # Ruby (string inline variables like #$foo, #@bar) +    :exception           => 'exception',          # Java, PHP, Python +    :filename            => 'filename',           # Diff +    :float               => 'float',              # most scanners +    :function            => 'function',           # CSS, JavaScript, PHP +    :global_variable     => 'global-variable',    # Ruby, YAML +    :hex                 => 'hex',                # hexadecimal number; lots of scanners +    :id                  => 'id',                 # CSS +    :imaginary           => 'imaginary',          # Python +    :important           => 'important',          # CSS, Taskpaper +    :include             => 'include',            # C, Groovy, Java, Python, Sass +    :inline              => 'inline',             # nested code, eg. inline string evaluation; lots of scanners +    :inline_delimiter    => 'inline-delimiter',   # used instead of :inline > :delimiter FIXME: Why? +    :instance_variable   => 'instance-variable',  # Ruby +    :integer             => 'integer',            # most scanners +    :key                 => 'key',                # lots of scanners, used together with :value +    :keyword             => 'keyword',            # reserved word that's actually implemented; most scanners +    :label               => 'label',              # C, PHP +    :local_variable      => 'local-variable',     # local and magic variables; some scanners +    :modifier            => 'modifier',           # used inside on strings; lots of scanners +    :namespace           => 'namespace',          # Clojure, Java, Taskpaper +    :octal               => 'octal',              # lots of scanners +    :predefined          => 'predefined',         # predefined function: lots of scanners +    :predefined_constant => 'predefined-constant',# lots of scanners +    :predefined_type     => 'predefined-type',    # C, Java, PHP +    :preprocessor        => 'preprocessor',       # C, Delphi, HTML +    :pseudo_class        => 'pseudo-class',       # CSS +    :regexp              => 'regexp',             # Groovy, JavaScript, Ruby +    :reserved            => 'reserved',           # most scanners +    :shell               => 'shell',              # Ruby +    :string              => 'string',             # most scanners +    :symbol              => 'symbol',             # Clojure, Ruby, YAML +    :tag                 => 'tag',                # CSS, HTML +    :type                => 'type',               # CSS, Java, SQL, YAML +    :value               => 'value',              # used together with :key; CSS, JSON, YAML +    :variable            => 'variable',           # Sass, SQL, YAML -    :eyecatcher          => 'eyecatcher', +    :change              => 'change',             # Diff +    :delete              => 'delete',             # Diff +    :head                => 'head',               # Diff, YAML +    :insert              => 'insert',             # Diff +    :eyecatcher          => 'eyecatcher',         # Diff -    :ident               => false, -    :operator            => false, +    :ident               => false,                # almost all scanners +    :operator            => false,                # almost all scanners -    :space               => false, -    :plain               => false +    :space               => false,                # almost all scanners +    :plain               => false                 # almost all scanners    ) -  TokenKinds[:method]    = TokenKinds[:function] +  TokenKinds[:method] = TokenKinds[:function]  end | 
