InputOutput
in package
Input and Output for CLI.
Table of Contents
Properties
- $readlineSupport : bool
- Is the readline library on the system?
Methods
- __construct() : mixed
- fwrite() : void
- While the library is intended for use on CLI commands, commands can be called from controllers and elsewhere so we need a way to allow them to still work.
- input() : string
- Get input from the shell, using readline or the standard STDIN
- markAnsiNonPrinting() : string
- Wraps ANSI escape sequences in readline's non-printing markers so line-redraw column accounting skips them.
- readlinePrompt() : string|null
- Builds the prompt handed to readline(), or returns null when the caller has to write the prompt to STDOUT itself because the line-editing library cannot render it.
Properties
$readlineSupport read-only
Is the readline library on the system?
private
bool
$readlineSupport
Methods
__construct()
public
__construct() : mixed
fwrite()
While the library is intended for use on CLI commands, commands can be called from controllers and elsewhere so we need a way to allow them to still work.
public
fwrite(resource $handle, string $string) : void
For now, just echo the content, but look into a better solution down the road.
Parameters
- $handle : resource
- $string : string
input()
Get input from the shell, using readline or the standard STDIN
public
input([string|null $prefix = null ]) : string
Named options must be in the following formats: php index.php user -v --v -name=John --name=John
Parameters
- $prefix : string|null = null
-
You may specify a string with which to prompt the user.
Return values
stringmarkAnsiNonPrinting()
Wraps ANSI escape sequences in readline's non-printing markers so line-redraw column accounting skips them.
private
markAnsiNonPrinting(string $prefix) : string
Parameters
- $prefix : string
Return values
stringreadlinePrompt()
Builds the prompt handed to readline(), or returns null when the caller has to write the prompt to STDOUT itself because the line-editing library cannot render it.
private
readlinePrompt(string|null $prefix, mixed $libraryVersion) : string|null
GNU readline gets ANSI sequences wrapped in its non-printing markers so line-redraw column accounting skips them. Libedit reports "EditLine wrapper" and mangles the markers, so it gets the raw prompt. Windows builds use WinEditLine, which prints ANSI sequences literally, and readline_info() omits the version there (php-src guards it with #ifndef PHP_WIN32), so they get no prompt.
Parameters
- $prefix : string|null
- $libraryVersion : mixed
-
The value of readline_info('library_version')