Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22398563
ArcanistDisplayRef.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
ArcanistDisplayRef.php
View Options
<?php
final
class
ArcanistDisplayRef
extends
Phobject
implements
ArcanistTerminalStringInterface
{
private
$ref
;
private
$uri
;
private
$lines
=
array
();
public
function
setRef
(
ArcanistRef
$ref
)
{
$this
->
ref
=
$ref
;
return
$this
;
}
public
function
getRef
()
{
return
$this
->
ref
;
}
public
function
setURI
(
$uri
)
{
$this
->
uri
=
$uri
;
return
$this
;
}
public
function
getURI
()
{
return
$this
->
uri
;
}
public
function
appendLine
(
$line
)
{
$this
->
lines
[]
=
$line
;
return
$this
;
}
public
function
newTerminalString
()
{
$ref
=
$this
->
getRef
();
if
(
$ref
instanceof
ArcanistDisplayRefInterface
)
{
$object_name
=
$ref
->
getDisplayRefObjectName
();
$title
=
$ref
->
getDisplayRefTitle
();
}
else
{
$object_name
=
null
;
$title
=
$ref
->
getRefDisplayName
();
}
if
(
$object_name
!==
null
)
{
$reserve_width
=
phutil_utf8_console_strlen
(
$object_name
)
+
1
;
}
else
{
$reserve_width
=
0
;
}
$marker_width
=
6
;
$display_width
=
phutil_console_get_terminal_width
();
$usable_width
=
(
$display_width
-
$marker_width
-
$reserve_width
);
// If the terminal is extremely narrow, don't degrade so much that the
// output is completely unusable.
$usable_width
=
max
(
$usable_width
,
16
);
// TODO: This should truncate based on console display width, not
// glyphs, but there's currently no "setMaximumConsoleCharacterWidth()".
$title
=
id
(
new
PhutilUTF8StringTruncator
())
->
setMaximumGlyphs
(
$usable_width
)
->
truncateString
(
$title
);
if
(
$object_name
!==
null
)
{
if
(
strlen
(
$title
))
{
$display_text
=
tsprintf
(
'**%s** %s'
,
$object_name
,
$title
);
}
else
{
$display_text
=
tsprintf
(
'**%s**'
,
$object_name
);
}
}
else
{
$display_text
=
$title
;
}
$ref
=
$this
->
getRef
();
$output
=
array
();
$output
[]
=
tsprintf
(
"<bg:cyan>** * **</bg> %s
\n
"
,
$display_text
);
$uri
=
$this
->
getURI
();
if
(
$uri
!==
null
)
{
$output
[]
=
tsprintf
(
"<bg:cyan>** :// **</bg> __%s__
\n
"
,
$uri
);
}
foreach
(
$this
->
lines
as
$line
)
{
$output
[]
=
tsprintf
(
" %s
\n
"
,
$line
);
}
return
$output
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Nov 27, 17:24 (1 d, 17 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1227022
Default Alt Text
ArcanistDisplayRef.php (2 KB)
Attached To
Mode
R118 Arcanist - fork
Attached
Detach File
Event Timeline