Page MenuHomePhabricator

D11328.diff
No OneTemporary

D11328.diff

diff --git a/src/console/PhutilConsoleTable.php b/src/console/PhutilConsoleTable.php
--- a/src/console/PhutilConsoleTable.php
+++ b/src/console/PhutilConsoleTable.php
@@ -124,12 +124,18 @@
$columns = array();
foreach ($this->columns as $key => $column) {
- $columns[] = PhutilConsoleFormatter::formatString(
- '**%s**',
- $this->alignString(
+ if (!$this->shouldAddSpacing($key, $column)) {
+ $column_str = $column['title'];
+ } else {
+ $column_str = $this->alignString(
$column['title'],
$this->getWidth($key),
- idx($column, 'align', self::ALIGN_LEFT)));
+ idx($column, 'align', self::ALIGN_LEFT));
+ }
+
+ $columns[] = PhutilConsoleFormatter::formatString(
+ '**%s**',
+ $column_str);
}
$output .= $this->formatRow($columns);
@@ -148,10 +154,14 @@
$columns = array();
foreach ($this->columns as $key => $column) {
- $columns[] = $this->alignString(
- (string)idx($data, $key, ''),
- $this->getWidth($key),
- idx($column, 'align', self::ALIGN_LEFT));
+ if (!$this->shouldAddSpacing($key, $column)) {
+ $columns[] = (string)idx($data, $key, '');
+ } else {
+ $columns[] = $this->alignString(
+ (string)idx($data, $key, ''),
+ $this->getWidth($key),
+ idx($column, 'align', self::ALIGN_LEFT));
+ }
}
$output .= $this->formatRow($columns);
@@ -180,6 +190,27 @@
/* -( Internals )---------------------------------------------------------- */
/**
+ * Returns if the specified column should have spacing added.
+ *
+ * @return bool
+ */
+ private function shouldAddSpacing($key, $column) {
+ if (!$this->borders) {
+ if (last_key($this->columns) === $key) {
+ if (idx($column, 'align', self::ALIGN_LEFT) === self::ALIGN_LEFT) {
+ // Don't add extra spaces to this column since it's the last column,
+ // left aligned, and we're not showing borders. This prevents
+ // unnecessary empty lines from appearing when the extra spaces
+ // wrap around the terminal.
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+
+ /**
* Returns the column IDs.
*
* @return list<string>

File Metadata

Mime Type
text/plain
Expires
Nov 11 2025, 7:43 PM (5 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
11799338
Default Alt Text
D11328.diff (2 KB)

Event Timeline