-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding "Clear" Function For Cleaning The Terminal (#160)
* feat(clear): adding clear command. * chore(clear): improving playground test. * fix(syntax): fixing issues of static analysis. * Move rendering concern * Fix padding after clear * Simplify playground example * Formatting --------- Co-authored-by: Jess Archer <jess@jessarcher.com>
- Loading branch information
1 parent
1ce74e5
commit 39a2f4e
Showing
6 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
use function Laravel\Prompts\clear; | ||
use function Laravel\Prompts\note; | ||
use function Laravel\Prompts\pause; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
note('This will disappear.'); | ||
|
||
pause('Press [Enter] to continue.'); | ||
|
||
clear(); | ||
|
||
note('This will also disappear.'); | ||
|
||
pause('Press [Enter] to continue.'); | ||
|
||
clear(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Laravel\Prompts; | ||
|
||
class Clear extends Prompt | ||
{ | ||
/** | ||
* Clear the terminal. | ||
*/ | ||
public function prompt(): bool | ||
{ | ||
// Fill the previous newline count so subsequent prompts won't add padding. | ||
static::output()->write(PHP_EOL.PHP_EOL); | ||
|
||
$this->writeDirectly($this->renderTheme()); | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Clear the terminal. | ||
*/ | ||
public function display(): void | ||
{ | ||
$this->prompt(); | ||
} | ||
|
||
/** | ||
* Get the value of the prompt. | ||
*/ | ||
public function value(): bool | ||
{ | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Laravel\Prompts\Themes\Default; | ||
|
||
class ClearRenderer extends Renderer | ||
{ | ||
/** | ||
* Clear the terminal. | ||
*/ | ||
public function __invoke(): string | ||
{ | ||
return "\033[H\033[J"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
use Laravel\Prompts\Prompt; | ||
|
||
use function Laravel\Prompts\clear; | ||
|
||
it('clears', function () { | ||
Prompt::fake(); | ||
|
||
clear(); | ||
|
||
Prompt::assertOutputContains("\033[H\033[J"); | ||
}); |