Skip to content

Commit

Permalink
REVERT console debug
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jan 29, 2025
1 parent 98a0d4f commit 5a70873
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 46 deletions.
6 changes: 1 addition & 5 deletions demos/interactive/console.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,11 @@ public function generateReport()
]);
$message = Message::addTo($vp, ['This demo may not work', 'type' => 'warning']);
$message->text->addParagraph('This demo requires Linux OS and will display error otherwise.');
$console = Console::addTo($vp)->set(static function (Console $console) {
Console::addTo($vp)->set(static function (Console $console) {
$console->exec('/sbin/ping', ['-c', '5', '-i', '1', '192.168.0.1']);
$console->exec('/sbin/ping', ['-c', '5', '-i', '2', '8.8.8.8']);
$console->exec('/bin/no-such-command');
});
$console->js(true, new \Atk4\Ui\Js\JsExpression(<<<'JS'
console.log([l]);
atk.elementRemoveObserver.addHandler($('#' + [id])[ 0], function () { console.log([ul]); });
JS, ['l' => 'loaded', 'ul' => 'unloaded - working!', 'id' => $console->getHtmlId()]));
});

$tab = $tabs->addTab('composer update', static function (VirtualPage $vp) {
Expand Down
79 changes: 38 additions & 41 deletions src/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,47 +271,44 @@ public function exec(string $command, array $args = []): ?bool
return null;
}

usleep(250_000);
$this->output('sleep(0.25)');

// [$proc, $pipes] = $this->execRaw($command, $args);
//
// stream_set_blocking($pipes[1], false);
// stream_set_blocking($pipes[2], false);
// // $pipes contain streams that are still open and not EOF
// while ($pipes) { // @TODO this condition is always true
// $read = $pipes;
// $j1 = null;
// $j2 = null;
// if (stream_select($read, $j1, $j2, 2) === false) {
// throw new Exception('Unexpected stream_select() result');
// }
//
// $status = proc_get_status($proc);
// if (!$status['running']) {
// proc_close($proc);
//
// break;
// }
//
// foreach ($read as $f) {
// $data = rtrim((string) fgets($f));
// if ($data === '') {
// // TODO fix coverage stability, add test with explicit empty string
// // @codeCoverageIgnoreStart
// continue;
// // @codeCoverageIgnoreEnd
// }
//
// if ($f === $pipes[2]) { // stderr
// $this->warning($data);
// } else { // stdout
// $this->output($data);
// }
// }
// }
//
// $this->lastExitCode = $status['exitcode'];
[$proc, $pipes] = $this->execRaw($command, $args);

stream_set_blocking($pipes[1], false);
stream_set_blocking($pipes[2], false);
// $pipes contain streams that are still open and not EOF
while ($pipes) { // @TODO this condition is always true
$read = $pipes;
$j1 = null;
$j2 = null;
if (stream_select($read, $j1, $j2, 2) === false) {
throw new Exception('Unexpected stream_select() result');
}

$status = proc_get_status($proc);
if (!$status['running']) {
proc_close($proc);

break;
}

foreach ($read as $f) {
$data = rtrim((string) fgets($f));
if ($data === '') {
// TODO fix coverage stability, add test with explicit empty string
// @codeCoverageIgnoreStart
continue;
// @codeCoverageIgnoreEnd
}

if ($f === $pipes[2]) { // stderr
$this->warning($data);
} else { // stdout
$this->output($data);
}
}
}

$this->lastExitCode = $status['exitcode'];

return $this->lastExitCode ? false : true;
}
Expand Down

0 comments on commit 5a70873

Please sign in to comment.