Top Level Namespace

Includes:
ColorMap, Ncurses, RubyCurses

Defined Under Namespace

Modules: ColorMap, DSL, Io, ListEditable, ListScrollable, RubyCurses, Scrollable, Selectable, TableExtended, VER, ViEditable Classes: Fixnum, Mapper, Module, OrderedHash, Rbcurse

Constant Summary collapse

KEY_TAB =
9
KEY_BTAB =
353

Constants included from RubyCurses

RubyCurses::META_KEY

Instance Method Summary collapse

Methods included from ColorMap

colors, get_color, get_color_const, install_color, setup

Methods included from RubyCurses

startup

Instance Method Details

#alert(text, config = {}, &block) ⇒ Object

pops up a modal box with a message and an OK button. No return value. Usage: alert(“You did not enter anything!”) alert(“You did not enter anything!”, “title”=>“Wake Up”) alert(“You did not enter anything!”, Up”, “bgcolor”=>“blue”, “color”=>“white”) block currently ignored. don’t know what to do, can’t pass it to MB since alread sending in a block



29
30
31
32
33
34
35
36
37
# File 'lib/rbcurse/rdialogs.rb', line 29

def alert text, config={}, &block
  title = config['title'] || "Alert"
  #instance_eval &block if block_given?
  mb = RubyCurses::MessageBox.new nil, config  do
    title title
    message text
    button_type :ok
  end
end

#confirm(text, config = {}, &block) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/rbcurse/rdialogs.rb', line 38

def confirm text, config={}, &block
  title = config['title'] || "Confirm"
  #instance_eval &block if block_given?
  mb = RubyCurses::MessageBox.new nil, config  do
    title title
    message text
    button_type :yes_no
  end
  return mb.selected_index == 0 ? :YES : :NO
end

#get_string(message, len = 20, default = "", config = {}) ⇒ Object

allows user entry of a string. In config you may pass Field related properties such as chars_allowed, valid_regex, values, etc.



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rbcurse/rdialogs.rb', line 52

def get_string(message, len=20, default="", config={})
  config["maxlen"]=len
  title = config["title"] || "Input required"
  mb = RubyCurses::MessageBox.new nil, config do
    title title
    message message
    type :input
    button_type :ok
    default_value default
  end
  return mb.input_value
end

#get_string_with_options(message, len = 20, default = "", config = {}) ⇒ Object

@param: message to print, @param: length of entry field @param: default value of field @param: configuration of box or field

checkboxes: array of strings to use as checkboxes
checkbox_defaults : array of true/false default values for each cb

@return: int 0 OK, 1 cancel pressed @return: string value entered @return: hash of strings and booleans for checkboxes and values



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/rbcurse/rdialogs.rb', line 83

def get_string_with_options(message, len=20, default="", config={})
  title = config["title"] || "Input required"
  input_config = config["input_config"] || {}
  checks = config["checkboxes"] 
  checkbox_defaults = config["checkbox_defaults"] || []

  height = config["height"] || 1
  display_length = config["display_length"] || 30

  r = 3
  c = 4
  mform = RubyCurses::Form.new nil
  message_label = RubyCurses::Label.new mform, {'text' => message, "name"=>"message_label","row" => r, "col" => c, "display_length" => display_length,  "height" => height, "attr"=>"reverse"}

  r += 1
  input = RubyCurses::Field.new mform, input_config do
    name   "input" 
    row  r 
    col  c 
    display_length  display_length
    maxlen len
    set_buffer default
  end
  if !checks.nil?
    r += 2
    checks.each_with_index do |cbtext,ix|
      field = RubyCurses::CheckBox.new mform do
        text cbtext
        name cbtext
        value checkbox_defaults[ix]||false
        color 'black'
        bgcolor 'white'
        row r
        col c
      end
      r += 1
    end
  end
  radios = config["radiobuttons"] 
  if !radios.nil?
    radio_default = config["radio_default"] || radios[0]
    radio = RubyCurses::Variable.new radio_default
    r += 2
    radios.each_with_index do |cbtext,ix|
      field = RubyCurses::RadioButton.new mform do
        variable radio
        text cbtext
        value cbtext
        color 'black'
        bgcolor 'white'
        row r
        col c
      end
      r += 1
    end
  end
  mb = RubyCurses::MessageBox.new mform do
    title title
    button_type :ok_cancel
    default_button 0
  end
  hash = {}
  if !checks.nil?
  checks.each do |c|
    hash[c] = mform.by_name[c].getvalue
  end
  end
  hash["radio"] = radio.get_value unless radio.nil?
  # returns button index (0 = OK), value of field, hash containing values of checkboxes
  return mb.selected_index, mform.by_name['input'].getvalue, hash
end