MMO\core\shell
MMO\core\shell · 64 symbols · generated 5 Oct 2026
ask
shell.php:1155Ask input from the user
- Namespace
MMO\core\shell
| $message | string | the message to display |
| $options = null | null | array | read |
| $default = null | null | string | the default value to return |
| returns | null | string | the command. null if the user has pressed escape. empty string if nothing was typed |
characters
shell.php:217Split a text into the characters a terminal shows, one column each: a character is one whatever its bytes (UTF-8), and a letter followed by a combining accent is one character too. A text that is not valid UTF-8 is split into bytes.
- Namespace
MMO\core\shell
Call graph
Used by (3)
choose
shell.php:1224Ask for one of a few choices, listed one per line and numbered, with what each one means.
- Namespace
MMO\core\shell
| $message | string | the question |
| $options | array | key => what choosing it means, or a list of keys |
| $default = null | string | int | null | the key ENTER answers |
| returns | string | int | null | the chosen key. null when there was no valid answer (prompt) |
Call graph
Uses (2)
colorCard
shell.php:2037Print a table with a preview of every SHELL_* color/style constant. Useful to check what your terminal supports.
- Namespace
MMO\core\shell
| returns | string |
Call graph
Uses (1)
columns
shell.php:1460Attempt to get the number of columns of the current terminal
- Namespace
MMO\core\shell
Call graph
Uses (1)
Used by (4)
commandExists
shell.php:412Tells if a command is available and executable on the current system
- Namespace
MMO\core\shell
Call graph
Uses (1)
Used by (1)
confirm
shell.php:1141Ask the user for a confirmation
- Namespace
MMO\core\shell
| $message | string | |
| $default = true | bool | what ENTER answers, shown in brackets. Make it false when a yes is hard to undo |
| returns | null | bool | true/false for yes/no, null if the user pressed ESC or nobody answered (read) |
Call graph
Uses (1)
Used by (1)
diff
shell.php:1937The differences between two texts, line by line, the way diff -u shows them: a removed line in red after a -, an added one in green after a +, each change among a few unchanged lines around it, and before each group an @@ line saying where it is. Ready to print, so that a change to a file is read before it is made.
- Namespace
MMO\core\shell
| $old | string | |
| $new | string | |
| $context = 3 | int | how many unchanged lines to show around a change |
| returns | string | '' when both texts have the same lines |
error
shell.php:1371Print an error message, prefixed with '!! ' in red. $message is rendered through
- Namespace
MMO\core\shell- See
printf, so{key}placeholders are replaced with $context values.
Call graph
Uses (1)
Used by (1)
escape
shell.php:1712Escapes a string to be used as an argument and qotes it.
- Namespace
MMO\core\shell
| $arg | null | string | the argument that will be escaped |
| $force = false | bool | if false won't quote the argument unless it needs to. |
| $isWin = MMO\core\shell\IS_WINDOWS | bool | if true, escape for windows command line. Else escape for shell |
| returns | string |
evalColors
shell.php:372Used to put shell colors directly into a text Any SHELL_* colors must be in brackets to be replaced
- Namespace
MMO\core\shell
exec
shell.php:1772Execute a command through php exec, serializing the parameters passed
- Namespace
MMO\core\shell
| $command | string | the command to execute |
| $throwException = true | bool | if true, will throw eRuntime if exit code > 0 |
| $exitCode = null | null | int | the returned exit code |
| returns | string | the output of the command |
Call graph
execInBackground
shell.php:1786Launch a command in the background (fire and forget), serializing the parameters passed
- Namespace
MMO\core\shell
| $command | string | the command to execute |
| $isWin = MMO\core\shell\IS_WINDOWS | bool | force the execution in WINDOWS or SHELL |
| returns | void |
explain
shell.php:1416Print a paragraph of explanation, indented and wrapped to the terminal (100 columns at most), so that it reads as prose rather than as lines running off the screen.
- Namespace
MMO\core\shell
Call graph
getCursor
shell.php:575Get the current position of the terminal cursor
- Namespace
MMO\core\shell
| returns | null | array | int, 1: int}|null [line, column]. null if the terminal did not answer the position report |
Call graph
getEnv
shell.php:1563Alias to getenv(). Return null instead of false in case value is not set in the env
- Namespace
MMO\core\shell
Call graph
Used by (2)
getInput
shell.php:470The stream user input is read from.
- Namespace
MMO\core\shell
| returns | the one given to setInput, else STDIN |
Call graph
heading
shell.php:1398Print a title: set apart from what comes before it by a blank line, and ruled across the terminal (100 columns at most) -- how the steps of a long run are told apart at a glance.
- Namespace
MMO\core\shell
Call graph
Uses (1)
hideCursor
shell.php:191- Namespace
MMO\core\shell
| returns | void |
isInteractive
shell.php:484Tells if the answers are typed by someone at a terminal, rather than read from a pipe, a file or a stream given to setInput. Only a terminal has keys: without one, input is read a whole line at a time, and an answer that is not valid cannot be typed again.
- Namespace
MMO\core\shell
| returns | bool |
Call graph
Uses (1)
isRunning
shell.php:426Tells if a process with the given PID is currently running.
- Namespace
MMO\core\shell
Call graph
isTty
shell.php:1538Tells if the current terminal is a tty (native terminal device)
- Namespace
MMO\core\shell
| returns | bool |
lengthANSI
shell.php:229Get length of a text, removing ansi sequences: a character is counted as one whatever its bytes (UTF-8).
- Namespace
MMO\core\shell
Call graph
lines
shell.php:1473Attempt to get the number of lines of the current terminal
- Namespace
MMO\core\shell
Call graph
Uses (1)
Used by (1)
moveBack
shell.php:187- Namespace
MMO\core\shell
Call graph
Used by (2)
moveCursorCol
shell.php:190- Namespace
MMO\core\shell
moveCursorLine
shell.php:189- Namespace
MMO\core\shell
Call graph
Used by (1)
padANSI
shell.php:305Pad string ingoring ANSI sequences
- Namespace
MMO\core\shell
| $text | string | |
| $length | int | |
| $pad_string = ' ' | string | |
| $pad_type = MMO\core\shell\STR_PAD_RIGHT | int | |
| returns | string |
Call graph
Uses (2)
Used by (2)
parse
shell.php:1646Parse a command line This command line option parser supports any combination of three types of options [single character options (-a -b or -ab or -c -d=dog or -cd=dog), long options (--foo or --bar=baz) and arguments (arg1 arg2)]
- Namespace
MMO\core\shell- Author
- Marc Mouret and Patrick Fisher <patrick@pwfisher.com>
Call graph
Uses (2)
Used by (1)
printInRect
shell.php:2087Print lines in a rectangle and returns text's positions in the rectangle This function is safe with ANSI sequences
- Namespace
MMO\core\shell
| $lines | array | a list of texts |
| $maxColCount = null | null | int | number max of columns |
| $maxLineCount = null | null | int | number max of lines |
| $colDelimiter = ' ' | string | delimiter between columns |
| returns | array | [ -1: [lineCount, lineLength, colCount, colLength], text index => [[line1, column1], [line2, column2], ...] ] |
| throws | if the texts cannot fit in the rectangle -- nothing is printed then (select) |
Call graph
Used by (1)
progress
shell.php:1805Print and redraw an in-place progress bar. Call repeatedly with an increasing $current to update it.
- Namespace
MMO\core\shell
| $current | int | the current progress |
| $total | int | the total (100%) progress |
| $label = '' | string | an optional label printed after the bar |
| $width = 30 | int | the width (in characters) of the bar itself |
| returns | void |
Call graph
Uses (1)
prompt
shell.php:1176Ask for a value, showing the one ENTER keeps, until the answer is a valid one.
- Namespace
MMO\core\shell
| $message | string | the question |
| $default = null | null | string | what ENTER answers, shown in brackets |
| $validate = null | null | callable | fn(string $answer): ?string -- null when the answer is fine, otherwise why it is not, shown before the question is asked again |
| returns | null | string | the answer, trimmed: '' for -, or for ENTER when there is no default. null when there was no valid answer: the input ended (Ctrl+D), or an invalid one came from something that is not a terminal |
Call graph
Uses (2)
Used by (1)
promptList
shell.php:1199Ask for a list of values, separated by commas.
- Namespace
MMO\core\shell
| $message | string | the question |
| $default = [] | array | what ENTER answers |
| $validate = null | null | callable | fn(array $answer): ?string, as for prompt |
| returns | null | array | the values, trimmed, without empty ones. null when there was no valid answer (prompt) |
Call graph
Uses (1)
protectShellBuffering
shell.php:518Install a SIGINT/SIGTERM safety net so the terminal is not left in raw/no-echo mode if the process is interrupted (e.g. Ctrl+C) while shell buffering is stopped. Without this, an interrupted read()/select()/ readCallback() leaves the user's terminal broken (no echo) since finally blocks never run on a signal.
- Namespace
MMO\core\shell
| returns | void |
Call graph
Used by (1)
read
shell.php:705Read a command from the user input.
- Namespace
MMO\core\shell
| $options = null | null | array | possible options: if given, they are auto-completed as the user types and can be navigated with the up/down arrow keys |
| $default = null | null | string | returned if the user presses ENTER without typing anything. Shown in brackets |
| returns | null | string | the command. null if the user has pressed escape or the input has ended -- nobody answered, so neither is an answer, the default included -- or, without a terminal, if the line matched none of $options. empty string if nothing was typed |
Call graph
readAnswer
internalshell.php:1262Show what ENTER answers, then read the answer.
- Namespace
MMO\core\shell
| $default | null | string | |
| returns | null | string | the answer, trimmed: $default for ENTER alone, '' for - alone. null when the input has ended |
Call graph
readCallback
shell.php:599Read every key press by the user on the command line (as opposed to fgets which waits on return key)
- Namespace
MMO\core\shell
| $fn | callable | ($char, $current_user_input): string|false. The closure SHOULD return the new user input. The closure MUST return false to stop the user input or a string started with \0 |
| $echo = true | bool | if false, no characters are printed on the screen |
| returns | string | the complete user input |
Call graph
Used by (1)
readKeys
shell.php:672Wait for the user to press a key, then read it with every key that came with it -- a paste, fast typing, keys sent in one go over ssh -- one string for each: a character, or a whole escape sequence (the up arrow is "\e[A").
- Namespace
MMO\core\shell
| returns | array | the keys, in the order they were typed. empty when the input has ended |
Call graph
Uses (2)
Used by (1)
readLine
shell.php:497Read one line of user input, without its line ending.
- Namespace
MMO\core\shell
| $echo = true | bool | false to never print the line (a secret) |
| returns | null | string | the line. null when the input has ended (Ctrl+D at a terminal) |
Call graph
Uses (2)
Used by (2)
readOption
internalshell.php:853The half of read that has no terminal to read keys from: the next line of the input is the answer.
- Namespace
MMO\core\shell
| $options | null | array | what read() was given, sorted |
| $default | null | string | |
| returns | null | string | the answer, null when the input has ended or the line matches none of $options |
readPending
shell.php:635Take what the user has typed that nothing has read yet, without waiting for more -- or, given a timeout, waiting that long at most for a first key. Every question drops it before asking (read, prompt, choose,
- Namespace
MMO\core\shell- See
readSecret): keys typed before a question is on screen are no answer to it. At a terminal only: nothing else can be asked whether something is waiting, and gives ''. Out of line buffering (stopShellBuffering) that is every key typed; in it, the lines ENTER has ended.
| $timeout = 0.0 | float | seconds to wait for a first key when none is waiting. 0: not at all |
| returns | string | what was typed, '' if nothing was |
Call graph
Uses (1)
Used by (4)
readSecret
shell.php:1293Ask for a secret (e.g. a password) from the user. The typed characters are never echoed by the terminal itself.
- Namespace
MMO\core\shell
| $message | string | the message to display |
| $mask = '*' | null | string | a single character to display in place of each typed character, for feedback. null to display nothing at all. |
| returns | null | string | the secret typed by the user. null when the input ended before ENTER: half a secret is not one |
removeANSI
shell.php:204Strip ANSI escape sequences (colors, cursor movement, ...) from a text, leaving only the visible characters.
- Namespace
MMO\core\shell
Call graph
Used by (3)
restoreShellBuffering
shell.php:563Undo one call to stopShellBuffering. Calls nest: buffering is only actually restored once every stopShellBuffering() call has a matching restoreShellBuffering() call.
- Namespace
MMO\core\shell
| returns | bool | false if buffering was already fully restored (nothing to do), or if stty itself failed |
Call graph
say
shell.php:1347Print an informational message, prefixed with '- ' in purple. $message is rendered through
- Namespace
MMO\core\shell- See
printf, so{key}placeholders are replaced with $context values.
select
shell.php:891Print a menu of choices and return the keys of the selected options
- Namespace
MMO\core\shell
| $title | string | the title of the menu |
| $options | array | {value => text} or [...value] |
| $min = null | null | int | minimum number of options the user must select before ENTER is accepted |
| $max = null | null | int | maximum number of options that can be selected; selection stops automatically once reached. 1 is a single choice (menu): selecting an option replaces the one selected before, and ends it |
| $selection = [] | array | the keys of $options that start out pre-selected |
| returns | null | array | the selected keys of $options. null if escape was pressed, or if the options do not fit the terminal and the input has ended |
Call graph
serialize
shell.php:1739Serialize the command All parameters with no string key (plain args) are left untouched (no escape).
- Namespace
MMO\core\shell
| $cmd | array | the command arguments |
| $long = '=' | string | the separator for long argument (--xxx) |
| $short = '=' | string | the separator for short argument (-x) |
| $isWin = MMO\core\shell\IS_WINDOWS | bool | escape for windows command line if true, else escape for shell |
| returns | string |
Call graph
Uses (1)
setCursor
shell.php:188- Namespace
MMO\core\shell
setInput
shell.php:460Read the user's answers from another stream than STDIN: a file of answers, or -- in a test -- a php://memory stream written beforehand. Every function reading user input reads from it (read, readLine,
- Namespace
MMO\core\shell- See
prompt,choose,confirm,readSecret,readCallback,select,menu). select() and menu() read keys from it rather than lines, one read per key as a terminal gives them: aphp://memorystream holding several keys hands them over four bytes at a time, and they run together.
| $stream | null to read from STDIN again | |
| returns | void |
showCursor
shell.php:192- Namespace
MMO\core\shell
| returns | void |
sigchildEnabled
shell.php:1503Tells if PHP has been compiled with the '--enable-sigchild' option.
- Namespace
MMO\core\shell
| returns | bool |
split
shell.php:1595Split string on space, except for quoted words
- Namespace
MMO\core\shell
Call graph
Used by (1)
splitANSI
shell.php:243Split text ignoring ANSI sequences
- Namespace
MMO\core\shell
Call graph
Uses (1)
Used by (3)
stopShellBuffering
shell.php:548Stop shell line buffering so you can capture direct input from user, without waiting for a flush (ENTER)
- Namespace
MMO\core\shell
| $echo = false | bool | if false, no characters are printed on the screen |
| returns | bool | if false, shell could not be stopped from buffering -- or there is no terminal to stop (isInteractive). |
Call graph
substrANSI
shell.php:281substr() ignoring ANSI sequences: offset and length count visible characters, whatever their bytes (UTF-8).
- Namespace
MMO\core\shell
Call graph
Uses (2)
Used by (1)
success
shell.php:1383Print what went right, prefixed with '✔ ' in green. $message is rendered through
- Namespace
MMO\core\shell- See
printf, so{key}placeholders are replaced with $context values.
Call graph
Uses (1)
supportColor
shell.php:1486Tells if the current output supports ANSI colors/escape sequences.
- Namespace
MMO\core\shell
| returns | bool |
supportPty
shell.php:1518Tells if the current terminal support pty (pseudo terminal device).
- Namespace
MMO\core\shell
| returns | bool |
Call graph
Used by (2)
table
shell.php:1844Make a table text WARNING: to make sure columns are ordered correctly, make sure last item has all the columns in the right order
- Namespace
MMO\core\shell
| $data | array | (array(col1 => AA, col2 => AB), array(col1 => BA, col2 => BB)). Last item must have all the columns |
| $title = '' | string | table's title |
| $size = null | null | int | table's size. use null to fit to content size |
| returns | string |
Call graph
warning
shell.php:1359Print a warning message, prefixed with '! ' in brown/yellow. $message is rendered through
- Namespace
MMO\core\shell- See
printf, so{key}placeholders are replaced with $context values.
Call graph
Uses (1)
windowsConsoleSize
internalshell.php:1444Parse mode con's output (windows only).
- Namespace
MMO\core\shell
wrapANSI
shell.php:336Wrap a text so that no line is wider than $width visible characters -- an ANSI sequence takes no room, and a character is counted as one whatever its bytes (UTF-8).
- Namespace
MMO\core\shell
Call graph
Uses (2)
Used by (1)
writeAt
shell.php:193- Namespace
MMO\core\shell