1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 07:44:48 -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 (idx) Values
a "test" a "test"
b 1 b 1
`, `,
); );
@ -1305,8 +1305,8 @@ unitTest(function consoleTable(): void {
`┌───────┬────┐ `┌───────┬────┐
(idx) c (idx) c
a a
b 30 b 30
`, `,
); );
@ -1316,13 +1316,13 @@ unitTest(function consoleTable(): void {
assertEquals( assertEquals(
stripColor(out.toString()), stripColor(out.toString()),
`┌───────┬───────┬───────┬────────┐ `┌───────┬───────┬───────┬────────┐
(idx) 0 1 Values (idx) 0 1 Values
0 1 0 1
1 2 1 2
2 3 [ 4 ] 2 3 [ 4 ]
3 5 6 3 5 6
4 [ 7 ] [ 8 ] 4 [ 7 ] [ 8 ]
`, `,
); );
@ -1334,10 +1334,10 @@ unitTest(function consoleTable(): void {
`┌────────────┬────────┐ `┌────────────┬────────┐
(iter idx) Values (iter idx) Values
0 1 0 1
1 2 1 2
2 3 2 3
3 "test" 3 "test"
`, `,
); );
@ -1354,8 +1354,8 @@ unitTest(function consoleTable(): void {
`┌────────────┬─────┬────────┐ `┌────────────┬─────┬────────┐
(iter idx) Key Values (iter idx) Key Values
0 1 "one" 0 1 "one"
1 2 "two" 1 2 "two"
`, `,
); );
@ -1371,13 +1371,13 @@ unitTest(function consoleTable(): void {
assertEquals( assertEquals(
stripColor(out.toString()), stripColor(out.toString()),
`┌───────┬───────────┬───────────────────┬────────┐ `┌───────┬───────────┬───────────────────┬────────┐
(idx) c e Values (idx) c e Values
a true a true
b { d: 10 } [ 1, 2, [Array] ] b { d: 10 } [ 1, 2, [Array] ]
f "test" f "test"
g g
h h
`, `,
); );
@ -1393,13 +1393,13 @@ unitTest(function consoleTable(): void {
assertEquals( assertEquals(
stripColor(out.toString()), stripColor(out.toString()),
`┌───────┬────────┬──────────────────────┬────┬────────┐ `┌───────┬────────┬──────────────────────┬────┬────────┐
(idx) 0 1 a Values (idx) 0 1 a Values
0 1 0 1
1 "test" 1 "test"
2 false 2 false
3 10 3 10
4 "test" { b: 20, c: "test" } 4 "test" { b: 20, c: "test" }
`, `,
); );
@ -1459,9 +1459,9 @@ unitTest(function consoleTable(): void {
`┌───────┬─────────┐ `┌───────┬─────────┐
(idx) Values (idx) Values
0 "Hello" 0 "Hello"
1 "你好" 1 "你好"
2 "Amapá" 2 "Amapá"
`, `,
); );
@ -1476,8 +1476,8 @@ unitTest(function consoleTable(): void {
`┌───────┬───┬───┐ `┌───────┬───┬───┐
(idx) 0 1 (idx) 0 1
0 1 2 0 1 2
1 3 4 1 3 4
`, `,
); );
@ -1489,9 +1489,9 @@ unitTest(function consoleTable(): void {
`┌───────┬───┐ `┌───────┬───┐
(idx) b (idx) b
1 5 1 5
2 2
3 6 3 6
`, `,
); );
@ -1503,10 +1503,10 @@ unitTest(function consoleTable(): void {
`┌───────┬───┬───┐ `┌───────┬───┬───┐
(idx) a b (idx) a b
0 0 0 0
1 1 1 1 1 1
2 2 2 2
3 3 3 3 3 3
`, `,
); );
@ -1521,10 +1521,10 @@ unitTest(function consoleTable(): void {
`┌───────┬───┬───┬───┐ `┌───────┬───┬───┬───┐
(idx) a b c (idx) a b c
0 0 0 0
1 1 1 1 1 1
2 2 2 2
3 3 3 3 3 3
`, `,
); );

View file

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