Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add brew widget #51

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .config/sketchybar/items/widgets/brew.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
local icons = require("icons")
local colors = require("colors")
local settings = require("settings")

local thresholds = {
-- default color green will be returned if count is less than the first threshold
[3] = colors.yellow,
[5] = colors.orange,
[10] = colors.red,
}

local brew = sbar.add("item", "widgets.brew", {
position = "right",
drawing = "off",
icon = {
string = icons.brew.empty,
color = colors.green,
align = "left",
},
label = {
string = "0",
font = { family = settings.font.numbers },
},
updates = "on",
update_freq = 10,
})

brew:subscribe({ "routine", "brew_update" }, function()
sbar.exec("brew outdated | wc -l | tr -d ' '", function(brew_outdated)
local function getThresholdColor(count)
local thresholdKeys = {}
for key in pairs(thresholds) do
table.insert(thresholdKeys, key)
end

table.sort(thresholdKeys, function(a, b)
return a > b
end)

for _, threshold in ipairs(thresholdKeys) do
if tonumber(count) >= threshold then
return thresholds[threshold]
end
end
return colors.green
end

local icon = icons.brew.empty
local color = colors.green
local label = "0"
local count = brew_outdated
local drawing = "off"

if tonumber(count) > 0 then
icon = icons.brew.full
label = count
color = getThresholdColor(count)
drawing = "on"
end
--print("color: ", color, "count: ", count, "icon: ", icon, "label: ", label, "drawing: ", drawing)
brew:set({
icon = {
string = icon,
color = color,
},
drawing = drawing,
label = { string = label },
})
end)
end)

sbar.add("bracket", "widgets.brew.bracket", { brew.name }, {
background = { color = colors.bg1 },
})

sbar.add("item", "widgets.brew.padding", {
position = "right",
width = settings.group_paddings,
})
1 change: 1 addition & 0 deletions .config/sketchybar/items/widgets/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ require("items.widgets.battery")
require("items.widgets.volume")
require("items.widgets.wifi")
require("items.widgets.cpu")
require("items.widgets.brew")