Class: RETerm::Components::Dialog

Inherits:
RETerm::Component show all
Includes:
RETerm::CDKComponent
Defined in:
lib/reterm/components/dialog.rb

Overview

CDK Dialog Component

Constant Summary collapse

BUTTONS =
{
  :ok        => ["</B/24>OK"],
  :ok_cancel => ["</B/24>OK", "</B16>Cancel"]
}

Constants included from LogHelpers

LogHelpers::LOG_FILE

Instance Attribute Summary collapse

Attributes inherited from RETerm::Component

#activatable, #activate_focus, #highlight_focus, #window

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RETerm::CDKComponent

#activatable?, #activate!, #bind_key, #cdk?, #colors=, #component, #deactivate!, #draw!, #early_exit?, #erase, #escape_hit?, #init?, #init_cdk, #normal_exit?, #strip_formatting, #title_attrib=, #value

Methods inherited from RETerm::Component

#activatable?, #activate!, #activate_focus?, #cdk?, #colored?, #colors=, #deactivate!, #deactivate?, #distance_from, #extra_padding, #finalize!, #highlight_focus?, #reactivate!, #resize, #sync!, #sync_getch

Methods included from KeyBindings

#bind_key, #invoke_key_bindings, #key_bindings, #key_bound?

Methods included from LogHelpers

#logger

Methods included from EventDispatcher

#dispatch, #handle

Constructor Details

#initialize(args = {}) ⇒ Dialog

Initialize the Dialog component

Parameters:

  • args (Hash) (defaults to: {})

    dialog params

Options Hash (args):

  • :message (String, Array<String>)

    string message(s) to assign to dialog

  • :buttons (String, Array<String>)

    string buttons to assign to dialog



22
23
24
25
26
27
28
# File 'lib/reterm/components/dialog.rb', line 22

def initialize(args={})
  super
  @message = [args[:message]].flatten.compact
  @buttons = [args[:buttons]].flatten.compact

  @buttons = BUTTONS[:ok_cancel] if @buttons.empty?
end

Instance Attribute Details

#buttonsObject (readonly)

Returns the value of attribute buttons.



7
8
9
# File 'lib/reterm/components/dialog.rb', line 7

def buttons
  @buttons
end

Class Method Details

.show(args = {}) ⇒ Object

Client may invoke this to

- create dialog and window
- activate it
- close / cleanup


38
39
40
41
42
43
44
45
46
# File 'lib/reterm/components/dialog.rb', line 38

def self.show(args={})
  dlg = self.new args
  win = Window.new
  win.component = dlg
  dlg.activate!
  dlg.close!
  return "" unless dlg.normal_exit?
  dlg.selected
end

Instance Method Details

#close!Object



56
57
58
59
60
# File 'lib/reterm/components/dialog.rb', line 56

def close!
  window.erase
  window.finalize!
  self
end

#requested_colsObject



52
53
54
# File 'lib/reterm/components/dialog.rb', line 52

def requested_cols
  [message.size, total_button_size].max
end

#requested_rowsObject



48
49
50
# File 'lib/reterm/components/dialog.rb', line 48

def requested_rows
  5
end

#selectedObject



30
31
32
# File 'lib/reterm/components/dialog.rb', line 30

def selected
  strip_formatting(buttons[component.current_button])
end