Class: RETerm::Components::Splash

Inherits:
RETerm::Component show all
Defined in:
lib/reterm/components/splash.rb

Overview

Splash Screen

Constant Summary

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 inherited from RETerm::Component

#activatable?, #activate_focus?, #cdk?, #colored?, #colors=, #deactivate!, #deactivate?, #distance_from, #extra_padding, #finalize!, #highlight_focus?, #reactivate!, #resize, #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 = {}) ⇒ Splash

Initialize the Splash component

Parameters:

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

    splash params

Options Hash (args):

  • :widget (Component)

    component to include in the slash window



12
13
14
15
16
17
# File 'lib/reterm/components/splash.rb', line 12

def initialize(args={})
  super
  @widget    = args[:widget]
  @callback  = args[:callback]
  @terminate = false
end

Instance Attribute Details

#callbackObject (readonly)

Returns the value of attribute callback.



5
6
7
# File 'lib/reterm/components/splash.rb', line 5

def callback
  @callback
end

#widgetObject (readonly)

Returns the value of attribute widget.



5
6
7
# File 'lib/reterm/components/splash.rb', line 5

def widget
  @widget
end

Class Method Details

.show(args = {}, &bl) ⇒ Object

Client may invoke this to

- create dialog and window
- activate it
- periodically invoke callback,
  check return value
- close / cleanup


25
26
27
28
29
30
31
32
33
34
# File 'lib/reterm/components/splash.rb', line 25

def self.show(args={}, &bl)
  splash = self.new args.merge(:callback => bl)
  win    = Window.new args.merge(:component => splash,
                                 :x         => :center,
                                 :y         => :center)
  #win.component = splash
  splash.activate!
  update_reterm(true)
  splash.close!
end

Instance Method Details

#activate!(*input) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'lib/reterm/components/splash.rb', line 74

def activate!(*input)
  until @terminate
    window.draw!

    sleep SYNC_TIMEOUT.to_f / 1000
    run_sync!
    @terminate = !!callback.call
  end
end

#close!Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/reterm/components/splash.rb', line 44

def close!
  widget.erase
  widget.finalize!

  window.erase
  window.finalize!

  # get rid of all outstanding input
  flush_input
end

#draw!Object



59
60
61
62
# File 'lib/reterm/components/splash.rb', line 59

def draw!
  window.border!
  widget.draw!
end

#requested_colsObject



40
41
42
# File 'lib/reterm/components/splash.rb', line 40

def requested_cols
  @widget.requested_cols + 3
end

#requested_rowsObject



36
37
38
# File 'lib/reterm/components/splash.rb', line 36

def requested_rows
  @widget.requested_rows + 3
end

#sync!Object



55
56
57
# File 'lib/reterm/components/splash.rb', line 55

def sync!
  widget.sync!
end

#window=(win) ⇒ Object

Raises:

  • (ArgumentError)


64
65
66
67
68
69
70
71
72
# File 'lib/reterm/components/splash.rb', line 64

def window=(win)
  super(win)
  cw = win.create_child :rows => widget.requested_rows,
                        :cols => widget.requested_cols,
                        :x    => 1,
                        :y    => 1
  raise ArgumentError, "could not create child" if cw.win.nil?
  cw.component = widget
end