diff options
author | Stefan Huber <shuber@sthu.org> | 2022-12-30 16:15:54 +0100 |
---|---|---|
committer | Stefan Huber <shuber@sthu.org> | 2023-01-18 07:59:53 +0100 |
commit | 81d725fe84ba96f689ad1e4e8990c7750bc40d33 (patch) | |
tree | 74fa1e2dcf5ddbc9cdd5f8cff149c597d8ce524b /pactl-widget/utils.lua | |
parent | 5f251902cf2b5cc25e54e2ce3b6292a741d52399 (diff) |
pactl: A new volume widget using pactl only
Add a new volume widget that is using pactl only for controlling volume
and selecting sources and sinks. It therefore works with PulseAudio or
PipeWire as backend, unlike the original Volume widget.
The code is split as follows:
- volume.lua contains the UI logic
- pactl.lua contains the pactl interfacing and output parsing
- utils.lua contains some shared helper routines
It is heavily based on the original Volume code and supports the same
configuration options and uses the same widget code.
Diffstat (limited to 'pactl-widget/utils.lua')
-rw-r--r-- | pactl-widget/utils.lua | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/pactl-widget/utils.lua b/pactl-widget/utils.lua new file mode 100644 index 0000000..52e7869 --- /dev/null +++ b/pactl-widget/utils.lua @@ -0,0 +1,28 @@ +local utils = {} + + +function utils.trim(str) + return string.match(str, "^%s*(.-)%s*$") +end + +function utils.split(string_to_split, separator) + if separator == nil then separator = "%s" end + local t = {} + + for str in string.gmatch(string_to_split, "([^".. separator .."]+)") do + table.insert(t, str) + end + + return t +end + +function utils.popen_and_return(cmd) + local handle = io.popen(cmd) + local result = handle:read("*a") + handle:close() + + return result +end + + +return utils |