From 8544bb8cd4caeb539d8f4669dd801c2cce8d1a75 Mon Sep 17 00:00:00 2001 From: fbt Date: Wed, 15 May 2019 11:50:16 +0300 Subject: [PATCH] Fuck erb Signed-off-by: fbt --- mod/bspwm_taskbar | 3 +-- mod/memory | 4 ++-- moltenbar | 24 ++++++++++++++---------- rc.yaml.example | 13 +++++++------ 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/mod/bspwm_taskbar b/mod/bspwm_taskbar index 5ee050f..03b7063 100644 --- a/mod/bspwm_taskbar +++ b/mod/bspwm_taskbar @@ -9,8 +9,7 @@ class BspwmTaskbar < Worker if line == "" self.write "" else - tmpl = Template.new(@my_config['begin'] + line + @my_config['end']) - self.write tmpl.render(@config, nil) + self.write @my_config['begin'] + line + @my_config['end'] end end end diff --git a/mod/memory b/mod/memory index d249eb1..1a42527 100644 --- a/mod/memory +++ b/mod/memory @@ -11,9 +11,9 @@ class ModMemory < Worker used_part = 100 - (mem["MemAvailable:"]/(mem["MemTotal:"]/100)) - if used_part < @my_config['crit_value'] + if used_part > @my_config['crit_value'] fg_colour = @my_config['crit_colour'] - elsif used_part < @my_config['warn_value'] + elsif used_part > @my_config['warn_value'] fg_colour = @my_config['warn_colour'] else fg_colour = @my_config['ok_colour'] diff --git a/moltenbar b/moltenbar index a5e1d6a..39c3548 100755 --- a/moltenbar +++ b/moltenbar @@ -81,16 +81,21 @@ module Modules end end -class Template +class Panel + attr_accessor :modData + def initialize(template) + @modData = {} @template = template end - def render(config, data) - @config = config - @panel_data = data + def render + panel = @template + @modData.each do |modName, modData| + panel = panel.gsub(/@{#{modName}}/, modData) + end - return ERB.new(@template).result(binding()) + return panel end end @@ -107,7 +112,6 @@ def get_x_dims() return `xrandr`.scan(/current (\d+) x (\d+)/).flatten end -require 'erb' require 'yaml' require 'optparse' @@ -182,6 +186,7 @@ lemonbar_cmd = [ printf("Launching lemonbar as:\n %s\n", lemonbar_cmd.join(" ")) +p = Panel.new(config['format']) IO.popen(lemonbar_cmd, "w+") do |pipe_lb| pipe_lb.sync = true @@ -189,9 +194,8 @@ IO.popen(lemonbar_cmd, "w+") do |pipe_lb| pipe_r.each do |line| mod_name, data = line.chomp.split("\0") - panel_data[mod_name] = data - - t = Template.new(config['format']) - pipe_lb.printf("%s\n", t.render(config, panel_data)) + data ||= "" + p.modData[mod_name] = data + pipe_lb.printf("%s\n", p.render()) end end diff --git a/rc.yaml.example b/rc.yaml.example index 175a2de..2e3402e 100644 --- a/rc.yaml.example +++ b/rc.yaml.example @@ -13,7 +13,7 @@ modules: - load_average - network - memory -format: "<%= @panel_data['bspwm_pager'] %><%= @panel_data['bspwm_taskbar'] %>%{r}%{F<%= @config['colours']['bg_focused'] %>} %{F-}%{B<%= @config['colours']['bg_focused'] %>} LA: <%= @panel_data['load_average'] %> Mem (used): <%= @panel_data['memory'] %>% Internet: <%= @panel_data['network'] %> Warp: <%= @panel_data['warp'] %> <%= @panel_data['date'] %> %{B-}" +format: "@{bspwm_pager}@{bspwm_taskbar}%{r}%{F#467EC2} %{F-}%{B#467EC2} LA: @{load_average} Mem (used): @{memory} Internet: @{network} Warp: @{warp} XNT: @{xnt} @{date} %{B-}" colours: fg: '#f9f9f9' fg_focused: '#f9f9f9' @@ -30,10 +30,11 @@ mod: #monitors: # - "main" blacklist: - -h + -0 + -p bspwm_taskbar: - begin: "%{F<%= @config['colours']['bg'] %>}%{B<%= @config['colours']['bg_focused'] %>}%{F-} " - end: "%{F<%= @config['colours']['bg_focused'] %>} %{B-} " + begin: "%{F#001f1f1f}%{B#467EC2}%{F-} " + end: "%{F#467EC2} %{B-} " date: format: '%A, %Y.%m.%d %H:%M:%S' load_average: @@ -70,5 +71,5 @@ mod: ok_colour: "#00FF00" warn_colour: "#FFFF00" crit_colour: "#FF0000" - warn_value: 25 - crit_value: 10 + warn_value: 75 + crit_value: 90