Class: DialogTui::Dialog

Inherits:
Object
  • Object
show all
Includes:
UserAction
Defined in:
lib/dialog_tui.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from UserAction

read_char, show_single_key, user_action

Constructor Details

#initialize(&block) ⇒ Dialog

Returns a new instance of Dialog.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dialog_tui.rb', line 39

def initialize &block
  @options = []

  if block.arity == 0
    instance_eval &block
  else
    block.call self
  end

  raise unless @options.count > 0
  # options list is assumed to be fixed now

  @current = @options.first
  @neighbors = Neighbors.new @options
end

Class Method Details

.run(&block) ⇒ Object



34
35
36
# File 'lib/dialog_tui.rb', line 34

def self.run &block
  new(&block).run
end

Instance Method Details

#chosen?(option) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/dialog_tui.rb', line 84

def chosen? option
  @current == option  # so current or chosen?)
end

#runObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/dialog_tui.rb', line 55

def run
  begin
    # print_usage  #...
    print_options  # would be nice to have a printer...

    done = false
    
    user_action { |key|

      key.up do
        @current = prev
      end

      key.down do
        @current = nexxt
      end

      #key.ctrl_c do  exit 0  end
      #key.esc do     exit 0  end

      key.enter do
        done = true
      end
    }
  end until done

  @current.call
end