-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Width calculations are off when table contains terminal hyperlink control characters #147
Comments
If there is a way that I can hint what the actual width of the data is or provide the naked string, that would be very useful. |
As a data point, I noticed that https://github.com/oclif/cli-ux#clitable doesn't seem to have this problem. #!/usr/bin/env ts-node --transpile-only
// cli_ux_table_hyperlink_test.ts
import { cli } from 'cli-ux';
import Table from 'cli-table';
import hyperlinker from 'hyperlinker';
const data = [
{ url: 'https://google.com', name: 'Google' },
{ url: 'https://adobe.com', name: 'Adobe' },
];
console.log('Table without hyperlinks\n');
const tableWithoutHyperlinks = new Table({ head: ['Link', 'Web site'] });
for (const row of data) {
const { name, url } = row;
tableWithoutHyperlinks.push([url, name]);
}
console.log(tableWithoutHyperlinks.toString());
console.log('\nTable with hyperlinks\n');
const tableWithHyperlinks = new Table({ head: ['Link', 'Web site'] });
for (const row of data) {
const { name, url } = row;
tableWithHyperlinks.push([hyperlinker('Link', url), name]);
}
console.log(tableWithHyperlinks.toString());
// ---------- cli-ux table -----------
console.log('\ncli-ux table with hyperlinks\n');
const dataWithLinks = [
{ url: hyperlinker('Link', 'https://google.com'), name: 'Google' },
{ url: hyperlinker('Link', 'https://adobe.com'), name: 'Adobe' },
];
cli.table(dataWithLinks, {
url: { header: 'Link', minWidth: 20 },
name: { header: 'Web site', minWidth: 20 },
}); Running this yields:
|
I think the magic that makes https://github.com/oclif/cli-ux#clitable work for these links is: |
chrean
added a commit
that referenced
this issue
Nov 17, 2021
Fix width calc w/ certain new ANSI escapes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using this code:
The output is:
As you can see, the table rendering is messed up for the column with hyperlinks.
The text was updated successfully, but these errors were encountered: