Class: RubyJard::Screens::VariablesScreen
Overview
Display the relevant variables and constants of current context, scopes
Constant Summary
collapse
- KINDS =
[
KIND_SELF = :self,
KIND_LOC = :local_variable,
KIND_INS = :instance_variable,
KIND_CON = :constant,
KIND_GLOB = :global_variable
].freeze
- KIND_STYLES =
{
KIND_SELF => :constant,
KIND_LOC => :local_variable,
KIND_INS => :instance_variable,
KIND_CON => :constant,
KIND_GLOB => :instance_variable
}.freeze
- KIND_PRIORITIES =
{
KIND_SELF => 0,
KIND_LOC => 1,
KIND_INS => 2,
KIND_CON => 3,
KIND_GLOB => 4
}.freeze
- TOKEN_KIND_MAPS =
{
ident: KIND_LOC,
instance_variable: KIND_INS,
constant: KIND_CON,
predefined_constant: KIND_CON,
global_variable: KIND_GLOB
}.freeze
- TOKEN_KINDS =
TOKEN_KIND_MAPS.keys.flatten
Instance Attribute Summary
#cursor, #layout, #rows, #selected, #window
Instance Method Summary
collapse
#click, #move_down, #move_up, #page_down, #page_up
Constructor Details
Returns a new instance of VariablesScreen.
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/ruby_jard/screens/variables_screen.rb', line 41
def initialize(*args)
super
@frame_file = @session.current_frame&.frame_file
@frame_line = @session.current_frame&.frame_line
@frame_self = @session.current_frame&.frame_self
@frame_class = @session.current_frame&.frame_class
@frame_binding = @session.current_frame&.frame_binding
@inline_tokens = generate_inline_tokens(@frame_file, @frame_line)
@file_tokens = generate_file_tokens(@frame_file)
@inspection_decorator = RubyJard::Decorators::InspectionDecorator.new
@selected = 0
end
|
Instance Method Details
#base_row(name, size, assignment, mark, base_inspection) ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/ruby_jard/screens/variables_screen.rb', line 92
def base_row(name, size, assignment, mark, base_inspection)
RubyJard::Row.new(
line_limit: 3,
columns: [
RubyJard::Column.new(spans: [mark]),
RubyJard::Column.new(
word_wrap: RubyJard::Column::WORD_WRAP_BREAK_WORD,
spans: [name, size, assignment, base_inspection].flatten.compact
)
]
)
end
|
#build ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/ruby_jard/screens/variables_screen.rb', line 62
def build
variables = fetch_relevant_variables
@rows = variables.map do |variable|
name = span_name(variable)
size = span_size(variable)
assignment = RubyJard::Span.new(margin_right: 1, margin_left: 1, content: '=', styles: :text_primary)
inline_limit =
(@layout.width - 3) * 3 - name.content_length - size.content_length - assignment.content_length
inspections = @inspection_decorator.decorate_multiline(
variable[2], first_line_limit: inline_limit, line_limit: @layout.width - 3, lines: 7
)
base_inspection = inspections.shift
mark = span_mark(variable, inspections)
[
base_row(name, size, assignment, mark, base_inspection),
nested_rows(variable, inspections)
]
end.flatten.compact
end
|
#fetch_relevant_variables ⇒ Object
82
83
84
85
86
87
88
89
90
|
# File 'lib/ruby_jard/screens/variables_screen.rb', line 82
def fetch_relevant_variables
sort_variables(
self_variable +
fetch_local_variables +
fetch_instance_variables +
fetch_constants +
fetch_global_variables
)
end
|
#nested_rows(variable, nested_inspections) ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/ruby_jard/screens/variables_screen.rb', line 105
def nested_rows(variable, nested_inspections)
return nil if nested_inspections.empty? || variable[0] == KIND_SELF
nested_inspections.map do |spans|
RubyJard::Row.new(
line_limit: 1,
columns: [
RubyJard::Column.new,
RubyJard::Column.new(
word_wrap: RubyJard::Column::WORD_WRAP_BREAK_WORD,
spans: spans
)
]
)
end
end
|
#span_mark(variable, nested_inspections) ⇒ Object
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/ruby_jard/screens/variables_screen.rb', line 122
def span_mark(variable, nested_inspections)
if variable[0] == KIND_SELF || nested_inspections.empty?
RubyJard::Span.new(
content: ' ',
styles: :text_dim
)
else
RubyJard::Span.new(
content: '▾',
styles: :text_dim
)
end
end
|
#span_name(variable) ⇒ Object
136
137
138
139
140
141
|
# File 'lib/ruby_jard/screens/variables_screen.rb', line 136
def span_name(variable)
RubyJard::Span.new(
content: variable[1].to_s,
styles: [KIND_STYLES[variable[0].to_sym], inline?(variable[1]) ? :underline : nil]
)
end
|
#span_size(variable) ⇒ Object
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/ruby_jard/screens/variables_screen.rb', line 143
def span_size(variable)
value = variable[2]
size_label =
if RubyJard::Reflection.call_is_a?(value, Array) && !value.empty?
"(len:#{value.length})"
elsif RubyJard::Reflection.call_is_a?(value, String) && value.length > 20
"(len:#{value.length})"
elsif RubyJard::Reflection.call_is_a?(value, Hash) && !value.empty?
"(size:#{value.length})"
end
RubyJard::Span.new(
margin_left: 1,
content: size_label,
styles: :text_primary
)
end
|
#title ⇒ Object
58
59
60
|
# File 'lib/ruby_jard/screens/variables_screen.rb', line 58
def title
'Variables'
end
|