From: Matt Portas Date: Fri, 21 Nov 2008 15:39:31 +0000 (+0100) Subject: screen_play: scroll long song names in the playlist X-Git-Tag: v0.12_beta1~25 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=cfad0fdfca5821eb2d17f93bc08d4e5efc23beae;p=ncmpc.git screen_play: scroll long song names in the playlist If the song name under the cursor is too long for the terminal, scroll it like in the statusbar. --- diff --git a/src/screen_play.c b/src/screen_play.c index 6cc7277..aff41ba 100644 --- a/src/screen_play.c +++ b/src/screen_play.c @@ -94,6 +94,7 @@ static const char * list_callback(unsigned idx, int *highlight, mpd_unused void *data) { static char songname[MAX_SONG_LENGTH]; + static scroll_state_t st; mpd_Song *song; if (playlist == NULL || idx >= playlist_length(playlist)) @@ -104,6 +105,24 @@ list_callback(unsigned idx, int *highlight, mpd_unused void *data) *highlight = 1; strfsong(songname, MAX_SONG_LENGTH, options.list_format, song); + + if (options.scroll && (unsigned)song->pos == lw->selected && + utf8_width(songname) > (unsigned)COLS) { + static unsigned current_song; + char *tmp; + + if (current_song != lw->selected) { + st.offset = 0; + current_song = lw->selected; + } + + tmp = strscroll(songname, options.scroll_sep, + MAX_SONG_LENGTH, &st); + g_strlcpy(songname, tmp, MAX_SONG_LENGTH); + g_free(tmp); + } else if ((unsigned)song->pos == lw->selected) + st.offset = 0; + return songname; } @@ -448,7 +467,7 @@ play_update(mpdclient_t *c) current_song_id = c->song != NULL && c->status != NULL && !IS_STOPPED(c->status->state) ? c->song->id : -1; - if (current_song_id != prev_song_id) { + if (options.scroll || current_song_id != prev_song_id) { prev_song_id = current_song_id; /* center the cursor */