mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-26 00:32:41 +01:00
Convert arc tasks
to use PhutilConsoleTable
.
Summary: `PhutilConsoleTable` does a better job at aligning columns. We still probably need to do some work to `PhutilConsoleTable` to set a maximum width for a specified column, or elect which columns can be truncated etc but this can probably come later. Test Plan: {F167687} Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: epriestley, Korvin Differential Revision: https://secure.phabricator.com/D9601
This commit is contained in:
parent
46e0553c46
commit
9f8a23d598
1 changed files with 18 additions and 84 deletions
|
@ -39,7 +39,6 @@ EOTEXT
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getArguments() {
|
public function getArguments() {
|
||||||
return array(
|
return array(
|
||||||
'status' => array(
|
'status' => array(
|
||||||
|
@ -69,7 +68,7 @@ EOTEXT
|
||||||
),
|
),
|
||||||
'unassigned' => array(
|
'unassigned' => array(
|
||||||
'help' => 'Only show tasks that are not assigned (upforgrabs).',
|
'help' => 'Only show tasks that are not assigned (upforgrabs).',
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,27 +100,24 @@ EOTEXT
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$task_rows = array();
|
$table = id(new PhutilConsoleTable())
|
||||||
|
->setShowHeader(false)
|
||||||
|
->addColumn('id', array('title' => 'ID'))
|
||||||
|
->addColumn('title', array('title' => 'Title'))
|
||||||
|
->addColumn('priority', array('title' => 'Priority'))
|
||||||
|
->addColumn('status', array('title' => 'Status'));
|
||||||
|
|
||||||
foreach ($this->tasks as $task) {
|
foreach ($this->tasks as $task) {
|
||||||
$output = array();
|
$output = array();
|
||||||
|
|
||||||
// Render the "T123" column.
|
// Render the "T123" column.
|
||||||
$task_id = 'T'.$task['id'];
|
$task_id = 'T'.$task['id'];
|
||||||
$formatted_task_id = phutil_console_format(
|
$formatted_task_id = phutil_console_format('**%s**', $task_id);
|
||||||
'**%s**',
|
$output['id'] = $formatted_task_id;
|
||||||
$task_id);
|
|
||||||
$output['id'] = array(
|
|
||||||
'text' => $formatted_task_id,
|
|
||||||
'len' => phutil_utf8_console_strlen($task_id),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Render the "Title" column.
|
// Render the "Title" column.
|
||||||
$formatted_title = rtrim($task['title']);
|
$formatted_title = rtrim($task['title']);
|
||||||
$output['title'] = array(
|
$output['title'] = $formatted_title;
|
||||||
'text' => $formatted_title,
|
|
||||||
'len' => phutil_utf8_console_strlen($formatted_title),
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
// Render the "Priority" column.
|
// Render the "Priority" column.
|
||||||
$web_to_terminal_colors = array(
|
$web_to_terminal_colors = array(
|
||||||
|
@ -142,7 +138,7 @@ EOTEXT
|
||||||
'lightblue' => 'blue',
|
'lightblue' => 'blue',
|
||||||
'lightsky' => 'blue',
|
'lightsky' => 'blue',
|
||||||
'lightindigo' => 'magenta',
|
'lightindigo' => 'magenta',
|
||||||
'lightviolet' => 'magenta'
|
'lightviolet' => 'magenta',
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isset($task['priorityColor'])) {
|
if (isset($task['priorityColor'])) {
|
||||||
|
@ -153,10 +149,7 @@ EOTEXT
|
||||||
$formatted_priority = phutil_console_format(
|
$formatted_priority = phutil_console_format(
|
||||||
"<bg:{$color}> </bg> %s",
|
"<bg:{$color}> </bg> %s",
|
||||||
$task['priority']);
|
$task['priority']);
|
||||||
$output['priority'] = array(
|
$output['priority'] = $formatted_priority;
|
||||||
'text' => $formatted_priority,
|
|
||||||
'len' => phutil_utf8_console_strlen($task['priority']) + 2,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Render the "Status" column.
|
// Render the "Status" column.
|
||||||
if (isset($task['isClosed'])) {
|
if (isset($task['isClosed'])) {
|
||||||
|
@ -170,70 +163,15 @@ EOTEXT
|
||||||
$formatted_status = phutil_console_format(
|
$formatted_status = phutil_console_format(
|
||||||
"<bg:{$status_color}> </bg> %s",
|
"<bg:{$status_color}> </bg> %s",
|
||||||
$status_text);
|
$status_text);
|
||||||
$output['status'] = array(
|
$output['status'] = $formatted_status;
|
||||||
'text' => $formatted_status,
|
|
||||||
'len' => phutil_utf8_console_strlen('status') + 2,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
$output['status'] = array(
|
$output['status'] = '';
|
||||||
'text' => '',
|
|
||||||
'len' => 0,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$task_rows[] = $output;
|
$table->addRow($output);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the longest string in each column.
|
$table->draw();
|
||||||
$col_size = array();
|
|
||||||
foreach ($task_rows as $row) {
|
|
||||||
foreach ($row as $key => $col) {
|
|
||||||
if (empty($col_size[$key])) {
|
|
||||||
$col_size[$key] = 0;
|
|
||||||
}
|
|
||||||
$col_size[$key] = max($col_size[$key], $col['len']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine the terminal width. If we can't figure it out, assume 80.
|
|
||||||
$width = nonempty(phutil_console_get_terminal_width(), 80);
|
|
||||||
|
|
||||||
|
|
||||||
// We're going to clip the titles so they'll all fit in one line on the
|
|
||||||
// terminal. Figure out where to clip them.
|
|
||||||
$padding_between_columns = 4;
|
|
||||||
$clip_title_at = max(
|
|
||||||
// Always show at least a little bit of text even if it will make the
|
|
||||||
// UI wrap, since it's useless if we don't show anything.
|
|
||||||
16,
|
|
||||||
$width -
|
|
||||||
($col_size['id'] + $col_size['priority'] + $col_size['status'] +
|
|
||||||
($padding_between_columns * 3)));
|
|
||||||
$col_size['title'] = min($col_size['title'], $clip_title_at);
|
|
||||||
|
|
||||||
foreach ($task_rows as $key => $cols) {
|
|
||||||
$new_title = phutil_utf8_shorten($cols['title']['text'], $clip_title_at);
|
|
||||||
|
|
||||||
$task_rows[$key]['title']['len'] = phutil_utf8_console_strlen($new_title);
|
|
||||||
$task_rows[$key]['title']['text'] = $new_title;
|
|
||||||
}
|
|
||||||
|
|
||||||
$table = array();
|
|
||||||
foreach ($task_rows as $row) {
|
|
||||||
$trow = array();
|
|
||||||
foreach ($row as $col => $cell) {
|
|
||||||
$text = $cell['text'];
|
|
||||||
$pad_len = $col_size[$col] - $cell['len'];
|
|
||||||
if ($pad_len) {
|
|
||||||
$text .= str_repeat(' ', $pad_len);
|
|
||||||
}
|
|
||||||
$trow[] = $text;
|
|
||||||
}
|
|
||||||
$table[] = implode(str_repeat(' ', $padding_between_columns), $trow);
|
|
||||||
}
|
|
||||||
$table = implode("\n", $table)."\n";
|
|
||||||
|
|
||||||
echo $table;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function findOwnerPHID($owner) {
|
private function findOwnerPHID($owner) {
|
||||||
|
@ -268,11 +206,7 @@ EOTEXT
|
||||||
$find_params['order'] = ($order ? 'order-'.$order : 'order-priority');
|
$find_params['order'] = ($order ? 'order-'.$order : 'order-priority');
|
||||||
$find_params['status'] = ($status ? 'status-'.$status : 'status-open');
|
$find_params['status'] = ($status ? 'status-'.$status : 'status-open');
|
||||||
|
|
||||||
$tasks = $conduit->callMethodSynchronous(
|
return $conduit->callMethodSynchronous('maniphest.query', $find_params);
|
||||||
'maniphest.query',
|
|
||||||
$find_params);
|
|
||||||
|
|
||||||
return $tasks;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue