Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F3281786
PhutilConsoleMetrics.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
1 KB
Referenced Files
None
Subscribers
None
PhutilConsoleMetrics.php
View Options
<?php
final
class
PhutilConsoleMetrics
extends
Phobject
{
const
DEFAULT_CONSOLE
=
'default'
;
private
static
$consoles
=
array
(
)
;
private
$width
=
false
;
public
static
function
getNamedConsole
(
$key
)
{
if
(
!
isset
(
self
::
$consoles
[
$key
]
)
)
{
self
::
$consoles
[
$key
]
=
new
self
(
)
;
}
return
self
::
$consoles
[
$key
]
;
}
public
static
function
getDefaultConsole
(
)
{
return
self
::
getNamedConsole
(
self
::
DEFAULT_CONSOLE
)
;
}
public
function
didGetWINCHSignal
(
)
{
// When we receive a "WINCH" ("WINdow CHange") signal, clear the cached
// information we have about the terminal.
$this
->
width
=
false
;
return
$this
;
}
public
function
getTerminalWidth
(
)
{
if
(
$this
->
width
===
false
)
{
$this
->
width
=
$this
->
computeTerminalWidth
(
)
;
}
return
$this
->
width
;
}
private
function
computeTerminalWidth
(
)
{
if
(
phutil_is_windows
(
)
)
{
// TODO: Figure out how to do this on 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.
$err
=
id
(
new
PhutilExecPassthru
(
'tput cols > %s'
,
$tmp
)
)
->
resolve
(
)
;
$stdout
=
Filesystem
::
readFile
(
$tmp
)
;
unset
(
$tmp
)
;
if
(
$err
)
{
return
null
;
}
$width
=
(int)
trim
(
$stdout
)
;
if
(
$width
>
0
)
{
return
$width
;
}
return
null
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, Mar 24, 01:41 (1 d, 10 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1113326
Default Alt Text
PhutilConsoleMetrics.php (1 KB)
Attached To
Mode
rARC Arcanist
Attached
Detach File
Event Timeline
Log In to Comment