lib/dialog_tui.rb in dialog_tui-0.1.1 vs lib/dialog_tui.rb in dialog_tui-0.1.2
- old
+ new
@@ -73,10 +73,14 @@
#key.esc do exit 0 end
key.enter do
done = true
end
+
+ key.ctrl_c do
+ @ctrl_c.each(&:call) if @ctrl_c
+ end
}
end until done
@current.call
end
@@ -88,10 +92,15 @@
def option text, &reaction
option = Option.new self, text, &reaction # order?
@options.push option
end
+ def ctrl_c &block
+ @ctrl_c ||= []
+ @ctrl_c << block
+ end
+
private
def print_options
puts '-'*10
@options.each &:print
puts '-'*10
@@ -160,21 +169,27 @@
end
option '3. bye' do
puts '*waving*'
end
+
+ ctrl_c do
+ puts 'ctrl+c worked!'
+ exit 0
+ end
+
}.
tap { |result|
raise unless result.nil?
# because it works for effect, not for return value
}
end
end
- puts '-----'
- puts '3 times - choose any option:'
- puts '-----'
+ puts
+ puts ?_*10
puts 'manual testing here - use arrows and enter'
puts 'no way to fail it - just look at behavior'
- 3.times { My.new.act }
+ puts 'ctrl+c when finished'
+ My.new.act
end