Changeset View
Changeset View
Standalone View
Standalone View
src/console/format.php
Show First 20 Lines • Show All 198 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Determine the width of the terminal, if possible. Returns `null` on failure. | * Determine the width of the terminal, if possible. Returns `null` on failure. | ||||
* | * | ||||
* @return int|null Terminal width in characters, or null on failure. | * @return int|null Terminal width in characters, or null on failure. | ||||
*/ | */ | ||||
function phutil_console_get_terminal_width() { | function phutil_console_get_terminal_width() { | ||||
static $width; | return PhutilConsoleMetrics::getDefaultConsole() | ||||
->getTerminalWidth(); | |||||
if ($width === null) { | |||||
if (phutil_is_windows()) { | |||||
// TODO: Figure out how to get this working in Windows. | |||||
return null; | |||||
} | |||||
$tmp = new TempFile(); | |||||
// NOTE: We can't just execute this because it won't be connected to a TTY | |||||
// if we do. | |||||
amckinley: Maybe keep this comment? I was briefly confused by this too. | |||||
Not Done Inline ActionsOh, sure -- I originally thought I could write this in a slightly less dumb way and make what was going on a little more obvious, but PhutilExecPassthru doesn't currently have a mode to pass some kind of normal pipe for stdout/stderr. epriestley: Oh, sure -- I originally thought I could write this in a slightly less dumb way and make what… | |||||
$err = phutil_passthru('tput cols > %s', $tmp); | |||||
if ($err) { | |||||
return null; | |||||
} | |||||
try { | |||||
$cols = Filesystem::readFile($tmp); | |||||
} catch (FilesystemException $ex) { | |||||
return null; | |||||
} | |||||
$width = (int)$cols; | |||||
if (!$width) { | |||||
$width = null; | |||||
} | |||||
} | |||||
return $width; | |||||
} | } |
Maybe keep this comment? I was briefly confused by this too.