Class: Barabara::Modules::Lemonbar
- Inherits:
-
Object
- Object
- Barabara::Modules::Lemonbar
- Defined in:
- lib/barabara/modules/lemonbar.rb
Instance Attribute Summary collapse
-
#panel_clicks ⇒ Object
readonly
Returns the value of attribute panel_clicks.
-
#panel_data ⇒ Object
Returns the value of attribute panel_data.
-
#panel_out ⇒ Object
Returns the value of attribute panel_out.
-
#panel_pid ⇒ Object
readonly
Returns the value of attribute panel_pid.
Instance Method Summary collapse
- #bar_options(options) ⇒ Object
- #bootstrap_panel ⇒ Object
- #fill_panel ⇒ Object
- #fill_snippets(snippets) ⇒ Object
-
#initialize ⇒ Lemonbar
constructor
A new instance of Lemonbar.
- #render ⇒ Object
- #run_panel ⇒ Object
- #update_panel(data) ⇒ Object
Constructor Details
#initialize ⇒ Lemonbar
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 = GlobalConfig.config.module_config('lemonbar') @colors = GlobalConfig.config.colors @monitors = GlobalConfig.config.monitors @format = [:format].chomp @snippets = fill_snippets([:snippets]) @cmd = ['lemonbar', *()].join(' ') @panel_data = bootstrap_panel run_panel end |
Instance Attribute Details
#panel_clicks ⇒ Object (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_data ⇒ Object
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_out ⇒ Object
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_pid ⇒ Object (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 () 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([:fonts]) cmd_opts.concat [:extra_opts] if .key?(:extra_opts) cmd_opts end |
#bootstrap_panel ⇒ Object
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_panel ⇒ Object
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 |
#render ⇒ Object
69 70 71 |
# File 'lib/barabara/modules/lemonbar.rb', line 69 def render @panel_out.puts fill_panel + "\n" end |
#run_panel ⇒ Object
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 |