Download the PHP package krzysztofzylka/console without Composer
On this page you can find all versions of the php package krzysztofzylka/console. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package console
krzysztofzylka/console
Small PHP console helper library for:
- colored output,
- argument parsing,
- interactive prompts,
- help rendering,
- ASCII table rendering.
Install
Examples
Ready-to-run examples are available in example/:
example/print.phpexample/form.phpexample/help.phpexample/table.phpexample/args.phpexample/progress.php
Output
Preferred API:
Legacy aliases still work for backward compatibility:
Formatter helpers:
Prints::section()/Prints::formatSection()Prints::bulletList()/Prints::formatBulletList()Prints::numberedList()/Prints::formatNumberedList()Prints::kv()/Prints::formatKv()Prints::json()/Prints::formatJson()Prints::blankLine()
Utilities:
Prints::terminalWidth()Prints::fitLineToWidth()
Arguments
Args::getArgs($argv) returns a normalized array with script path, positional arguments and parsed options.
Supported forms:
--env=prod--env prod--force-project taskello- repeated options like
--tag v1 --tag v2 --to stop option parsing
Schema-aware parsing:
Forms
Input
Parameters for Form::input():
$label- text shown before input$default- optional default value$trim- trim input value$required- keep asking until non-empty value is provided
Form::secretInput() works similarly to input(), but hides typed characters when the current environment supports it.
Prompt
Parameters for Form::prompt():
$label- question text$append- suffix shown next to label$exit- exit the script when the answer is negative$default- default yes/no answer
Accepted positive answers:
yyesttak
Accepted negative answers:
nnonie
Help generator
Detailed help for a single command:
Detailed mode supports:
- title
- description
- usage
- commands
- arguments
- options
- examples
- wrapping long descriptions to terminal width
Recommended usage:
php bin/app-> render compact overviewphp bin/app serve --help-> render detailed command help
Table generator
Column options:
$alignsupportsleft,right,center$maxWidthlimits visible width$truncatetrims long lines with...
Table options:
addRow(array $row)setShowHeader(bool $showHeader)setShowBorder(bool $showBorder)setMaxWidth(?int $maxWidth)
Progress helpers
Colors
Supported names include:
blackgrayredgreenyellowbluemagentacyanwhitegraylightbolddimunderlinebg-whitebg-graybg-redbg-greenbg-yellowbg-bluebg-magentabg-cyan
Named presets:
infosuccesswarningerrormutedtitlehighlight
Notes
- ANSI colors are automatically disabled when the output stream is not a TTY or when
NO_COLORis set. HelpandTableusemb_strwidth()when available for better UTF-8 alignment.Tablesupports per-column alignment, multiline cells, optional headers, optional borders and global/per-column max width.