Class: R3Status::StatusLine

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

Overview

This class encapsulates a status output. Blocks are added by the user and are displayed each iteration.

Example

s = StatusLine.new
s = StatusLine.new update_interval: 3

s << Blocks::Volume.new

s.run

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefix: " ", postfix: nil, update_interval: 0.4) ⇒ StatusLine

Creates a new StatusLine object.



39
40
41
42
43
44
# File 'lib/r3status.rb', line 39

def initialize(prefix: " ", postfix: nil, update_interval: 0.4)
  @blocks = []
  @prefix = prefix
  @postfix = postfix
  @update_interval = update_interval
end

Instance Attribute Details

#blocksObject (readonly)

A list blocks to display, right to left, in the bar.



30
31
32
# File 'lib/r3status.rb', line 30

def blocks
  @blocks
end

#postfixObject

An object (e.g. String)that will be inserted at the ebd of a block’s text. Default: nil.



34
35
36
# File 'lib/r3status.rb', line 34

def postfix
  @postfix
end

#prefixObject

An object (e.g. String) that will be inserted at the start of a block’s text. Default: _“ ”_.



32
33
34
# File 'lib/r3status.rb', line 32

def prefix
  @prefix
end

#update_intervalObject

The time (in seconds) between iterations. Default: 0.4.



36
37
38
# File 'lib/r3status.rb', line 36

def update_interval
  @update_interval
end

Instance Method Details

#<<(block) ⇒ Object

Appends a new block to this StatusLine object.



47
48
49
# File 'lib/r3status.rb', line 47

def << block
  @blocks << block
end

#runObject

Starts the operation of the status line and the output of the data to the standard output.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/r3status.rb', line 52

def run
  @reader_thread = Thread.new do
    loop do
      s = gets.chomp
      parse s
    end
  end
  @reader_thread.run
  
  at_exit do
    @reader_thread.kill
    @blocks.each { |b| b.terminate }
  end
  
  puts "{\"version\":1, \"click_events\":true}["
  loop_with_interval(0.2) do
    @blocks.each {|b| b.update }
    puts "[#{transmission}],"
  end
  
end