cli-table / cli-table3

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

feat: ability to set/override wordWrap and wrapOnWordBoundary options per cell #303

Closed shazron closed 2 years ago

shazron commented 2 years ago

Description

This adds the ability to set wordWrap and wrapOnWordBoundary options per cell, instead of it being set globally via the table options.

Use case is for when you want one column to have wrapOnWordBoundary=false, and another column with wrapOnWordBoundary=true (see screenshot and sample code)

Sample Code

const Table = require("cli-table3");

let table = new Table({
  style: { head: [], border: [] },
  colWidths: [15, 50],
  wordWrap: true,
  wrapOnWordBoundary: true
});

table.push(
  ['URLs', 'Description'],
  [{ content: 'https://en.wikipedia.org/wiki/Voyager_program', wrapOnWordBoundary: false }, { content: 'The Voyager program is an American scientific program that employs two robotic interstellar probes, Voyager 1 and Voyager 2. They were launched in 1977 to take advantage of a favorable alignment of Jupiter and Saturn, to fly near them while collecting data for transmission back to Earth. After launch the decision was taken to send Voyager 2 near Uranus and Neptune to collect data for transmission back to Earth.'}],
  [{ content: 'https://en.wikipedia.org/wiki/SpaceX', wrapOnWordBoundary: false }, { content: 'Space Exploration Technologies Corp. (doing business as SpaceX) is an American spacecraft manufacturer, space launch provider, and a satellite communications corporation headquartered in Hawthorne, California. SpaceX was founded in 2002 by Elon Musk, with the goal of reducing space transportation costs to enable the colonization of Mars. SpaceX manufactures the Falcon 9 and Falcon Heavy launch vehicles, several rocket engines, Cargo Dragon, crew spacecraft, and Starlink communications satellites.' }]
);

console.log(table.toString())

Screenshot

image
shazron commented 2 years ago

Unit tests added.

shazron commented 2 years ago

I know there is the hyperlink option, but you can imagine instead of urls, there could be a long identifier in the column, like npm package names, etc

shazron commented 2 years ago

@speedytwenty any chance of this getting pulled in and released? Thanks!

speedytwenty commented 2 years ago

The CI tests didn't execute for this PR. Not sure why or how to induce them. Must be something with first-time contributors and github. Once we can trigger these so we have a record of passing tests, I can get it merged.

shazron commented 2 years ago

You have to configure your test.yml like so, with the pull_request section: https://github.com/adobe/aio-cli-plugin-app/blob/8ca3187eb887336a6f4246e8a586ab24dd99d3a7/.github/workflows/node.js.yml#L6-L10

Here's the whole reference for pull_request (which you have empty) in your test.yml: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request

shazron commented 2 years ago

FWIW, until you've fixed up your CI issue, I have included the video of my tests passing:

https://user-images.githubusercontent.com/36107/188873002-1f657985-717c-4154-8c7f-b1371bf0c1e0.mp4

speedytwenty commented 2 years ago

I apologize for the delay between responses. You've caught me during my peak busy time of the year.

I'm quite sure the CI issue is a github bug. I had glanced at the PR before you added tests, and there was an option to approve you as a new contributor to execute the GA workflow but that option disappeared after you pushed another commit.

I suggest we try this:

  1. Squash your commits and let's see if the approve option returns.
  2. If not, open a new PR and I should be able to approve it then.
shazron commented 2 years ago

@speedytwenty thanks! I've squashed all 3 commits into one. I see "1 workflow awaiting approval" so I think it may have worked

shazron commented 2 years ago

@speedytwenty thank you for the merge! any chance there can be a new release?