ok this time for sure

Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
Jack L. Frost 2016-09-28 23:30:07 +03:00
parent c477498102
commit c1ffc8cb6c
7 changed files with 42 additions and 59 deletions

View File

@ -1,16 +1,12 @@
# vim: ft=ruby
class ModBspwmPager < ModBasic
@@mod_name = 'bspwm_pager'
def data_loop()
class BspwmPager < Worker
def mainloop()
while true do
pipe = IO.popen("bspc subscribe")
$children << pipe.pid
pipe.each do |line|
$panel_data[@@mod_name.to_sym] = parse_data(line.chomp)
$queue << 1
@pipe_in.puts "bspwm_pager" + "\0" + parse_data(line)
end
end
end
@ -22,21 +18,21 @@ class ModBspwmPager < ModBasic
string.split(":").each do |part|
n = part[1..-1]
if $config['mod']['bspwm_pager']['blacklist'] != nil
if $config['mod']['bspwm_pager']['blacklist'].include? n
if @config['mod']['bspwm_pager']['blacklist'] != nil
if @config['mod']['bspwm_pager']['blacklist'].include? n
next
end
end
case part
when /^(O|F|U).+/
out << "%{B#{$config['colours']['bg_focused']}} #{n} %{B-}"
out << "%{B#{@config['colours']['bg_focused']}} #{n} %{B-}"
when /^u.+/
out << "%{A:bspc desktop -f #{n}:}%{R} #{n} %{R}%{A}"
when /^o.+/
out << "%{A:bspc desktop -f #{n}:} #{n} %{A}"
when /^f.+/
if $config['mod']['bspwm_pager']['show_empty_desktops']
if @config['mod']['bspwm_pager']['show_empty_desktops']
out << " #{n} "
end
when /^L.+/
@ -57,4 +53,4 @@ class ModBspwmPager < ModBasic
end
end
ModBspwmPager.new.mainloop()
Modules.add("bspwm_pager", "BspwmPager")

View File

@ -1,24 +1,19 @@
# vim: ft=ruby
class ModBspwmTaskbar < ModBasic
@@mod_name = 'bspwm_taskbar'
def data_loop()
class BspwmTaskbar < Worker
def mainloop()
while true do
pipe = IO.popen("xtitle -s -f '%s'")
$children << pipe.pid
pipe.each do |line|
if line == "\n"
$panel_data[@@mod_name.to_sym] = ""
self.write ""
else
$panel_data[@@mod_name.to_sym] = $config['mod']['bspwm_taskbar']['begin'].erb + line.chomp + $config['mod']['bspwm_taskbar']['end'].erb
self.write @config['mod']['bspwm_taskbar']['begin'].erb + line.chomp + @config['mod']['bspwm_taskbar']['end'].erb + "\n"
end
$queue << 1
end
end
end
end
ModBspwmTaskbar.new.mainloop()
Modules.add("bspwm_taskbar", "BspwmTaskbar")

View File

@ -1,15 +1,12 @@
# vim: ft=ruby
class ModDate < ModBasic
@@mod_name = 'date'
def data_loop()
class ModDate < Worker
def mainloop()
while true do
$panel_data[@@mod_name.to_sym] = Time.now.strftime($config['mod']['date']['format'])
$queue << 1
self.write Time.now.strftime(@config['mod']['date']['format'])
sleep(1)
end
end
end
ModDate.new.mainloop()
Modules.add("date", "ModDate")

View File

@ -1,26 +1,23 @@
# vim: ft=ruby
class ModLoadAverage < ModBasic
@@mod_name = 'load_average'
def data_loop()
class LoadAverage < Worker
def mainloop()
while true do
file = File.open("/proc/loadavg", "r")
la_m = file.gets.split[0]
if la_m.to_i > $config['mod']['load_average']['crit_value']
fg_colour = $config['mod']['load_average']['crit_colour']
elsif la_m.to_i > $config['mod']['load_average']['warn_value']
fg_colour = $config['mod']['load_average']['warn_colour']
if la_m.to_i > @config['mod']['load_average']['crit_value']
fg_colour = @config['mod']['load_average']['crit_colour']
elsif la_m.to_i > @config['mod']['load_average']['warn_value']
fg_colour = @config['mod']['load_average']['warn_colour']
else
fg_colour = $config['mod']['load_average']['ok_colour']
fg_colour = @config['mod']['load_average']['ok_colour']
end
$panel_data[@@mod_name.to_sym] = "%{F#{fg_colour}}#{la_m}%{F-}"
$queue << 1
self.write "%{F#{fg_colour}}#{la_m}%{F-}"
sleep(5)
end
end
end
ModLoadAverage.new.mainloop()
Modules.add("load_average", "LoadAverage")

View File

@ -1,45 +1,41 @@
# vim: ft=ruby
class ModNetwork < ModBasic
@@mod_name = 'network'
class Network < Worker
require 'open3'
def data_loop()
$panel_data[@@mod_name.to_sym] = "checking..."
def mainloop()
self.write "checking..."
while true do
$panel_data[@@mod_name.to_sym] = network_status.chomp
$queue << 1
self.write network_status
sleep(10)
end
end
def network_status
hosts = $config['mod']['network']['hosts']
hosts = @config['mod']['network']['hosts']
net_ok = 0
hosts.each do |h|
i,o,t = Open3.popen2("ping", "-c", "1", h)
i.close; o.close
t.join
net_ok += 1 if t.value
net_ok += 1 if t.value.exitstatus == 0
end
if net_ok == 0
status = "CRIT"
fg_colour = $config['mod']['network']['crit_colour']
fg_colour = @config['mod']['network']['crit_colour']
elsif net_ok < hosts.length
status = "WARN"
fg_colour = $config['mod']['network']['warn_colour']
fg_colour = @config['mod']['network']['warn_colour']
else
status = "ok"
fg_colour = $config['mod']['network']['ok_colour']
fg_colour = @config['mod']['network']['ok_colour']
end
return "%{F#{fg_colour}}#{status}%{F-}"
end
end
ModNetwork.new.mainloop()
Modules.add("network", "Network")

View File

@ -25,7 +25,7 @@ class Worker
def mainloop()
loop do
@pipe_in.puts "#{@name}\0I am a dummy\n"
self.write("I am a dummy")
sleep(1)
end
end
@ -44,6 +44,10 @@ class Worker
puts "#{err}: #{@wpid}"
end
end
def write(data)
@pipe_in.puts @name + "\0" + data
end
end
class ::String
@ -96,7 +100,6 @@ config = YAML.load_file(config_file)
# Create a named pipe unless one exists
File.mkfifo(config['fifo_in']) unless File.exist?(config['fifo_in'])
File.mkfifo(config['fifo_out']) unless File.exist?(config['fifo_out'])
for m in config['modules'] do
load("#{mod_dir}/#{m}")

View File

@ -8,7 +8,6 @@ fontspec: '-*-terminesspowerline-medium-*-normal-*-14-*-*-*-*-*-iso10646-*'
window_name: 'moltenbar'
active_areas: '128'
fifo_in: "/run/user/1000/moltenbar_in.fifo"
fifo_out: "/run/user/1000/moltenbar_out.fifo"
modules:
- bspwm_pager
- date