summaryrefslogtreecommitdiff
path: root/cmus-widget/cmus.lua
diff options
context:
space:
mode:
authorAugusto Gunsch <augusto@augustogunsch.com>2022-09-21 11:36:37 +0200
committerzachir <zachir@librem.one>2023-10-19 08:22:37 -0500
commit7af31e151d0219a60b408913783056caee1f8392 (patch)
treef89633190be42ccd9236e725e71e5db951b75169 /cmus-widget/cmus.lua
parent23180ef9dc14817b8d1d33706369c20fead4fd99 (diff)
Copy ellipsize function from Spotify widget
Diffstat (limited to 'cmus-widget/cmus.lua')
-rw-r--r--cmus-widget/cmus.lua13
1 files changed, 12 insertions, 1 deletions
diff --git a/cmus-widget/cmus.lua b/cmus-widget/cmus.lua
index b1287c5..a2eddf5 100644
--- a/cmus-widget/cmus.lua
+++ b/cmus-widget/cmus.lua
@@ -12,6 +12,16 @@ local watch = require("awful.widget.watch")
local spawn = require("awful.spawn")
local beautiful = require('beautiful')
+local function ellipsize(text, length)
+ -- utf8 only available in Lua 5.3+
+ if utf8 == nil then
+ return text:sub(0, length)
+ end
+ return (utf8.len(text) > length and length > 0)
+ and text:sub(0, utf8.offset(text, length - 2) - 1) .. '...'
+ or text
+end
+
local cmus_widget = {}
local function worker(user_args)
@@ -21,6 +31,7 @@ local function worker(user_args)
local path_to_icons = args.path_to_icons or "/usr/share/icons/Arc/actions/symbolic/"
local timeout = args.timeout or 10
+ local max_length = args.max_length or 30
local space = args.space or 3
cmus_widget.widget = wibox.widget {
@@ -86,7 +97,7 @@ local function worker(user_args)
widget:update_icon("media-playback-stop-symbolic.svg")
end
- widget:set_title(title)
+ widget:set_title(ellipsize(title, max_length))
widget.visible = true
else
widget.visible = false