Printing Output¶
The OutputHandler service has a series of methods to enable advanced output features, such as printing with colors, printing with pre-defined styles, and outputting content to a file instead of the default output.
This service is available at the application container as printer, also accessible via the helper method getPrinter() on controllers.
You can call all the methods from the OutputHandler class directly in your application container or controllers as shown below (recommended):
This will print a "Hello World!" message wrapped in new lines, using default settings.
Printing with Pre-defined Styles¶
The following shortcut methods are available via the OutputHandler class:
display($message, $alt = false)- Uses thedefaultstyle. Ifaltis set to true, it will use thealtstyle.info($message, $alt = false)- Uses theinfostyle. Ifaltis set to true, it will use theinfo_altstyle.error($message, $alt = false)- Uses theerrorstyle. Ifaltis set to true, it will use theerror_altstyle.success($message, $alt = false)- Uses thesuccessstyle. Ifaltis set to true, it will use thesuccess_altstyle.
Example of output produced by these methods:

Other Print Methods¶
out($message, $style = null)- Outputs a message and optionally sets a style. This won't include newlines.rawOutput($message)- Outputs a message without newlines or formatting.newline()- Prints a newline / line break.printTable(array $table)- Helper method that uses theTableHelperto format and print a table.
Extended Styles¶
The DefaultTheme theme contains additional styles that can be used directly with the out method:
bolditalicdimunderlineinverted

Usage example:
| PHP | |
|---|---|
The same usage applies for creating custom styles within a Custom Theme.
Note
Remember that the out method doesn't wrap the content with newlines, so you'll have to use the newline() method to manually include your line breaks.
Printing Tables¶
You can also format content output in tables. The simplest way to do so is by building your data as an array, with headers as first row, and calling the printTable() method from the printer object.
The following single-command Minicli app prints an example table using this method:
The command called with ./minicli tables will output the following:

In some cases, you'll want to have more flexibility on the output created, and you may want to build the table in a more programmatically way. You can use the TableHelper to build your table before printing out.
As the name suggests, the TableHelper is a utility class to format output as a table. This method can receive an array upon instantiation with the contents to be printed, but you can also build the table programmatically as in the following example:
addRow() method, you can use the getFormattedTable() method to obtain the raw content and output it using rawOutput().
