public function resume() { if ($this->oldMode === null) { $this->oldMode = shell_exec('stty -g'); // Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead) shell_exec('stty -icanon -echo'); parent::resume(); } }
public function toggle(Stream $stream, $toggle) { // pause actual stream instance to continue operation on raw stream socket $stream->pause(); // TODO: add write() event to make sure we're not sending any excessive data $deferred = new Deferred(); // get actual stream socket from stream instance $socket = $stream->stream; $toggleCrypto = function () use($socket, $deferred, $toggle) { $this->toggleCrypto($socket, $deferred, $toggle); }; $this->loop->addWriteStream($socket, $toggleCrypto); $this->loop->addReadStream($socket, $toggleCrypto); $toggleCrypto(); return $deferred->promise()->then(function () use($stream) { $stream->resume(); return $stream; }, function ($error) use($stream) { $stream->resume(); throw $error; }); }
/** * Wait a message result * * @param Stream $stdout Stdout Stream * @param MessageInterface $message Command waiting result * * @return mixed The result */ public function waitMessage(Stream $stdout, MessageInterface $message) { $buffer = []; $this->waitingMessageId = $message->id; $this->isWaitingMessage = true; // Read the stdin until we get the message replied while ($this->isWaitingMessage) { $this->tick(); usleep(1); } $stdout->resume(); $result = $this->waitingMessageResult; $this->waitingMessageResult = null; foreach ($this->parseMessagesBuffer as $key => $message) { $this->parseNormal($message); } $this->parseMessagesBuffer = []; return $result; }