-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix width calc w/ certain new ANSI escapes
Fixes width calculations that were off when table contained terminal hyperlink ANSI escape codes, which are some newer kind of ANSI escape codes, supported by some terminals, such as iTerm. This was accomplished by replacing regexes with use of the [strip-ansi](https://www.npmjs.com/package/strip-ansi) module, which presumably has more up-to-date regexes that know how to deal with these newer ANSI escape codes.
- Loading branch information
Showing
5 changed files
with
93 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
*/ | ||
|
||
var Table = require('../lib'); | ||
var hyperlinker = require('hyperlinker'); | ||
|
||
/** | ||
* Example. | ||
|
@@ -22,12 +23,16 @@ table.push( | |
|
||
console.log(table.toString()); | ||
|
||
|
||
/* compact */ | ||
var table = new Table({ | ||
head: ['Rel', 'Change', 'By', 'When'] | ||
, colWidths: [6, 21, 25, 17] | ||
, style : {compact : true, 'padding-left' : 1} | ||
head: ['Rel', 'Change', 'By', 'Link', 'When'] | ||
, style: { | ||
'padding-left': 1 | ||
, 'padding-right': 1 | ||
, head: [] | ||
, border: [] | ||
} | ||
, colWidths: [6, 21, 25, 17, 17] | ||
}); | ||
|
||
table.push( | ||
|
@@ -39,6 +44,20 @@ table.push( | |
|
||
console.log(table.toString()); | ||
|
||
/* with hyperlinks */ | ||
var table = new Table({ | ||
head: ['Rel', 'Change', 'By', 'Link', 'When'] | ||
, colWidths: [6, 21, 25, 17, 17] | ||
, style : {compact : true, 'padding-left' : 1} | ||
}); | ||
|
||
table.push( | ||
['v0.1', 'testing something cool', '[email protected]', hyperlinker('link', 'https://adobe.com'), '7 minutes ago'] | ||
, ['v0.1', 'testing something cool', '[email protected]', hyperlinker('link', 'https://adobe.com'), '8 minutes ago'] | ||
); | ||
|
||
console.log(table.toString()); | ||
|
||
/* headless */ | ||
var headless_table = new Table(); | ||
headless_table.push(['v0.1', 'Testing something cool', '[email protected]', '7 minutes ago']); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
*/ | ||
|
||
require('should'); | ||
var hyperlinker = require('hyperlinker'); | ||
|
||
var Table = require('../'); | ||
|
||
|
@@ -43,6 +44,37 @@ module.exports = { | |
table.toString().should.eql(expected.join("\n")); | ||
}, | ||
|
||
'test table with ANSI hyperlink escape codes': function (){ | ||
var table = new Table({ | ||
head: ['Rel', 'Change', 'By', 'Link', 'When'] | ||
, colWidths: [6, 21, 25, 17, 17] | ||
, style : {compact : true, 'padding-left' : 1, head: [], border: []} | ||
}); | ||
|
||
table.push( | ||
['v0.1', 'Testing something cool', '[email protected]', hyperlinker('link', 'https://adobe.com'), '7 minutes ago'] | ||
, ['v0.1', 'Testing something cool', '[email protected]', hyperlinker('link', 'https://adobe.com'), '8 minutes ago'] | ||
); | ||
|
||
var expected = [ | ||
'┌──────┬─────────────────────┬─────────────────────────┬─────────────────┬─────────────────┐' | ||
, '│ Rel │ Change │ By │ Link │ When │' | ||
, '├──────┼─────────────────────┼─────────────────────────┼─────────────────┼─────────────────┤' | ||
, '│ v0.1 │ Testing something … │ [email protected] │ \x1B]8;;https://adobe.com\x07link\x1B]8;;\x07 │ 7 minutes ago │' | ||
, '│ v0.1 │ Testing something … │ [email protected] │ \x1B]8;;https://adobe.com\x07link\x1B]8;;\x07 │ 8 minutes ago │' | ||
, '└──────┴─────────────────────┴─────────────────────────┴─────────────────┴─────────────────┘' | ||
// '┌──────┬─────────────────────┬─────────────────────────┬─────────────────┐' | ||
// , '│ Rel │ Change │ By │ When │' | ||
// , '├──────┼─────────────────────┼─────────────────────────┼─────────────────┤' | ||
// , '│ v0.1 │ Testing something … │ [email protected] │ 7 minutes ago │' | ||
// , '├──────┼─────────────────────┼─────────────────────────┼─────────────────┤' | ||
// , '│ v0.1 │ Testing something … │ [email protected] │ 8 minutes ago │' | ||
// , '└──────┴─────────────────────┴─────────────────────────┴─────────────────┘' | ||
]; | ||
|
||
table.toString().should.eql(expected.join("\n")); | ||
}, | ||
|
||
'test width property': function (){ | ||
var table = new Table({ | ||
head: ['Cool'], | ||
|