/** * @group console */ function phutil_console_prompt($prompt, $history = '') { echo "\n\n"; $prompt = phutil_console_wrap($prompt . ' ', 4); try { phutil_console_require_tty(); } catch (PhutilConsoleStdinNotInteractiveException $ex) { // Throw after echoing the prompt so the user has some idea what happened. echo $prompt; throw $ex; } $use_history = true; if ($history == '') { $use_history = false; } else { // Test if bash is available by seeing if it can run `true`. list($err) = exec_manual('bash -c %s', 'true'); if ($err) { $use_history = false; } } if (!$use_history) { echo $prompt; $response = fgets(STDIN); } else { // There's around 0% chance that readline() is available directly in PHP, // so we're using bash/read/history instead. $command = csprintf('bash -c %s', csprintf('history -r %s 2>/dev/null; ' . 'read -e -p %s; ' . 'echo "$REPLY"; ' . 'history -s "$REPLY" 2>/dev/null; ' . 'history -w %s 2>/dev/null', $history, $prompt, $history)); // execx() doesn't work with input, phutil_passthru() doesn't return output. $response = shell_exec($command); } return rtrim($response, "\r\n"); }
/** * @group console */ function phutil_console_prompt($prompt) { $prompt = "\n\n " . $prompt . " "; $prompt = phutil_console_wrap($prompt, 4); echo $prompt; // Require after echoing the prompt so the user has some idea what happened // if this throws. phutil_console_require_tty(); $response = fgets(STDIN); return rtrim($response, "\n"); }
public function handleServerMessage(PhutilConsoleMessage $message) { $data = $message->getData(); if ($this->getArgument('excuse')) { try { phutil_console_require_tty(); } catch (PhutilConsoleStdinNotInteractiveException $ex) { $this->excuses[$data['type']] = $this->getArgument('excuse'); return null; } } $response = ''; if (isset($data['prompt'])) { $response = phutil_console_prompt($data['prompt'], idx($data, 'history')); } else { if (phutil_console_confirm($data['confirm'])) { $response = $this->getArgument('excuse'); } } if ($response == '') { throw new ArcanistUserAbortException(); } $this->excuses[$data['type']] = $response; return null; }