8000 DX Improvements by WendellAdriel · Pull Request #1 · minicli/miniterm · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml,json}]
indent_size = 2
6 changes: 3 additions & 3 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run Pint
run: composer lint
- name: Check code style
run: composer test:lint

- name: Run test suite
run: composer run-script test
run: composer test:unit
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<div align="center">
<p>
<img src="https://github.com/WendellAdriel/miniterm/raw/main/art/minicli.png" alt="Minicli" width="150"/>
<img src="https://github.com/WendellAdriel/miniterm/raw/main/art/termwind.png" alt="Termwind" width="150"/>
<img src="https://github.com/WendellAdriel/miniterm/raw/main/art/plates.png" alt="Plates" width="150"/>
<img src="https://github.com/minicli/miniterm/raw/main/art/minicli.png" alt="Minicli" width="150"/>
<img src="https://github.com/minicli/miniterm/raw/main/art/termwind.png" alt="Termwind" width="150"/>
<img src="https://github.com/minicli/miniterm/raw/main/art/plates.png" alt="Plates" width="150"/>
<h1>MiniTerm</h1>
Minicli Application Template powered with Termwind and Plates
<h4>Minicli Application Template powered with Termwind and Plates</h4>
</p>
</div>
<hr>

This repository is an application template for building command-line applications in PHP with [Minicli](https://github.com/minicli/minicli), [Termwind](https://github.com/nunomaduro/termwind) and [Plates](https://github.com/thephpleague/plates).

Expand Down
2 changes: 2 additions & 0 deletions app/Command/BaseController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Command;

use Minicli\Command\CommandController;
Expand Down
2 changes: 2 additions & 0 deletions app/Command/Demo/AskController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Command\Demo;

use App\Command\BaseController;
Expand Down
32 changes: 17 additions & 15 deletions app/Command/Demo/ColorController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Command\Demo;

use App\Command\BaseController;
Expand All @@ -8,20 +10,20 @@ class ColorController extends BaseController
{
public function handle(): void
{
$this->getPrinter()->display("Hello World");
$this->getPrinter()->error("Hello World");
$this->getPrinter()->info("Hello World");
$this->getPrinter()->success("Hello World");
$this->getPrinter()->warning("Hello World");
$this->getPrinter()->display("Hello World", true);
$this->getPrinter()->error("Hello World", true);
$this->getPrinter()->info("Hello World", true);
$this->getPrinter()->success("Hello World", true);
$this->getPrinter()->warning("Hello World", true);
$this->getPrinter()->out("Hello World!\r\n", 'underline');
$this->getPrinter()->out("Hello World!\r\n", 'dim');
$this->getPrinter()->out("Hello World!\r\n", 'bold');
$this->getPrinter()->out("Hello World!\r\n", 'invert');
$this->getPrinter()->out("Hello World!\r\n", 'italic');
$this->display("Hello World");
$this->error("Hello World");
$this->info("Hello World");
$this->success("Hello World");
$this->warning("Hello World");
$this->display("Hello World", true);
$this->error("Hello World", true);
$this->info("Hello World", true);
$this->success("Hello World", true);
$this->warning("Hello World", true);
$this->out("Hello World!\r\n", 'underline');
$this->out("Hello World!\r\n", 'dim');
$this->out("Hello World!\r\n", 'bold');
$this->out("Hello World!\r\n", 'invert');
$this->out("Hello World!\r\n", 'italic');
}
}
2 changes: 2 additions & 0 deletions app/Command/Demo/DefaultController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Command\Demo;

use App\Command\BaseController;
Expand Down
4 changes: 3 additions & 1 deletion app/Command/Demo/TableController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Command\Demo;

use App\Command\BaseController;
Expand All @@ -12,7 +14,7 @@ public function handle(): void
$rows = [];

for ($i = 1; $i <= 10; $i++) {
$rows[] = [(string) $i, (string) rand(0, 10), "other string $i"];
$rows[] = [(string) $i, (string) rand(0, 10), "other string {$i}"];
}

$this->view('table', [
Expand Down
2 changes: 2 additions & 0 deletions app/Command/Demo/TestController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Command\Demo;

use App\Command\BaseController;
Expand Down
2 changes: 2 additions & 0 deletions app/Config/TermwindOutputConfig.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Config;

class TermwindOutputConfig
Expand Down
17 changes: 9 additions & 8 deletions app/Config/TermwindOutputHandler.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<?php

declare(strict_types=1);

namespace App\Config;

use Minicli\Output\OutputHandler;
use Minicli\Output\PrinterAdapterInterface;

use function Termwind\render;

class TermwindOutputHandler extends OutputHandler
{
private TermwindOutputConfig $config;

public function __construct(?PrinterAdapterInterface $printer = null)
public function __construct()
{
parent::__construct($printer);
parent::__construct();
$this->config = new TermwindOutputConfig();
}

Expand All @@ -24,9 +25,9 @@ public function out(string $content, string $style = "default"): void

$formatted = <<<HTML
<div>
$label
<span class="ml-1 $cssClass">
$content
{$label}
<span class="ml-1 {$cssClass}">
{$content}
</span>
</div>
HTML;
Expand Down Expand Up @@ -87,8 +88,8 @@ private function getLabel(string $style): string

$cssClass = $this->getCssClass($style);
$color = str_replace('text-', 'bg-', $cssClass);
$label = str_replace('_ALT', '', strtoupper($style));
$label = str_replace('_ALT', '', mb_strtoupper($style));

return "<div class='px-1 $color text-black'>$label</div>";
return "<div class='px-1 {$color} text-black'>{$label}</div>";
}
}
4 changes: 3 additions & 1 deletion app/Services/PlatesService.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Services;

use League\Plates\Engine;
Expand All @@ -12,7 +14,7 @@ class PlatesService implements ServiceInterface

public function __construct()
{
$this->plates = new Engine(__DIR__ . '/../../app/Views');
$this->plates = new Engine(__DIR__.'/../../app/Views');
}

public function view(string $template, array $data = []): string
Expand Down
11 changes: 7 additions & 4 deletions app/Services/TermwindService.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
<?php

declare(strict_types=1);

namespace App\Services;

use Minicli\App;
use Minicli\ServiceInterface;
use Symfony\Component\Console\Output\OutputInterface;

use Termwind\Terminal;
use Termwind\ValueObjects\Style;

use function Termwind\ask;

use function Termwind\render;
use function Termwind\style;

use Termwind\Terminal;
use function Termwind\style;

use function Termwind\terminal;

use Termwind\ValueObjects\Style;

class TermwindService implements ServiceInterface
{
public function load(App $app): void
Expand Down
15 changes: 10 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
}
},
"require": {
"php": ">=8",
"minicli/minicli": "^3.0",
"minicli/command-help": "^0.1.0",
"php": ">=8.1",
"minicli/minicli": "^4.0",
"minicli/command-help": "^1.0",
"nunomaduro/termwind": "^1.15",
"league/plates": "^3.5"
},
Expand All @@ -21,8 +21,13 @@
"laravel/pint": "^1.10"
},
"scripts": {
"test" : ["pest"],
"lint" : ["pint"]
"lint" : ["pint"],
"test:lint" : ["pint --test"],
"test:unit" : ["pest"],
"test": [
"@test:lint",
"@test:unit"
]
},
"config": {
"allow-plugins": {
Expand Down
40 changes: 22 additions & 18 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions minicli
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ $app->setOutputHandler(new TermwindOutputHandler());
try {
$app->runCommand($argv);
} catch (CommandNotFoundException $notFoundException) {
$app->getPrinter()->error("Command Not Found.");
$app->error("Command Not Found.");
return 1;
} catch (Exception $exception) {
if ($app->config->debug) {
$app->getPrinter()->error("An error occurred:");
$app->getPrinter()->error($exception->getMessage());
$app->error("An error occurred:");
$app->error($exception->getMessage());
}
return 1;
}
Expand Down
Loading
0