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

Automatic style detection #22

Open
fabiospampinato opened this issue Nov 12, 2021 · 3 comments
Open

Automatic style detection #22

fabiospampinato opened this issue Nov 12, 2021 · 3 comments

Comments

@fabiospampinato
Copy link

It'd be cool, although probably a bit unnecessary and overcomplicated, if for example when truncating at the end the style of the character preceding the ellipses is detected and the ellipsis is written using the same style.

@fabiospampinato fabiospampinato changed the title Automatic color detection Automatic style detection Nov 12, 2021
@sindresorhus
Copy link
Owner

sindresorhus commented Nov 17, 2021

Can you show an example on how you would use this? (Including an example string before and after)

@fabiospampinato
Copy link
Author

Example use case (basically any line that uses any styles):

import {color} from 'specialist';
import truncate from 'cli-truncate';
import width from 'cli-width';

// Example - Code
const lineCurrent = truncate ( `${color.cyan ( 'title' )} ${color.dim ( 'desc'.repeat ( 1000 ) )}`, width () );
const lineWanted = truncate ( `${color.cyan ( 'title' )} ${color.dim ( 'desc'.repeat ( 1000 ).slice ( 0, width () - 7 ) )}${color.dim ( '…' )}`, width () ); // I don't want to write this, it's just a hard-coded way to produce the wanted output

console.log ( 'Example - Visual - Current' );
console.log ( lineCurrent );

console.log ();

console.log ( 'Example - Visual - Wanted' );
console.log ( lineWanted );

Example visual output (basically the ellipsis just looks nice given the style at the truncation point):

Screen Shot 2021-11-17 at 12 07 44

@sindresorhus
Copy link
Owner

Yeah, I like that. That's really how it should work.

Also, the fact that it currently makes the truncation character bold in your example, seems like a bug.

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

No branches or pull requests

2 participants