Skip to content

Output streams

Greg Bowler edited this page May 14, 2026 · 1 revision

Output streams

Command output is written to StreamName::OUT by default. To write to another stream, pass a StreamName enum value to the output helper.

use GT\Cli\StreamName;

$this->writeLine("Saved successfully");
$this->writeLine("Could not save file", StreamName::ERROR);

The available stream names are:

  • StreamName::IN
  • StreamName::OUT
  • StreamName::ERROR

Using StreamName prevents accidental writes to unknown stream names. Passing a raw string such as "error" is not supported.

Writing output

writeLine() appends a line ending after the message. write() writes the message exactly as provided.

$this->write("Downloading...");
$this->writeLine("done");

Both helpers accept a StreamName argument:

$this->write("Warning: ", StreamName::ERROR);
$this->writeLine("configuration file missing", StreamName::ERROR);

Colour and streams

The output() helper writes a coloured line and also accepts a stream name as its fourth argument:

$this->output(
	"Could not connect",
	Palette::RED,
	null,
	StreamName::ERROR
);

Progress bars and cursor helpers also use StreamName when you need to target a stream other than standard output.


Next, read coloured output for terminal styling, or progress bars for in-place updates.

Clone this wiki locally