h3rald / min

A small but practical concatenative programming language and shell
https://min-lang.org
MIT License
310 stars 23 forks source link

shell redirection of text output to a file is corrupted with additional characters #184

Closed limbicrevision closed 11 months ago

limbicrevision commented 2 years ago

Hello I just found this issue on PureOS/Debian bullseye/zsh shell/min -v -> 0.37.0

I am trying to capture puts! text output from a min program but I managed to recreate the problem from the command line:

min -e:'"junk" print' > junk.txt emacs junk.txt (with hexl-mode) this is the output: 6a75 6e6b 1b5b 306d 1b5b 306d junk.[0m.[0m

Many thanks

inivekin commented 1 year ago

This is caused by the resetAttributes being added to the exit process by niftylogger and nimline. I was able to fix it by conditioning the addExitProc(resetAttributes) calls with a if isatty(stdin):. Is there a more complicated reason this issue has stuck around a while or has it just not been trouble for anyone to fix already?

h3rald commented 1 year ago

I personally didn't encounter the problem, and also these days my time is very limited.

But pull requests will definitely be merged! Or I'll try out your suggestion when I get a change, thanks!

inivekin commented 1 year ago

Ok, I'll get those pull requests ready momentarily. I often use these interpreters from an editor (e.g. specifically in kakoune by piping the selection to the binary and appending the output), making this issue kind of obvious/annoying.

Thanks for your software by the way. In rereading my comment I might have sounded a bit whiny. What I meant to imply was that I am new to nim and was thinking I could be missing something important. I found it very easy to solve this issue given the simple dependencies and code despite knowing little!

Hope you find more time to work on this! Some open issues for features look very interesting...