2.2 KiB
POSIX Piped Input in FTXUI
Warning
This feature works only on Linux and macOS. It is not supported on Windows and WebAssembly.
What is a POSIX Pipe?
A POSIX pipe is a way for two separate programs to communicate. One program sends its output directly as input to another program. Think of it like a one-way tube for data.
Example:
Imagine you want to list files and then filter them interactively.
ls
: Lists files.interactive_grep
: An FTXUI application that filters text and lets you type.
You can connect them with a pipe (|
):
ls -l | interactive_grep
Here's what happens:
ls -l
lists files with details.- The
|
sends this list directly tointeractive_grep
. interactive_grep
receives the list and displays it. Because it's an FTXUI app, you can then type to filter the list, even though it received initial data fromls
.
How FTXUI Handles Piped Input
Now that you understand what a POSIX pipe is, let's look at how FTXUI uses them.
FTXUI lets your application read data from other programs (like from a pipe) while still allowing you to use your keyboard for interaction. This is useful for interactive command-line tools that process data.
Normally, FTXUI applications receive all input from stdin
. However, when FTXUI detects that stdin
is connected to the output of a pipe (meaning data is being piped into your application), it automatically switches to reading interactive keyboard input from /dev/tty
. This ensures that your application can still receive user input even while processing piped data.
This feature is turned on by default.
If your FTXUI application needs to read piped data and also respond to keyboard input, you typically don't need to do anything special:
auto screen = ScreenInteractive::Fullscreen();
// screen.HandlePipedInput(true); // This is enabled by default
screen.Loop(component);
Turning Off Piped Input
If you don't need this feature, or if it conflicts with your custom input handling, you can turn it off.
To disable it, call HandlePipedInput(false)
before starting your application's main loop:
auto screen = ScreenInteractive::Fullscreen();
screen.HandlePipedInput(false); // Turn off piped input handling
screen.Loop(component);