Skip to content

Commit e59cb95

Browse files
committed
chore: update readme
1 parent 3947a39 commit e59cb95

File tree

2 files changed

+40
-22
lines changed

2 files changed

+40
-22
lines changed

README.md

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ You can then register this command with the app instance:
8282
$app->register(\MyCliApp\Commands\GreetCommand::class);
8383
```
8484

85-
## Styling Output
85+
<!-- ## Styling Output
8686
8787
Leaf Sprout comes with a built-in output styling system that allows you to style your output using a simple API adapted from TermWind. Here's an example of how you can style your output:
8888
@@ -118,24 +118,37 @@ Most of the styling options are chainable, so you can chain multiple styles toge
118118
119119
```php
120120
style()->bold()->underline()->apply('text-red-500')->to('Hello, world!');
121+
``` -->
122+
123+
## Styling Output
124+
125+
Leaf Sprout comes with a built-in output styling system that allows you to style your output using a simple API adapted from Symfony Console. Here's an example of how you can style your output:
126+
127+
```php
128+
$this->write("<info>Hello</info>, <comment>world</comment>!");
129+
$this->write("<error>Error occurred!</error>");
130+
$this->write("<question>Are you sure?</question>");
131+
```
132+
133+
Or you can use pre-configured styles like `success()`, `error()`, `warning()`, and `info()`:
134+
135+
```php
136+
$this->success('Operation successful');
137+
$this->error('Operation failed');
138+
$this->warning('This is a warning');
139+
$this->info('This is some information');
121140
```
122141

142+
Later versions will include more advanced styling options modelled after TailwindCSS and TermWind.
143+
123144
## Input Handling
124145

125146
Leaf Sprout comes with a built-in input handling system that allows you to easily get input from the user. The easiest way is to use the `prompt()` method:
126147

127148
```php
128149
$name = sprout()->prompt([
129150
'type' => 'text', // 'select', 'confirm', 'password', 'number', 'text'
130-
'initial' => 'John Doe',
131151
'message' => 'What is your name?',
132-
'validate' => function ($value) {
133-
if (empty($value)) {
134-
return 'Name cannot be empty';
135-
}
136-
137-
return true;
138-
}
139152
]);
140153

141154
$command->write("Hello, $name!"); // Hello, John Doe!
@@ -151,20 +164,13 @@ $results = sprout()->prompt([
151164
'type' => 'text',
152165
'name' => 'name',
153166
'message' => 'What is your project name?',
154-
'initial' => 'my-project',
155-
'validate' => function ($value) {
156-
if (empty($value)) {
157-
return 'Name cannot be empty';
158-
}
159-
160-
return true;
161-
}
167+
'default' => 'my-project',
162168
],
163169
[
164170
'type' => $possiblySetValue ? null : 'select',
165171
'name' => 'type',
166172
'message' => 'What type of project do you want?',
167-
'initial' => 0,
173+
'default' => 0,
168174
'choices' => [
169175
['title' => 'Web', 'value' => 'web'],
170176
['title' => 'API', 'value' => 'api'],
@@ -175,7 +181,7 @@ $results = sprout()->prompt([
175181
'type' => 'confirm',
176182
'name' => 'install',
177183
'message' => 'Do you want to install dependencies?',
178-
'initial' => true,
184+
'default' => true,
179185
],
180186
]);
181187

@@ -222,12 +228,14 @@ $process->isSuccessful(); // true
222228
$process->getExitCode(); // 0
223229
```
224230

225-
You can also use the `run()` method to run a process and get the output:
231+
You can also use the `run()` method to run a process and log the output to the console in real-time, and then return it's exit code:
226232

227233
```php
228-
$output = sprout()->run('ls -la');
234+
$exitCode = sprout()->run('ls -la');
229235

230-
$command->write($output);
236+
if ($exitCode !== 0) {
237+
$command->error("An error occurred while running the process");
238+
}
231239
```
232240

233241
## Composer & Npm Scripts

src/Sprout/Prompt.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ protected function getAnswer($prompt)
132132
$this->currentSelection = 0;
133133
} elseif ($prompt['type'] === 'text') {
134134
if ($this->currentInput === '') {
135+
// if (isset($prompt['validate']) && is_callable($prompt['validate'])) {
136+
// $validation = $prompt['validate']($this->currentInput, $this->answers);
137+
138+
// if ($validation !== true) {
139+
// echo ($validation);
140+
// $this->renderPrompt($this->questions[$this->cursor], false);
141+
// continue;
142+
// }
143+
// }
144+
135145
$this->currentInput = $prompt['default'] ?? '';
136146
}
137147

0 commit comments

Comments
 (0)