diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2017-09-25 19:26:37 +0200 |
---|---|---|
committer | Michał Cichoń <michcic@gmail.com> | 2018-10-30 12:01:26 +0100 |
commit | 99fc43dec0fc2132d6b3a1a2a4c4cbd771802473 (patch) | |
tree | 3620ccf36134e7b1abb1bd8131829d1417ed528f /src | |
parent | d85cf786935f3b3517b4156074d2bbbbf1e43494 (diff) | |
download | pianobar-windows-99fc43dec0fc2132d6b3a1a2a4c4cbd771802473.tar.gz pianobar-windows-99fc43dec0fc2132d6b3a1a2a4c4cbd771802473.tar.bz2 pianobar-windows-99fc43dec0fc2132d6b3a1a2a4c4cbd771802473.zip |
Add (optional) song duration to song list format string
Closes #636.
Diffstat (limited to 'src')
-rw-r--r-- | src/ui.c | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -647,20 +647,27 @@ void BarUiPrintSong (const BarSettings_t *settings, size_t BarUiListSongs (const BarSettings_t *settings, const PianoSong_t *song, const char *filter) { size_t i = 0; - char digits[8]; PianoListForeachP (song) { if (filter == NULL || (filter != NULL && (BarStrCaseStr (song->artist, filter) != NULL || BarStrCaseStr (song->title, filter) != NULL))) { - char outstr[512]; + char outstr[512], digits[8], duration[8] = "??:??"; const char *vals[] = {digits, song->artist, song->title, (song->rating == PIANO_RATE_LOVE) ? settings->loveIcon : - ((song->rating == PIANO_RATE_BAN) ? settings->banIcon : "")}; + ((song->rating == PIANO_RATE_BAN) ? settings->banIcon : ""), + duration}; + /* pre-format a few strings */ snprintf (digits, sizeof (digits) / sizeof (*digits), "%2zu", i); + const unsigned int length = song->length; + if (length > 0) { + snprintf (duration, sizeof (duration), "%02u:%02u", + length / 60, length % 60); + } + BarUiCustomFormat (outstr, sizeof (outstr), settings->listSongFormat, - "iatr", vals); + "iatrd", vals); BarUiAppendNewline (outstr, sizeof (outstr)); BarUiMsg (settings, MSG_LIST, "%s", outstr); } |