ruby_jard 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -1
- data/CHANGELOG.md +18 -0
- data/CNAME +1 -0
- data/README.md +206 -33
- data/_config.yml +1 -0
- data/docs/_config.yml +8 -0
- data/docs/demo.png +0 -0
- data/docs/index.md +238 -0
- data/docs/logo.jpg +0 -0
- data/docs/screen-backtrace.png +0 -0
- data/docs/screen-repl.png +0 -0
- data/docs/screen-source.png +0 -0
- data/docs/screen-threads.png +0 -0
- data/docs/screen-variables.png +0 -0
- data/images/bg_hr.png +0 -0
- data/images/blacktocat.png +0 -0
- data/images/body-bg.jpg +0 -0
- data/images/download-button.png +0 -0
- data/images/github-button.png +0 -0
- data/images/header-bg.jpg +0 -0
- data/images/highlight-bg.jpg +0 -0
- data/images/icon_download.png +0 -0
- data/images/sidebar-bg.jpg +0 -0
- data/images/sprite_download.png +0 -0
- data/javascripts/main.js +1 -0
- data/lib/ruby_jard.rb +3 -18
- data/lib/ruby_jard/box_drawer.rb +68 -22
- data/lib/ruby_jard/color_scheme.rb +28 -0
- data/lib/ruby_jard/color_schemes.rb +26 -0
- data/lib/ruby_jard/color_schemes/256_color_scheme.rb +64 -0
- data/lib/ruby_jard/color_schemes/deep_space_color_scheme.rb +63 -0
- data/lib/ruby_jard/column.rb +12 -6
- data/lib/ruby_jard/commands/continue_command.rb +1 -0
- data/lib/ruby_jard/commands/list_command.rb +29 -0
- data/lib/ruby_jard/commands/next_command.rb +1 -0
- data/lib/ruby_jard/commands/step_command.rb +1 -0
- data/lib/ruby_jard/commands/step_out_command.rb +1 -0
- data/lib/ruby_jard/console.rb +102 -18
- data/lib/ruby_jard/control_flow.rb +9 -8
- data/lib/ruby_jard/decorators/color_decorator.rb +46 -57
- data/lib/ruby_jard/decorators/inspection_decorator.rb +76 -0
- data/lib/ruby_jard/decorators/loc_decorator.rb +83 -107
- data/lib/ruby_jard/decorators/source_decorator.rb +1 -1
- data/lib/ruby_jard/keys.rb +1 -0
- data/lib/ruby_jard/layout.rb +9 -99
- data/lib/ruby_jard/layout_calculator.rb +151 -0
- data/lib/ruby_jard/layouts/narrow_layout.rb +41 -0
- data/lib/ruby_jard/layouts/wide_layout.rb +17 -103
- data/lib/ruby_jard/repl_processor.rb +5 -1
- data/lib/ruby_jard/repl_proxy.rb +2 -1
- data/lib/ruby_jard/row.rb +5 -5
- data/lib/ruby_jard/row_renderer.rb +108 -0
- data/lib/ruby_jard/screen.rb +20 -115
- data/lib/ruby_jard/screen_drawer.rb +8 -75
- data/lib/ruby_jard/screen_manager.rb +78 -55
- data/lib/ruby_jard/screen_renderer.rb +138 -0
- data/lib/ruby_jard/screens/backtrace_screen.rb +67 -69
- data/lib/ruby_jard/screens/menu_screen.rb +43 -38
- data/lib/ruby_jard/screens/source_screen.rb +43 -27
- data/lib/ruby_jard/screens/threads_screen.rb +91 -39
- data/lib/ruby_jard/screens/variables_screen.rb +72 -56
- data/lib/ruby_jard/session.rb +16 -0
- data/lib/ruby_jard/span.rb +8 -6
- data/lib/ruby_jard/version.rb +1 -1
- data/ruby_jard.gemspec +4 -4
- data/stylesheets/github-light.css +130 -0
- data/stylesheets/normalize.css +424 -0
- data/stylesheets/print.css +228 -0
- data/stylesheets/stylesheet.css +245 -0
- metadata +52 -21
- data/lib/ruby_jard/templates/column_template.rb +0 -17
- data/lib/ruby_jard/templates/row_template.rb +0 -22
- data/lib/ruby_jard/templates/space_template.rb +0 -15
- data/lib/ruby_jard/templates/span_template.rb +0 -25
data/lib/ruby_jard/console.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'tty-screen'
|
3
4
|
require 'io/console'
|
4
5
|
require 'English'
|
5
6
|
|
@@ -11,75 +12,158 @@ module RubyJard
|
|
11
12
|
return unless output.tty?
|
12
13
|
|
13
14
|
output.print tput('smcup')
|
15
|
+
rescue RubyJard::Error
|
16
|
+
# If tput not found, fallback to hard-coded sequence.
|
17
|
+
output.print "\e[?1049h\e[22;0;0t"
|
14
18
|
end
|
15
19
|
|
16
20
|
def stop_alternative_terminal(output)
|
17
21
|
return unless output.tty?
|
18
22
|
|
19
23
|
output.print tput('rmcup')
|
24
|
+
rescue RubyJard::Error
|
25
|
+
# If tput not found, fallback to hard-coded sequence.
|
26
|
+
output.print "\e[?1049l\e[23;0;0t"
|
20
27
|
end
|
21
28
|
|
22
29
|
def move_to(output, x, y)
|
23
30
|
return unless output.tty?
|
24
31
|
|
25
|
-
output.
|
32
|
+
output.print format("\e[%<row>d;%<col>dH", row: y + 1, col: x + 1)
|
26
33
|
end
|
27
34
|
|
28
35
|
def screen_size(output)
|
29
36
|
return [0, 0] unless output.tty?
|
30
37
|
|
31
|
-
|
32
|
-
[width, height]
|
38
|
+
[TTY::Screen.width, TTY::Screen.height]
|
33
39
|
end
|
34
40
|
|
35
|
-
def
|
41
|
+
def clear_screen(output)
|
36
42
|
return unless output.tty?
|
37
43
|
|
38
|
-
output.print
|
44
|
+
output.print "\e[3J"
|
39
45
|
end
|
40
46
|
|
41
|
-
def
|
47
|
+
def clear_screen_to_end(output)
|
42
48
|
return unless output.tty?
|
43
49
|
|
44
|
-
output.
|
50
|
+
output.print "\e[0J"
|
45
51
|
end
|
46
52
|
|
47
|
-
def
|
53
|
+
def disable_cursor!(output = STDOUT)
|
48
54
|
return unless output.tty?
|
49
55
|
|
50
56
|
output.print tput('civis')
|
57
|
+
rescue RubyJard::Error
|
58
|
+
# If tput not found, fallback to hard-coded sequence.
|
59
|
+
output.print "\e[?25l"
|
51
60
|
end
|
52
61
|
|
53
|
-
def
|
62
|
+
def enable_cursor!(output = STDOUT)
|
54
63
|
return unless output.tty?
|
55
64
|
|
56
|
-
output.print tput('
|
65
|
+
output.print tput('cnorm')
|
66
|
+
rescue RubyJard::Error
|
67
|
+
# If tput not found, fallback to hard-coded sequence.
|
68
|
+
output.print "\e[?12l\e[?25h"
|
69
|
+
end
|
70
|
+
|
71
|
+
def getch(input, timeout)
|
72
|
+
return input.getch(min: 0, time: timeout) if input.respond_to?(:getch)
|
73
|
+
|
74
|
+
raw!
|
75
|
+
disable_echo!
|
76
|
+
key =
|
77
|
+
begin
|
78
|
+
input.read_nonblock(255)
|
79
|
+
rescue IO::WaitReadable
|
80
|
+
io = IO.select([input], nil, nil, timeout)
|
81
|
+
if io.nil?
|
82
|
+
nil
|
83
|
+
else
|
84
|
+
retry
|
85
|
+
end
|
86
|
+
rescue IO::WaitWritable
|
87
|
+
nil
|
88
|
+
end
|
89
|
+
|
90
|
+
key
|
91
|
+
ensure
|
92
|
+
cooked!
|
93
|
+
enable_echo!
|
57
94
|
end
|
58
95
|
|
59
|
-
def
|
96
|
+
def raw!(output = STDOUT)
|
60
97
|
return unless output.tty?
|
61
98
|
|
62
|
-
|
99
|
+
begin
|
100
|
+
output.raw!
|
101
|
+
rescue StandardError
|
102
|
+
stty('raw')
|
103
|
+
end
|
63
104
|
end
|
64
105
|
|
65
|
-
def
|
106
|
+
def cooked!(output = STDOUT)
|
66
107
|
return unless output.tty?
|
67
108
|
|
68
|
-
|
109
|
+
begin
|
110
|
+
output.cooked!
|
111
|
+
rescue StandardError
|
112
|
+
# If stty not found, or raise error, nothing I can do
|
113
|
+
stty('-raw')
|
114
|
+
end
|
69
115
|
end
|
70
116
|
|
71
|
-
def
|
72
|
-
|
117
|
+
def disable_echo!(output = STDOUT)
|
118
|
+
return unless output.tty?
|
119
|
+
|
120
|
+
begin
|
121
|
+
output.echo = false
|
122
|
+
rescue StandardError
|
123
|
+
# If stty not found, or raise error, nothing I can do
|
124
|
+
stty('-echo')
|
125
|
+
end
|
126
|
+
end
|
73
127
|
|
128
|
+
def enable_echo!(output = STDOUT)
|
129
|
+
return unless output.tty?
|
130
|
+
|
131
|
+
begin
|
132
|
+
output.echo = true
|
133
|
+
rescue StandardError
|
134
|
+
# If stty not found, or raise error, nothing I can do
|
135
|
+
stty('echo')
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def cached_tput
|
140
|
+
@cached_tput ||= {}
|
141
|
+
end
|
142
|
+
|
143
|
+
def tput(*args)
|
74
144
|
command = "tput #{args.join(' ')}"
|
145
|
+
return cached_tput[command] unless cached_tput[command].nil?
|
146
|
+
|
147
|
+
output = `#{command}`
|
148
|
+
if $CHILD_STATUS.success?
|
149
|
+
cached_tput[command] = output
|
150
|
+
else
|
151
|
+
raise RubyJard::Error, "Fail to call `#{command}`: #{$CHILD_STATUS}"
|
152
|
+
end
|
153
|
+
rescue StandardError => e
|
154
|
+
raise RubyJard::Error, "Fail to call `#{command}`. Error: #{e}"
|
155
|
+
end
|
156
|
+
|
157
|
+
def stty(*args)
|
158
|
+
command = "stty #{args.join(' ')}"
|
75
159
|
output = `#{command}`
|
76
160
|
if $CHILD_STATUS.success?
|
77
161
|
output
|
78
162
|
else
|
79
|
-
raise
|
163
|
+
raise RubyJard::Error, "Fail to call `#{command}`: #{$CHILD_STATUS}"
|
80
164
|
end
|
81
165
|
rescue StandardError => e
|
82
|
-
raise
|
166
|
+
raise RubyJard::Error, "Fail to call `#{command}`. Error: #{e}"
|
83
167
|
end
|
84
168
|
end
|
85
169
|
end
|
@@ -7,14 +7,15 @@ module RubyJard
|
|
7
7
|
class ControlFlow
|
8
8
|
THROW_KEYWORD = :jard_control_flow
|
9
9
|
ALLOW_LIST = {
|
10
|
-
continue: [:times],
|
11
|
-
frame: [:frame],
|
12
|
-
up: [:times],
|
13
|
-
down: [:times],
|
14
|
-
next: [:times],
|
15
|
-
step: [:times],
|
16
|
-
step_out: [:times],
|
17
|
-
key_binding: [:action] # lib/ruby_jard/commands/step_command.rb
|
10
|
+
continue: [:times], # lib/ruby_jard/commands/continue_command.rb
|
11
|
+
frame: [:frame], # lib/ruby_jard/commands/frame_command.rb
|
12
|
+
up: [:times], # lib/ruby_jard/commands/up_command.rb
|
13
|
+
down: [:times], # lib/ruby_jard/commands/down_command.rb
|
14
|
+
next: [:times], # lib/ruby_jard/commands/next_command.rb
|
15
|
+
step: [:times], # lib/ruby_jard/commands/step_command.rb
|
16
|
+
step_out: [:times], # lib/ruby_jard/commands/step_out_command.rb
|
17
|
+
key_binding: [:action], # lib/ruby_jard/commands/step_command.rb
|
18
|
+
list: [] # lib/ruby_jard/commands/step_command.rb
|
18
19
|
}.freeze
|
19
20
|
|
20
21
|
attr_reader :command, :arguments
|
@@ -1,77 +1,66 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'pastel'
|
4
|
-
|
5
3
|
module RubyJard
|
6
4
|
module Decorators
|
7
5
|
##
|
8
|
-
# Manipulate and decorate color for texts.
|
9
|
-
# inject escape sequences to let the terminal emulator aware of target color. This
|
10
|
-
# class wraps around the core, validates, and standardizes the styles before feeding
|
11
|
-
# styling information to Pastel.
|
6
|
+
# Manipulate and decorate color for texts.
|
12
7
|
class ColorDecorator
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
:green,
|
17
|
-
:yellow,
|
18
|
-
:blue,
|
19
|
-
:magenta,
|
20
|
-
:cyan,
|
21
|
-
:white
|
22
|
-
].freeze
|
8
|
+
HEX_PATTERN_6 = /^#([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})$/i.freeze
|
9
|
+
HEX_PATTERN_3 = /^#([A-Fa-f0-9]{1})([A-Fa-f0-9]{1})([A-Fa-f0-9]{1})$/i.freeze
|
10
|
+
XTERM_NUMBER_PATTERN = /^([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])$/i.freeze
|
23
11
|
|
24
|
-
|
25
|
-
|
26
|
-
|
12
|
+
CSI_RESET = "\e[0m"
|
13
|
+
CSI_FOREGROUND_24BIT = "\e[38;2;%d;%d;%dm"
|
14
|
+
CSI_BACKGROUND_24BIT = "\e[48;2;%d;%d;%dm"
|
15
|
+
CSI_FOREGROUND_256 = "\e[38;5;%dm"
|
16
|
+
CSI_BACKGROUND_256 = "\e[48;5;%dm"
|
27
17
|
|
28
|
-
|
29
|
-
|
30
|
-
@pastel.decorate(text, *styles)
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
18
|
+
CSI_ITALIC = "\e[3m"
|
19
|
+
CSI_UNDERLINE = "\e[4m"
|
34
20
|
|
35
|
-
|
36
|
-
|
21
|
+
STYLES_CSI_MAP = {
|
22
|
+
underline: CSI_UNDERLINE,
|
23
|
+
italic: CSI_ITALIC
|
24
|
+
}.freeze
|
37
25
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
elsif styles.include?(:brighter)
|
42
|
-
# Convert all color -> bright_color
|
43
|
-
styles = brighter(styles)
|
44
|
-
end
|
26
|
+
def initialize(color_scheme)
|
27
|
+
@color_scheme = color_scheme
|
28
|
+
end
|
45
29
|
|
46
|
-
|
30
|
+
# TODO: rename and replace #decorate by this method
|
31
|
+
def decorate(element, content)
|
32
|
+
styles = @color_scheme.styles_for(element) || []
|
33
|
+
foreground = translate_color(styles.shift, true)
|
34
|
+
background = translate_color(styles.shift, false)
|
35
|
+
"#{foreground}#{background}#{translate_styles(styles)}#{content}#{CSI_RESET}"
|
47
36
|
end
|
48
37
|
|
49
|
-
|
50
|
-
styles.map do |color|
|
51
|
-
next if [:darker, :brighter].include?(color)
|
38
|
+
private
|
52
39
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
40
|
+
def translate_color(color, foreground)
|
41
|
+
if matches = HEX_PATTERN_6.match(color.to_s)
|
42
|
+
red = matches[1].to_i(16)
|
43
|
+
green = matches[2].to_i(16)
|
44
|
+
blue = matches[3].to_i(16)
|
45
|
+
sequence = foreground ? CSI_FOREGROUND_24BIT : CSI_BACKGROUND_24BIT
|
46
|
+
format sequence, red, green, blue
|
47
|
+
elsif matches = HEX_PATTERN_3.match(color.to_s)
|
48
|
+
red = (matches[1] * 2).to_i(16)
|
49
|
+
green = (matches[2] * 2).to_i(16)
|
50
|
+
blue = (matches[3] * 2).to_i(16)
|
51
|
+
sequence = foreground ? CSI_FOREGROUND_24BIT : CSI_BACKGROUND_24BIT
|
52
|
+
format sequence, red, green, blue
|
53
|
+
elsif matches = XTERM_NUMBER_PATTERN.match(color.to_s)
|
54
|
+
color = matches[1]
|
55
|
+
sequence = foreground ? CSI_FOREGROUND_256 : CSI_BACKGROUND_256
|
56
|
+
format sequence, color
|
57
|
+
else
|
58
|
+
''
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
def
|
63
|
-
styles.map
|
64
|
-
next if [:darker, :brighter].include?(color)
|
65
|
-
|
66
|
-
color_str = color.to_s
|
67
|
-
if color_str.start_with?('bright_')
|
68
|
-
color
|
69
|
-
elsif COLORS.include?(color)
|
70
|
-
"bright_#{color}".to_sym
|
71
|
-
else
|
72
|
-
color
|
73
|
-
end
|
74
|
-
end
|
62
|
+
def translate_styles(styles = [])
|
63
|
+
styles.map { |key| STYLES_CSI_MAP[key] }.compact.join
|
75
64
|
end
|
76
65
|
end
|
77
66
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyJard
|
4
|
+
# PP subclass for streaming inspect output in color.
|
5
|
+
class InspectionDecorator < ::PP::SingleLine
|
6
|
+
def self.inspect(obj, output = [], max_width = 79)
|
7
|
+
queue = new(output, max_width)
|
8
|
+
queue.guard_inspect_key { queue.pp obj }
|
9
|
+
queue.flush
|
10
|
+
|
11
|
+
queue.output.flatten
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :output
|
15
|
+
|
16
|
+
def initialize(output, max_width = nil, new_line = nil)
|
17
|
+
@output = output
|
18
|
+
@first = [true]
|
19
|
+
@max_width = max_width
|
20
|
+
@width = 0
|
21
|
+
@new_line = new_line
|
22
|
+
@loc_decorator = RubyJard::Decorators::LocDecorator.new
|
23
|
+
end
|
24
|
+
|
25
|
+
def pp(object)
|
26
|
+
return if @width > @max_width
|
27
|
+
return super unless object.is_a?(String)
|
28
|
+
|
29
|
+
puts @output.length
|
30
|
+
text(object.inspect)
|
31
|
+
end
|
32
|
+
|
33
|
+
def text(str, _max_width = str.length)
|
34
|
+
if str.start_with?('#<') || ['>'].include?(str)
|
35
|
+
append_output(str, :object)
|
36
|
+
elsif [' ', '=', '=>'].include?(str)
|
37
|
+
append_output(str, :trivial_inspection)
|
38
|
+
elsif str.start_with?("\e")
|
39
|
+
append_output(str.gsub(/\e/i, '\e'), :trivial_inspection)
|
40
|
+
else
|
41
|
+
spans, _tokens = @loc_decorator.decorate(str)
|
42
|
+
spans.each do |span|
|
43
|
+
break if @width > @max_width
|
44
|
+
|
45
|
+
@output << span
|
46
|
+
@width += span.content_length
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def breakable(sep = ' ', _width = nil)
|
52
|
+
append_output(sep, :trivial_inspection)
|
53
|
+
end
|
54
|
+
|
55
|
+
def group(_indent = nil, open_obj = nil, close_obj = nil, _open_width = nil, _close_width = nil)
|
56
|
+
@first.push true
|
57
|
+
append_output(open_obj, :normal_token) unless open_obj.nil?
|
58
|
+
yield
|
59
|
+
append_output(close_obj, :normal_token) unless close_obj.nil?
|
60
|
+
@first.pop
|
61
|
+
end
|
62
|
+
|
63
|
+
def append_output(str, style)
|
64
|
+
return if str.empty?
|
65
|
+
return if @width > @max_width
|
66
|
+
|
67
|
+
@output << Span.new(
|
68
|
+
span_template: nil,
|
69
|
+
content: str,
|
70
|
+
content_length: str.length,
|
71
|
+
styles: style
|
72
|
+
)
|
73
|
+
@width += str.length
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -9,28 +9,23 @@ module RubyJard
|
|
9
9
|
# The line is tokenized, and feed into JardEncoder to append color (with
|
10
10
|
# Span).
|
11
11
|
class LocDecorator
|
12
|
-
|
13
|
-
|
14
|
-
def initialize(file, loc)
|
15
|
-
@file = file
|
16
|
-
@loc = loc
|
12
|
+
def initialize
|
17
13
|
@encoder = JardLocEncoder.new
|
18
|
-
|
19
|
-
decorate
|
20
14
|
end
|
21
15
|
|
22
|
-
def decorate
|
23
|
-
|
24
|
-
|
16
|
+
def decorate(loc, file = nil)
|
17
|
+
tokens = CodeRay.scan(loc, extension(file))
|
18
|
+
spans = @encoder.encode_tokens(tokens)
|
19
|
+
[spans, tokens]
|
25
20
|
end
|
26
21
|
|
27
22
|
private
|
28
23
|
|
29
|
-
def extension
|
24
|
+
def extension(file)
|
30
25
|
# TODO: A map constant is better
|
31
|
-
if
|
26
|
+
if file =~ /.*\.erb$/
|
32
27
|
:erb
|
33
|
-
elsif
|
28
|
+
elsif file =~ /.*\.haml$/
|
34
29
|
:haml
|
35
30
|
else
|
36
31
|
:ruby
|
@@ -39,111 +34,93 @@ module RubyJard
|
|
39
34
|
|
40
35
|
# A shameless copy from https://github.com/rubychan/coderay/blob/master/lib/coderay/encoders/terminal.rb
|
41
36
|
class JardLocEncoder < CodeRay::Encoders::Encoder
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
attribute_value: [:blue],
|
37
|
+
DEFAULT_STYLE = :normal_token
|
38
|
+
TOKEN_STYLES = {
|
39
|
+
annotation: :keyword,
|
40
|
+
attribute_name: :keyword,
|
41
|
+
attribute_value: :keyword,
|
48
42
|
binary: {
|
49
|
-
self:
|
50
|
-
char:
|
51
|
-
delimiter:
|
43
|
+
self: :keyword,
|
44
|
+
char: :keyword,
|
45
|
+
delimiter: :keyword
|
52
46
|
},
|
53
47
|
char: {
|
54
|
-
self:
|
55
|
-
delimiter:
|
48
|
+
self: :keyword,
|
49
|
+
delimiter: :keyword
|
56
50
|
},
|
57
|
-
class:
|
58
|
-
class_variable:
|
59
|
-
color:
|
51
|
+
class: :constant,
|
52
|
+
class_variable: :constant,
|
53
|
+
color: :constant,
|
60
54
|
comment: {
|
61
|
-
self:
|
62
|
-
char:
|
63
|
-
delimiter:
|
55
|
+
self: :comment,
|
56
|
+
char: :comment,
|
57
|
+
delimiter: :comment
|
64
58
|
},
|
65
|
-
constant:
|
66
|
-
decorator:
|
67
|
-
definition:
|
68
|
-
directive:
|
69
|
-
docstring:
|
70
|
-
doctype:
|
71
|
-
done:
|
72
|
-
entity:
|
73
|
-
error:
|
74
|
-
exception:
|
75
|
-
float:
|
76
|
-
function:
|
77
|
-
method:
|
78
|
-
global_variable:
|
79
|
-
hex:
|
80
|
-
id:
|
81
|
-
include:
|
82
|
-
integer:
|
83
|
-
imaginary:
|
84
|
-
important:
|
59
|
+
constant: :constant,
|
60
|
+
decorator: :keyword,
|
61
|
+
definition: :keyword,
|
62
|
+
directive: :keyword,
|
63
|
+
docstring: :keyword,
|
64
|
+
doctype: :keyword,
|
65
|
+
done: :keyword,
|
66
|
+
entity: :keyword,
|
67
|
+
error: :constant,
|
68
|
+
exception: :keyword,
|
69
|
+
float: :literal,
|
70
|
+
function: :constant,
|
71
|
+
method: :method,
|
72
|
+
global_variable: :constant,
|
73
|
+
hex: :keyword,
|
74
|
+
id: :keyword,
|
75
|
+
include: :keyword,
|
76
|
+
integer: :literal,
|
77
|
+
imaginary: :keyword,
|
78
|
+
important: :keyword,
|
85
79
|
key: {
|
86
|
-
self:
|
87
|
-
char:
|
88
|
-
delimiter:
|
80
|
+
self: :literal,
|
81
|
+
char: :literal,
|
82
|
+
delimiter: :literal
|
89
83
|
},
|
90
|
-
label:
|
91
|
-
local_variable:
|
92
|
-
namespace:
|
93
|
-
octal:
|
94
|
-
predefined:
|
95
|
-
predefined_constant:
|
96
|
-
predefined_type:
|
97
|
-
preprocessor:
|
98
|
-
pseudo_class:
|
84
|
+
label: :literal,
|
85
|
+
local_variable: :keyword,
|
86
|
+
namespace: :keyword,
|
87
|
+
octal: :keyword,
|
88
|
+
predefined: :keyword,
|
89
|
+
predefined_constant: :keyword,
|
90
|
+
predefined_type: :constant,
|
91
|
+
preprocessor: :keyword,
|
92
|
+
pseudo_class: :keyword,
|
99
93
|
regexp: {
|
100
|
-
self:
|
101
|
-
delimiter:
|
102
|
-
modifier:
|
103
|
-
char:
|
94
|
+
self: :keyword,
|
95
|
+
delimiter: :keyword,
|
96
|
+
modifier: :keyword,
|
97
|
+
char: :keyword
|
104
98
|
},
|
105
|
-
reserved:
|
106
|
-
keyword:
|
99
|
+
reserved: :keyword,
|
100
|
+
keyword: :keyword,
|
107
101
|
shell: {
|
108
|
-
self:
|
109
|
-
char:
|
110
|
-
delimiter:
|
111
|
-
escape:
|
102
|
+
self: :keyword,
|
103
|
+
char: :keyword,
|
104
|
+
delimiter: :keyword,
|
105
|
+
escape: :keyword
|
112
106
|
},
|
113
107
|
string: {
|
114
|
-
self:
|
115
|
-
modifier:
|
116
|
-
char:
|
117
|
-
delimiter:
|
118
|
-
escape:
|
108
|
+
self: :string,
|
109
|
+
modifier: :string,
|
110
|
+
char: :string,
|
111
|
+
delimiter: :string,
|
112
|
+
escape: :string,
|
113
|
+
content: :string
|
119
114
|
},
|
120
115
|
symbol: {
|
121
|
-
self:
|
122
|
-
delimiter:
|
123
|
-
},
|
124
|
-
tag: [:green],
|
125
|
-
type: [:blue],
|
126
|
-
value: [:blue],
|
127
|
-
variable: [:blue],
|
128
|
-
insert: {
|
129
|
-
self: [:on_green],
|
130
|
-
insert: [:green, :on_green],
|
131
|
-
eyecatcher: [:italic]
|
132
|
-
},
|
133
|
-
delete: {
|
134
|
-
self: [:on_red],
|
135
|
-
delete: [:blue, :on_red],
|
136
|
-
eyecatcher: [:italic]
|
137
|
-
},
|
138
|
-
change: {
|
139
|
-
self: [:on_blue],
|
140
|
-
change: [:white, :on_blue]
|
141
|
-
},
|
142
|
-
head: {
|
143
|
-
self: [:on_red],
|
144
|
-
filename: [:white, :on_red]
|
116
|
+
self: :literal,
|
117
|
+
delimiter: :literal
|
145
118
|
},
|
146
|
-
|
119
|
+
tag: :constant,
|
120
|
+
type: :keyword,
|
121
|
+
value: :keyword,
|
122
|
+
variable: :keyword,
|
123
|
+
instance_variable: :instance_variable
|
147
124
|
}.freeze
|
148
125
|
|
149
126
|
protected
|
@@ -151,7 +128,7 @@ module RubyJard
|
|
151
128
|
def setup(options)
|
152
129
|
super
|
153
130
|
@opened = []
|
154
|
-
@color_scopes = [
|
131
|
+
@color_scopes = [TOKEN_STYLES]
|
155
132
|
@out = []
|
156
133
|
end
|
157
134
|
|
@@ -160,19 +137,18 @@ module RubyJard
|
|
160
137
|
def text_token(text, kind)
|
161
138
|
color = @color_scopes.last[kind]
|
162
139
|
text.gsub!("\n", '')
|
163
|
-
|
140
|
+
style =
|
164
141
|
if !color
|
165
|
-
|
142
|
+
DEFAULT_STYLE
|
166
143
|
elsif color.is_a? Hash
|
167
144
|
color[:self]
|
168
145
|
else
|
169
146
|
color
|
170
147
|
end
|
171
148
|
@out << Span.new(
|
172
|
-
span_template: nil,
|
173
149
|
content: text,
|
174
150
|
content_length: text.length,
|
175
|
-
styles:
|
151
|
+
styles: style.to_sym
|
176
152
|
)
|
177
153
|
end
|
178
154
|
|