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
|
# File 'lib/multish.rb', line 112
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.init_pair(2, Curses::COLOR_WHITE, Curses::COLOR_GREEN)
Curses.init_pair(3, Curses::COLOR_WHITE, Curses::COLOR_RED)
Curses.init_pair(4, Curses::COLOR_WHITE, Curses::COLOR_BLACK)
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
ensure
Curses.curs_set(1)
Curses.close_screen
if errored?
warn 'At least one of the commands exited with error.'
@commands.select(&:errored?).each do |command|
command.print_output!
end
exit 1
else
exit 0
end
end
end
|