cpp-terminal
cpp-terminal copied to clipboard
Adding pipe_cin to examples dir
@flagarde That pull request addresses the use of an unnamed pipe to read input stream in a program that uses the cpp_terminal library, as mentioned in issue #320.
It introduces a new example in the examples
directory called cin_pipe
. For my initial tests, I executed the following commands:
When the example program is executed without any unnamed pipe:
$ echo -e "Testing std::cin\nTesting stdin" | build/debug/examples/pipe_cin Checking if std::cin is empty
std::cin => "Testing std::cin"
Checking if stdin is empty
stdin => "Testing stdin"
When the example program is the consumer of a unnamed pipe from a cat command:
$ echo "testing std::cin" | build/debug/examples/pipe_cin
Checking if std::cin is empty
std::cin => "testing std::cin"
Checking if stdin is empty
stdin => ""
$ echo -e "Testing std::cin\nTesting stdin" | build/debug/examples/pipe_cin Checking if std::cin is empty
std::cin => "Testing std::cin"
Checking if stdin is empty
stdin => "Testing stdin"
Please verify the program in Windows and Mac environments, as it has only been tested on Linux Ubuntu 22.04 (xterm). Note that it uses only POSIX and C++11 flavors, so I believe it should work in any environment.
@wmarini Thx for the code. unfortunately it seems windows is not totallt POSIX compatible but we can use your code as basis to do one with windows support.