lib/dialog_tui.rb in dialog_tui-0.1.2 vs lib/dialog_tui.rb in dialog_tui-0.1.3

- old
+ new

@@ -53,10 +53,11 @@ end def run begin # print_usage #... + before_draw! # like controller method here... print_options # would be nice to have a printer... done = false user_action { |key| @@ -97,10 +98,19 @@ def ctrl_c &block @ctrl_c ||= [] @ctrl_c << block end + def before_draw &block + @before_draw ||= [] + @before_draw << block + end + def before_draw! + @before_draw.each &:call if @before_draw + end + # third => to DRY I guess + private def print_options puts '-'*10 @options.each &:print puts '-'*10 @@ -175,21 +185,28 @@ ctrl_c do puts 'ctrl+c worked!' exit 0 end + before_draw do + system 'clear' + puts + puts ?_*10 + puts 'manual testing here - use arrows and enter' + puts 'no way to fail it - just look at behavior' + puts 'ctrl+c when finished' + end + }. tap { |result| raise unless result.nil? # because it works for effect, not for return value } end end - puts - puts ?_*10 - puts 'manual testing here - use arrows and enter' - puts 'no way to fail it - just look at behavior' - puts 'ctrl+c when finished' - My.new.act + loop { + My.new.act + gets + } end