Class: AsciiParadise::ClockCounter
- Inherits:
-
Object
- Object
- AsciiParadise::ClockCounter
show all
- Defined in:
- lib/ascii_paradise/clock_counter/clock_counter.rb
Overview
AsciiParadise::ClockCounter
Constant Summary
collapse
- SLEEP_FOR_N_SECONDS =
1
- RUN_ALREADY =
true
Instance Method Summary
collapse
Constructor Details
#initialize(run_already = RUN_ALREADY) ⇒ ClockCounter
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/ascii_paradise/clock_counter/clock_counter.rb', line 29
def initialize(
run_already = RUN_ALREADY
)
register_sigint
reset
case run_already
when :no_colours
disable_colours
run_already = RUN_ALREADY
end
if block_given?
yielded = yield
case yielded
when :rename_kde_konsole_tab
do_rename_kde_konsole_tab
end
end
run if run_already
end
|
Instance Method Details
#consider_requiring_the_kde_konsole_tab_renamer ⇒ Object
#
consider_requiring_the_kde_konsole_tab_renamer
#
163
164
165
166
167
168
169
|
# File 'lib/ascii_paradise/clock_counter/clock_counter.rb', line 163
def consider_requiring_the_kde_konsole_tab_renamer
if @rename_kde_konsole_tab
begin
require 'roebe/requires/require_kde_konsole.rb'
rescue LoadError; end
end
end
|
#disable_colours ⇒ Object
115
116
117
|
# File 'lib/ascii_paradise/clock_counter/clock_counter.rb', line 115
def disable_colours
use_colours(false)
end
|
#display_time ⇒ Object
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/ascii_paradise/clock_counter/clock_counter.rb', line 149
def display_time
use_this_time = Time.now.strftime('%H:%M:%S').strip
e use_this_time
if @rename_kde_konsole_tab
Roebe.rename_kde_konsole_tab(use_this_time)
end
end
|
#do_rename_kde_konsole_tab ⇒ Object
#
do_rename_kde_konsole_tab
#
71
72
73
|
# File 'lib/ascii_paradise/clock_counter/clock_counter.rb', line 71
def do_rename_kde_konsole_tab
@rename_kde_konsole_tab = true
end
|
#e(i) ⇒ Object
132
133
134
135
136
137
|
# File 'lib/ascii_paradise/clock_counter/clock_counter.rb', line 132
def e(i) if Object.const_defined? :Colours
i = Colours::GREEN+i+Colours.rev if @use_colours
end
puts i
end
|
#exit_program ⇒ Object
104
105
106
107
108
109
110
|
# File 'lib/ascii_paradise/clock_counter/clock_counter.rb', line 104
def exit_program
if @run_standalone == true
exit
else
@run_standalone = :quit
end
end
|
#register_sigint ⇒ Object
78
79
80
|
# File 'lib/ascii_paradise/clock_counter/clock_counter.rb', line 78
def register_sigint
trap('INT') { exit_program }
end
|
#reset ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/ascii_paradise/clock_counter/clock_counter.rb', line 55
def reset
use_colours
set_mode
@rename_kde_konsole_tab = false
end
|
#run ⇒ Object
174
175
176
177
178
179
180
181
182
183
184
185
|
# File 'lib/ascii_paradise/clock_counter/clock_counter.rb', line 174
def run
consider_requiring_the_kde_konsole_tab_renamer
loop {
print `clear`
display_time
sleep SLEEP_FOR_N_SECONDS
break if @run_standalone == :quit
}
end
|
#set_connected ⇒ Object
85
86
87
|
# File 'lib/ascii_paradise/clock_counter/clock_counter.rb', line 85
def set_connected
set_mode :connected
end
|
#set_mode(i = :standalone) ⇒ Object
92
93
94
95
96
97
98
99
|
# File 'lib/ascii_paradise/clock_counter/clock_counter.rb', line 92
def set_mode(i = :standalone)
case i
when :standalone
@run_standalone = true
else
@run_standalone = false
end
end
|
#use_colours(shall_we_use_colours = true) ⇒ Object
122
123
124
125
126
127
|
# File 'lib/ascii_paradise/clock_counter/clock_counter.rb', line 122
def use_colours(shall_we_use_colours = true) begin
require 'colours'
rescue LoadError; end
@use_colours = shall_we_use_colours
end
|
#use_colours? ⇒ Boolean
142
143
144
|
# File 'lib/ascii_paradise/clock_counter/clock_counter.rb', line 142
def use_colours?
@use_colours
end
|