Class: HandyToolbox::App

Inherits:
Object
  • Object
show all
Defined in:
lib/handy_toolbox/app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title: "Tools", default_colors: false) ⇒ App

Returns a new instance of App.



6
7
8
9
10
11
12
13
14
# File 'lib/handy_toolbox/app.rb', line 6

def initialize(title: "Tools", default_colors: false)
  @title = title
  @loop = true
  @builder = Menu.new(nil, nil)
  @screen = Screen.new(default_colors: default_colors)
  @navigator = Navigator.new
  @tool_runner = ToolRunner.new
  @positions = {}
end

Instance Attribute Details

#titleObject (readonly)

Returns the value of attribute title.



4
5
6
# File 'lib/handy_toolbox/app.rb', line 4

def title
  @title
end

Instance Method Details



40
41
42
# File 'lib/handy_toolbox/app.rb', line 40

def menu(group, &block)
  builder.menu(group, &block)
end


44
45
46
# File 'lib/handy_toolbox/app.rb', line 44

def menu_loader(group, loader_class)
  builder.menu_loader(group, loader_class)
end

#plugin(plugin_class) ⇒ Object



36
37
38
# File 'lib/handy_toolbox/app.rb', line 36

def plugin(plugin_class)
  builder.plugin(plugin_class)
end

#runObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/handy_toolbox/app.rb', line 16

def run
  screen.init
  navigator.enter(builder)

  begin

    while @loop
      screen.draw do
        screen.header(title)
        draw_tools
      end
      handle_input
    end

  ensure
    screen.close
    tool_runner.run
  end
end

#tool(cmd, opts = {}) ⇒ Object



48
49
50
# File 'lib/handy_toolbox/app.rb', line 48

def tool(cmd, opts = {})
  builder.tool(cmd, opts)
end