stefanhaustein / TerminalImageViewer

Small C++ program to display images in a (modern) terminal using RGB ANSI codes and unicode block graphics characters
Other
1.56k stars 111 forks source link

Explicit size specification needed when redirecting output #92

Open nielsbasjes opened 3 years ago

nielsbasjes commented 3 years ago

I would like to have the option to write the ASCII with escape codes and all to a file in such a way that at a later moment I can simply do cat file.ans and see the image.

nielsbasjes commented 3 years ago

NOTE: I tried to simply redirect the output to a file which resulted in a 0 bytes file.

stefanhaustein commented 3 years ago

Redirection should work... Perhaps something trivial is missing such as flushing the output stream...?

On which platform did you encounter this problem?

stefanhaustein commented 3 years ago

p.p.s: Did you try with an explicit size? I think a problem might be failure to detect the terminal size?

clort81 commented 3 years ago

Redirecting to file works fine here. Be sure to specify a -w width and a -h larger than required.

e.g. tiv -w 80 -h 400 mypic.png > mypic.ans && cat mypic.ans

nielsbasjes commented 3 years ago

Sorry for the late reply. Yes, the redirect with the -h and -w works like a charm. Thanks.

Perhaps it is useful having this in the readme? Or a helpful message to stderr in case of the 0 bytes situation?

stefanhaustein commented 3 years ago

I think we could check whether the value is reasonable if there is no explicit width, and use a default value if not