aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralexander-yakushev <yakushev.alex@gmail.com>2011-07-19 03:36:24 -0700
committeralexander-yakushev <yakushev.alex@gmail.com>2011-07-19 03:36:24 -0700
commit8d59c5f5b5644574a9a6c131e9a43da866ddc490 (patch)
tree6d788c76252129866ca864311bc7d712d32d3057
parentad48622a9703c553619fc67bd18ba16ff168a576 (diff)
parent13aa065e4ca102ab7a03bf9b61e5c788a0a06893 (diff)
downloadawesompd-8d59c5f5b5644574a9a6c131e9a43da866ddc490.tar.gz
awesompd-8d59c5f5b5644574a9a6c131e9a43da866ddc490.tar.bz2
Merge pull request #2 from nberth/common
Corrected escaped character handling in widget.
-rw-r--r--awesompd.lua26
1 files changed, 20 insertions, 6 deletions
diff --git a/awesompd.lua b/awesompd.lua
index 9af3778..e2e4c27 100644
--- a/awesompd.lua
+++ b/awesompd.lua
@@ -7,6 +7,10 @@ require('utf8')
local naughty = naughty
local awful = awful
+-- Debug stuff:
+local function dbg (...) return nil end
+-- local function dbg (...) print (...) end
+
awesompd = {}
-- Constants
@@ -349,7 +353,7 @@ function awesompd:get_list_menu()
local start_num = (self.current_number - 15 > 0) and self.current_number - 15 or 1
local end_num = (self.current_number + 15 < total_count ) and self.current_number + 15 or total_count
for i = start_num, end_num do
- print(self.list_array[i])
+ dbg (self.list_array[i])
if (string.find(self.list_array[i],"jamendo.com")) then
table.insert(new_menu, { self.jamendo_list[awesompd.get_id_from_link(self.list_array[i])],
self:command_play_specific(i),
@@ -477,7 +481,7 @@ end
function awesompd:add_hint(hint_title, hint_text)
self:remove_hint()
self.notification = naughty.notify({ title = hint_title
- , text = hint_text
+ , text = awesompd.protect_string(hint_text)
, timeout = 5
, position = "top_right"
})
@@ -512,7 +516,8 @@ function awesompd:notify_state(state_changed)
end
function awesompd:wrap_output(text)
- return '<span font="' .. self.font .. '">| ' .. text .. ' |</span>'
+ return '<span font="' .. self.font .. '"> ' ..
+ awesompd.protect_string (text) .. ' </span>'
end
function awesompd:retrieve_cache()
@@ -564,9 +569,15 @@ function awesompd.find_pattern(text, pattern, start)
return utf8sub(text, string.find(text, pattern, start))
end
+-- NB: If there may be escaped characters in `text' already, then we need to use
+-- a different algorithm here (some sort of `pcdata' library instead of the
+-- `utf8' one directly) so that we do not give malformed strings to the
+-- widget. However, it is much simpler to scroll unescaped strings here, and
+-- protect them upon update of the widget.
function awesompd:scroll_text(text)
local text = text
local result = text
+
if self.output_size < utf8len(text) then
text = text .. " - "
if self.scroll_pos + self.output_size - 1 > utf8len(text) then
@@ -636,15 +647,18 @@ function awesompd:update_track()
self.recreate_playback = true
self.recreate_list = true
end
- else
- local new_track = awesompd.protect_string(info_ar[1])
+ else
+ -- delay character escaping until widget update.
+ local new_track = -- awesompd.protect_string(
+ info_ar[1]-- )
if new_track ~= self.unique_text then
if (string.find(new_track,"jamendo.com")) then
self.text = self.jamendo_list[awesompd.get_id_from_link(new_track)]
else
self.text = new_track
end
- self.unique_text = new_track
+ self.unique_text = new_track --<- NB: what does this mean? could it
+ --be `self.text' instead?
self.to_notify = true
self.recreate_menu = true
self.recreate_playback = true