map

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

commit 1f7cd4079da305817cea75a02e48f99dc59e8f24
parent aea1b7045fd27af8ad1c297c35bd88dca669f091
Author: Thomas Philippe <dev@porkepik.fr>
Date:   Wed, 28 Aug 2019 02:05:59 +0200

optimize print_playlist

Diffstat:
Mmap.c | 15+++------------
1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/map.c b/map.c @@ -93,23 +93,14 @@ print_cursor(int oldx, int newx) static void print_playlist(struct track **tracks, int start_index) { - int line_len; - char *buf; - - set_cursor(rows - 4, 1); - write_term("\x1b[1J\x1b[H"); + set_cursor(rows - 3, 1); + write_term("\x1b[1J"); for (int i = start_index; i < start_index + rows - 5; i++) { if (i == ntracks) break; - line_len = strlen(tracks[i]->name) + 2; - if (line_len > cols) - line_len = cols; - 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_term("\x1b[1K%s", tracks[i]->name); } print_cursor(1, 1); }