When trapping INT ask if the task was completed #15

Closed
tj opened this Issue Oct 16, 2009 · 5 comments

3 participants

@tj
Owner
tj commented Oct 16, 2009

yup

@JosephPecoraro

This would require stopping the progress bar, which is in the commander lib. Otherwise you might get overlapping output if the progress ticks.

@tj
Owner
tj commented Jan 18, 2010

Even if you say its not completed it would still exit the process, but if you finish a project early and just press CTRL+C it would be nice to have a quick confirmation

@JosephPecoraro

Interesting. I thought that in the background the progress's output would fill up a STDOUT buffer. But, that doesn't seem to be the case when waiting on Ruby's gets. So this can be done without worrying about stopping the progress bar.

Example I used:

require 'rubygems'
require 'commander/import'

program :name, 'commander'
program :version, Commander::VERSION
program :description, 'Commander utility program.'
default_command :tst

trap('INT') {
  puts "inside interrupt, waiting for user input:"
  s = gets
  puts "thanks for saying: #{s}"
  exit
}

command :tst do |c|
  c.action do |args, options|
    progress (1..4).to_a do |x|
      sleep 1
    end
  end
end

I think, because commander already has program :int_message it might be appropriate to add a program :int_block or something like that.

@JosephPecoraro

I added a tiny patch to commander to provide an :int_block. Commit is 1498502f.

The above code's trap('INT') would turn into something like:

program :int_block do
  puts # Newline to move past the progress bar
  puts "inside interrupt, waiting for user input:"
  s = gets
  puts "thanks for saying: #{s}"
  abort "aborting" # Supplying a block, means we must choose to abort
end

If this gets upstreamed into commander then we can use the program :int_block, otherwise we could just do our own trap('INT').

@stephenmckinney
Collaborator

Pomo 2.0 will default to a background process. Closing this until it becomes apparent whether the foreground process is being used heavily and users still want this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment