diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2016-10-23 01:01:07 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2016-10-23 01:01:07 +0200 |
commit | 214c6e848b5a6e5bb3ab93abe058a662513bdb78 (patch) | |
tree | ef5100c1a8f8a1312c24536cd92c525a3eb434d3 | |
parent | 1a1347839ca34b0544ef414ede1007a1a2d272e4 (diff) | |
download | nncmpp-214c6e848b5a6e5bb3ab93abe058a662513bdb78.tar.gz nncmpp-214c6e848b5a6e5bb3ab93abe058a662513bdb78.tar.xz nncmpp-214c6e848b5a6e5bb3ab93abe058a662513bdb78.zip |
Show song length in the playlist
-rw-r--r-- | nncmpp.c | 32 |
1 files changed, 27 insertions, 5 deletions
@@ -1209,8 +1209,8 @@ app_draw_song_info (void) app_flush_header (&buf, a_normal); } -static void -app_write_time (struct row_buffer *buf, int seconds, chtype attrs) +static char * +app_time_string (int seconds) { int minutes = seconds / 60; seconds %= 60; int hours = minutes / 60; minutes %= 60; @@ -1224,8 +1224,15 @@ app_write_time (struct row_buffer *buf, int seconds, chtype attrs) str_append_printf (&s, "%d:", minutes); str_append_printf (&s, "%02d", seconds); - row_buffer_append (buf, s.str, attrs); - str_free (&s); + return str_steal (&s); +} + +static void +app_write_time (struct row_buffer *buf, int seconds, chtype attrs) +{ + char *s = app_time_string (seconds); + row_buffer_append (buf, s, attrs); + free (s); } static void @@ -1969,7 +1976,9 @@ static void current_tab_on_item_draw (size_t item_index, struct row_buffer *buffer, int width) { - // TODO: better output + // TODO: configurable output, maybe dynamically sized columns + int length_len = 1 /*separator */ + 2 /* h */ + 3 /* m */+ 3 /* s */; + compact_map_t map = item_list_get (&g_ctx.playlist, item_index); const char *artist = compact_map_find (map, "artist"); const char *title = compact_map_find (map, "title"); @@ -1980,6 +1989,19 @@ current_tab_on_item_draw (size_t item_index, struct row_buffer *buffer, artist, attrs, " - ", attrs, title, attrs, NULL); else row_buffer_append (buffer, compact_map_find (map, "file"), attrs); + + row_buffer_align (buffer, width - length_len, attrs); + + char *s = NULL; + unsigned long n; + const char *time = compact_map_find (map, "time"); + if (!time || !xstrtoul (&n, time, 10) || !(s = app_time_string (n))) + s = xstrdup ("?"); + + char *right_aligned = xstrdup_printf ("%*s", length_len, s); + row_buffer_append (buffer, right_aligned, attrs); + free (right_aligned); + free (s); } static bool |