From 2e3e72d87086e2469f6f922f4f0a82f30643fcd5 Mon Sep 17 00:00:00 2001 From: vincent Date: Wed, 17 Apr 2019 21:39:31 +0200 Subject: [PATCH] update lain --- awesome/.config/awesome/lain/README.rst | 4 +- awesome/.config/awesome/lain/widget/cal.lua | 51 +++++++++++++++++-- awesome/.config/awesome/lain/widget/fs.lua | 24 ++++++--- .../.config/awesome/lain/widget/weather.lua | 11 ++-- 4 files changed, 72 insertions(+), 18 deletions(-) diff --git a/awesome/.config/awesome/lain/README.rst b/awesome/.config/awesome/lain/README.rst index 098f6bc..f1a2841 100644 --- a/awesome/.config/awesome/lain/README.rst +++ b/awesome/.config/awesome/lain/README.rst @@ -24,11 +24,11 @@ If you want to create a pull request, make sure that: - Your code fits with the general style of the module. In particular, you should use the same indentation pattern that the code uses, and also avoid adding space at the ends of lines. -- Your code its easy to understand, maintainable, and modularized. You should also avoid code duplication wherever possible by adding functions to or using lain.helpers_. If something is unclear, or you can't write it in such a way that it will be clear, explain it with a comment. +- Your code its easy to understand, maintainable, and modularized. You should also avoid code duplication wherever possible by adding functions to or using lain.helpers_. If something is unclear, or you can not write it in such a way that it will be clear, explain it with a comment. - You test your changes before submitting to make sure that you code works and does not break other parts of the module. -- You eventually update ``wiki`` submodule with a thorough section. +- You update ``wiki`` submodule with a thorough section, if necessary. Contributed widgets have to be put in ``widget/contrib``. diff --git a/awesome/.config/awesome/lain/widget/cal.lua b/awesome/.config/awesome/lain/widget/cal.lua index 9b613bf..11c4bf2 100644 --- a/awesome/.config/awesome/lain/widget/cal.lua +++ b/awesome/.config/awesome/lain/widget/cal.lua @@ -14,6 +14,7 @@ local os = os local pairs = pairs local string = string local tconcat = table.concat +local type = type local tonumber = tonumber local tostring = tostring @@ -27,12 +28,22 @@ local function factory(args) week_start = args.week_start or 2, three = args.three or false, followtag = args.followtag or false, + week_number = args.week_number or "none", + week_number_format = args.week_number_format or args.week_number == "left" and "%3d | " or "| %-3d", icons = args.icons or helpers.icons_dir .. "cal/white/", notification_preset = args.notification_preset or { font = "Monospace 10", fg = "#FFFFFF", bg = "#000000" } } + function cal.get_week_number(m, st_day, x) + return string.format(cal.week_number_format, os.date("%V", m) + (x ~= 0 and floor((x + st_day) / 7) - 1 or 0)) + end + + function cal.sum_week_days(x, y) + return (x + y) % 7 + end + function cal.build(month, year) local current_month, current_year = tonumber(os.date("%m")), tonumber(os.date("%Y")) local is_current_month = (not month or not year) or (month == current_month and year == current_year) @@ -43,13 +54,47 @@ local function factory(args) local notifytable = { [1] = string.format("%s%s\n", string.rep(" ", floor((28 - this_month:len())/2)), markup.bold(this_month)) } for x = 0,6 do notifytable[#notifytable+1] = os.date("%a ", os.time { year=2006, month=1, day=x+cal.week_start }) end notifytable[#notifytable] = string.format("%s\n%s", notifytable[#notifytable]:sub(1, -2), string.rep(" ", st_day*4)) + local strx for x = 1,mth_days do - local strx = x ~= today and x or markup.bold(markup.color(cal.notification_preset.bg, cal.notification_preset.fg, x) .. " ") + strx = x + if x == today then + if x < 10 then x = " " .. x end + strx = markup.bold(markup.color(cal.notification_preset.bg, cal.notification_preset.fg, x) .. " ") + end strx = string.format("%s%s", string.rep(" ", 3 - tostring(x):len()), strx) notifytable[#notifytable+1] = string.format("%-4s%s", strx, (x+st_day)%7==0 and x ~= mth_days and "\n" or "") end if string.len(cal.icons or "") > 0 and today then cal.icon = cal.icons .. today .. ".png" end cal.month, cal.year = d.month, d.year + + if cal.week_number ~= "none" then + local m = os.time { year = year or current_year, month = month and month or current_month, day = 0 } + local head_prepend = string.rep(" ", tostring(string.format(cal.week_number_format, 0)):len()) + + if cal.week_number == "left" then + notifytable[1] = head_prepend .. notifytable[1] -- month-year row + notifytable[2] = head_prepend .. notifytable[2] -- weekdays row + notifytable[8] = notifytable[8]:gsub("\n", "\n" .. cal.get_week_number(m, st_day, 0)) -- first week of the month + + for x = 10,#notifytable do + if cal.sum_week_days(st_day, x) == 2 then + notifytable[x] = cal.get_week_number(m, st_day, x) .. notifytable[x] + end + end + elseif cal.week_number == "right" then + notifytable[8] = notifytable[8]:gsub("\n", head_prepend .. "\n") -- weekdays row + for x = 9,#notifytable do + if cal.sum_week_days(st_day, x) == 1 then + notifytable[x] = notifytable[x]:gsub("\n", cal.get_week_number(m, st_day, x - 7) .. "\n") + end + end + -- last week of the month + local end_days = cal.sum_week_days(st_day, mth_days) + if end_days ~= 0 then end_days = 7 - end_days end + notifytable[#notifytable] = notifytable[#notifytable] .. string.rep(" ", 4 * end_days) .. cal.get_week_number(m, st_day, mth_days + end_days) + end + end + return notifytable end @@ -80,7 +125,7 @@ local function factory(args) cal.notification = nil end - function cal.show(timeout, month, year, scr) + function cal.show(seconds, month, year, scr) cal.notification_preset.text = tconcat(cal.build(month, year)) if cal.three then @@ -98,7 +143,7 @@ local function factory(args) preset = cal.notification_preset, screen = cal.followtag and awful.screen.focused() or scr or 1, icon = cal.icon, - timeout = timeout or cal.notification_preset.timeout or 5 + timeout = type(seconds) == "number" and seconds or cal.notification_preset.timeout or 5 } end diff --git a/awesome/.config/awesome/lain/widget/fs.lua b/awesome/.config/awesome/lain/widget/fs.lua index d1b7a97..58fbf93 100644 --- a/awesome/.config/awesome/lain/widget/fs.lua +++ b/awesome/.config/awesome/lain/widget/fs.lua @@ -15,6 +15,7 @@ local naughty = require("naughty") local math = math local string = string local tconcat = table.concat +local type = type local tonumber = tonumber local query_size = Gio.FILE_ATTRIBUTE_FILESYSTEM_SIZE local query_free = Gio.FILE_ATTRIBUTE_FILESYSTEM_FREE @@ -45,7 +46,7 @@ local function factory(args) fs.notification_preset.screen = fs.followtag and focused() or scr or 1 fs.notification = naughty.notify { preset = fs.notification_preset, - timeout = seconds or 5 + timeout = type(seconds) == "number" and seconds or 5 } end @@ -68,8 +69,9 @@ local function factory(args) end function fs.update() - local notifytable = { [1] = string.format("%-10s %-5s %s\t%s\t\n", "path", "used", "free", "size") } + local notifytable = { [1] = string.format("%-10s %4s\t%6s\t%6s\t\n", "path", "used", "free", "size") } local pathlen = 10 + local maxpathidx = 1 fs_now = {} for _, mount in ipairs(Gio.unix_mounts_get()) do @@ -94,11 +96,14 @@ local function factory(args) } if fs_now[path].percentage > 0 then -- don't notify unused file systems - notifytable[#notifytable+1] = string.format("\n%-10s %-5s %.2f\t%.2f\t%s", path, - fs_now[path].percentage .. "%", fs_now[path].free, fs_now[path].size, + notifytable[#notifytable+1] = string.format("\n%-10s %3s%%\t%6.2f\t%6.2f\t%s", path, + math.floor(fs_now[path].percentage), fs_now[path].free, fs_now[path].size, fs_now[path].units) - pathlen = math.max(pathlen, #path) + if #path > pathlen then + pathlen = #path + maxpathidx = #notifytable + end end end end @@ -120,10 +125,13 @@ local function factory(args) end end - if pathlen > 10 then -- formatting aesthetics + if pathlen > 10 then -- if are there paths longer than 10 chars, reformat first column accordingly + local pathspaces for i = 1, #notifytable do - local pathspaces = notifytable[i]:match("/%w*[/%w*]*%s*") or notifytable[i]:match("path%s*") - notifytable[i] = notifytable[i]:gsub(pathspaces, pathspaces .. string.rep(" ", pathlen - 10) .. "\t") + pathspaces = notifytable[i]:match("[ ]+") + if i ~= maxpathidx and pathspaces then + notifytable[i] = notifytable[i]:gsub(pathspaces, pathspaces .. string.rep(" ", pathlen - 10)) + end end end diff --git a/awesome/.config/awesome/lain/widget/weather.lua b/awesome/.config/awesome/lain/widget/weather.lua index f35ca68..c998ed9 100644 --- a/awesome/.config/awesome/lain/widget/weather.lua +++ b/awesome/.config/awesome/lain/widget/weather.lua @@ -13,6 +13,7 @@ local wibox = require("wibox") local math = math local os = os local string = string +local type = type local tonumber = tonumber -- OpenWeatherMap @@ -51,7 +52,7 @@ local function factory(args) weather.icon_path = icons_path .. "na.png" weather.icon = wibox.widget.imagebox(weather.icon_path) - function weather.show(t_out) + function weather.show(seconds) weather.hide() if followtag then @@ -63,12 +64,12 @@ local function factory(args) weather.forecast_update() end - weather.notification = naughty.notify({ + weather.notification = naughty.notify { + preset = notification_preset, text = weather.notification_text, icon = weather.icon_path, - timeout = t_out, - preset = notification_preset - }) + timeout = type(seconds == "number") and seconds or notification_preset.timeout + } end function weather.hide()