move format_progress to mpd module
The function is not used by any other module and is only really useful for formatting durations as exposed by mpd.
This commit is contained in:
parent
a902a23b5c
commit
d11703d589
19
helpers.lua
19
helpers.lua
|
@ -136,25 +136,6 @@ function helpers.uformat(array, key, value, unit)
|
||||||
end
|
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
|
-- {{{ Escape a string
|
||||||
function helpers.escape(text)
|
function helpers.escape(text)
|
||||||
local xml_entities = {
|
local xml_entities = {
|
||||||
|
|
|
@ -23,6 +23,24 @@ local function cbool(number)
|
||||||
end
|
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
|
-- {{{ MPD widget type
|
||||||
local function worker(format, warg)
|
local function worker(format, warg)
|
||||||
|
@ -72,7 +90,7 @@ local function worker(format, warg)
|
||||||
f:close()
|
f:close()
|
||||||
|
|
||||||
-- Formatted elapsed and duration
|
-- 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}"])
|
mpd_state["{elapsed}"], mpd_state["{duration}"])
|
||||||
|
|
||||||
return mpd_state
|
return mpd_state
|
||||||
|
|
Loading…
Reference in New Issue