Download the PHP package hoathis/symfony-console-bridge without Composer
On this page you can find all versions of the php package hoathis/symfony-console-bridge. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package symfony-console-bridge
Hoa is a modular, extensible and structured set of PHP libraries. Moreover, Hoa aims at being a bridge between industrial and research worlds.
Hoathis\SymfonyConsoleBridge
- Installation
- How to use
- Symfony
- Output
- Formatter
- Helpers
- Window
- Cursor
- Readline
- Pager
- Tput
All the examples in this readme are available and working in the test application.
Installation
With Composer, to include this library into your dependencies, you need to require
hoathis/symfony-console-bridge
:
Please, read the website to get more informations about how to install.
Finally, install dependencies:
How to use
Symfony
To use this library with the Symfony framework, please use
the dedicated bundle:
hoathis/symfony-console-bundle
.
Output
Hoathis\SymfonyConsoleBridge\Output\ConsoleOutput
is an alternative to the
native ConsoleOutput
which is able to detect output type and automatically
configure verbosity and text decoration.
Let's have the following command:
Running:
As you will see in your terminal, output will be decorated and verbose by default. However if you run:
The verbosity level will automatically be switched to very verbose because the output has detected that you were redirecting it to a file.
Here are the rules used to determine verbosity level and text decoration support:
Verbosity | Decoration | |
---|---|---|
Pipe | normal | disabled |
Redirect | very verbose | disabled |
Terminal | verbose | enabled |
Those rules will only be used if you do not provide any verbosity level using command line arguments. If you want to redirect outputs to a file using the debug verbosity level, simply run:
You can still force ANSI output using the --ansi
option:
Want to try it? Run
bin/console output:verbosity
to get a live demo and code snippet.
Formatter
Hoathis\SymfonyConsoleBridge\Formatter\OutputFormatterStyle
will let you do
everything you were able to do with the native symfony/console
formatter with
some more cool things:
- supports
xterm-8color
color names, - supports
xterm-256color
color codes, - automatically translates hexadecimal color codes,
- supports text styling (normal, bold, underlined, blink and inverse).
To use those new OutputFormatterStyle
, use the usual API:
As you can see in the previous example, you can replace built-in styles by simply redifining them with the new formatter.
Want to try it? Run
bin/console output:formatter:custom
orbin/console output:formatter:native
to get a live demo and code snippet.
Helpers
The real power of the library comes from its helpers: they let you manage every terminal components. You will first have to manually load them:
Every helper has a dedicated test command. Just run
bin/console list
to get a list.
Window
The window helper will let you manipulate the current terminal window. It provides several utility methods, each one being bound to an action:
Many other utility methods are available:
setTitle
,getTitle
,getLabel
to manipulate terminal title,setSize
,getSize
,move
,setPosition
,getPosition
to manipulate window position,minimize
,restore
,lower
,raise
to manipulate window placement,scroll
,refresh
,copy
to manipulate window content.
Want to try it? Run
bin/console helper:window:animate
to get a live demo and code snippet.
Cursor
The cursor helper will let you manipulate the cursor. It provides several utility methods, each one being bound to an action:
Many other utility method are available:
move
,moveTo
to change cursor position,getPosition
to retrieve the current cursor position,save
andrestore
to save and restore the cursor position,clear
to clear whole or part of the screen,hide
,show
andstyle
to change cursor display options,colorize
andreset
to manage text styling,bip
to emit a bell.
Want to try it? Run
bin/console helper:cursor:draw
to get a live demo and code snippet.
Readline
The readline helper will help you gather inputs from the user. It provides some methods to ask and validates user's inputs:
read
will prompt the user for an input,autocomplete
will display a prompt and let the user input text and use autocompletion,select
will display a list of choices to the user and let him select one or more values,validate
will keep asking for an input until it validates against a validator you provide.
Note that for select
you can provide a special choice that will display as a
separator using 'label' => ReadlineHelper::SEPARATOR
items in you choices
list.
Want to try it? Run
bin/console helper:readline:select
orbin/console helper:readline:autocomplete
to get a live demo and code snippet.
Pager
The pager helper will let you display outputs through a pager so the user can
easily read and scroll. The helper provides two pagers: less
and more
. You
will have to feed them using a closure wrapping code producing output:
Want to try it? Run
bin/console helper:pager:less
orbin/console helper:pager:more
to get a live demo and code snippet.
Tput
The tput helper will help you get informed about user's terminal capabilities. The helper provides
a single entry point to all capabilities: the get
method. Here is how you would do to get the clear_screen
capability:
Want to try it? Run
bin/console helper:tput:capabilities
orbin/console helper:tput:echo
orbin/console helper:tput:get
to get a live demo and code snippet.
All versions of symfony-console-bridge with dependencies
hoa/console Version >=1.0,<3.0
symfony/console Version ~2.3,>=2.3.6|~3.0.0