Class: Multish

Inherits:
Object
  • Object
show all
Defined in:
lib/multish.rb,
lib/multish/version.rb

Constant Summary collapse

VERSION =
'0.4.0'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run!(args) ⇒ Object



297
298
299
# File 'lib/multish.rb', line 297

def self.run!(args)
  self.new.run!(args)
end

Instance Method Details

#errored?Boolean

Returns:

  • (Boolean)


301
302
303
# File 'lib/multish.rb', line 301

def errored?
  @commands.any?(&:errored?)
end

#run!(args) ⇒ Object



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