diff options
author | Freya Murphy <freya@freyacat.org> | 2025-06-18 11:34:06 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2025-06-18 11:34:06 -0400 |
commit | f11ff2f2ea4bd8ad65aa8a4fbae6f4c083117672 (patch) | |
tree | a3b4425f1e87b1aef2f0e93d6570b1d3f3c69d8d /pkgs/astal/src/lib.lua | |
parent | update hyprland config (diff) | |
download | dotfiles-nix-f11ff2f2ea4bd8ad65aa8a4fbae6f4c083117672.tar.gz dotfiles-nix-f11ff2f2ea4bd8ad65aa8a4fbae6f4c083117672.tar.bz2 dotfiles-nix-f11ff2f2ea4bd8ad65aa8a4fbae6f4c083117672.zip |
add notifications to astal
Diffstat (limited to 'pkgs/astal/src/lib.lua')
-rw-r--r-- | pkgs/astal/src/lib.lua | 67 |
1 files changed, 63 insertions, 4 deletions
diff --git a/pkgs/astal/src/lib.lua b/pkgs/astal/src/lib.lua index 93f4bc1..992c0af 100644 --- a/pkgs/astal/src/lib.lua +++ b/pkgs/astal/src/lib.lua @@ -1,4 +1,7 @@ +local astal = require("astal") local Variable = require("astal").Variable +local Astal = require("astal.gtk3").Astal +local GLib = astal.require("GLib") local lib @@ -55,12 +58,31 @@ lib = { return new_arr end, - --- returns length of table - count = function(array) - if not array then + --- returns if value is an array + is_array = function(val) + return type(val) == 'table' + end, + + --- returns if value is an string + is_string = function(val) + return type(val) == 'string' + end, + + --- returns if value is nil + is_nil = function(val) + return val == nil + end, + + --- returns length of table or string + count = function(val) + if lib.is_array(val) then + return #val + elseif lib.is_string(val) then + return val:len() + elseif lib.is_nil(val) then return 0 else - return #array + return nil end end, @@ -73,6 +95,43 @@ lib = { neg = function(val) return not val end, + + --- better truthy function + is_true = function(val) + -- zero is false + if val == 0 then + return false + end + + -- empty array or string is false + if lib.empty(val) then + return false + end + + -- default truthyness + return val and true or false + end, + + --- better fasly function + is_false = function(val) + return not lib.is_true(val) + end, + + --- checks if a file exists + file_exists = function(path) + return GLib.file_test(path, "EXISTS") + end, + + --- checks if a string is an icon + is_icon = function(icon) + return Astal.Icon.lookup_icon(icon) ~= nil + end, + + --- formats a time + time = function(time, format) + format = format or "%H:%M" + return GLib.DateTime.new_from_unix_local(time):format(format) + end, } return lib |