Skip to content

Commit 098fdd4

Browse files
committed
Use TC metadata to provide ThreadClient info about TUI
Since TUI needs to display up-to-date information once enabled, I think it makes sense to pass its information to ThreadClient in every request. This information will help ThreadClient 1. know when to send back TUI data when not to. 2. send back data that fits the best on TUI. For example: the line of content.
1 parent d4e6796 commit 098fdd4

File tree

3 files changed

+47
-29
lines changed

3 files changed

+47
-29
lines changed

lib/debug/local.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,9 @@ def after_fork_parent
113113
class UI_LocalTuiConsole < UI_LocalConsole
114114
SUPPORTED_TYPES = [:locals, :src]
115115

116-
attr_reader :type
116+
attr_reader :screen
117117

118118
def initialize(type)
119-
@type = type
120119
@screen = Screen.new(width, height, top_frame: type)
121120
super()
122121
end
@@ -211,7 +210,7 @@ def clear_screen!
211210
end
212211

213212
class Window
214-
attr_reader :width, :height
213+
attr_reader :width, :height, :content_width, :content_height
215214

216215
def initialize(width, height)
217216
@width = width
@@ -258,6 +257,8 @@ def clear!
258257
class TopFrame < Window
259258
HEIGHT = 15
260259

260+
attr_reader :type
261+
261262
def initialize(width, height, type:)
262263
super(width, height)
263264
# border and padding

lib/debug/session.rb

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,28 @@ def session_server_main
202202
deactivate
203203
end
204204

205+
def tui_metadata
206+
if @ui.tui?
207+
top_frame = @ui.screen.top_frame
208+
{ type: top_frame.type, height: top_frame.content_height }
209+
end
210+
end
211+
205212
def request_tc(req)
206-
@tc << req
213+
metadata = {}
214+
215+
if tui_meta = tui_metadata
216+
metadata[:tui] = tui_meta
217+
end
218+
219+
@tc << [req, metadata]
207220
end
208221

209222
def process_event evt
210223
# variable `@internal_info` is only used for test
211224
@tc, output, ev, @internal_info, *ev_args = evt
212225

213-
capture_tui_data if @ui.tui?
226+
capture_tui_data(@internal_info[:tui]) if @ui.tui?
214227

215228
output.each{|str| @ui.puts str} if ev != :suspend
216229

@@ -1770,9 +1783,9 @@ def after_fork_parent
17701783
@ui.after_fork_parent
17711784
end
17721785

1773-
def capture_tui_data
1774-
if tui_data = @internal_info[:tui]
1775-
@ui.store_tui_data(tui_data[@ui.type])
1786+
def capture_tui_data(tui_data)
1787+
if tui_data
1788+
@ui.store_tui_data(tui_data[@ui.screen.top_frame.type])
17761789
end
17771790
end
17781791

@@ -1784,7 +1797,8 @@ def start_tui(type)
17841797
end
17851798

17861799
@ui = UI_LocalTuiConsole.new(type)
1787-
capture_tui_data
1800+
tui_data = @tc.generate_tui_data(tui_metadata)
1801+
capture_tui_data(tui_data)
17881802
@ui.puts
17891803
else
17901804
@ui.puts("TUI can't be activated under this mode")

lib/debug/thread_client.rb

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -187,33 +187,35 @@ def << req
187187
@q_cmd << req
188188
end
189189

190-
def generate_tui_data(type)
191-
case type
192-
when :src
193-
frame = current_frame
194-
start_line, end_line, lines = get_src(frame: frame, max_lines: 15)
195-
196-
if start_line
197-
lines[start_line, end_line]
198-
else
199-
"# No sourcefile available for #{frame.path}"
200-
end
201-
when :locals
202-
locals = collect_locals(current_frame).map do |var, val|
203-
variable_info(var, val, nil)
190+
def generate_tui_data(metadata)
191+
type = metadata[:type]
192+
data =
193+
case type
194+
when :src
195+
frame = current_frame
196+
start_line, end_line, lines = get_src(frame: frame, max_lines: metadata[:height])
197+
198+
if start_line
199+
lines[start_line, end_line]
200+
else
201+
"# No sourcefile available for #{frame.path}"
202+
end
203+
when :locals
204+
locals = collect_locals(current_frame).map do |var, val|
205+
variable_info(var, val, nil)
206+
end
204207
end
205-
end
208+
209+
{ type => data }
206210
end
207211

208212
def generate_info
209213
return {} unless current_frame
210214

211215
result = { location: current_frame.location_str, line: current_frame.location.lineno }
212216

213-
result[:tui] = {}
214-
215-
[:locals, :src].each do |type|
216-
result[:tui][type] = generate_tui_data(type)
217+
if @tui_metadata
218+
result[:tui] = generate_tui_data(@tui_metadata)
217219
end
218220

219221
result
@@ -755,13 +757,14 @@ def wait_next_action_
755757
while true
756758
begin
757759
set_mode :waiting if !waiting?
758-
cmds = @q_cmd.pop
760+
cmds, metadata = @q_cmd.pop
759761
# pp [self, cmds: cmds]
760762
break unless cmds
761763
ensure
762764
set_mode :running
763765
end
764766

767+
@tui_metadata = metadata[:tui]
765768
cmd, *args = *cmds
766769

767770
case cmd

0 commit comments

Comments
 (0)