Class: AsciiParadise::ClockCounter
- Inherits:
-
Object
- Object
- AsciiParadise::ClockCounter
- Defined in:
- lib/ascii_paradise/clock_counter/clock_counter.rb
Overview
AsciiParadise::ClockCounter
Constant Summary collapse
- SLEEP_FOR_N_SECONDS =
#
SLEEP_FOR_N_SECONDS
#
1
- RUN_ALREADY =
#
RUN_ALREADY
#
true
Instance Method Summary collapse
-
#consider_requiring_the_kde_konsole_tab_renamer ⇒ Object
# === consider_requiring_the_kde_konsole_tab_renamer ========================================================================= #.
-
#disable_colours ⇒ Object
# === disable_colours ========================================================================= #.
-
#display_time ⇒ Object
# === display_time ========================================================================= #.
-
#do_rename_kde_konsole_tab ⇒ Object
# === do_rename_kde_konsole_tab ========================================================================= #.
-
#e(i) ⇒ Object
# === e ========================================================================= #.
-
#exit_program ⇒ Object
# === exit_program ========================================================================= #.
-
#initialize(run_already = RUN_ALREADY) ⇒ ClockCounter
constructor
# === initialize ========================================================================= #.
-
#register_sigint ⇒ Object
# === register_sigint ========================================================================= #.
-
#reset ⇒ Object
# === reset ========================================================================= #.
-
#run ⇒ Object
# === run ========================================================================= #.
-
#set_connected ⇒ Object
# === set_connected ========================================================================= #.
-
#set_mode(i = :standalone) ⇒ Object
# === set_mode ========================================================================= #.
-
#use_colours(shall_we_use_colours = true) ⇒ Object
# === use_colours ========================================================================= #.
-
#use_colours? ⇒ Boolean
# === use_colours? ========================================================================= #.
Constructor Details
#initialize(run_already = RUN_ALREADY) ⇒ ClockCounter
#
initialize
#
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 # ===================================================================== # # === :rename_kde_konsole_tab # ===================================================================== # 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
#
disable_colours
#
115 116 117 |
# File 'lib/ascii_paradise/clock_counter/clock_counter.rb', line 115 def disable_colours use_colours(false) end |
#display_time ⇒ Object
#
display_time
#
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 # ======================================================================= # # Also check if we have to modify the KDE konsole tab. # ======================================================================= # 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
#
e
#
132 133 134 135 136 137 |
# File 'lib/ascii_paradise/clock_counter/clock_counter.rb', line 132 def e(i) # E tag. if Object.const_defined? :Colours i = Colours::GREEN+i+Colours.rev if @use_colours end puts i end |
#exit_program ⇒ Object
#
exit_program
#
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
#
register_sigint
#
78 79 80 |
# File 'lib/ascii_paradise/clock_counter/clock_counter.rb', line 78 def register_sigint trap('INT') { exit_program } end |
#reset ⇒ Object
#
reset
#
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 # # If the following variable is true then this class will rename the # KDE konsole tab as well. By default this is false, but this # can be changed by the user. # ======================================================================= # @rename_kde_konsole_tab = false end |
#run ⇒ Object
#
run
#
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 # ======================================================================= # # Our main loop: # ======================================================================= # loop { print `clear` display_time sleep SLEEP_FOR_N_SECONDS break if @run_standalone == :quit } end |
#set_connected ⇒ Object
#
set_connected
#
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
#
set_mode
#
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
#
use_colours
#
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) # We enable colours here. begin require 'colours' rescue LoadError; end @use_colours = shall_we_use_colours end |
#use_colours? ⇒ Boolean
#
use_colours?
#
142 143 144 |
# File 'lib/ascii_paradise/clock_counter/clock_counter.rb', line 142 def use_colours? @use_colours end |