Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ tests/Screenshots
docs/*.blade.php
docs/**/*.blade.php
.phpunit.cache/test-results
.DS_Store
6 changes: 6 additions & 0 deletions src/Commands/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace SoloTerm\Solo\Commands;

use Carbon\Carbon;
use Chewie\Concerns\Ticks;
use Chewie\Contracts\Loopable;
use Illuminate\Support\Collection;
Expand Down Expand Up @@ -50,6 +51,8 @@ class Command implements Loopable
public ?KeyPressListener $keyPressListener = null;

protected ?string $workingDirectory = null;

public ?Carbon $lastOutput = null;

public static function from(string $command): static
{
Expand Down Expand Up @@ -178,6 +181,7 @@ public function addOutput($text)
$text = Str::after($text, $this->outputStartMarker);

$this->screen->write($text);
$this->lastOutput = now();
}

public function addLine($line)
Expand Down Expand Up @@ -307,6 +311,8 @@ protected function makeNewScreen()
width: $this->scrollPaneWidth(),
height: $this->scrollPaneHeight()
);

$this->lastOutput = now();

return $screen->respondToQueriesVia(function ($output) {
$this->input->write($output);
Expand Down
19 changes: 18 additions & 1 deletion src/Prompt/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace SoloTerm\Solo\Prompt;

use Carbon\CarbonImmutable;
use Carbon\{Carbon, CarbonImmutable};
use Chewie\Concerns\CreatesAnAltScreen;
use Chewie\Concerns\Loops;
use Chewie\Concerns\SetsUpAndResets;
Expand Down Expand Up @@ -49,6 +49,8 @@ class Dashboard extends Prompt

public ?Popup $popup = null;

protected ?Carbon $lastInput = null;

public static function start(): void
{
(new static)->run();
Expand Down Expand Up @@ -80,6 +82,8 @@ public function __construct()
->all();

$this->registerLoopables(...$this->commands);

$this->lastInput = now();
}

public function listenForEvents()
Expand Down Expand Up @@ -167,6 +171,7 @@ public function rebindHotkeys()
$hotkey->init($this->currentCommand(), $this);
$this->listener->on($hotkey->keys, $hotkey->handle(...));
});
$this->listener->wildcard(fn() => ($this->lastInput = now()));
}

public function enterInteractiveMode()
Expand All @@ -185,6 +190,7 @@ public function exitInteractiveMode()

public function selectTab(int $index)
{
$this->lastInput = now();
$this->currentCommand()->blur();
$this->selectedCommand = $index;
$this->currentCommand()->focus();
Expand Down Expand Up @@ -218,6 +224,17 @@ protected function renderSingleFrame()
$this->rebindHotkeys();
}

// if last input was 5 seconds ago, skip rendering to save cpu cycles
// if last output was less than a second ago - render it!
if (
$this->lastInput?->diffInSeconds(now()) > 5 &&
$this->currentCommand()->lastOutput?->diffInSeconds(now()) > 1
) {
$this->listener->once();

return;
}

$this->currentCommand()->catchUpScroll();

if ($this->popup) {
Expand Down