From 081ea72ae2c9b630766f3f1b9ad9e19091f5dd16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stevica=20Stojkovi=C4=87?= Date: Sat, 7 Nov 2020 00:22:37 +0100 Subject: [PATCH] refactor: extract conky script logic --- Light | 60 +-------------------- base.lua | 75 ++++++++++++++++++++++++++ config.lua | 2 - icons/{white => light}/01d.png | Bin icons/{white => light}/01n.png | Bin icons/{white => light}/02d.png | Bin icons/{white => light}/02n.png | Bin icons/{white => light}/03d.png | Bin icons/{white => light}/03n.png | Bin icons/{white => light}/04d.png | Bin icons/{white => light}/04n.png | Bin icons/{white => light}/09d.png | Bin icons/{white => light}/09n.png | Bin icons/{white => light}/10d.png | Bin icons/{white => light}/10n.png | Bin icons/{white => light}/11d.png | Bin icons/{white => light}/11n.png | Bin icons/{white => light}/13d.png | Bin icons/{white => light}/13n.png | Bin icons/{white => light}/50d.png | Bin icons/{white => light}/50n.png | Bin icons/{white => light}/arrow-down.png | Bin icons/{white => light}/arrow-up.png | Bin icons/{white => light}/blackline.png | Bin icons/{white => light}/line.png | Bin icons/{white => light}/map-marker.png | Bin 26 files changed, 77 insertions(+), 60 deletions(-) create mode 100644 base.lua rename icons/{white => light}/01d.png (100%) rename icons/{white => light}/01n.png (100%) rename icons/{white => light}/02d.png (100%) rename icons/{white => light}/02n.png (100%) rename icons/{white => light}/03d.png (100%) rename icons/{white => light}/03n.png (100%) rename icons/{white => light}/04d.png (100%) rename icons/{white => light}/04n.png (100%) rename icons/{white => light}/09d.png (100%) rename icons/{white => light}/09n.png (100%) rename icons/{white => light}/10d.png (100%) rename icons/{white => light}/10n.png (100%) rename icons/{white => light}/11d.png (100%) rename icons/{white => light}/11n.png (100%) rename icons/{white => light}/13d.png (100%) rename icons/{white => light}/13n.png (100%) rename icons/{white => light}/50d.png (100%) rename icons/{white => light}/50n.png (100%) rename icons/{white => light}/arrow-down.png (100%) rename icons/{white => light}/arrow-up.png (100%) rename icons/{white => light}/blackline.png (100%) rename icons/{white => light}/line.png (100%) rename icons/{white => light}/map-marker.png (100%) diff --git a/Light b/Light index 04d836d..1112a5b 100644 --- a/Light +++ b/Light @@ -1,60 +1,4 @@ require 'config'; +require 'base'; -conky.text = [[ -${goto 90}${voffset 25}${font adele:size=25} ${time %A, %d %B} -${goto 90}${voffset -}${font LG Weather_Z:size=100}${time %H:%M}${image ./icons/white/line.png -p 354,23 -s 3x189} -${offset 370}${voffset -183}${font ADELE:size=22} -\ -# --- Weather --- # -################### -\ -# --- WOEID (Location id) --- # -${execi 300 ./scripts/weather.sh}\ -\ -# --- Temperature --- # -####################### -\ -${font ADELE :size=30}${offset 375}${voffset 10}${execi 300 ./scripts/kelvin2celsius.sh $(cat ~/.cache/eleg-weather.json | jq '.main.temp')}°${font ADELE :size=15}C${font ADELE :size=30}${voffset -20} | -\ -# --- Weather icon --- # -######################## -\ -${execi 300 ./scripts/weather-icon.sh white $(cat ~/.cache/eleg-weather.json | jq -r '.weather[0].icon')}${image ~/.cache/eleg-weather-icon.png -p 410,8 -s 100x100} -\ -# --- Textual condition (e.g. Partly cloudy) --- # -################################################## -\ -${font Roboto Light:size=18}${offset 462}${voffset -82}${execi 300 cat ~/.cache/eleg-weather.json | jq -r '.weather[0].main'} -\ -# --- Icon - high temperature --- # -################################### -\ -${image ./icons/white/arrow-up.png -p 375,172 -s 12x12} -\ -# --- High temperature --- # -############################ -\ -${font Roboto Light:size=12}${offset 395}${voffset -25}${execi 300 ./scripts/kelvin2celsius.sh $(cat ~/.cache/eleg-weather.json | jq '.main.temp_max')}° -\ -# --- Icon - low temperature icon --- # -####################################### -\ -${image ./icons/white/arrow-down.png -p 422,172 -s 12x12} -\ -# --- Low temperature --- # -########################### -\ -${font Roboto Light:size=12}${offset 438}${voffset -44}${execi 300 ./scripts/kelvin2celsius.sh $(cat ~/.cache/eleg-weather.json | jq '.main.temp_min')}° -\ -# --- Icon - map marker --- # -############################# -\ -${image ./icons/white/map-marker.png -p 463,168 -s 16x16} -\ -# --- Location name (city) --- # -############################################ -\ -${font Roboto Light:size=12}${offset 485}${voffset -45}${execi 300 cat ~/.cache/eleg-weather.json | jq -r '.name'} - -${goto 285}${voffset -35}${font adele:bold:size=25}${time %p} -]]; +conky.text = load('light', '#FFFFFF'); \ No newline at end of file diff --git a/base.lua b/base.lua new file mode 100644 index 0000000..ddae2f2 --- /dev/null +++ b/base.lua @@ -0,0 +1,75 @@ +script = [[ + ${color #{color}} + ${goto 90}${voffset 25}${font adele:size=25} ${time %A, %d %B} + \ + # --- Separator line --- # + ${goto 90}${voffset -}${font LG Weather_Z:size=100}${time %H:%M}${image ./icons/#{theme}/line.png -p 360,30 -s 3x189} + \ + ${offset 370}${voffset -183}${font ADELE:size=22} + \ + # --- Weather --- # + ################### + \ + # --- WOEID (Location id) --- # + ${execi 300 ./scripts/weather.sh}\ + \ + # --- Temperature --- # + ####################### + \ + ${font ADELE :size=30}${offset 260}${voffset 10}${execi 300 ./scripts/kelvin2celsius.sh $(cat ~/.cache/eleg-weather.json | jq '.main.temp')}°${font ADELE :size=15}C${font ADELE :size=30}${voffset -20} | + \ + # --- Weather icon --- # + ######################## + \ + ${execi 300 ./scripts/weather-icon.sh #{theme} $(cat ~/.cache/eleg-weather.json | jq -r '.weather[0].icon')}${image ~/.cache/eleg-weather-icon.png -p 410,30 -s 100x100} + \ + # --- Textual condition (e.g. Partly cloudy) --- # + ################################################## + \ + ${font Roboto Light:size=18}${offset 380}${voffset -82}${execi 300 cat ~/.cache/eleg-weather.json | jq -r '.weather[0].main'} + \ + # --- Icon - high temperature --- # + ################################### + \ + ${image ./icons/#{theme}/arrow-up.png -p 375,190 -s 12x12} + \ + # --- High temperature --- # + ############################ + \ + ${font Roboto Light:size=12}${offset 330}${voffset -25}${execi 300 ./scripts/kelvin2celsius.sh $(cat ~/.cache/eleg-weather.json | jq '.main.temp_max')}° + \ + # --- Icon - low temperature icon --- # + ####################################### + \ + ${image ./icons/#{theme}/arrow-down.png -p 422,190 -s 12x12} + \ + # --- Low temperature --- # + ########################### + \ + ${font Roboto Light:size=12}${offset 400}${voffset -44}${execi 300 ./scripts/kelvin2celsius.sh $(cat ~/.cache/eleg-weather.json | jq '.main.temp_min')}° + \ + # --- Icon - map marker --- # + ############################# + \ + ${image ./icons/#{theme}/map-marker.png -p 463,187 -s 16x16} + \ + # --- Location name (city) --- # + ############################################ + \ + ${font Roboto Light:size=12}${offset 440}${voffset -45}${execi 300 cat ~/.cache/eleg-weather.json | jq -r '.name'} + + ${goto 285}${voffset -35}${font adele:bold:size=25}${time %p} +]]; + +local function interp (s, t) + return s:gsub('(#%b{})', function (w) + return t[w:sub(3, -2)] or w + end) +end + +function load(theme, color) + return interp(script, { + theme = theme, + color = color + }) +end diff --git a/config.lua b/config.lua index b9a65b6..8e2d6e2 100644 --- a/config.lua +++ b/config.lua @@ -1,7 +1,6 @@ conky.config = { alignment = 'top_middle', background = false, - border_margin = 5, border_width = 5, cpu_avg_samples = 2, default_color = '#ffffff', @@ -14,7 +13,6 @@ conky.config = { draw_shades = false, gap_x = 0, gap_y = 100, - max_specials = 1024, max_user_text = 10000, maximum_width = 900, net_avg_samples = 2, diff --git a/icons/white/01d.png b/icons/light/01d.png similarity index 100% rename from icons/white/01d.png rename to icons/light/01d.png diff --git a/icons/white/01n.png b/icons/light/01n.png similarity index 100% rename from icons/white/01n.png rename to icons/light/01n.png diff --git a/icons/white/02d.png b/icons/light/02d.png similarity index 100% rename from icons/white/02d.png rename to icons/light/02d.png diff --git a/icons/white/02n.png b/icons/light/02n.png similarity index 100% rename from icons/white/02n.png rename to icons/light/02n.png diff --git a/icons/white/03d.png b/icons/light/03d.png similarity index 100% rename from icons/white/03d.png rename to icons/light/03d.png diff --git a/icons/white/03n.png b/icons/light/03n.png similarity index 100% rename from icons/white/03n.png rename to icons/light/03n.png diff --git a/icons/white/04d.png b/icons/light/04d.png similarity index 100% rename from icons/white/04d.png rename to icons/light/04d.png diff --git a/icons/white/04n.png b/icons/light/04n.png similarity index 100% rename from icons/white/04n.png rename to icons/light/04n.png diff --git a/icons/white/09d.png b/icons/light/09d.png similarity index 100% rename from icons/white/09d.png rename to icons/light/09d.png diff --git a/icons/white/09n.png b/icons/light/09n.png similarity index 100% rename from icons/white/09n.png rename to icons/light/09n.png diff --git a/icons/white/10d.png b/icons/light/10d.png similarity index 100% rename from icons/white/10d.png rename to icons/light/10d.png diff --git a/icons/white/10n.png b/icons/light/10n.png similarity index 100% rename from icons/white/10n.png rename to icons/light/10n.png diff --git a/icons/white/11d.png b/icons/light/11d.png similarity index 100% rename from icons/white/11d.png rename to icons/light/11d.png diff --git a/icons/white/11n.png b/icons/light/11n.png similarity index 100% rename from icons/white/11n.png rename to icons/light/11n.png diff --git a/icons/white/13d.png b/icons/light/13d.png similarity index 100% rename from icons/white/13d.png rename to icons/light/13d.png diff --git a/icons/white/13n.png b/icons/light/13n.png similarity index 100% rename from icons/white/13n.png rename to icons/light/13n.png diff --git a/icons/white/50d.png b/icons/light/50d.png similarity index 100% rename from icons/white/50d.png rename to icons/light/50d.png diff --git a/icons/white/50n.png b/icons/light/50n.png similarity index 100% rename from icons/white/50n.png rename to icons/light/50n.png diff --git a/icons/white/arrow-down.png b/icons/light/arrow-down.png similarity index 100% rename from icons/white/arrow-down.png rename to icons/light/arrow-down.png diff --git a/icons/white/arrow-up.png b/icons/light/arrow-up.png similarity index 100% rename from icons/white/arrow-up.png rename to icons/light/arrow-up.png diff --git a/icons/white/blackline.png b/icons/light/blackline.png similarity index 100% rename from icons/white/blackline.png rename to icons/light/blackline.png diff --git a/icons/white/line.png b/icons/light/line.png similarity index 100% rename from icons/white/line.png rename to icons/light/line.png diff --git a/icons/white/map-marker.png b/icons/light/map-marker.png similarity index 100% rename from icons/white/map-marker.png rename to icons/light/map-marker.png