fn generate_output(state: BackendState, playlist: &Playlist) -> Result<Vec<String>> {
        let mut ret = Vec::new();
        let mut center: usize = 0; // Index of the currently played song

        let (terminal_height, terminal_width) = {
            let (w, h) = termion::terminal_size()?;
            (usize::try_from(h)?, usize::try_from(w)?)
        };

        // TODO: This group_by() is being ran every 100ms or so
        // It might be better to store the songs grouped by album
        // in the playlist instead. This would, however, make Playlist
        // more complex.
        for (album, songs) in &playlist
            .iter()
            .group_by(|(_, song)| song.album_info.to_string())
        {
            ret.push(format!(
                "{}{:>width$}{}\r",
                termion::style::Underline,
                album,
                termion::style::Reset,
                width = terminal_width,
            ));

            for (playing, song) in songs {
                if playing {
                    center = ret.len();
                    ret.push(Self::format_playing_song(song, &state, terminal_width));
                } else {
                    ret.push(Self::format_song(song, terminal_width));
                }
            }
        }

        // Determine which part of the output to print for it to fit
        // the screen and for the currently playing song to be visible
        if ret.len() <= terminal_height {
            Ok(ret)
        } else if ret.len() - center < terminal_height / 2 {
            let start_index = ret.len() - terminal_height;
            Ok(ret[start_index..].to_vec())
        } else {
            let start_index = center.saturating_sub(terminal_height / 2);
            let end_index = std::cmp::min(ret.len(), start_index + terminal_height);
            Ok(ret[start_index..end_index].to_vec())
        }
    }
/// Returns the lines to be printed to the terminal.
///
/// If the whole playlist does not fit into the terminal, the lines
/// are printed so that the currently played song is in the middle
/// of the window.
Returns the lines to be printed to the terminal.
If the whole playlist does not fit into the terminal, the lines
are printed so that the currently played song is in the middle
of the window.
Returns the lines to be printed to the terminal . If the whole playlist does not fit into the terminal the lines are printed so that the currently played song is in the middle of the window .
fn generate_output(state: BackendState, playlist: &Playlist) -> Result<Vec<String>> {
        let mut ret = Vec::new();
        let mut center: usize = 0; // Index of the currently played song
        let (terminal_height, terminal_width) = {
            let (w, h) = termion::terminal_size()?;
            (usize::try_from(h)?, usize::try_from(w)?)
        };
        // TODO: This group_by() is being ran every 100ms or so
        // It might be better to store the songs grouped by album
        // in the playlist instead. This would, however, make Playlist
        // more complex.
        for (album, songs) in &playlist
            .iter()
            .group_by(|(_, song)| song.album_info.to_string())
        {
            ret.push(format!(
                "{}{:>width$}{}\r",
                termion::style::Underline,
                album,
                termion::style::Reset,
                width = terminal_width,
            ));
            for (playing, song) in songs {
                if playing {
                    center = ret.len();
                    ret.push(Self::format_playing_song(song, &state, terminal_width));
                } else {
                    ret.push(Self::format_song(song, terminal_width));
                }
            }
        }
        // Determine which part of the output to print for it to fit
        // the screen and for the currently playing song to be visible
        if ret.len() <= terminal_height {
            Ok(ret)
        } else if ret.len() - center < terminal_height / 2 {
            let start_index = ret.len() - terminal_height;
            Ok(ret[start_index..].to_vec())
        } else {
            let start_index = center.saturating_sub(terminal_height / 2);
            let end_index = std::cmp::min(ret.len(), start_index + terminal_height);
            Ok(ret[start_index..end_index].to_vec())
        }
    }
fn generate_output ( state : BackendState , playlist : & Playlist ) -> Result < Vec < String > > { let mut ret = Vec :: new ( ) ; let mut center : usize = 0 ; // Index of the currently played song let ( terminal_height , terminal_width ) = { let ( w , h ) = termion :: terminal_size ( ) ? ; ( usize :: try_from ( h ) ? , usize :: try_from ( w ) ? ) } ; // TODO: This group_by() is being ran every 100ms or so // It might be better to store the songs grouped by album // in the playlist instead. This would, however, make Playlist // more complex. for ( album , songs ) in & playlist . iter ( ) . group_by ( | ( _ , song ) | song . album_info . to_string ( ) ) { ret . push ( format ! ( " \r " termion style Underline album termion style Reset width terminal_width ) ) ; for ( playing , song ) in songs { if playing { center = ret . len ( ) ; ret . push ( Self :: format_playing_song ( song , & state , terminal_width ) ) ; } else { ret . push ( Self :: format_song ( song , terminal_width ) ) ; } } } // Determine which part of the output to print for it to fit // the screen and for the currently playing song to be visible if ret . len ( ) <= terminal_height { Ok ( ret ) } else if ret . len ( ) - center < terminal_height / 2 { let start_index = ret . len ( ) - terminal_height ; Ok ( ret [ start_index .. ] . to_vec ( ) ) } else { let start_index = center . saturating_sub ( terminal_height / 2 ) ; let end_index = std :: cmp :: min ( ret . len ( ) , start_index + terminal_height ) ; Ok ( ret [ start_index .. end_index ] . to_vec ( ) ) } }
Returns the lines to be printed to the terminal.
Returns the lines to be printed to the terminal .
state
BackendState
playlist
&Playlist