denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
93.41k stars 5.18k forks source link

Objects in console.table break table layout #18828

Open nicolo-ribaudo opened 1 year ago

nicolo-ribaudo commented 1 year ago

Input code

console.table([
  [
    "b0a6d0c1-7b6c-4fea-9efa-cb2629ce6068",
    {
      id: "b0a6d0c1-7b6c-4fea-9efa-cb2629ce6068",
      name: "Trenitalia",
      countryCode: "IT",
    },
  ],
  [
    "371fe41e-349c-40b7-be93-10c58fbbb95f",
    {
      id: "371fe41e-349c-40b7-be93-10c58fbbb95f",
      name: "Deutsche Bahn",
      countryCode: "DE",
    },
  ],
  [
    "55e41a17-13d4-4994-8828-ec93efab568f",
    {
      id: "55e41a17-13d4-4994-8828-ec93efab568f",
      name: "ÖBB",
      countryCode: "AT",
    },
  ],
]);

Output

┌───────┬────────────────────────────────────────┬────────────────────────────────────────────────────────────────────────────────────────────────┐
│ (idx) │ 0                                      │ 1                                                                                              │
├───────┼────────────────────────────────────────┼────────────────────────────────────────────────────────────────────────────────────────────────┤
│     0 │ "b0a6d0c1-7b6c-4fea-9efa-cb2629ce6068" │ { id: "b0a6d0c1-7b6c-4fea-9efa-cb2629ce6068", name: "Trenitalia", countryCode: "IT" }          │
│     1 │ "371fe41e-349c-40b7-be93-10c58fbbb95f" │ {
  id: "371fe41e-349c-40b7-be93-10c58fbbb95f",
  name: "Deutsche Bahn",
  countryCode: "DE"
} │
│     2 │ "55e41a17-13d4-4994-8828-ec93efab568f" │ { id: "55e41a17-13d4-4994-8828-ec93efab568f", name: "ÖBB", countryCode: "AT" }                 │
└───────┴────────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────────────────────────┘

Expected behavior

console.table should always print objects on a single line, to avoid breaking the table layout:

┌───────┬────────────────────────────────────────┬────────────────────────────────────────────────────────────────────────────────────────────────┐
│ (idx) │ 0                                      │ 1                                                                                              │
├───────┼────────────────────────────────────────┼────────────────────────────────────────────────────────────────────────────────────────────────┤
│     0 │ "b0a6d0c1-7b6c-4fea-9efa-cb2629ce6068" │ { id: "b0a6d0c1-7b6c-4fea-9efa-cb2629ce6068", name: "Trenitalia", countryCode: "IT" }          │
│     1 │ "371fe41e-349c-40b7-be93-10c58fbbb95f" │ { id: "371fe41e-349c-40b7-be93-10c58fbbb95f", name: "Deutsche Bahn", countryCode: "DE" }       │
│     2 │ "55e41a17-13d4-4994-8828-ec93efab568f" │ { id: "55e41a17-13d4-4994-8828-ec93efab568f", name: "ÖBB", countryCode: "AT" }                 │
└───────┴────────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────────────────────────┘

As an alternative, it could properly pad all the lines for multi-line values:

┌───────┬────────────────────────────────────────┬────────────────────────────────────────────────────────────────────────────────────────────────┐
│ (idx) │ 0                                      │ 1                                                                                              │
├───────┼────────────────────────────────────────┼────────────────────────────────────────────────────────────────────────────────────────────────┤
│     0 │ "b0a6d0c1-7b6c-4fea-9efa-cb2629ce6068" │ { id: "b0a6d0c1-7b6c-4fea-9efa-cb2629ce6068", name: "Trenitalia", countryCode: "IT" }          │
│     1 │ "371fe41e-349c-40b7-be93-10c58fbbb95f" │ {                                                                                              |
|       |                                        |   id: "371fe41e-349c-40b7-be93-10c58fbbb95f",                                                  |
|       |                                        |   name: "Deutsche Bahn",                                                                       |
|       |                                        |   countryCode: "DE"                                                                            |
|       |                                        | }                                                                                              |
│     2 │ "55e41a17-13d4-4994-8828-ec93efab568f" │ { id: "55e41a17-13d4-4994-8828-ec93efab568f", name: "ÖBB", countryCode: "AT" }                 │
└───────┴────────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────────────────────────┘

Environment

deno 1.32.5 (release, aarch64-apple-darwin) v8 11.2.214.9 typescript 5.0.3

bartlomieju commented 1 year ago

@crowlKats will this be fixed by https://github.com/denoland/deno/pull/18691?

crowlKats commented 1 year ago

@bartlomieju it doesnt; it actually makes it worse:

┌───────┬────────────────────────────────────────┬────────────────────────────────────────────────────────────────────────────────────────────┐
│ (idx) │ 0                                      │ 1                                                                                          │
├───────┼────────────────────────────────────────┼────────────────────────────────────────────────────────────────────────────────────────────┤
│     0 │ "b0a6d0c1-7b6c-4fea-9efa-cb2629ce6068" │ {
  id: "b0a6d0c1-7b6c-4fea-9efa-cb2629ce6068",
  name: "Trenitalia",
  countryCode: "IT"
}    │
│     1 │ "371fe41e-349c-40b7-be93-10c58fbbb95f" │ {
  id: "371fe41e-349c-40b7-be93-10c58fbbb95f",
  name: "Deutsche Bahn",
  countryCode: "DE"
} │
│     2 │ "55e41a17-13d4-4994-8828-ec93efab568f" │ {
  id: "55e41a17-13d4-4994-8828-ec93efab568f",
  name: "ÖBB",
  countryCode: "AT"
}           │
└───────┴────────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────────────────────┘