Class: BaseUI
- Inherits:
-
Object
show all
- Defined in:
- lib/libisi/ui/base.rb
Overview
Copyright © 2007-2010 Logintas AG Switzerland
This file is part of Libisi.
Libisi is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Libisi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Libisi. If not, see <www.gnu.org/licenses/>.
Instance Method Summary
collapse
-
#bell(options = {}) ⇒ Object
-
#colorize(color, options = {}) ⇒ Object
-
#enable_progress_bar(val = true) ⇒ Object
-
#error(text, options = {}) ⇒ Object
-
#execute_in_console(command, options = {}) ⇒ Object
-
#info(text, options = {}) ⇒ Object
-
#info_non_blocking(text, options = {}) ⇒ Object
-
#name ⇒ Object
-
#not_implemented ⇒ Object
-
#pinc(action = nil, object = nil) ⇒ Object
-
#pmsg(action = nil, object = nil) ⇒ Object
-
#progress(count) ⇒ Object
-
#progress_bar(text, elements, &block) ⇒ Object
-
#progress_bar_enabled? ⇒ Boolean
-
#progress_bar_implementation(text, total, &block) ⇒ Object
-
#progress_inc ⇒ Object
-
#progress_message(message) ⇒ Object
-
#question(text, options = {}) ⇒ Object
-
#question_yes_no(text, options = {}) ⇒ Object
-
#question_yes_no_retry(text, options = {}) ⇒ Object
-
#select(list, multi_select = false, options = {}) ⇒ Object
-
#select_index(list, multi_select = false, &block) ⇒ Object
-
#warn(text, options = {}) ⇒ Object
Instance Method Details
#bell(options = {}) ⇒ Object
28
|
# File 'lib/libisi/ui/base.rb', line 28
def bell(options = {}); not_implemented; end
|
#colorize(color, options = {}) ⇒ Object
47
|
# File 'lib/libisi/ui/base.rb', line 47
def colorize(color, options={}); yield; end
|
#enable_progress_bar(val = true) ⇒ Object
104
105
106
107
108
109
110
111
|
# File 'lib/libisi/ui/base.rb', line 104
def enable_progress_bar(val = true)
old_val = @progress
@progress = val
if block_given?
yield
@progress = old_val
end
end
|
#error(text, options = {}) ⇒ Object
35
36
37
|
# File 'lib/libisi/ui/base.rb', line 35
def error(text, options = {})
info("/!\\ ERROR: #{text}")
end
|
#execute_in_console(command, options = {}) ⇒ Object
49
|
# File 'lib/libisi/ui/base.rb', line 49
def execute_in_console(command, options = {}); not_implemented; end
|
#info(text, options = {}) ⇒ Object
32
|
# File 'lib/libisi/ui/base.rb', line 32
def info(text, options = {}); not_impelmented; end
|
#info_non_blocking(text, options = {}) ⇒ Object
33
|
# File 'lib/libisi/ui/base.rb', line 33
def info_non_blocking(text, options = {}); info(text, options); end
|
#name ⇒ Object
20
21
22
|
# File 'lib/libisi/ui/base.rb', line 20
def name
self.class.name
end
|
#not_implemented ⇒ Object
24
25
26
|
# File 'lib/libisi/ui/base.rb', line 24
def not_implemented
raise "Not implemented in UI #{self.name}"
end
|
#pinc(action = nil, object = nil) ⇒ Object
99
100
101
102
103
|
# File 'lib/libisi/ui/base.rb', line 99
def pinc(action = nil, object = nil)
return unless progress_bar_enabled?
progress_inc
pmsg(action, object) if action or object
end
|
#pmsg(action = nil, object = nil) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/libisi/ui/base.rb', line 88
def pmsg(action = nil,object = nil)
return unless progress_bar_enabled?
if action
@max_action_withs ||= []
@max_action_withs.insert(0,action.to_s.length)
@max_action_withs = @max_action_withs[0..5]
action = action.ljust(@max_action_withs.max)
end
message = [action,object].compact.map {|s| s.to_s}.join(": ")
progress_message(message)
end
|
#progress(count) ⇒ Object
#progress_bar(text, elements, &block) ⇒ Object
52
53
54
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
|
# File 'lib/libisi/ui/base.rb', line 52
def progress_bar(text,elements,&block)
elements = elements.call if elements.class == Proc
raise "Please provide an array if you expect elements for your block." if
block.arity == 1 and elements.class == Fixnum
if progress_bar_enabled?
if block.arity == 1
progress_bar_implementation(text, elements.length) {
index = 0
elements.map {|el|
r = yield(el)
progress(index)
index += 1
r
}
}
else
progress_bar_implementation(text, elements, &block)
end
else
if block.arity == 1
elements.map {|el|
yield(el)
}
else
yield
end
end
end
|
#progress_bar_enabled? ⇒ Boolean
#progress_bar_implementation(text, total, &block) ⇒ Object
83
|
# File 'lib/libisi/ui/base.rb', line 83
def progress_bar_implementation(text, total, &block); not_implemented if progress_bar_enabled?; end
|
#progress_inc ⇒ Object
86
|
# File 'lib/libisi/ui/base.rb', line 86
def progress_inc ; not_implemented if progress_bar_enabled?; end
|
#progress_message(message) ⇒ Object
85
|
# File 'lib/libisi/ui/base.rb', line 85
def progress_message(message); not_implemented if progress_bar_enabled?; end
|
#question(text, options = {}) ⇒ Object
31
|
# File 'lib/libisi/ui/base.rb', line 31
def question(text, options = {}); not_implemented; end
|
#question_yes_no(text, options = {}) ⇒ Object
29
|
# File 'lib/libisi/ui/base.rb', line 29
def question_yes_no(text, options = {}); info_non_blocking(text);select([:yes,:no],false, options)[0]; end
|
#question_yes_no_retry(text, options = {}) ⇒ Object
30
|
# File 'lib/libisi/ui/base.rb', line 30
def question_yes_no_retry(text, options = {}); info_non_blocking(text); select([:yes,:no,:retry],false,options)[0]; end
|
#select(list, multi_select = false, options = {}) ⇒ Object
42
|
# File 'lib/libisi/ui/base.rb', line 42
def select(list, multi_select = false, options = {}) ; not_implemented; end
|
#select_index(list, multi_select = false, &block) ⇒ Object
43
44
45
|
# File 'lib/libisi/ui/base.rb', line 43
def select_index(list, multi_select = false, &block)
select(list, multi_select, {:return_indexes => true}, &block)
end
|
#warn(text, options = {}) ⇒ Object
38
39
40
|
# File 'lib/libisi/ui/base.rb', line 38
def warn(text, options = {})
info("/!\\ WARNING: #{text}")
end
|