99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/mrubyc/debugger/console.rb', line 99
def run(show_colors_at_start = false)
mainwin = init_screen
mainwin.keypad true
mainwin.timeout = 0
curs_set(0)
start_color
make_pair
show_colors if show_colors_at_start
begin
wins = []
num = @srcs.size
num.times do |i|
win = {}
win[:src] = mainwin.subwin(lines - 6, cols / num, 0, i * cols / num)
win[:out] = mainwin.subwin(1, cols / num, lines - 6, i * cols / num)
win[:var] = mainwin.subwin(5, cols / num, lines - 5, i * cols / num)
wins << win
end
while true
@key = mainwin.getch
handle_key
num.times do |i|
wins[i][:src].resize(lines - 6, cols / num)
wins[i][:out].resize(1, cols / num)
wins[i][:var].resize(5, cols / num)
unless $sleep_queues[i].empty?
@sleepers[i] = $sleep_queues[i].pop
end
if @sleepers[i] && @sleepers[i] < Process.clock_gettime(Process::CLOCK_MONOTONIC_RAW, :millisecond)
@sleepers[i] = nil
$threads[i].run
end
unless $debug_queues[i].empty?
message = $debug_queues[i].pop
wins[i][:out].setpos(0, 0)
color_num = color_num_by(message[:level])
wins[i][:out].addstr '|'
wins[i][:out].attron(color_pair color_num)
wins[i][:out].addstr " #{message[:level].to_s[0].upcase}) " + message[:body].ljust(wins[i][:out].maxx-6)
wins[i][:out].attroff(color_pair color_num)
wins[i][:out].addstr '|'
wins[i][:out].refresh
end
unless $event_queues[i].empty?
@events[i] = $event_queues[i].pop
end
if @events[i]
threads_debug_print(i)
(1..(wins[i][:src].maxy - 2)).each do |y|
wins[i][:src].setpos(y, 1)
if !@srcs[i][y]
wins[i][:src].addstr ' ' * wins[i][:src].maxx
else
lineno = @events[i][:lineno] - 1 wins[i][:src].attron(A_UNDERLINE) if y == @cursor_pos[:y] && i == @cursor_pos[:x]
wins[i][:src].attron(A_REVERSE) if y == lineno
lineno_color = if $breakpoints.any? {|bp| bp == [i, y] }
21
else
16
end
wins[i][:src].attron(color_pair lineno_color)
wins[i][:src].attron(A_BOLD)
wins[i][:src].addstr y.to_s.rjust(2).to_s
wins[i][:src].attroff(A_BOLD)
wins[i][:src].attroff(color_pair lineno_color)
wins[i][:src].addstr ' ' + @srcs[i][y]
wins[i][:src].attroff(A_REVERSE) if y == lineno
wins[i][:src].attroff(A_UNDERLINE) if y == @cursor_pos[:y] && i == @cursor_pos[:x]
end
end
wins[i][:src].box(?|,?-,?+)
wins[i][:src].refresh
if @events[i][:breakpoint]
command_line(i, wins[i][:var], @events[i][:tp_binding])
@events[i][:breakpoint] = nil else
vars = {}
@events[i][:tp_binding].local_variables.each do |var|
vars[var] = @events[i][:tp_binding].local_variable_get(var).inspect
end
vars.each_with_index do |(k,v),j|
wins[i][:var].setpos(j+1, 2)
wins[i][:var].addstr (k.to_s + ' => ' + v).ljust(wins[i][:var].maxx)
end
box_var_win(wins[i][:var], 16)
end
end
end
refresh
end
rescue => e
sleep 5
ensure
finish
end
end
|