Skip to content

Commit

Permalink
Make make-table duospace-aware
Browse files Browse the repository at this point in the history
  • Loading branch information
japhb committed Sep 23, 2023
1 parent 37a9797 commit 52ba9a4
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/MUGS/App/CLI.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Terminal::Capabilities;
use Terminal::ANSIColor;
use Text::MiscUtils::Layout;
use Terminal::LineEditor::RawTerminalInput;

use MUGS::Core;
Expand Down Expand Up @@ -111,25 +112,29 @@ class MUGS::App::CLI is MUGS::App::LocalUI {
}

method make-table(@columns, @data) {
# XXXX: Correct for duowidth
my @widths = @columns.map(*.chars // 1);
my @widths = @columns.map({ duospace-width(~$_) || 1 });
for @data -> @row {
die "Table data has wrong number of columns" if @row != @columns;

for @row.kv -> $i, $v {
@widths[$i] max= $v.chars;
@widths[$i] max= duospace-width(~$v);
}
}

my $format = @widths.map('%-' ~ * ~ 's').join(' ');
my sub layout-row(@row) {
@row.kv.map(-> $i, $v {
$v ~ ' ' x (@widths[$i] - duospace-width(~$v))
}).join(' ')
}

my @lines;
@lines.push: colored(sprintf($format, |@columns), 'bold');
@lines.push: sprintf($format, |$_) for @data;
my $header = layout-row(@columns);
@lines.push: $!ansi ?? colored($header, 'bold') !! $header;
@lines.push: layout-row($_) for @data;
@lines
}



#| Connect to server and authenticate as a valid user
method ensure-authenticated-session(Str $server, Str $universe) {
my $decoded = self.decode-server($server);
Expand Down

0 comments on commit 52ba9a4

Please sign in to comment.