atanunq / viuer

Rust library for displaying images in the terminal.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feature request: get String from Read trait

RCasatta opened this issue · comments

In my opinion, your lib would benefit from a method like the following

pub fn image_to_string<R: Read>(from: R) -> Result<String, ViuError>

Disclosure:
I am interested in using this lib for tests of library https://crates.io/crates/bmp-monochrome
The library had a bug RCasatta/bmp-monochrome#2 that wasn't catch because it was on both encode and decode method, so I thought the only way to catch this kind of bug is introducing external image library in tests.

Hi!
I don't quite get what the job of this function should be. Can you elaborate what the returned String represents?

I was thinking about something like:

█▀▀▀▀▀█  ▀▀▀█ █▀▀▀▀▀█
█ ███ █ █ █ ▀ █ ███ █
█ ▀▀▀ █ ██ ▄▀ █ ▀▀▀ █
▀▀▀▀▀▀▀ █ █ ▀ ▀▀▀▀▀▀▀
▀ ▀█▀▀▀ ▄▀ █▄▄█▀▀██ ▄
  █▀▀█▀▄▄▀█▄█▄█▀ ██▀
 ▀▀▀  ▀▀█▀▀ █  █ ▄  ▀
█▀▀▀▀▀█ ▄▀▄▀ ▀ ▄█▄██
█ ███ █ █▄ █▄█▄▄▀▄ ▀
█ ▀▀▀ █ ▀█ ▄█▄█▀▄▄█
▀▀▀▀▀▀▀ ▀▀  ▀   ▀  ▀

that I can assert_eq! against an expected value in a rust test or that I can easily convert in a bit grid (a vec of boolean if the pixel is light or dark)

However, I am not sure if the output of the terminal is just a utf-8 string or something else

Hmm, I guess it would be possible to pass around references to where the writing should be, i.e stdout in most cases, maybe a Vec in yours.
I have been thinking about doing something similar to allow me to write tests, but I think it will overcomplicate the lib.

The problem is that the characters sent are not only the blocks, but escape sequences, too, for coloring.

Also, in the case of Kitty, the terminal has to respond to certain queries. When that is the case, it doesn't really make sense to write to anything else but stdout.

I understand, closing