Skip to content

Latest commit

 

History

History
63 lines (43 loc) · 2.44 KB

getting-started.md

File metadata and controls

63 lines (43 loc) · 2.44 KB

Getting started

A five-minute tour: install laranail/console, print your first styled output, and read your first prompt. For the full reference see the Documentation index.

1. Install

composer require laranail/console

The Console and Prompter facades + the prompter() helper are auto-discovered. Optionally publish the config + language files:

php artisan vendor:publish --tag=laranail::console-config
php artisan vendor:publish --tag=laranail::console-lang

2. Your first output

Inside an Artisan command you have $this->output; anywhere else pass any Symfony OutputInterface. Markup-bearing helpers go through the output; finished-string renderers echo fine:

use Simtabi\Laranail\Console\Facades\Console;

$output->writeln(Console::status()->success('Build complete'));
echo Console::box(['Name: app', 'Env:  prod'])->title('Config')->render();
echo Console::tree('project')->child('src', fn ($t) => $t->child('Console'))->render();

Know which of the three output styles a helper returns — it decides whether you writeln() or echo.

Writing through an output

Style Examples How to print it
Symfony Console markup (<fg=green>…</>) Console::status()->success(), ConsoleUIFormatter::success(), badge(), link() $output->writeln(...) (in a command, $this->line(...)). echo prints the tags literally.
Finished string render() on Console::box(), Console::tree(), Console::table() and the other string-returning widgets; colorize() echo, or writeln()
Self-writing Spinner, ProgressBar, TaskProgress Nothing to print: they write to the OutputInterface they are given and have no render().

See Output widgets and Formatting for which helper is which.

3. Progress + a prompt

Console::spinner('Compiling…')->run(fn () => compile());

$name = Console::prompter()->text('Your name', required: true)->getResult();

Next steps


← Docs index