Tasklist: Fail less badly with invalid utf8

xterm is famous for messing up the utf8 in its title (unless correctly
configured).

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2010-10-07 18:42:05 +02:00
parent a4b8fc4894
commit 9e79d18747
1 changed files with 8 additions and 1 deletions

View File

@ -7,6 +7,7 @@
-- Grab environment we need -- Grab environment we need
local math = math local math = math
local type = type local type = type
local pcall = pcall
local ipairs = ipairs local ipairs = ipairs
local setmetatable = setmetatable local setmetatable = setmetatable
local capi = { widget = widget, button = button } local capi = { widget = widget, button = button }
@ -73,7 +74,13 @@ function list_update(w, buttons, label, data, widgets, objects)
end end
local text, bg, bg_image, icon = label(o) local text, bg, bg_image, icon = label(o)
w[k + 1].text, w[k + 1].bg, w[k + 1].bg_image = text, bg, bg_image
-- Check if we got a valid text here, it might contain e.g. broken utf8.
if not pcall(function() w[k + 1].text = text end) then
w[k + 1].text = "<i>Invalid</i>"
end
w[k + 1].bg, w[k + 1].bg_image = bg, bg_image
w[k].bg, w[k].image = bg, icon w[k].bg, w[k].image = bg, icon
if not w[k + 1].text then if not w[k + 1].text then
w[k+1].visible = false w[k+1].visible = false