Repository navigation
Expand file tree
/
Copy pathHasWindows.php
More file actions
54 lines (40 loc) · 1.56 KB
/
Copy pathHasWindows.php
File metadata and controls
54 lines (40 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace RubenVanErk\ArtisanWindow\Traits;
use Closure;
use Symfony\Component\Console\Output\ConsoleSectionOutput;
use function Termwind\render;
use function Termwind\renderUsing;
use function Termwind\terminal;
trait HasWindows
{
protected function window(string $title, int $maxHeight, Closure $callable): string
{
$width = min(terminal()->width(), 150);
$originalOutput = $this->output->getOutput();
render('<div class="text-center font-bold bg-green-700 w-'.$width.'">'.$title.'</div>');
/** @var ConsoleSectionOutput $window */
$window = $originalOutput->section();
$window->setMaxHeight($maxHeight);
$this->output = $window;
renderUsing($window);
$result = false;
$startTime = microtime(true);
try {
$result = $callable();
} finally {
$this->output = $originalOutput;
renderUsing($originalOutput);
$runTime = number_format((microtime(true) - $startTime) * 1000).'ms';
$resultColor = $result !== false ? 'text-green-500' : 'text-red-500';
$resultText = $result !== false ? 'DONE' : 'FAIL';
render(<<<HTML
<div class="flex w-$width space-x-1">
<span class="flex-1 text-gray-300 content-repeat-[.]"></span>
<span class="text-gray-500">$runTime</span>
<span class="font-bold $resultColor">$resultText</span>
</div>
HTML);
}
return $window->getContent();
}
}