gajus / table

Formats data into a string table.
Other
900 stars 77 forks source link

Terminal links are broken #113

Open ericbiewener opened 4 years ago

ericbiewener commented 4 years ago

I'm testing this with the exact test case from this repo:

const { table } = require('table')

const OSC = '\u001B]';
const BEL = '\u0007';
const SEP = ';';
const url = 'https://example.com';
const text = 'This is a link to example.com';

const link = [
  OSC,
  '8',
  SEP,
  SEP,
  url,
  BEL,
  text,
  OSC,
  '8',
  SEP,
  SEP,
  BEL
].join('');

console.log(table([[link]]));

Output:

╔═══════════════════════════════╗
║ ttps://example.comThis is a link to exa         ║
║ ttps://exammple.com           ║
╚═══════════════════════════════╝

Additionally, if I change the text variable to be something shorter, i.e. foo, it throws an error:

Error: Subject parameter value width cannot be greater than the container width.
    at alignString (/Users/ericbiewener/Repos/Walmart/github-api/node_modules/table/dist/alignString.js:78:11)
    at /Users/ericbiewener/Repos/Walmart/github-api/node_modules/table/dist/alignTableData.js:27:41
    at Array.map (<anonymous>)
    at /Users/ericbiewener/Repos/Walmart/github-api/node_modules/table/dist/alignTableData.js:21:18
    at Array.map (<anonymous>)
    at alignTableData (/Users/ericbiewener/Repos/Walmart/github-api/node_modules/table/dist/alignTableData.js:20:15)
    at table (/Users/ericbiewener/Repos/Walmart/github-api/node_modules/table/dist/table.js:102:38)
    at Object.<anonymous> (/Users/ericbiewener/Repos/Walmart/github-api/src/test.js:24:13)
    at Module._compile (internal/modules/cjs/loader.js:759:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)

From testing, it appears that error gets thrown if text is shorter than url.

I'm using zsh, node v12.2.0, and OSX 10.15.5.

mizdra commented 2 years ago

Probably, this problem is caused by slice-ansi problem.

https://github.com/chalk/slice-ansi/issues/31 is not completely fixed, ~but it seems to be fixed only in the case of no wrapping. This fix has been released in slice-ansi 5.0.0.~

~Therefore, upgrading the slice-ansi version to 5.0.0 may fix the problem in the no-wrapping case.~

~On the other hand, slice-ansi 5.0.0 is a Pure ESM. Importing a Pure ESM requires that the importer also be an ESM. To import a Pure ESM, the import source must also be an ESM, i.e., it must wait for the work of https://github.com/gajus/table/pull/194.~


I'm sorry, I have misunderstood something. https://github.com/chalk/slice-ansi/pull/32 was just adding the test.