From d11703d589a783be44965b7045acb9768d9695f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 14 Dec 2018 15:31:08 +0000 Subject: [PATCH] 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. --- helpers.lua | 19 ------------------- widgets/mpd_all.lua | 20 +++++++++++++++++++- 2 files changed, 19 insertions(+), 20 deletions(-) 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