cli-table / cli-table3

Pretty unicode tables for the command line
MIT License
515 stars 44 forks source link

wordWrap still trims messages #315

Closed TranVanDung-Leo closed 1 year ago

TranVanDung-Leo commented 1 year ago

When I show error.stack of an Error Example: Error("This article shows how to fetch GraphQL data in React with the useQuery hook and attach the result to your UI. You'll also learn how Apollo Client simplifies data management code by tracking error and loading states for you. { data: This article shows how to fetch GraphQL data in React with the useQuery hook and attach the result to your UI. You'll also learn how Apollo Client \n simplifies data management code by tracking error and loading states for you, data2: This article shows how to fetch GraphQL data in React with the useQuery hook and attach the result to your UI. You'll also learn how Apollo Client simplifies data management code by tracking error and loading states for you}");

image

speedytwenty commented 1 year ago

Please provide the code that produces the table with this behavior for attempting to reproduce your issue.

TranVanDung-Leo commented 1 year ago
try {
  throw new Error("This article shows how to fetch GraphQL data in React with the useQuery hook and attach the result to your UI. You'll also learn how Apollo Client simplifies data management code by tracking error and loading states for you. { data: This article shows how to fetch GraphQL data in React with the useQuery hook and attach the result to your UI. You'll also learn how Apollo Client \n simplifies data management code by tracking error and loading states for you, data2: This article shows how to fetch GraphQL data in React with the useQuery hook and attach the result to your UI. You'll also learn how Apollo Client simplifies data management code by tracking error and loading states for you}");
} catch (error) {
  var table = new Table({
      head: [String(error)],
      colWidths: [74],
      wordWrap: true,
   });
  table.push([
     error.stack
        .split(/\n+/)
        .map((line) => line.trim())
        .filter((line) => line.startsWith("at "))
        .join("\n"),
    ]);
   console.log(table.toString());
}
speedytwenty commented 1 year ago

"Words" (non-space delimited strings) that exceed your column width are being truncated instead of wrapped.

Try adding the option wrapOnWordBoundary: false to your table options.

This option is described here.

Eg.

  var table = new Table({
      head: [String(error)],
      colWidths: [74],
      wordWrap: true,
      wrapOnWordBoundary: false,
   });