mirror of
https://github.com/ArthurSonzogni/FTXUI
synced 2026-06-08 10:24:55 +00:00
1
Redirect stdin stdout
Arthur Sonzogni edited this page 2023-08-19 17:14:13 +02:00
FTXUI communicates with the terminal using stdout / stdin. It means if you redirect one of them toward a file or another application, then the UI will be read/written directly into them!
It exist some platform specific ways (Linux) to redirect back stdout/stdint toward the terminal:
#include <unistd.h> // dup
#include <fcntl.h> // fileno
#include <cstdio> // freopen
[...]
// Backup the current file descriptor for stdin/stdout
auto old_stdout = dup(fileno(stdout));
auto old_stdin = dup(fileno(stdin));
// Reroute stdin and stdout toward the console.
stdin = freopen("/dev/tty", "r", stdin);
stdout = freopen("/dev/tty", "w", stdout);