map

minimalist audio player
git clone https://porkepik.fr/map
Log | Files | Refs | README | LICENSE

commit aea1b7045fd27af8ad1c297c35bd88dca669f091
parent 11324966ff96538c14e0bd37a3624e2f4379a181
Author: Thomas Philippe <dev@porkepik.fr>
Date:   Wed, 28 Aug 2019 01:52:38 +0200

fix print_playlist

Diffstat:
Mmap.c | 19+++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/map.c b/map.c @@ -93,8 +93,8 @@ print_cursor(int oldx, int newx) static void print_playlist(struct track **tracks, int start_index) { - size_t buf_len = 0, line_len; - char *buf = NULL; + int line_len; + char *buf; set_cursor(rows - 4, 1); write_term("\x1b[1J\x1b[H"); @@ -102,16 +102,15 @@ print_playlist(struct track **tracks, int start_index) for (int i = start_index; i < start_index + rows - 5; i++) { if (i == ntracks) break; - line_len = strlen(tracks[i]->name) + 8; - if (line_len > (unsigned long) cols) + line_len = strlen(tracks[i]->name) + 2; + if (line_len > cols) line_len = cols; - buf = realloc(buf, buf_len + line_len); - sprintf(&buf[buf_len], " %s\n", tracks[i]->name); - buf_len += line_len; + buf = malloc(line_len); + sprintf(buf, "%s\n", tracks[i]->name); + set_cursor(i - start_index + 1, 7); + write(STDOUT_FILENO, buf, line_len); + free(buf); } - - write(STDOUT_FILENO, buf, buf_len); - free(buf); print_cursor(1, 1); }