305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
|
# File 'lib/multish.rb', line 305
def run!(args)
@commands = args.each_with_index.map { |arg, index| MultishItem.new(arg, index, args.count) }
Curses.init_screen
Curses.start_color
Curses.curs_set(0)
Curses.use_default_colors
Curses.cbreak
@commands.each(&:create_window!)
@commands.each(&:open_process!)
fdlist = @commands.flat_map(&:streams)
begin
while true
fdlist.reject!(&:closed?)
break if fdlist.empty?
ready = IO.select(fdlist)[0]
ready.each do |fd|
@commands.each { |command| command.try_update(fd) }
end
@commands.each(&:update_title!)
break if @commands.all?(&:finished?)
end
rescue StandardError => e
Curses.close_screen
warn 'INTERNAL ERROR'.red
warn e.message
warn e.backtrace
ensure
Curses.curs_set(1)
Curses.close_screen
warn $log.join("\n").blue
if errored?
warn 'At least one of the commands exited with error.'
@commands.select(&:errored?).each(&:print_output!)
exit 1
else
exit 0
end
end
end
|