Changeset View
Changeset View
Standalone View
Standalone View
src/console/PhutilInteractiveEditor.php
| Show First 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | public function editInteractively() { | ||||
| } | } | ||||
| $editor = $this->getEditor(); | $editor = $this->getEditor(); | ||||
| $offset = $this->getLineOffset(); | $offset = $this->getLineOffset(); | ||||
| $err = $this->invokeEditor($editor, $path, $offset); | $err = $this->invokeEditor($editor, $path, $offset); | ||||
| if ($err) { | if ($err) { | ||||
| // See T13297. On macOS, "vi" and "vim" may exit with errors even though | |||||
| // the edit succeeded. If the binary is "vi" or "vim" and we get an exit | |||||
| // code, we perform an additional test on the binary. | |||||
| $vi_binaries = array( | |||||
| 'vi' => true, | |||||
| 'vim' => true, | |||||
| ); | |||||
| $binary = basename($editor); | |||||
| if (isset($vi_binaries[$binary])) { | |||||
| // This runs "Q" (an invalid command), then "q" (a valid command, | |||||
| // meaning "quit"). Vim binaries with behavior that makes them poor | |||||
| // interactive editors will exit "1". | |||||
| list($diagnostic_err) = exec_manual('%R +Q +q', $binary); | |||||
| // If we get an error back, the binary is badly behaved. Ignore the | |||||
| // original error and assume it's not meaningful, since it just | |||||
| // indicates the user made a typo in a command when editing | |||||
| // interactively, which is routine and unconcerning. | |||||
| if ($diagnostic_err) { | |||||
| $err = 0; | |||||
| } | |||||
| } | |||||
| } | |||||
| if ($err) { | |||||
| Filesystem::remove($tmp); | Filesystem::remove($tmp); | ||||
| throw new Exception(pht('Editor exited with an error code (#%d).', $err)); | throw new Exception(pht('Editor exited with an error code (#%d).', $err)); | ||||
| } | } | ||||
| try { | try { | ||||
| $result = Filesystem::readFile($path); | $result = Filesystem::readFile($path); | ||||
| Filesystem::remove($tmp); | Filesystem::remove($tmp); | ||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||
| ▲ Show 20 Lines • Show All 195 Lines • Show Last 20 Lines | |||||