summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2021-07-07 21:26:30 +0530
committerGitHub <noreply@github.com>2021-07-07 08:56:30 -0700
commita8dcf9e2617999223f586403c200dea5601bec5f (patch)
tree336eeb2400e29abf3314eccf824a61d521a1f8c5
parente3a4e9cf11438948ddd86a7ebdac344190acafa8 (diff)
fix(extensions/console): left align table entries (#11295)
-rw-r--r--cli/tests/unit/console_test.ts88
-rw-r--r--extensions/console/02_console.js9
2 files changed, 46 insertions, 51 deletions
diff --git a/cli/tests/unit/console_test.ts b/cli/tests/unit/console_test.ts
index 268659d98..0fb75c89f 100644
--- a/cli/tests/unit/console_test.ts
+++ b/cli/tests/unit/console_test.ts
@@ -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 │
└───────┴───┴───┴───┘
`,
);
diff --git a/extensions/console/02_console.js b/extensions/console/02_console.js
index 05f149cfe..6f2ed0c0e 100644
--- a/extensions/console/02_console.js
+++ b/extensions/console/02_console.js
@@ -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;
}