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

don't trim wrapped lines #93

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

apaleslimghost
Copy link

unwrapped/before/after:

Screenshot 2024-04-22 at 18 17 12

@apaleslimghost
Copy link
Author

oh, this fails some tests. is the current behaviour expected?

@Caesarovich
Copy link
Collaborator

That seems like a good idea. I will try it out later this afternoon to see how it reacts with padding options.

In the mean time, it would be nice to add some tests to check if it works perfectly with the padding/wrapping Boxen does.

You can update the snapshots and commit the changes for CI to complete the tests.

@Caesarovich Caesarovich self-assigned this Apr 24, 2024
@Caesarovich
Copy link
Collaborator

Hi,

I'm back after some experimenting. Here I've made a simple test to see how text looks like with the trim: false option.

import wrapAnsi from 'wrap-ansi'


const text = `
    Hello

I like cookies   very much

anticonstitucional indeed agree
`



console.log(text)

console.log('----- 20')

console.log(wrapAnsi(text, 20, {
	hard: true,
	trim: false
}))

console.log('----- 10')

console.log(wrapAnsi(text, 10, {
	hard: true,
	trim: false
}))

console.log('----- 8')

console.log(wrapAnsi(text, 8, {
	hard: true,
	trim: false
}))

console.log('----- 6')

console.log(wrapAnsi(text, 6, {
	hard: true,
	trim: false
}))

Here is what the output looks like:

    Hello

I like cookies   very much

anticonstitucional indeed agree

----- 20

    Hello

I like cookies   
very much

anticonstitucional 
indeed agree

----- 10

    Hello

I like 
cookies   
very much

anticonsti
tucional 
indeed 
agree

----- 8

    
Hello

I like 
cookies 
  very 
much

anticons
titucion
al 
indeed 
agree

----- 6

    
Hello

I like
 cooki
es   
very 
much

antico
nstitu
cional
 
indeed
 agree

It does keep the formatting of the original text (The hello with 4 spaces on the left), which is nice. But it also doesn't trim spaces between words when they are wrapped to a new line. With a result like:

I like 
cookies 
  very 
much

Which looks very unpleasing to me. Is that the intended way wrap-ansi should handle it @sindresorhus ?
Although this only show up when we crank down the max-width a lot, so we might disregard it.

What are your thoughts on this @sindresorhus ?

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

Successfully merging this pull request may close these issues.

None yet

2 participants