Show song length in the playlist
This commit is contained in:
parent
1a1347839c
commit
214c6e848b
32
nncmpp.c
32
nncmpp.c
|
@ -1209,8 +1209,8 @@ app_draw_song_info (void)
|
||||||
app_flush_header (&buf, a_normal);
|
app_flush_header (&buf, a_normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static char *
|
||||||
app_write_time (struct row_buffer *buf, int seconds, chtype attrs)
|
app_time_string (int seconds)
|
||||||
{
|
{
|
||||||
int minutes = seconds / 60; seconds %= 60;
|
int minutes = seconds / 60; seconds %= 60;
|
||||||
int hours = minutes / 60; minutes %= 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, "%d:", minutes);
|
||||||
|
|
||||||
str_append_printf (&s, "%02d", seconds);
|
str_append_printf (&s, "%02d", seconds);
|
||||||
row_buffer_append (buf, s.str, attrs);
|
return str_steal (&s);
|
||||||
str_free (&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
|
static void
|
||||||
|
@ -1969,7 +1976,9 @@ static void
|
||||||
current_tab_on_item_draw (size_t item_index, struct row_buffer *buffer,
|
current_tab_on_item_draw (size_t item_index, struct row_buffer *buffer,
|
||||||
int width)
|
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);
|
compact_map_t map = item_list_get (&g_ctx.playlist, item_index);
|
||||||
const char *artist = compact_map_find (map, "artist");
|
const char *artist = compact_map_find (map, "artist");
|
||||||
const char *title = compact_map_find (map, "title");
|
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);
|
artist, attrs, " - ", attrs, title, attrs, NULL);
|
||||||
else
|
else
|
||||||
row_buffer_append (buffer, compact_map_find (map, "file"), attrs);
|
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
|
static bool
|
||||||
|
|
Loading…
Reference in New Issue