@@ -19,105 +19,135 @@ class Terminal < Encoder
19
19
register_for :terminal
20
20
21
21
TOKEN_COLORS = {
22
- :annotation => "\e [35m" ,
23
- :attribute_name => "\e [33m" ,
22
+ :debug => "\e [1;37;44m" ,
23
+
24
+ :annotation => "\e [34m" ,
25
+ :attribute_name => "\e [35m" ,
24
26
:attribute_value => "\e [31m" ,
25
- :binary => "\e [1;35m" ,
27
+ :binary => {
28
+ :self => "\e [31m" ,
29
+ :char => "\e [1;31m" ,
30
+ :delimiter => "\e [1;31m" ,
31
+ } ,
26
32
:char => {
27
- :self => "\e [36m" , :delimiter => "\e [1;34m"
33
+ :self => "\e [35m" ,
34
+ :delimiter => "\e [1;35m"
28
35
} ,
29
- :class => "\e [1;35m " ,
36
+ :class => "\e [1;35;4m " ,
30
37
:class_variable => "\e [36m" ,
31
38
:color => "\e [32m" ,
32
- :comment => "\e [37m" ,
33
- :complex => "\e [1;34m" ,
34
- :constant => "\e [1;34m\e [4m" ,
35
- :decoration => "\e [35m" ,
36
- :definition => "\e [1;32m" ,
37
- :directive => "\e [32m\e [4m" ,
38
- :doc => "\e [46m" ,
39
- :doctype => "\e [1;30m" ,
40
- :docstring => "\e [31m\e [4m" ,
41
- :entity => "\e [33m" ,
42
- :error => "\e [1;33m\e [41m" ,
39
+ :comment => {
40
+ :self => "\e [1;30m" ,
41
+ :char => "\e [37m" ,
42
+ :delimiter => "\e [37m" ,
43
+ } ,
44
+ :constant => "\e [1;34;4m" ,
45
+ :decorator => "\e [35m" ,
46
+ :definition => "\e [1;33m" ,
47
+ :directive => "\e [33m" ,
48
+ :docstring => "\e [31m" ,
49
+ :doctype => "\e [1;34m" ,
50
+ :done => "\e [1;30;2m" ,
51
+ :entity => "\e [31m" ,
52
+ :error => "\e [1;37;41m" ,
43
53
:exception => "\e [1;31m" ,
44
54
:float => "\e [1;35m" ,
45
55
:function => "\e [1;34m" ,
46
- :global_variable => "\e [42m " ,
56
+ :global_variable => "\e [1;32m " ,
47
57
:hex => "\e [1;36m" ,
48
- :include => "\e [33m" ,
58
+ :id => "\e [1;34m" ,
59
+ :include => "\e [31m" ,
49
60
:integer => "\e [1;34m" ,
50
- :key => "\e [35m" ,
51
- :label => "\e [1;15m" ,
61
+ :imaginary => "\e [1;34m" ,
62
+ :important => "\e [1;31m" ,
63
+ :key => {
64
+ :self => "\e [35m" ,
65
+ :char => "\e [1;35m" ,
66
+ :delimiter => "\e [1;35m" ,
67
+ } ,
68
+ :keyword => "\e [32m" ,
69
+ :label => "\e [1;33m" ,
52
70
:local_variable => "\e [33m" ,
53
- :octal => "\e [1;35m" ,
54
- :operator_name => "\e [1;29m" ,
71
+ :namespace => "\e [1;35m" ,
72
+ :octal => "\e [1;34m" ,
73
+ :predefined => "\e [36m" ,
55
74
:predefined_constant => "\e [1;36m" ,
56
- :predefined_type => "\e [1;30m" ,
57
- :predefined => "\e [4m\e [1;34m" ,
58
- :preprocessor => "\e [36m" ,
75
+ :predefined_type => "\e [1;32m" ,
76
+ :preprocessor => "\e [1;36m" ,
59
77
:pseudo_class => "\e [1;34m" ,
60
78
:regexp => {
61
- :self => "\e [31m" ,
62
- :content => "\e [31m" ,
63
- :delimiter => "\e [1;29m" ,
79
+ :self => "\e [35m" ,
80
+ :delimiter => "\e [1;35m" ,
64
81
:modifier => "\e [35m" ,
82
+ :char => "\e [1;35m" ,
65
83
} ,
66
- :reserved => "\e [1;31m " ,
84
+ :reserved => "\e [32m " ,
67
85
:shell => {
68
- :self => "\e [42m" ,
69
- :content => "\e [1;29m" ,
70
- :delimiter => "\e [37m" ,
86
+ :self => "\e [33m" ,
87
+ :char => "\e [1;33m" ,
88
+ :delimiter => "\e [1;33m" ,
89
+ :escape => "\e [1;33m" ,
71
90
} ,
72
91
:string => {
73
- :self => "\e [32m" ,
74
- :modifier => "\e [1;32m" ,
75
- :escape => "\e [1;36m" ,
76
- :delimiter => "\e [1;32m" ,
77
- :char => "\e [1;36m" ,
92
+ :self => "\e [31m" ,
93
+ :modifier => "\e [1;31m" ,
94
+ :char => "\e [1;35m" ,
95
+ :delimiter => "\e [1;31m" ,
96
+ :escape => "\e [1;31m" ,
97
+ } ,
98
+ :symbol => {
99
+ :self => "\e [33m" ,
100
+ :delimiter => "\e [1;33m" ,
78
101
} ,
79
- :symbol => "\e [1;32m" ,
80
- :tag => "\e [1;34m" ,
102
+ :tag => "\e [32m" ,
81
103
:type => "\e [1;34m" ,
82
104
:value => "\e [36m" ,
83
- :variable => "\e [1; 34m" ,
105
+ :variable => "\e [34m" ,
84
106
85
- :insert => "\e [42m" ,
86
- :delete => "\e [41m" ,
87
- :change => "\e [44m" ,
88
- :head => "\e [45m"
107
+ :insert => {
108
+ :self => "\e [42m" ,
109
+ :insert => "\e [1;32;42m" ,
110
+ :eyecatcher => "\e [102m" ,
111
+ } ,
112
+ :delete => {
113
+ :self => "\e [41m" ,
114
+ :delete => "\e [1;31;41m" ,
115
+ :eyecatcher => "\e [101m" ,
116
+ } ,
117
+ :change => {
118
+ :self => "\e [44m" ,
119
+ :change => "\e [37;44m" ,
120
+ } ,
121
+ :head => {
122
+ :self => "\e [45m" ,
123
+ :filename => "\e [37;45m"
124
+ } ,
89
125
}
126
+
90
127
TOKEN_COLORS [ :keyword ] = TOKEN_COLORS [ :reserved ]
91
128
TOKEN_COLORS [ :method ] = TOKEN_COLORS [ :function ]
92
- TOKEN_COLORS [ :imaginary ] = TOKEN_COLORS [ :complex ]
93
- TOKEN_COLORS [ :begin_group ] = TOKEN_COLORS [ :end_group ] =
94
- TOKEN_COLORS [ :escape ] = TOKEN_COLORS [ :delimiter ]
129
+ TOKEN_COLORS [ :escape ] = TOKEN_COLORS [ :delimiter ]
95
130
96
131
protected
97
132
98
133
def setup ( options )
99
134
super
100
135
@opened = [ ]
101
- @subcolors = nil
136
+ @color_scopes = [ TOKEN_COLORS ]
102
137
end
103
138
104
139
public
105
140
106
141
def text_token text , kind
107
- if color = ( @subcolors || TOKEN_COLORS ) [ kind ]
108
- if Hash === color
109
- if color [ :self ]
110
- color = color [ :self ]
111
- else
112
- @out << text
113
- return
114
- end
115
- end
142
+ if color = @color_scopes . last [ kind ]
143
+ color = color [ :self ] if color . is_a? Hash
116
144
117
145
@out << color
118
- @out << text . gsub ( "\n " , "\e [0m\n " + color )
146
+ @out << ( text . index ( " \n " ) ? text . gsub ( "\n " , "\e [0m\n " + color ) : text )
119
147
@out << "\e [0m"
120
- @out << @subcolors [ :self ] if @subcolors
148
+ if outer_color = @color_scopes . last [ :self ]
149
+ @out << outer_color
150
+ end
121
151
else
122
152
@out << text
123
153
end
@@ -130,40 +160,33 @@ def begin_group kind
130
160
alias begin_line begin_group
131
161
132
162
def end_group kind
133
- if @opened . empty?
134
- # nothing to close
135
- else
136
- @opened . pop
163
+ if @opened . pop
164
+ @color_scopes . pop
137
165
@out << "\e [0m"
138
- @out << open_token ( @opened . last )
166
+ if outer_color = @color_scopes . last [ :self ]
167
+ @out << outer_color
168
+ end
139
169
end
140
170
end
141
171
142
172
def end_line kind
143
- if @opened . empty?
144
- # nothing to close
145
- else
146
- @opened . pop
147
- # whole lines to be highlighted,
148
- # eg. added/modified/deleted lines in a diff
149
- @out << ( @line_filler ||= "\t " * 100 + "\e [0m" )
150
- @out << open_token ( @opened . last )
151
- end
173
+ @out << ( @line_filler ||= "\t " * 100 )
174
+ end_group kind
152
175
end
153
176
154
177
private
155
178
156
179
def open_token kind
157
- if color = TOKEN_COLORS [ kind ]
158
- if Hash === color
159
- @subcolors = color
180
+ if color = @color_scopes . last [ kind ]
181
+ if color . is_a? Hash
182
+ @color_scopes << color
160
183
color [ :self ]
161
184
else
162
- @subcolors = { }
185
+ @color_scopes << @color_scopes . last
163
186
color
164
187
end
165
188
else
166
- @subcolors = nil
189
+ @color_scopes << @color_scopes . last
167
190
''
168
191
end
169
192
end
0 commit comments