1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00

fix(extensions/console): left align table entries (#11295)

This commit is contained in:
Divy Srivastava 2021-07-07 21:26:30 +05:30 committed by GitHub
parent e3a4e9cf11
commit a8dcf9e261
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 51 deletions

View file

@ -1292,8 +1292,8 @@ unitTest(function consoleTable(): void {
`┌───────┬────────┐
(idx) Values
a "test"
b 1
a "test"
b 1
`,
);
@ -1305,8 +1305,8 @@ unitTest(function consoleTable(): void {
`┌───────┬────┐
(idx) c
a
b 30
a
b 30
`,
);
@ -1316,13 +1316,13 @@ unitTest(function consoleTable(): void {
assertEquals(
stripColor(out.toString()),
`┌───────┬───────┬───────┬────────┐
(idx) 0 1 Values
(idx) 0 1 Values
0 1
1 2
2 3 [ 4 ]
3 5 6
4 [ 7 ] [ 8 ]
0 1
1 2
2 3 [ 4 ]
3 5 6
4 [ 7 ] [ 8 ]
`,
);
@ -1334,10 +1334,10 @@ unitTest(function consoleTable(): void {
`┌────────────┬────────┐
(iter idx) Values
0 1
1 2
2 3
3 "test"
0 1
1 2
2 3
3 "test"
`,
);
@ -1354,8 +1354,8 @@ unitTest(function consoleTable(): void {
`┌────────────┬─────┬────────┐
(iter idx) Key Values
0 1 "one"
1 2 "two"
0 1 "one"
1 2 "two"
`,
);
@ -1371,13 +1371,13 @@ unitTest(function consoleTable(): void {
assertEquals(
stripColor(out.toString()),
`┌───────┬───────────┬───────────────────┬────────┐
(idx) c e Values
(idx) c e Values
a true
b { d: 10 } [ 1, 2, [Array] ]
f "test"
g
h
a true
b { d: 10 } [ 1, 2, [Array] ]
f "test"
g
h
`,
);
@ -1393,13 +1393,13 @@ unitTest(function consoleTable(): void {
assertEquals(
stripColor(out.toString()),
`┌───────┬────────┬──────────────────────┬────┬────────┐
(idx) 0 1 a Values
(idx) 0 1 a Values
0 1
1 "test"
2 false
3 10
4 "test" { b: 20, c: "test" }
0 1
1 "test"
2 false
3 10
4 "test" { b: 20, c: "test" }
`,
);
@ -1459,9 +1459,9 @@ unitTest(function consoleTable(): void {
`┌───────┬─────────┐
(idx) Values
0 "Hello"
1 "你好"
2 "Amapá"
0 "Hello"
1 "你好"
2 "Amapá"
`,
);
@ -1476,8 +1476,8 @@ unitTest(function consoleTable(): void {
`┌───────┬───┬───┐
(idx) 0 1
0 1 2
1 3 4
0 1 2
1 3 4
`,
);
@ -1489,9 +1489,9 @@ unitTest(function consoleTable(): void {
`┌───────┬───┐
(idx) b
1 5
2
3 6
1 5
2
3 6
`,
);
@ -1503,10 +1503,10 @@ unitTest(function consoleTable(): void {
`┌───────┬───┬───┐
(idx) a b
0 0
1 1 1
2 2
3 3 3
0 0
1 1 1
2 2
3 3 3
`,
);
@ -1521,10 +1521,10 @@ unitTest(function consoleTable(): void {
`┌───────┬───┬───┬───┐
(idx) a b c
0 0
1 1 1
2 2
3 3 3
0 0
1 1 1
2 2
3 3 3
`,
);

View file

@ -79,7 +79,6 @@
MapPrototypeForEach,
Error,
ErrorCaptureStackTrace,
MathCeil,
MathAbs,
MathMax,
MathMin,
@ -192,12 +191,8 @@
for (let i = 0; i < row.length; i++) {
const cell = row[i];
const len = getStringWidth(cell);
const needed = (columnWidths[i] - len) / 2;
// round(needed) + ceil(needed) will always add up to the amount
// of spaces we need while also left justifying the output.
out += `${StringPrototypeRepeat(" ", needed)}${cell}${
StringPrototypeRepeat(" ", MathCeil(needed))
}`;
const needed = columnWidths[i] - len;
out += `${cell}${StringPrototypeRepeat(" ", needed)}`;
if (i !== row.length - 1) {
out += tableChars.middle;
}