Skip to content

Commit

Permalink
Fix gcal widget bug
Browse files Browse the repository at this point in the history
Fix bug where the markup substitution would fail for consecutive
holidays
  • Loading branch information
ojv committed Nov 13, 2017
1 parent cbc72ed commit 91548aa
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions widgets/gcal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ local settings = {
tooltip = {}
}

local gcal_cmd = "/usr/bin/gcal --highlighting=\"{:]:[:]\" "
local gcal_cmd = "/usr/bin/gcal --highlighting=\" :}: :]\" "

local function span(attr, str)
local open = "<span " .. attr .. ">"
Expand All @@ -65,6 +65,11 @@ local function errormsg(msg)
return span("foreground='red'", msg)
end

local function wrap(markup)
local open, close = span(markup)
return open .. "%1" .. close .. " "
end

local tooltip = {
default = {
mode = "outside",
Expand All @@ -79,17 +84,10 @@ local tooltip = {
handle:close()

if ok then
local today_open, _ = span(settings.markup.today)
local holiday_open, close = span(settings.markup.holiday)

local cal = span(settings.markup.calendar,
settings.strip(result ):gsub(
"%{ ", " " .. today_open ):gsub(
"%{([^ ])", " " .. today_open .. "%1" ):gsub(
"%[ ", " " .. holiday_open ):gsub(
"%[([^ ])", " " .. holiday_open .. "%1" ):gsub(
"%]", close .. " "))
return cal
return span(settings.markup.calendar,
settings.strip(result):gsub(
"(%d+)}", wrap(settings.markup.today)):gsub(
"(%d+)]", wrap(settings.markup.holiday)))
else
return errormsg("handle:read error reading from gcal: " ..
(handle or "nil"))
Expand Down

0 comments on commit 91548aa

Please sign in to comment.