chalk / slice-ansi

Slice a string with ANSI escape codes
MIT License
47 stars 21 forks source link

Slice links created by terminal-link #31

Open vadimdemedes opened 4 years ago

vadimdemedes commented 4 years ago

Currently this module doesn't support slicing links created by https://github.com/sindresorhus/terminal-link, it results in invalid output. For example:

const sliceAnsi = require('slice-ansi');
const terminalLink = require('terminal-link');

const link = terminalLink('Google', 'https://google.com');
sliceAnsi(link, 0, 6);
// Actual => \u001b[8;;https://googlm\u0007Googl\u001b[0m
// Expected (same as input) => \u001b]8;;https://google.com\u0007Google\u001b]8;;\u0007
sindresorhus commented 4 years ago

For anyone that wants to work on this, see https://github.com/chalk/wrap-ansi/commit/0e49047e85508c75f394b854db835f8b48e020a7 by @nicholaschiasson for implementation and test inspiration.