Changeset View
Changeset View
Standalone View
Standalone View
src/console/format.php
Show First 20 Lines • Show All 181 Lines • ▼ Show 20 Lines | |||||
* | * | ||||
* @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; | static $width; | ||||
if ($width === null) { | if ($width === null) { | ||||
if (phutil_is_windows()) { | if (phutil_is_windows()) { | ||||
// TODO: Figure out how to get this working in Windows. | |||||
preg_match('/(\n[^|]+?){4}(\d+)/', `mode con`, $matches); | |||||
cspeckmim: In this case I would suggest adding a comment with an example output of `mode con`. It will… | |||||
hach-queUnsubmitted Not Done Inline ActionsDon't execute programs like this; use Exe Future or the exec passthru function that libphutil provides. hach-que: Don't execute programs like this; use Exe Future or the exec passthru function that libphutil… | |||||
if(is_array($matches)&&isset($matches[2])&&!empty($matches[2])) { | |||||
return (int)$matches[2]; | |||||
cspeckmimUnsubmitted Not Done Inline ActionsThis should probably verify that the value can be parsed as an int or try/catch. Otherwise it could break the existing behavior, and it appears that null is already handled as a return value. cspeckmim: This should probably verify that the value can be parsed as an `int` or try/catch. Otherwise it… | |||||
}else { | |||||
return null; | return null; | ||||
} | |||||
} | } | ||||
$tmp = new TempFile(); | $tmp = new TempFile(); | ||||
// NOTE: We can't just execute this because it won't be connected to a TTY | // NOTE: We can't just execute this because it won't be connected to a TTY | ||||
// if we do. | // if we do. | ||||
$err = phutil_passthru('tput cols > %s', $tmp); | $err = phutil_passthru('tput cols > %s', $tmp); | ||||
Show All 18 Lines |
In this case I would suggest adding a comment with an example output of mode con. It will give a much clearer idea to someone who comes across the code what the regex is attempting to parse. Additionally I would suggest explaining the magic 2.