Skip to content
You are viewing documentation for v6.1.5. Switch to latest (main).

POSIX Piped Input in FTXUI ​

Platform Support

This feature works only on Linux and macOS. It is not supported on Windows or 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 (|):

bash
ls -l | interactive_grep

Here's what happens:

  1. ls -l lists files with details.
  2. The | sends this list directly to interactive_grep.
  3. 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 from ls.

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:

cpp
auto app = App::Fullscreen();
// app.HandlePipedInput(true); // Enabled by default
app.Loop(component);

Turning Off Piped Input ​

If you don't need this feature, or if it conflicts with your custom input handling, call HandlePipedInput(false) before starting the main loop:

cpp
auto app = App::Fullscreen();
app.HandlePipedInput(false);
app.Loop(component);