Repository: aome510/spotify-player (language: rust)

Issue:
Blank space drawn on top left blocking content if `playback_window_position` is `Bottom`
**Symptom**
Weird album art artefact drawn on terminal when `playback_window_position` is set to `Bottom` as shown in this screenshot:
![image](https://github.com/aome510/spotify-player/assets/22890124/f095897c-e53e-44f0-be2b-85c9f49bc250)

Blank space drawn on top left that matches the dimensions of the album art.
I guess some logic that allocates space fell through some branch checks. 
You won't notice this if `playback_window_position` is set to Top.

**Expected behavior**
There should NOT be blank space on the top left.

**To Reproduce**
1. clean install of `spotify_player` with the `image` feature
2. start `spotify_player` to generate default `app.toml`
3. change `playback_window_position` to `Bottom` 
4. start `spotify_player`

**Log and backtrace**
No obvious trace from logs, will provide if needed.

**Environment**
+ Application version: `spotify_player 0.16.2`
+ Application features: I build my `spotify_player` using `cargo` with these options:
```
cargo install spotify_player --no-default-features --features daemon,rodio-backend,streaming,lyric-finder,clipboard,image,notify
```
+ `fastfetch` output (truncated):
```
OS: macOS Big Sur 11.4 20F71 x86_64
Shell: zsh 5.8
Terminal: kitty 0.30.0
```

**Additional context**
Issue appeared since version `0.16.2`.

**Issue rating**
+ Reproducibility: always (always/sometimes)
+ Impact: non-breaking (breaking/non-breaking)
  - set `playback_window_position` to `Top` to avoid the issue for now
  - can be work around by typing extra space so I can see what I typed
  - scroll further up or down to see what is behind the blank space.
+ Size: entire app (entire app/specific feature)


Discussion / hints:

Fix patch:
diff --git a/spotify_player/src/ui/mod.rs b/spotify_player/src/ui/mod.rs
index 624fb62c..86bf635c 100644
--- a/spotify_player/src/ui/mod.rs
+++ b/spotify_player/src/ui/mod.rs
@@ -36,18 +36,6 @@ pub fn run(state: SharedState) -> Result<()> {
             }
 
             if let Err(err) = terminal.draw(|frame| {
-                #[cfg(feature = "image")]
-                {
-                    for x in 1..state.configs.app_config.cover_img_length + 1 {
-                        for y in 1..state.configs.app_config.cover_img_width + 1 {
-                            frame
-                                .buffer_mut()
-                                .get_mut(x as u16, y as u16)
-                                .set_skip(true);
-                        }
-                    }
-                }
-
                 // set the background and foreground colors for the application
                 let rect = frame.size();
                 let block = Block::default().style(ui.theme.app_style());
diff --git a/spotify_player/src/ui/playback.rs b/spotify_player/src/ui/playback.rs
index 795c971d..2d274ba5 100644
--- a/spotify_player/src/ui/playback.rs
+++ b/spotify_player/src/ui/playback.rs
@@ -62,6 +62,14 @@ pub fn render_playback_window(
                             (hor_chunks[2], ver_chunks[0])
                         };
 
+                        // set the `skip` state of cells in the cover image area
+                        // to prevent buffer from overwriting image cells
+                        for x in cover_img_rect.left()..cover_img_rect.right() {
+                            for y in cover_img_rect.top()..cover_img_rect.bottom() {
+                                frame.buffer_mut().get_mut(x, y).set_skip(true);
+                            }
+                        }
+
                         let url = crate::utils::get_track_album_image_url(track).map(String::from);
                         if let Some(url) = url {
                             let needs_render = match &ui.last_cover_image_render_info {
@@ -105,20 +113,16 @@ pub fn render_playback_window(
         // clear the previous widget's area before rendering the text.
         #[cfg(feature = "image")]
         {
-            if ui.last_cover_image_render_info.is_some() {
+            if let Some((_, rect)) = ui.last_cover_image_render_info {
                 frame.render_widget(Clear, rect);
-                ui.last_cover_image_render_info = None;
-            }
-
-            // reset the `skip` state of cells in cover image area
-            // to render the "No playback found" message
-            for x in 1..state.configs.app_config.cover_img_length + 1 {
-                for y in 1..state.configs.app_config.cover_img_width + 1 {
-                    frame
-                        .buffer_mut()
-                        .get_mut(x as u16, y as u16)
-                        .set_skip(false);
+                // reset the `skip` state of cells in the cover image area
+                // in order to render the "No playback found" message
+                for x in rect.left()..rect.right() {
+                    for y in rect.top()..rect.bottom() {
+                        frame.buffer_mut().get_mut(x, y).set_skip(false);
+                    }
                 }
+                ui.last_cover_image_render_info = None;
             }
         }
 


Test patch: