Skip to main content
TUI4J provides two ways to hand control to something outside your application: exec launches an external process while the TUI steps aside, and suspend sends the process to the background so the shell can take over. Both patterns restore the TUI cleanly when control returns.

Launching an external process with ExecProcessMessage

Command.execProcess(process, outputHandler, errorHandler) pauses the TUI renderer, runs the external process with full terminal access, then resumes the TUI and dispatches an ExecCompletedMessage when the process exits. This is the right choice for spawning interactive programs like text editors, pagers, or sub-shells.
Redirect stdin, stdout, and stderr to INHERIT so the external process can read from and write to the real terminal. Without this the process won’t be able to render its own UI.

Handling ExecCompletedMessage

When the process exits, TUI4J dispatches an ExecCompletedMessage to your update() method. Inspect it to determine whether the process succeeded:

Complete example

Suspending the TUI

SuspendMessage sends the TUI process to the background (equivalent to Ctrl+Z in a shell). The terminal is restored to normal and the shell regains control. When the user brings the process back to the foreground (fg), TUI4J dispatches a ResumeMessage and redraws the interface.

Exec vs suspend

SuspendMessage has no effect on Windows because the platform does not support POSIX job control. Use exec if you need to hand off to an external process on Windows.
When a user opens an editor via exec, render a blank or minimal view() between the time you return Command.execProcess(...) and when you receive ExecCompletedMessage. The TUI renderer will not display during the exec, but this prevents a flash of stale content if the terminal is resized during the process.

Mouse input

Handle clicks and motion in your TUI

Spring Boot integration

Embed TUI4J into a Spring Boot app