diff options
-rw-r--r-- | contrib/config-example | 1 | ||||
-rw-r--r-- | contrib/pianobar.1 | 16 | ||||
-rw-r--r-- | src/settings.c | 5 | ||||
-rw-r--r-- | src/settings.h | 1 | ||||
-rw-r--r-- | src/ui.c | 31 |
5 files changed, 49 insertions, 5 deletions
diff --git a/contrib/config-example b/contrib/config-example index bcc1b47..3c13142 100644 --- a/contrib/config-example +++ b/contrib/config-example @@ -46,3 +46,4 @@ # Format strings #format_nowplaying_song = [32m%t[0m by [34m%a[0m on %l[31m%r[0m%@%s #format_nowplaying_station = Station [35m%n[0m +#format_list_song = %i) %a - %t%r diff --git a/contrib/pianobar.1 b/contrib/pianobar.1 index eae062f..3066ae5 100644 --- a/contrib/pianobar.1 +++ b/contrib/pianobar.1 @@ -183,6 +183,22 @@ usually the value above). See section .B REMOTE CONTROL .TP +.B format_list_song = %i) %a - %t%r +Available format characters: + +.B %i +Song number + +.B %a +Song artist + +.B %t +Song title + +.B %r +Rating icon + +.TP .B format_nowplaying_song = \[dq]%t\[dq] by \[dq]%a\[dq] on \[dq]%l\[dq]%r%@%s Now playing song message format. Available format characters are: diff --git a/src/settings.c b/src/settings.c index 49d75e6..9867b47 100644 --- a/src/settings.c +++ b/src/settings.c @@ -91,6 +91,7 @@ void BarSettingsDestroy (BarSettings_t *settings) { free (settings->atIcon); free (settings->npSongFormat); free (settings->npStationFormat); + free (settings->listSongFormat); free (settings->fifo); for (size_t i = 0; i < MSG_COUNT; i++) { free (settings->msgFormat[i].prefix); @@ -127,6 +128,7 @@ void BarSettingsRead (BarSettings_t *settings) { settings->atIcon = strdup (" @ "); settings->npSongFormat = strdup ("\"%t\" by \"%a\" on \"%l\"%r%@%s"); settings->npStationFormat = strdup ("Station \"%n\" (%i)"); + settings->listSongFormat = strdup ("%i) %a - %t%r"); settings->fifo = malloc (PATH_MAX * sizeof (*settings->fifo)); BarGetXdgConfigDir (PACKAGE "/ctl", settings->fifo, PATH_MAX); @@ -231,6 +233,9 @@ void BarSettingsRead (BarSettings_t *settings) { } else if (streq ("format_nowplaying_station", key)) { free (settings->npStationFormat); settings->npStationFormat = strdup (val); + } else if (streq ("format_list_song", key)) { + free (settings->listSongFormat); + settings->listSongFormat = strdup (val); } else if (streq ("fifo", key)) { free (settings->fifo); settings->fifo = strdup (val); diff --git a/src/settings.h b/src/settings.h index ca5db60..6162395 100644 --- a/src/settings.h +++ b/src/settings.h @@ -94,6 +94,7 @@ typedef struct { char *atIcon; char *npSongFormat; char *npStationFormat; + char *listSongFormat; char *fifo; BarMsgFormatStr_t msgFormat[MSG_COUNT]; } BarSettings_t; @@ -723,6 +723,20 @@ inline void BarUiPrintSong (const BarSettings_t *settings, BarUiMsg (settings, MSG_PLAYING, outstr); } +/* Incremets two digit ASCII counter + */ +static void BarUiIncDigits (char digits[3]) { + ++digits[1]; + if (digits[1] == ':') { + digits[1] = '0'; + digits[0] |= 0x30; + ++digits[0]; + if (digits[0] == ':') { + digits[0] = ' '; + } + } +} + /* Print list of songs * @param pianobar settings * @param linked list of songs @@ -732,18 +746,25 @@ inline 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[3] = " 0"; while (song != NULL) { if (filter == NULL || (filter != NULL && (BarStrCaseStr (song->artist, filter) != NULL || BarStrCaseStr (song->title, filter) != NULL))) { - BarUiMsg (settings, MSG_LIST, "%2lu) %s - %s %s%s\n", i, song->artist, - song->title, - (song->rating == PIANO_RATE_LOVE) ? settings->loveIcon : "", - (song->rating == PIANO_RATE_BAN) ? settings->banIcon : ""); + char outstr[512]; + const char *vals[] = {digits, song->artist, song->title, + (song->rating == PIANO_RATE_LOVE) ? settings->loveIcon : + ((song->rating == PIANO_RATE_BAN) ? settings->banIcon : "")}; + + BarUiCustomFormat (outstr, sizeof (outstr), settings->listSongFormat, + "iatr", vals); + BarUiAppendNewline (outstr, sizeof (outstr)); + BarUiMsg (settings, MSG_LIST, outstr); } - song = song->next; i++; + BarUiIncDigits (digits); + song = song->next; } return i; |