Initial commit
This commit is contained in:
commit
290c28cc83
34 changed files with 1157 additions and 0 deletions
64
yawl/README.md
Normal file
64
yawl/README.md
Normal file
|
@ -0,0 +1,64 @@
|
|||
# YAWL (yet another widget library)
|
||||
|
||||
This is my shot to create an Awesome Widget Library. Since I dislike all the
|
||||
other one I found, I created mine.
|
||||
|
||||
Consider all this as **experimental**.
|
||||
|
||||
## Overview
|
||||
|
||||
All the things are wrapped into module.
|
||||
|
||||
Each module in the widget folder provides it's own widget.
|
||||
|
||||
Each widget is made of two component, an icon and some text.
|
||||
|
||||
## Usage
|
||||
|
||||
Let's consider the battery widget
|
||||
|
||||
To use it, ensure `yawl` is in the awesome config directory, then add
|
||||
|
||||
```lua
|
||||
local battery = require("yawl.widgets.battery")
|
||||
|
||||
[..]
|
||||
|
||||
s.mywibox:setup {
|
||||
{ -- Right widgets
|
||||
battery.widget(),
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
### Configuration
|
||||
|
||||
Widgets colors can be configured using the following variables in your `theme.lua`
|
||||
|
||||
```lua
|
||||
-- YAWL required theme settings
|
||||
theme.yawl_font = theme.font
|
||||
theme.yawl_bg = "#458588" -- default bg
|
||||
theme.yawl_bg_ok = "#98971a" -- no email
|
||||
theme.yawl_bg_nok = "#fb4934" -- email in mailbox
|
||||
theme.yawl_fg = "#FFFFFF" -- default fg
|
||||
theme.yawl_spotify_absent = theme.bg_normal -- bg when spotify not running
|
||||
theme.yawl_spotify_pause = "#d79921" -- bg when spotify running (paused)
|
||||
theme.yawl_spotify_play = "#d3869b" -- bg when spotify running (playing)
|
||||
theme.yawl_battery_full = "#b8bb26" -- battery full + 70%
|
||||
theme.yawl_battery_mid = "#d79921" -- battery medium 30% - 70%
|
||||
theme.yawl_battery_low = "#fb4934" -- battery low - 30%
|
||||
```
|
||||
|
||||
Mail widget take path to watched imap folder as an argument
|
||||
|
||||
```lua
|
||||
mails.widget("/home/papey/mails/bt/Inbox/new"),
|
||||
```
|
||||
|
||||
## Dependencies
|
||||
|
||||
Here is a list of some dependencies required by some modules
|
||||
|
||||
- spotify : requires [playerctl](https://github.com/altdesktop/playerctl) to get current playing status
|
||||
- pomodoro : requires [calabash](https://github.com/papey/calabash) to track pomodoro sessions and `dkjson` to parse calabash client output
|
47
yawl/base.lua
Normal file
47
yawl/base.lua
Normal file
|
@ -0,0 +1,47 @@
|
|||
-- YAWL, Base widget module
|
||||
local base = {}
|
||||
|
||||
-- Requires
|
||||
local wibox = require("wibox")
|
||||
local beautiful = require("beautiful")
|
||||
|
||||
-- Draw a simple icon from a font (nerd font ftw)
|
||||
function base.icon(char)
|
||||
return wibox.widget {
|
||||
resize = true,
|
||||
widget = wibox.widget.textbox,
|
||||
font = beautiful.icon_font,
|
||||
text = " " .. char .. " "
|
||||
}
|
||||
end
|
||||
|
||||
-- Draw a simple separator
|
||||
function base.separator()
|
||||
return wibox.widget {
|
||||
widget = wibox.widget.separator,
|
||||
orientation = "vertical",
|
||||
forced_width = 10,
|
||||
color = beautiful.fg_normal,
|
||||
visible = true
|
||||
}
|
||||
end
|
||||
|
||||
-- Get a fresh text wibox
|
||||
function base.txt()
|
||||
return wibox.widget{
|
||||
font = beautiful.yawl_font,
|
||||
widget = wibox.widget.textbox,
|
||||
}
|
||||
end
|
||||
|
||||
-- Get a fresh background wibox
|
||||
function base.bg()
|
||||
return wibox.widget{
|
||||
widget = wibox.container.background,
|
||||
bg = beautiful.yawl_bg,
|
||||
fg = beautiful.yawl_fg,
|
||||
}
|
||||
end
|
||||
|
||||
-- Return the module
|
||||
return base
|
44
yawl/utils.lua
Normal file
44
yawl/utils.lua
Normal file
|
@ -0,0 +1,44 @@
|
|||
-- YAWL, utils module
|
||||
local utils = {}
|
||||
|
||||
-- strim, for simple trim
|
||||
function utils.strim(char)
|
||||
return char:gsub("\n", "")
|
||||
end
|
||||
|
||||
-- count line number
|
||||
function utils.lc(str)
|
||||
return select(2, str:gsub("\n", "\n"))
|
||||
end
|
||||
|
||||
-- cut line
|
||||
function utils.cut(str)
|
||||
return str:sub(1, 130)
|
||||
end
|
||||
|
||||
-- sanitize line with trim and cut
|
||||
function utils.sanitize(str)
|
||||
local temp = utils.strim(str)
|
||||
local temp = utils.cut(temp)
|
||||
return temp
|
||||
end
|
||||
|
||||
-- split is used to split a line using a regex
|
||||
function utils.split(str, regex)
|
||||
local content = {}
|
||||
for s in str:gmatch(regex) do
|
||||
table.insert(content, s)
|
||||
end
|
||||
return content
|
||||
end
|
||||
|
||||
-- run command and get output
|
||||
function utils.run(cmd)
|
||||
local reader = io.popen(cmd, "r")
|
||||
local content = reader:read('*a')
|
||||
reader:close()
|
||||
return content
|
||||
end
|
||||
|
||||
-- Return module
|
||||
return utils
|
85
yawl/widgets/battery.lua
Normal file
85
yawl/widgets/battery.lua
Normal file
|
@ -0,0 +1,85 @@
|
|||
-- YAWL, Battery widget module
|
||||
local battery = {}
|
||||
local mt = {}
|
||||
|
||||
-- Requires
|
||||
local wibox = require("wibox")
|
||||
local base = require("yawl.base")
|
||||
local utils = require("yawl.utils")
|
||||
local beautiful = require("beautiful")
|
||||
local watch = require("awful.widget.watch")
|
||||
|
||||
-- Entrypoint
|
||||
function mt.__call()
|
||||
|
||||
-- base txt widget
|
||||
local t = base.txt()
|
||||
local w = base.bg()
|
||||
w:set_widget(t)
|
||||
-- change default bg to battery full
|
||||
w:set_bg(beautiful.yawl_battery_full)
|
||||
|
||||
-- icon widget
|
||||
local i = base.icon("")
|
||||
|
||||
-- merge of the two
|
||||
local widget = wibox.widget {
|
||||
i,
|
||||
w,
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
}
|
||||
|
||||
-- watch func
|
||||
watch(
|
||||
'acpi', 10,
|
||||
function(_, stdout, stderr, exitreason, exitcode)
|
||||
-- get lines for acpi
|
||||
local lines = utils.split(stdout, "[^\r\n]+")
|
||||
-- use first line (BAT0), get elements
|
||||
-- 1 : Battery
|
||||
-- 2 : :0
|
||||
-- 3 : State (Full, Discharching, Charging)
|
||||
-- 4 : Level (X%)
|
||||
local parts = utils.split(lines[1], "%S+")
|
||||
|
||||
-- format data in dedicated vars
|
||||
local level = string.gsub(parts[4], "%%,?", "")
|
||||
local state = string.gsub(parts[3], ",", "")
|
||||
|
||||
-- set background based on level
|
||||
if tonumber(level) >= 70 then
|
||||
i:set_text(" ")
|
||||
w:set_bg(beautiful.yawl_battery_full)
|
||||
elseif tonumber(level) >= 30 then
|
||||
i:set_text(" ")
|
||||
w:set_bg(beautiful.yawl_battery_mid)
|
||||
else
|
||||
i:set_text(" ")
|
||||
w:set_bg(beautiful.yawl_battery_low)
|
||||
end
|
||||
|
||||
|
||||
-- set state based on charging, full or discharching
|
||||
local st = ""
|
||||
if state == "Full" then
|
||||
st = ""
|
||||
elseif state == "Discharging" then
|
||||
st = ""
|
||||
elseif state == "Charging" then
|
||||
st = ""
|
||||
else
|
||||
st = ""
|
||||
end
|
||||
|
||||
t:set_text(" " .. st .. " " .. level .. "% ")
|
||||
|
||||
end,
|
||||
w
|
||||
)
|
||||
|
||||
return widget
|
||||
|
||||
end
|
||||
|
||||
-- Return widget
|
||||
return setmetatable(battery, mt)
|
43
yawl/widgets/date.lua
Normal file
43
yawl/widgets/date.lua
Normal file
|
@ -0,0 +1,43 @@
|
|||
-- YAWL, Date widget module
|
||||
local date = {}
|
||||
local mt = {}
|
||||
|
||||
-- Requires
|
||||
local wibox = require("wibox")
|
||||
local base = require("yawl.base")
|
||||
local utils = require("yawl.utils")
|
||||
local watch = require("awful.widget.watch")
|
||||
|
||||
-- Entrypoint
|
||||
function mt.__call()
|
||||
|
||||
-- base
|
||||
local t = base.txt()
|
||||
local w = base.bg()
|
||||
w:set_widget(t)
|
||||
|
||||
-- icon widget
|
||||
local i = base.icon("")
|
||||
|
||||
-- merge of the two
|
||||
local widget = wibox.widget {
|
||||
i,
|
||||
w,
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
}
|
||||
|
||||
-- watch func
|
||||
watch(
|
||||
'date "+%H:%M - %d/%m/%y"', 10,
|
||||
function(_, stdout, stderr, exitreason, exitcode)
|
||||
t:set_text(" " .. utils.strim(stdout) .. " ")
|
||||
end,
|
||||
w
|
||||
)
|
||||
|
||||
return widget
|
||||
|
||||
end
|
||||
|
||||
-- Return widget
|
||||
return setmetatable(date, mt)
|
66
yawl/widgets/spotify.lua
Normal file
66
yawl/widgets/spotify.lua
Normal file
|
@ -0,0 +1,66 @@
|
|||
-- YAWL, Spotify widget module
|
||||
local spotify = {}
|
||||
local mt = {}
|
||||
|
||||
-- Requires
|
||||
local wibox = require("wibox")
|
||||
local base = require("yawl.base")
|
||||
local utils = require("yawl.utils")
|
||||
local beautiful = require("beautiful")
|
||||
local watch = require("awful.widget.watch")
|
||||
|
||||
-- Entrypoint
|
||||
function mt.__call()
|
||||
|
||||
-- base
|
||||
local t = base.txt()
|
||||
local w = base.bg()
|
||||
w:set_widget(t)
|
||||
-- change default bg to paused
|
||||
w:set_bg(beautiful.yawl_spotify_absent)
|
||||
|
||||
-- icon widget
|
||||
local i = base.icon("")
|
||||
|
||||
-- merge of the two
|
||||
local widget = wibox.widget {
|
||||
i,
|
||||
w,
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
}
|
||||
|
||||
-- watch func
|
||||
watch(
|
||||
-- is spotify running ?
|
||||
'pidof spotify', 5,
|
||||
function(_, stdout, stderr, exitreason, exitcode)
|
||||
|
||||
if stdout == "" then
|
||||
w:set_bg(beautiful.yawl_spotify_absent)
|
||||
w:set_fg(beautiful.yawl_spotify_absent_fg)
|
||||
t:set_text(" not running ")
|
||||
return
|
||||
end
|
||||
|
||||
w:set_fg(beautiful.yawl_fg)
|
||||
local status = utils.sanitize(utils.run("playerctl -p spotify status"))
|
||||
local np = utils.sanitize(utils.run('playerctl -p spotify metadata --format="{{ artist }} · {{ title }}"'))
|
||||
|
||||
if status == "Playing" then
|
||||
w:set_bg(beautiful.yawl_spotify_play)
|
||||
else
|
||||
w:set_bg(beautiful.yawl_spotify_pause)
|
||||
end
|
||||
|
||||
t:set_text(" " .. np .. " ")
|
||||
|
||||
end,
|
||||
w
|
||||
)
|
||||
|
||||
return widget
|
||||
|
||||
end
|
||||
|
||||
-- Return widget
|
||||
return setmetatable(spotify, mt)
|
Loading…
Add table
Add a link
Reference in a new issue