Page MenuHomePhabricator

D13519.id32683.diff
No OneTemporary

D13519.id32683.diff

diff --git a/src/console/format.php b/src/console/format.php
--- a/src/console/format.php
+++ b/src/console/format.php
@@ -183,31 +183,35 @@
* @return int|null Terminal width in characters, or null on failure.
*/
function phutil_console_get_terminal_width() {
- if (phutil_is_windows()) {
- // TODO: Figure out how to get this working in Windows.
- return null;
- }
+ static $width;
- $tmp = new TempFile();
+ if ($width === null) {
+ if (phutil_is_windows()) {
+ // TODO: Figure out how to get this working in Windows.
+ return null;
+ }
- // NOTE: We can't just execute this because it won't be connected to a TTY
- // if we do.
- $err = phutil_passthru('tput cols > %s', $tmp);
+ $tmp = new TempFile();
- if ($err) {
- return null;
- }
+ // NOTE: We can't just execute this because it won't be connected to a TTY
+ // if we do.
+ $err = phutil_passthru('tput cols > %s', $tmp);
- try {
- $cols = Filesystem::readFile($tmp);
- } catch (FilesystemException $ex) {
- return null;
- }
+ if ($err) {
+ return null;
+ }
- $cols = (int)$cols;
- if (!$cols) {
- return null;
+ try {
+ $cols = Filesystem::readFile($tmp);
+ } catch (FilesystemException $ex) {
+ return null;
+ }
+
+ $width = (int)$cols;
+ if (!$width) {
+ $width = null;
+ }
}
- return $cols;
+ return $width;
}

File Metadata

Mime Type
text/plain
Expires
Fri, Oct 18, 11:48 AM (3 w, 6 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6726704
Default Alt Text
D13519.id32683.diff (1 KB)

Event Timeline