Merge pull request #335 from nuno-silva/spotify-widget-utf8

spotify-widget: check for utf8 support
This commit is contained in:
streetturtle 2022-02-20 15:05:37 -05:00 committed by GitHub
commit 90958abb48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -16,6 +16,10 @@ local GET_SPOTIFY_STATUS_CMD = 'sp status'
local GET_CURRENT_SONG_CMD = 'sp current' local GET_CURRENT_SONG_CMD = 'sp current'
local function ellipsize(text, length) 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) return (utf8.len(text) > length and length > 0)
and text:sub(0, utf8.offset(text, length - 2) - 1) .. '...' and text:sub(0, utf8.offset(text, length - 2) - 1) .. '...'
or text or text
@ -154,4 +158,4 @@ end
return setmetatable(spotify_widget, { __call = function(_, ...) return setmetatable(spotify_widget, { __call = function(_, ...)
return worker(...) return worker(...)
end }) end })