diff --git a/helpers.lua b/helpers.lua index 4e0a072..d3ed859 100644 --- a/helpers.lua +++ b/helpers.lua @@ -136,25 +136,6 @@ function helpers.uformat(array, key, value, unit) end -- }}} --- {{{ Format playing progress -function helpers.format_progress(elapsed, duration) - local em, es = elapsed / 60, elapsed % 60 - local dm, ds = duration / 60, duration % 60 - - if dm < 10 then - return ("%d:%02d"):format(em, es), ("%d:%02d"):format(dm, ds) - elseif dm < 60 then - return ("%02d:%02d"):format(em, es), ("%02d:%02d"):format(dm, ds) - elseif dm < 600 then - return ("%d:%02d:%02d"):format(em / 60, em % 60, es), - ("%d:%02d:%02d"):format(dm / 60, dm % 60, ds) - else - return ("%02d:%02d:%02d"):format(em / 60, em % 60, es), - ("%02d:%02d:%02d"):format(dm / 60, dm % 60, ds) - end -end --- }}} - -- {{{ Escape a string function helpers.escape(text) local xml_entities = { diff --git a/widgets/mpd_all.lua b/widgets/mpd_all.lua index 4eebe6e..4ea983d 100644 --- a/widgets/mpd_all.lua +++ b/widgets/mpd_all.lua @@ -23,6 +23,24 @@ local function cbool(number) end -- }}} +-- {{{ Format playing progress +function format_progress(elapsed, duration) + local em, es = elapsed / 60, elapsed % 60 + local dm, ds = duration / 60, duration % 60 + + if dm < 10 then + return ("%d:%02d"):format(em, es), ("%d:%02d"):format(dm, ds) + elseif dm < 60 then + return ("%02d:%02d"):format(em, es), ("%02d:%02d"):format(dm, ds) + elseif dm < 600 then + return ("%d:%02d:%02d"):format(em / 60, em % 60, es), + ("%d:%02d:%02d"):format(dm / 60, dm % 60, ds) + else + return ("%02d:%02d:%02d"):format(em / 60, em % 60, es), + ("%02d:%02d:%02d"):format(dm / 60, dm % 60, ds) + end +end +-- }}} -- {{{ MPD widget type local function worker(format, warg) @@ -72,7 +90,7 @@ local function worker(format, warg) f:close() -- Formatted elapsed and duration - mpd_state["{Elapsed}"], mpd_state["{Duration}"] = helpers.format_progress( + mpd_state["{Elapsed}"], mpd_state["{Duration}"] = format_progress( mpd_state["{elapsed}"], mpd_state["{duration}"]) return mpd_state