Download the PHP package joetannenbaum/terminalia without Composer
On this page you can find all versions of the php package joetannenbaum/terminalia. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download joetannenbaum/terminalia
More information about joetannenbaum/terminalia
Files in joetannenbaum/terminalia
Package terminalia
Short Description Beautiful command line output for Laravel.
License MIT
Informations about the package terminalia
[!IMPORTANT] Hey! This was a fun project and I learned a lot. It's not the most stable though. I would recommend using Laravel Prompts. It gets the job done (better) and is well tested and stable.
The UX of Clack, the DX of Laravel for your Artisan commands.
- Features
- Demo
- Installation
- Retrieving Input
- Writing Output
Features
- Inline input validation using Laravel's built-in validator
- Interactive prompts for text, choice, and confirmation
- A spinner for long-running processes
Demo
Installation
This package implements a Console mixin, which should be automatically registered when the package is installed.
If the service provider doesn't automatically register (i.e. if you are using Laravel Zero), add the following to your config/app.php
file:
Retrieving Input
Input Validation
The rules
argument of these methods uses Laravel's built-in validator, so it accepts anything you are able to pass to Validator::make
.
Note: If you're using validation within a Laravel Zero app, remember to register your ValidationServiceProvider::class
and TranslationServiceProvider::class
in your config/app.php
file and also include a lang
directory in your project root.
termAsk
The termAsk
method prompts the user for input and return the response. It accepts the following arguments:
question
(string): The question to ask the userrules
(string|array): An array of validation rules to apply to the responsehidden
(bool): Whether or not to hide the user's input (useful for passwords)default
(string): The default value
termChoice
The termChoice
method prompts the user to select one or more items from a list of choices. It accepts the following arguments:
question
(string): The question to ask the userchoices
(array|Collection
|Helpers\Choices
): An array of choices to display to the usermultiple
(bool): Whether or not to allow the user to select multiple choicesrules
(string|array): An array of validation rules to apply to the responsefilterable
(bool): Whether or not to allow the user to filter the choicesminFilterLength
(int, default is5
): The minimum number of choices in the list before filtering is enableddefault
(string|array): The default value(s)
If multiple
is true
and you pass a Collection
as the choices
argument, the choices
will be returned as a Collection
as well, otherwise an array will be returned.
Instead of just passing a simple array as the choices
argument, you can choose to pass in a nested array or collection using the Choices
helper. This allows you to specify a label and a value for each item in the list. The label will be displayed to the user, and the value(s) will be returned when the user selects the item.
termConfirm
The termConfirm
method prompts the user to confirm a question. It accepts the following arguments:
question
(string): The question to ask the userdefault
(bool): The default answer to the question
Writing Output
termIntro
The termIntro
method writes an intro message to the output. It accepts the following arguments:
text
(string): The message to write to the output
termOutro
The termOutro
method writes an outro message to the output. It accepts the following arguments:
text
(string): The message to write to the output
termInfo
, termComment
, termError
, termWarning
Consistent with Laravel's built-in output methods, Terminalia provides methods for writing output in different colors with cohesive styling. They accept the following arguments:
text
(string|array): The message to write to the output
termNote
The termNote
method allows you to display a longer message to the user. You can include an optional title as the second argument, if you have multiple lines you can optionally pass in an array of strings as the first argument.
termSpinner
The termSpinner
method allows you to show a spinner while an indefinite process is running. It allows customization to you can inform your user of what's happening as the process runs. The result of the spinner will be whatever is returned from the task
argument.
Important: It's important to note that the task
runs in a forked process, so the task itself shouldn't create any side effects in your application. It should just process something and return a result.
Simple:
Displays a variable final message based on the result of the task:
Updates user of progress as it works:
Sends users encouraging messages while they wait:
Progress Bars
Progress bars have a very similar API to Laravel console progress bars with one small addition: You can pass in an optional title for the bar.
All versions of terminalia with dependencies
illuminate/collections Version ^10.10
illuminate/console Version ^10.10
illuminate/contracts Version ^10.10
illuminate/support Version ^10.10