Class: Scripted::Formatters::Announcer
- Defined in:
- lib/scripted/formatters/announcer.rb
Instance Attribute Summary
Attributes inherited from Blank
Instance Method Summary collapse
-
#execute(command) ⇒ Object
wrapped in a synchronize block to prevent asynchronous output clogging the output.
- #force_encoding(text) ⇒ Object
-
#initialize ⇒ Announcer
constructor
A new instance of Announcer.
- #start(commands, runner) ⇒ Object
Methods inherited from Blank
#close, #done, #each_char, #exception, #halted, #stop
Constructor Details
#initialize ⇒ Announcer
Returns a new instance of Announcer.
9 10 11 12 |
# File 'lib/scripted/formatters/announcer.rb', line 9 def initialize(*) super @semaphore = Mutex.new end |
Instance Method Details
#execute(command) ⇒ Object
wrapped in a synchronize block to prevent asynchronous output clogging the output
19 20 21 22 23 24 25 26 27 |
# File 'lib/scripted/formatters/announcer.rb', line 19 def execute(command) @semaphore.synchronize do puts "" puts cyan("┌" + force_encoding("─" * (@length - 2)) + "┐") puts "#{cyan("│")} #{command.name.center(@length - 4)} #{cyan("│")}" puts cyan("└" + force_encoding("─" * (@length - 2)) + "┘") puts "" end end |
#force_encoding(text) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/scripted/formatters/announcer.rb', line 29 def force_encoding(text) if text.respond_to?(:force_encoding) text.force_encoding('utf-8') else # ruby 1.8 text end end |
#start(commands, runner) ⇒ Object
14 15 16 |
# File 'lib/scripted/formatters/announcer.rb', line 14 def start(commands, runner) @length = [ 50, commands.max_by { |command| command.name.size }.name.size + 4 ].max end |