atanunq / viuer

Rust library for displaying images in the terminal.
MIT License
238 stars 42 forks source link

How to clear the image printed? #28

Open tramhao opened 3 years ago

tramhao commented 3 years ago

Firstly, thanks for your work and it provides very good display result in kitty. I'm using it in my repo(https://github.com/tramhao/termusic) to display the album photo. The display works without problems. However, i need to clear the printed image if the song doesn't have an album photo. I cannot figure out how to do it. Thanks so much.

tramhao commented 3 years ago

I solve it by sending control sequence to terminal directly

    pub fn clear_image(&mut self) {
        write!(self.context.backend_mut(), "\x1b_Ga=d\x1b\\").expect("error delete image");
        self.context
            .backend_mut()
            .flush()
            .expect("error flush delete image");
    }
tramhao commented 3 years ago

If this is the correct way, please close this issue. Thanks.

atanunq commented 3 years ago

Thank you for using viuer. This is a really good point, I think viuer could use a clear/delete_image method. I will leave this issue open as a reminder :)

tramhao commented 2 years ago

I met this problem again but for iterm2 protocol. I'm using same code to clear picture in iterm2, but not working. I'm using wezterm. Do you know if there is a way to clear image in iterm2? I didn't find related information in their website. Thanks so much.

kyoheiu commented 2 years ago

I faced the same problem: By using termion, for example, clearing the image goes like this:

for i in 0..terminal_row {
    print!("{}", cursor::Goto(BEGINNING_COLUMN, BEGINNING_ROW + i as u16));
    print!("{}", clear::UntilNewline);
}

Both cursor::Goto and clear::UntilNewline in termion write escape sequences. This works fine when using alacritty, which does not support sixel. However, with kitty, the above code does not work. Is there any solution to this, or do I miss something? Thanks.