Skip to content

Commit 1ebae6a

Browse files
committed
fixes
1 parent 8005af4 commit 1ebae6a

File tree

6 files changed

+49
-21
lines changed

6 files changed

+49
-21
lines changed

src/Buffers/PrintableBuffer.php

-1
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,4 @@ public function writeString(int $row, int $col, string $text): array
125125

126126
return [$advanceCursor, $remainder];
127127
}
128-
129128
}

src/Commands/Command.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Chewie\Concerns\Ticks;
1313
use Chewie\Contracts\Loopable;
1414
use Illuminate\Support\Collection;
15+
use Illuminate\Support\Str;
1516
use SoloTerm\Solo\Commands\Concerns\ManagesProcess;
1617
use SoloTerm\Solo\Hotkeys\Hotkey;
1718
use SoloTerm\Solo\Hotkeys\KeyHandler;
@@ -168,12 +169,13 @@ public function isInteractive(): bool
168169
*/
169170
public function dd()
170171
{
171-
dd($this->screen->output());
172+
dd($this->screen->printable->buffer);
172173
}
173174

174175
public function addOutput($text)
175176
{
176-
$text = str_replace('[screen is terminating]', '', $text);
177+
$text = Str::before($text, $this->outputEndMarker);
178+
$text = Str::after($text, $this->outputStartMarker);
177179

178180
$this->screen->write($text);
179181
}

src/Commands/Concerns/ManagesProcess.php

+28-9
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@
1818
use SoloTerm\Solo\Support\ErrorBox;
1919
use SoloTerm\Solo\Support\PendingProcess;
2020
use SoloTerm\Solo\Support\ProcessTracker;
21+
use SoloTerm\Solo\Support\Screen;
2122
use Symfony\Component\Process\InputStream;
2223
use Symfony\Component\Process\Process as SymfonyProcess;
2324

2425
trait ManagesProcess
2526
{
2627
public ?InvokedProcess $process = null;
2728

29+
public $outputStartMarker = '[[==SOLO_START==]]';
30+
31+
public $outputEndMarker = '[[==SOLO_END==]]';
32+
2833
protected array $afterTerminateCallbacks = [];
2934

3035
protected bool $stopping = false;
@@ -58,16 +63,9 @@ public function createPendingProcess(): PendingProcess
5863

5964
$screen = $this->makeNewScreen();
6065

61-
// Build the command by adding a few necessary arguments.
62-
$built = implode(' && ', [
63-
$this->localEnvironmentVariables(),
64-
"stty cols {$screen->width} rows {$screen->height}",
65-
"screen -U -q {$this->command}"
66-
]);
67-
6866
// We have to make our own so that we can control pty.
6967
$process = app(PendingProcess::class)
70-
->command(['bash', '-c', $built])
68+
->command($this->buildCommandArray($screen))
7169
->forever()
7270
->timeout(0)
7371
->idleTimeout(0)
@@ -96,7 +94,28 @@ public function createPendingProcess(): PendingProcess
9694
]);
9795
}
9896

99-
protected function localEnvironmentVariables()
97+
protected function buildCommandArray(Screen $screen): array
98+
{
99+
$local = $this->localeEnvironmentVariables();
100+
$size = sprintf('stty cols %d rows %d', $screen->width, $screen->height);
101+
102+
$inner = sprintf(
103+
"printf '%%s' %s; %s; printf '%%s' %s",
104+
$this->outputStartMarker,
105+
$this->command,
106+
$this->outputEndMarker
107+
);
108+
109+
$built = implode(' && ', [
110+
$local,
111+
$size,
112+
'screen -U -q sh -c ' . escapeshellarg($inner)
113+
]);
114+
115+
return ['bash', '-c', $built];
116+
}
117+
118+
protected function localeEnvironmentVariables()
100119
{
101120
$locale = $this->utf8Locale();
102121

tests/Integration/NamespacedCommandTest.php

+8-7
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,21 @@ class NamespacedCommandTest extends Base
1919
public function run_solo_command_in_directory()
2020
{
2121
$actions = [
22-
's', function ($ansi, $plain) {
22+
's',
23+
function ($ansi, $plain) {
2324
$this->assertStringContainsString('List', $plain);
2425
$this->assertStringContainsString('solo.php', $plain);
2526
},
26-
Key::LEFT, fn($plain) => $this->assertStringContainsString('Vue3', $plain),
27-
's', fn($plain) => $this->assertStringContainsString('Directory not found: resources/js/vue3', $plain),
27+
Key::LEFT,
28+
fn($plain) => $this->assertStringContainsString('Vue3', $plain),
29+
's',
30+
fn($plain) => $this->assertStringContainsString('Directory not found: resources/js/vue3', $plain),
2831
];
2932

3033
$this->runSolo($actions, function () {
3134
config()->set('solo.commands', [
32-
'List' => Command::from('ls')
33-
->inDirectory('config'),
34-
'Vue3' => Command::from('npm run dev')
35-
->inDirectory('resources/js/vue3'),
35+
'List' => Command::from('ls')->inDirectory('config'),
36+
'Vue3' => Command::from('npm run dev')->inDirectory('resources/js/vue3'),
3637
]);
3738
});
3839

tests/Unit/CommandSerializationTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010

1111
class CommandSerializationTest extends TestCase
1212
{
13+
protected function setUp(): void
14+
{
15+
$this->beforeApplicationDestroyed(function () {
16+
$this->artisan('config:clear');
17+
});
18+
19+
parent::setUp();
20+
}
21+
1322
#[Test]
1423
public function command_config_can_be_serialized_and_cached(): void
1524
{

tests/Unit/ScreenTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,4 @@ public function test_combining_characters(): void
911911
"\e[1G*" // Should treat combining characters as single unit
912912
], iterate: true);
913913
}
914-
915-
916914
}

0 commit comments

Comments
 (0)