Class: Sfdown::StatusBar

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

Overview

Two-line status region pinned to the bottom of the terminal, redrawn in place with ANSI. Thread-safe: a mutex serializes updates, logs and teardown so the ticker and log() never interleave. Assumes a VT-capable terminal.

Instance Method Summary collapse

Constructor Details

#initialize(out: $stdout, width: nil) ⇒ StatusBar

Returns a new instance of StatusBar.



738
739
740
741
742
743
744
745
746
# File 'lib/sfdown.rb', line 738

def initialize(out: $stdout, width: nil)
  @out = out
  @width = width
  @mutex = Mutex.new
  @top = ""
  @bottom = ""
  @drawn = false
  @out.sync = true
end

Instance Method Details

#finishObject

Remove the bar entirely (on completion).



768
769
770
# File 'lib/sfdown.rb', line 768

def finish
  @mutex.synchronize { erase }
end

#log(msg) ⇒ Object

Print a message above the bar (scrolls into history), then redraw the bar.



759
760
761
762
763
764
765
# File 'lib/sfdown.rb', line 759

def log(msg)
  @mutex.synchronize do
    erase
    @out.puts(msg)
    draw
  end
end

#update(top, bottom) ⇒ Object

Set both lines and redraw in place.



749
750
751
752
753
754
755
756
# File 'lib/sfdown.rb', line 749

def update(top, bottom)
  @mutex.synchronize do
    @top = top
    @bottom = bottom
    erase
    draw
  end
end