Neuron-PHP

Output
in package

Handles output formatting and display for CLI commands.

Provides methods for colored output, tables, progress bars, etc.

Table of Contents

Constants

BG_COLORS  = ['black' => 40, 'red' => 41, 'green' => 42, 'yellow' => 43, 'blue' => 44, 'magenta' => 45, 'cyan' => 46, 'white' => 47, 'default' => 49]
ANSI background color codes
COLORS  = ['black' => 30, 'red' => 31, 'green' => 32, 'yellow' => 33, 'blue' => 34, 'magenta' => 35, 'cyan' => 36, 'white' => 37, 'default' => 39]
ANSI color codes

Properties

$useColors  : bool
$verbosity  : int

Methods

__construct()  : mixed
Constructor
clearLine()  : void
Clear the current line
comment()  : void
Write a comment
createProgressBar()  : ProgressBar
Create a progress bar
debug()  : void
Write debug output (only if verbosity is high enough)
error()  : void
Write an error message
getVerbosity()  : int
Get verbosity level
info()  : void
Write an info message
newLine()  : void
Write a blank line
question()  : void
Write a question
section()  : void
Write a section header
setVerbosity()  : void
Set verbosity level
success()  : void
Write a success message
table()  : void
Display a table
title()  : void
Write a title
warning()  : void
Write a warning message
write()  : void
Write a line to output
writeln()  : void
Write a line with a specific color
colorize()  : string
Apply color to text
drawTableRow()  : void
Draw a table row
drawTableSeparator()  : void
Draw a table separator
supportsColors()  : bool
Check if the terminal supports colors

Constants

BG_COLORS

ANSI background color codes

private mixed BG_COLORS = ['black' => 40, 'red' => 41, 'green' => 42, 'yellow' => 43, 'blue' => 44, 'magenta' => 45, 'cyan' => 46, 'white' => 47, 'default' => 49]

COLORS

ANSI color codes

private mixed COLORS = ['black' => 30, 'red' => 31, 'green' => 32, 'yellow' => 33, 'blue' => 34, 'magenta' => 35, 'cyan' => 36, 'white' => 37, 'default' => 39]

Properties

$useColors

private bool $useColors

Whether to use colored output

$verbosity

private int $verbosity = 1

Verbosity level

Methods

__construct()

Constructor

public __construct([bool|null $useColors = null ]) : mixed
Parameters
$useColors : bool|null = null

Whether to use colors (null = auto-detect)

clearLine()

Clear the current line

public clearLine() : void

comment()

Write a comment

public comment(string $message) : void
Parameters
$message : string

createProgressBar()

Create a progress bar

public createProgressBar(int $total) : ProgressBar
Parameters
$total : int

Total steps

Return values
ProgressBar

debug()

Write debug output (only if verbosity is high enough)

public debug(string $message[, int $level = 2 ]) : void
Parameters
$message : string
$level : int = 2

Minimum verbosity level required

error()

Write an error message

public error(string $message) : void
Parameters
$message : string

getVerbosity()

Get verbosity level

public getVerbosity() : int
Return values
int

info()

Write an info message

public info(string $message) : void
Parameters
$message : string

newLine()

Write a blank line

public newLine([int $count = 1 ]) : void
Parameters
$count : int = 1

Number of blank lines

question()

Write a question

public question(string $message) : void
Parameters
$message : string

section()

Write a section header

public section(string $title) : void
Parameters
$title : string

setVerbosity()

Set verbosity level

public setVerbosity(int $level) : void
Parameters
$level : int

success()

Write a success message

public success(string $message) : void
Parameters
$message : string

table()

Display a table

public table(array<string|int, mixed> $headers, array<string|int, mixed> $rows) : void
Parameters
$headers : array<string|int, mixed>
$rows : array<string|int, mixed>

title()

Write a title

public title(string $title) : void
Parameters
$title : string

warning()

Write a warning message

public warning(string $message) : void
Parameters
$message : string

write()

Write a line to output

public write(string $message[, bool $newline = true ]) : void
Parameters
$message : string
$newline : bool = true

Add newline at the end

writeln()

Write a line with a specific color

public writeln(string $message[, string $color = 'default' ][, string|null $bgColor = null ]) : void
Parameters
$message : string
$color : string = 'default'
$bgColor : string|null = null

colorize()

Apply color to text

private colorize(string $text[, string $color = 'default' ][, string|null $bgColor = null ]) : string
Parameters
$text : string
$color : string = 'default'
$bgColor : string|null = null
Return values
string

drawTableRow()

Draw a table row

private drawTableRow(array<string|int, mixed> $row, array<string|int, mixed> $widths[, string $color = 'default' ]) : void
Parameters
$row : array<string|int, mixed>
$widths : array<string|int, mixed>
$color : string = 'default'

drawTableSeparator()

Draw a table separator

private drawTableSeparator(array<string|int, mixed> $widths) : void
Parameters
$widths : array<string|int, mixed>

supportsColors()

Check if the terminal supports colors

private supportsColors() : bool
Return values
bool

        
On this page

Search results