|
18 | 18 | use SoloTerm\Solo\Support\ErrorBox;
|
19 | 19 | use SoloTerm\Solo\Support\PendingProcess;
|
20 | 20 | use SoloTerm\Solo\Support\ProcessTracker;
|
| 21 | +use SoloTerm\Solo\Support\Screen; |
21 | 22 | use Symfony\Component\Process\InputStream;
|
22 | 23 | use Symfony\Component\Process\Process as SymfonyProcess;
|
23 | 24 |
|
24 | 25 | trait ManagesProcess
|
25 | 26 | {
|
26 | 27 | public ?InvokedProcess $process = null;
|
27 | 28 |
|
| 29 | + public $outputStartMarker = '[[==SOLO_START==]]'; |
| 30 | + |
| 31 | + public $outputEndMarker = '[[==SOLO_END==]]'; |
| 32 | + |
28 | 33 | protected array $afterTerminateCallbacks = [];
|
29 | 34 |
|
30 | 35 | protected bool $stopping = false;
|
@@ -58,16 +63,9 @@ public function createPendingProcess(): PendingProcess
|
58 | 63 |
|
59 | 64 | $screen = $this->makeNewScreen();
|
60 | 65 |
|
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 |
| - |
68 | 66 | // We have to make our own so that we can control pty.
|
69 | 67 | $process = app(PendingProcess::class)
|
70 |
| - ->command(['bash', '-c', $built]) |
| 68 | + ->command($this->buildCommandArray($screen)) |
71 | 69 | ->forever()
|
72 | 70 | ->timeout(0)
|
73 | 71 | ->idleTimeout(0)
|
@@ -96,7 +94,28 @@ public function createPendingProcess(): PendingProcess
|
96 | 94 | ]);
|
97 | 95 | }
|
98 | 96 |
|
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() |
100 | 119 | {
|
101 | 120 | $locale = $this->utf8Locale();
|
102 | 121 |
|
|
0 commit comments