Code

screen_play: scroll long song names in the playlist
authorMatt Portas <m.portas20@googlemail.com>
Fri, 21 Nov 2008 15:39:31 +0000 (16:39 +0100)
committerMax Kellermann <max@duempel.org>
Fri, 21 Nov 2008 15:39:31 +0000 (16:39 +0100)
If the song name under the cursor is too long for the terminal, scroll
it like in the statusbar.

src/screen_play.c

index 6cc7277ab73737893b1eda531fb91158ef64d9c7..aff41bac41371e90eb71b895414aa281b3d9c9ed 100644 (file)
@@ -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 */