diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2020-08-09 09:23:38 +0200 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2020-08-09 09:23:38 +0200 |
commit | 4c228cd60890c0ef09c345c13713453c4c2dd508 (patch) | |
tree | 12b39298dd172291ea82529354578cf6e0cf8d73 /src/main.c | |
parent | bc6bd8a2b8b84a79dd77b81d6a25b661c5d1d1ca (diff) | |
download | pianobar-4c228cd60890c0ef09c345c13713453c4c2dd508.tar.gz pianobar-4c228cd60890c0ef09c345c13713453c4c2dd508.tar.bz2 pianobar-4c228cd60890c0ef09c345c13713453c4c2dd508.zip |
Allow choosing time format
Introduce new format string for playback time, supporting formats like
-remaining/total, elapsed/total, …
Fixes #699.
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 23 |
1 files changed, 17 insertions, 6 deletions
@@ -312,7 +312,7 @@ static void BarMainPlayerCleanup (BarApp_t *app, pthread_t *playerThread) { */ static void BarMainPrintTime (BarApp_t *app) { unsigned int songRemaining; - char sign; + char sign[2] = {0, 0}; player_t * const player = &app->player; pthread_mutex_lock (&player->lock); @@ -322,15 +322,26 @@ static void BarMainPrintTime (BarApp_t *app) { if (songPlayed <= songDuration) { songRemaining = songDuration - songPlayed; - sign = '-'; + sign[0] = '-'; } else { /* longer than expected */ songRemaining = songPlayed - songDuration; - sign = '+'; + sign[0] = '+'; } - BarUiMsg (&app->settings, MSG_TIME, "%c%02u:%02u/%02u:%02u\r", - sign, songRemaining / 60, songRemaining % 60, - songDuration / 60, songDuration % 60); + + char outstr[512], totalFormatted[16], remainingFormatted[16], + elapsedFormatted[16]; + const char *vals[] = {totalFormatted, remainingFormatted, + elapsedFormatted, sign}; + snprintf (totalFormatted, sizeof (totalFormatted), "%02u:%02u", + songDuration/60, songDuration%60); + snprintf (remainingFormatted, sizeof (remainingFormatted), "%02u:%02u", + songRemaining/60, songRemaining%60); + snprintf (elapsedFormatted, sizeof (elapsedFormatted), "%02u:%02u", + songPlayed/60, songPlayed%60); + BarUiCustomFormat (outstr, sizeof (outstr), app->settings.timeFormat, + "tres", vals); + BarUiMsg (&app->settings, MSG_TIME, "%s\r", outstr); } /* main loop |