]> gitweb.fluxo.info Git - awesompd.git/commitdiff
Corrected escaped character handling in widget.
authorNicolas Berthier <nicolas.berthier@imag.fr>
Tue, 19 Jul 2011 07:48:29 +0000 (09:48 +0200)
committerNicolas Berthier <nicolas.berthier@imag.fr>
Tue, 19 Jul 2011 07:51:10 +0000 (09:51 +0200)
awesompd.lua

index 9af3778553ad4a40268184205c02efd216d8ae0f..855a7e8c7b2c6ed9f23d2289f01c6f076c57d77b 100644 (file)
@@ -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
@@ -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