Exemplo n.º 1
0
 public function testUTF8ConsoleStrlen()
 {
     $strings = array("" => 0, "" => 0, "x" => 1, "東" => 2);
     foreach ($strings as $str => $expect) {
         $this->assertEqual($expect, phutil_utf8_console_strlen($str), 'Console Length of ' . $str);
     }
 }
Exemplo n.º 2
0
 public function testUTF8ConsoleStrlen()
 {
     $strings = array('' => 0, "" => 0, 'x' => 1, "東" => 2, "x͠y" => 2, "東͠y" => 3, "x" => 1, "x" => 1);
     foreach ($strings as $str => $expect) {
         $this->assertEqual($expect, phutil_utf8_console_strlen($str), pht('Console Length of %s', $str));
     }
 }
Exemplo n.º 3
0
 protected function drawView()
 {
     $indent_depth = 6;
     $indent_string = str_repeat(' ', $indent_depth);
     if ($this->bullet !== null) {
         $bullet = $this->bullet . ' ';
         $indent_depth = $indent_depth + phutil_utf8_console_strlen($bullet);
     } else {
         $bullet = '';
     }
     $output = array();
     foreach ($this->getItems() as $item) {
         if ($this->wrap) {
             $item = phutil_console_wrap($item, $indent_depth);
         }
         $output[] = $indent_string . $bullet . $item;
     }
     return $this->drawLines($output);
 }
Exemplo n.º 4
0
 /**
  * Get human-readable linter statuses, padded to fixed width.
  *
  * @return map<string, string> Human-readable linter status names.
  */
 private function getStatusMap()
 {
     $text_map = array('configured' => pht('CONFIGURED'), 'available' => pht('AVAILABLE'), 'error' => pht('ERROR'));
     $sizes = array();
     foreach ($text_map as $key => $string) {
         $sizes[$key] = phutil_utf8_console_strlen($string);
     }
     $longest = max($sizes);
     foreach ($text_map as $key => $string) {
         if ($sizes[$key] < $longest) {
             $text_map[$key] .= str_repeat(' ', $longest - $sizes[$key]);
         }
     }
     $text_map['padding'] = str_repeat(' ', $longest);
     return $text_map;
 }
 protected function alignString($string, $width, $align)
 {
     $num_padding = $width - 2 * $this->padding - phutil_utf8_console_strlen($string);
     switch ($align) {
         case self::ALIGN_LEFT:
             $num_left_padding = 0;
             $num_right_padding = $num_padding;
             break;
         case self::ALIGN_CENTER:
             $num_left_padding = (int) ($num_padding / 2);
             $num_right_padding = $num_padding - $num_left_padding;
             break;
         case self::ALIGN_RIGHT:
             $num_left_padding = $num_padding;
             $num_right_padding = 0;
             break;
     }
     $left_padding = str_repeat(' ', $num_left_padding);
     $right_padding = str_repeat(' ', $num_right_padding);
     return array($left_padding, $string, $right_padding);
 }
 public function run()
 {
     $output = array();
     $status = $this->getArgument('status');
     $owner = $this->getArgument('owner');
     $order = $this->getArgument('order');
     $limit = $this->getArgument('limit');
     $this->tasks = $this->loadManiphestTasks($status == 'all' ? 'any' : $status, $owner ? $this->findOwnerPhid($owner) : $this->getUserPHID(), $order, $limit);
     if (!$this->tasks) {
         echo "No tasks found.\n";
         return 0;
     }
     $task_rows = array();
     foreach ($this->tasks as $task) {
         $output = array();
         // Render the "T123" column.
         $task_id = "T" . $task['id'];
         $formatted_task_id = phutil_console_format('**%s**', $task_id);
         $output['id'] = array('text' => $formatted_task_id, 'len' => phutil_utf8_console_strlen($task_id));
         // Render the "Title" column.
         $formatted_title = rtrim($task['title']);
         $output['title'] = array('text' => $formatted_title, 'len' => phutil_utf8_console_strlen($formatted_title));
         // Render the "Priority" column.
         switch ($task['priority']) {
             case 'Needs Triage':
                 $color = 'magenta';
                 break;
             case 'Unbreak Now!':
                 $color = 'red';
                 break;
             case 'High':
                 $color = 'yellow';
                 break;
             case 'Normal':
                 $color = 'green';
                 break;
             case 'Low':
                 $color = 'blue';
                 break;
             case 'Wishlist':
                 $color = 'cyan';
                 break;
             default:
                 $color = 'white';
                 break;
         }
         $formatted_priority = phutil_console_format("<bg:{$color}> </bg> %s", $task['priority']);
         $output['priority'] = array('text' => $formatted_priority, 'len' => phutil_utf8_console_strlen($task['priority']) + 2);
         // Render the "Status" column.
         if ($task['status']) {
             $status_text = 'Closed';
             $status_color = 'red';
         } else {
             $status_text = 'Open';
             $status_color = 'green';
         }
         $formatted_status = phutil_console_format("<bg:{$status_color}> </bg> %s", $status_text);
         $output['status'] = array('text' => $formatted_status, 'len' => phutil_utf8_console_strlen('status') + 2);
         $task_rows[] = $output;
     }
     // Find the longest string in each column.
     $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(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;
 }