Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15536679
D16926.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D16926.id.diff
View Options
diff --git a/src/console/format.php b/src/console/format.php
--- a/src/console/format.php
+++ b/src/console/format.php
@@ -82,9 +82,10 @@
*
* @param string Text to wrap.
* @param int Optional indent level.
+ * @param bool True to also indent the first line.
* @return string Wrapped text.
*/
-function phutil_console_wrap($text, $indent = 0) {
+function phutil_console_wrap($text, $indent = 0, $with_prefix = true) {
$lines = array();
$width = (78 - $indent);
@@ -163,7 +164,13 @@
}
foreach ($lines as $idx => $line) {
- $lines[$idx] = $pre.implode('', $line);
+ if ($idx == 0 && !$with_prefix) {
+ $prefix = null;
+ } else {
+ $prefix = $pre;
+ }
+
+ $lines[$idx] = $prefix.implode('', $line);
}
return implode('', $lines);
diff --git a/src/console/view/PhutilConsoleBlock.php b/src/console/view/PhutilConsoleBlock.php
--- a/src/console/view/PhutilConsoleBlock.php
+++ b/src/console/view/PhutilConsoleBlock.php
@@ -29,7 +29,10 @@
switch ($type) {
case 'paragraph':
- $item = phutil_console_wrap($item)."\n";
+ $item = array(
+ tsprintf('%s', $item)->applyWrap(),
+ "\n",
+ );
break;
case 'list':
$item = $item;
diff --git a/src/console/view/PhutilConsoleList.php b/src/console/view/PhutilConsoleList.php
--- a/src/console/view/PhutilConsoleList.php
+++ b/src/console/view/PhutilConsoleList.php
@@ -50,7 +50,8 @@
$output = array();
foreach ($this->getItems() as $item) {
if ($this->wrap) {
- $item = phutil_console_wrap($item, $indent_depth);
+ $item = tsprintf('%s', $item)
+ ->applyIndent($indent_depth, false);
}
$output[] = $indent_string.$bullet.$item;
diff --git a/src/xsprintf/PhutilTerminalString.php b/src/xsprintf/PhutilTerminalString.php
--- a/src/xsprintf/PhutilTerminalString.php
+++ b/src/xsprintf/PhutilTerminalString.php
@@ -15,6 +15,18 @@
return $this->string;
}
+ public function applyWrap() {
+ $string = (string)$this;
+ $string = phutil_console_wrap($string);
+ return new self($string);
+ }
+
+ public function applyIndent($depth, $with_prefix = true) {
+ $string = (string)$this;
+ $string = phutil_console_wrap($string, $depth, $with_prefix);
+ return new self($string);
+ }
+
public static function escapeStringValue($value, $allow_whitespace) {
if ($value instanceof PhutilTerminalString) {
return (string)$value;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Apr 25, 10:50 AM (5 h, 8 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7490411
Default Alt Text
D16926.id.diff (2 KB)
Attached To
Mode
D16926: Improve PhutilConsole rendering support for ANSI escape sequences
Attached
Detach File
Event Timeline
Log In to Comment