Class: Barabara::Modules::Lemonbar

Inherits:
Object
  • Object
show all
Defined in:
lib/barabara/modules/lemonbar.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLemonbar

Returns a new instance of Lemonbar.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/barabara/modules/lemonbar.rb', line 9

def initialize
  options = GlobalConfig.config.module_config('lemonbar')
  @colors = GlobalConfig.config.colors
  @monitors = GlobalConfig.config.monitors
  @format = options[:format].chomp
  @snippets = fill_snippets(options[:snippets])
  @cmd = ['lemonbar', *bar_options(options)].join(' ')
  @panel_data = bootstrap_panel

  run_panel
end

Instance Attribute Details

#panel_clicksObject (readonly)

Returns the value of attribute panel_clicks.



6
7
8
# File 'lib/barabara/modules/lemonbar.rb', line 6

def panel_clicks
  @panel_clicks
end

#panel_dataObject

Returns the value of attribute panel_data.



7
8
9
# File 'lib/barabara/modules/lemonbar.rb', line 7

def panel_data
  @panel_data
end

#panel_outObject

Returns the value of attribute panel_out.



7
8
9
# File 'lib/barabara/modules/lemonbar.rb', line 7

def panel_out
  @panel_out
end

#panel_pidObject (readonly)

Returns the value of attribute panel_pid.



6
7
8
# File 'lib/barabara/modules/lemonbar.rb', line 6

def panel_pid
  @panel_pid
end

Instance Method Details

#bar_options(options) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/barabara/modules/lemonbar.rb', line 33

def bar_options(options)
  cmd_opts = [
    "-B '#{@colors[:in_framebr]}'",
    "-F '#{@colors[:ac_text]}'",
    "-g 'x#{options[:height]}+0+0'",
    "-n '#{options[:name]}'", '-a 30'
  ]
  cmd_opts.concat font_opts(options[:fonts])
  cmd_opts.concat options[:extra_opts] if options.key?(:extra_opts)
  cmd_opts
end

#bootstrap_panelObject



45
46
47
48
49
50
51
52
53
54
# File 'lib/barabara/modules/lemonbar.rb', line 45

def bootstrap_panel
  @snippets.merge(
    window_title: 'Welcome home.',
    tagline: {},
    battery: 'U',
    weather: '',
    time: '',
    volume: Volume.new.update
  )
end

#fill_panelObject



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/barabara/modules/lemonbar.rb', line 56

def fill_panel
  string = ''
  # STDERR.puts 'Panel data:' + @panel_data.inspect
  @monitors.each do |monitor|
    string << format(@format,
                     @panel_data.merge(
                       tags: @panel_data.dig(:tagline, monitor) || '',
                       monitor: monitor
                     ))
  end
  string.delete "\n"
end

#fill_snippets(snippets) ⇒ Object



21
22
23
# File 'lib/barabara/modules/lemonbar.rb', line 21

def fill_snippets(snippets)
  Hash[snippets.map { |k, v| [k, v % @colors] }]
end

#renderObject



69
70
71
# File 'lib/barabara/modules/lemonbar.rb', line 69

def render
  @panel_out.puts fill_panel + "\n"
end

#run_panelObject



25
26
27
28
29
30
31
# File 'lib/barabara/modules/lemonbar.rb', line 25

def run_panel
  @panel_clicks, slave = PTY.open
  read, @panel_out = IO.pipe
  @panel_pid = spawn(@cmd, in: read, out: slave)
  slave.close
  read.close
end

#update_panel(data) ⇒ Object



73
74
75
76
# File 'lib/barabara/modules/lemonbar.rb', line 73

def update_panel(data)
  @panel_data.merge!(data)
  render
end