jupyter-xeus / cpp-terminal

C++ library for writing multiplatform terminal applications
https://jupyter-xeus.github.io/cpp-terminal/
Other
522 stars 55 forks source link

Attach or Allocate console on windows #230

Closed flagarde closed 1 year ago

flagarde commented 1 year ago

This PR has some commits, mainly :

The main one is to deal with Windows ""logic"": https://learn.microsoft.com/en-us/windows/console/attachconsole https://learn.microsoft.com/en-us/windows/console/allocconsole

and be safer on reading/writting to terminal/ changing parameters because we can't assure stdin/stdout/stderr has not been redirected. So the code directly open the console file handler to be sure it is dealing with a terminal

flagarde commented 1 year ago

@MCWertGaming The main change for user in Linux/macOS is that the get_size() return 0,0 on not tty, befor it was raising exception. I think it is better to return a value than crashing the software. Even worse, teh software what just checking stdout, but this one could have been redirected but we could still have stdin/stderr on terminal and still the program would crash :(. With thi PR if we have a tty we directly connect to it. The only case I can imagine the PR is doing unespected thing is if stdout was redirected to on other terminal with other size but we could improve the PR doing :

get_size(const int fd&) to let user chose the file handler wanted