Skip to content
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

Fix a bunch of issues #30

Merged
merged 9 commits into from
Mar 3, 2019
Merged

Conversation

stroncium
Copy link
Contributor

@stroncium stroncium commented Feb 27, 2019

Added tests, fixed incorrect treatment of rows which masked problem with tokenizer to proper way to treat tokens.


Fixes #23
Fixes #24
Fixes #25
Fixes #26
Fixes #27

@stroncium stroncium changed the title fixes #26, fixes #27 fixes #23, fixes #25, fixes #26, fixes #27 Feb 27, 2019
@stroncium
Copy link
Contributor Author

Turned out, #23 was depending on both #26 and #25(which also fixes #27), so I merged them all into one PR.

@stroncium stroncium mentioned this pull request Feb 27, 2019
@stroncium stroncium changed the title fixes #23, fixes #25, fixes #26, fixes #27 fixes #23, fixes #24, fixes #25, fixes #26, fixes #27 Feb 27, 2019
@stroncium
Copy link
Contributor Author

Proper tests for #24 (part about leading spaces) require previous fixes in this PR, so I merged this fix here too.

@stroncium stroncium changed the title fixes #23, fixes #24, fixes #25, fixes #26, fixes #27 fixes #23, #24, #25, #26, #27 Feb 27, 2019
@vadimdemedes
Copy link

Hey @stroncium, great work! Would you be able to copy test cases from https://github.com/chalk/wrap-ansi/pull/29/files#diff-1dd241c4cd3fd1dd89c570cee98b79dd into your PR to verify your fixes cover more stuff, so that I can close my PR?

@stroncium
Copy link
Contributor Author

@vadimdemedes Most of them were already there, added remaining except this one:

test('trim beginning of string if it starts with a space and not wrapped into background color escape', t => {
	const res = t.is(m(chalk.green(' hello '), 10, {hard: true, trim: false});
	t.is(res, chalk.green('hello '));
});

as I do believe that there is a mistake and it shouldn't be trimmed with trim:false.

@vadimdemedes
Copy link

Hey @stroncium, PR works great overall, there's only one issue I was able to find:

const chalk = require('chalk')
const figures = require('figures')
const wrapAnsi = require('.')

const str = [
	`${chalk.green('?')} ${chalk.bold('select packages to update')}`,
	'',
	`${chalk.yellow('other')}`,
	`${figures.pointer} ${figures.circle} standard-version ${chalk.green('devDep')} ${chalk.bold('MISSING > 5.0.0')} ${chalk.blue('https://github.com/conventional-changelog/standard-version#readme')}`,
	''
].join('\n')

console.log(wrapAnsi(str, 64, {hard: true, trim: false}))

Produces the following output:

cleanshot 2019-02-28 at 22 36 14 2x

Link is moved over to the next line, instead of being wrapped as well. Here's the expected output:

cleanshot 2019-02-28 at 22 37 08 2x

Would you be able to look into it?

@sindresorhus sindresorhus changed the title fixes #23, #24, #25, #26, #27 Fix a bunch of issues Mar 1, 2019
@stroncium
Copy link
Contributor Author

@vadimdemedes It actually isn't a regression, and it was there before and this behavior is locked in testcases. It boils down to following expectation failing:

t.is(m('AAA WWWWWWWW', 7, {hard: true, trim: false}), 'AAA WWW\nWWWWW'); // produces 'AAA \nWWWWWWW\nW'

// CC @sindresorhus
However, I looked into it and it actually seems to make more sense to do it that way. So I've implemented a simple heuristics on how to break words longer than columns in hard mode(minimizing number of breaks) using which would probably be a good idea.
It broke test breaks strings longer than "cols" characters(line 53) in part of exact breakdown of strings, so I propose to change it
Old expectation:

...
fox
jumpe
d
over
...

New expectation:

fox j
umped
over

Arguably, in this particular case neither option is looking quite pretty, but for real life purposes it should work good, and it fixes the problem stated above for example.

@vadimdemedes
Copy link

Works great, awesome work @stroncium!

@sindresorhus
Copy link
Member

@stroncium Yes, the change makes sense to me.

@sindresorhus sindresorhus merged commit c084e3e into chalk:master Mar 3, 2019
@sindresorhus
Copy link
Member

Really great work on this, @stroncium 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants