Class: Barr::Blocks::Conky

Inherits:
Barr::Block show all
Defined in:
lib/barr/blocks/conky.rb

Instance Attribute Summary collapse

Attributes inherited from Barr::Block

#align, #bgcolor, #fgcolor, #icon, #interval, #manager, #output

Instance Method Summary collapse

Methods inherited from Barr::Block

#<<, #colors, #destroy, #draw, #reassign_deprecated_option, #tmp_filename, #update

Constructor Details

#initialize(opts = {}) ⇒ Conky



8
9
10
11
12
13
14
# File 'lib/barr/blocks/conky.rb', line 8

def initialize opts={}
  super
  @text = opts[:text]

  write_template
  spawn_conky
end

Instance Attribute Details

#textObject (readonly)

Returns the value of attribute text.



7
8
9
# File 'lib/barr/blocks/conky.rb', line 7

def text
  @text
end

Instance Method Details

#destroy!Object



47
48
49
50
# File 'lib/barr/blocks/conky.rb', line 47

def destroy!
  `rm #{@filename_template}`
  `rm #{@filename_output}`
end

#spawn_conkyObject



42
43
44
45
# File 'lib/barr/blocks/conky.rb', line 42

def spawn_conky
  @process = spawn("conky -c #{@filename_template} > #{@filename_output}")
  Process.detach(@process)
end

#sys_cmdObject



20
21
22
# File 'lib/barr/blocks/conky.rb', line 20

def sys_cmd
  `tail -n1 #{@filename_output}`.chomp.gsub("#","\u2588")
end

#update!Object



16
17
18
# File 'lib/barr/blocks/conky.rb', line 16

def update!
  @output = sys_cmd
end

#write_templateObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/barr/blocks/conky.rb', line 24

def write_template
  @conky_template = " 
    out_to_x no 
    out_to_console yes
    own_window no 
    update_interval #{@interval.to_f.to_s}
    TEXT
    #{@text} 
  ".gsub(/^\s+/, '').chomp!

  @filename_template = tmp_filename+"-conky"
  @filename_output = tmp_filename+"-output"

  STDERR.puts "@conky_template: "
  STDERR.puts @conky_template
  File.open(@filename_template, "w") { |f| f.write(@conky_template) }
end