pax_global_header00006660000000000000000000000064141177127110014514gustar00rootroot0000000000000052 comment=99ada39978a880d8e0c060b6a972b552fddbb380 wrap-ansi-8.0.1/000077500000000000000000000000001411771271100134235ustar00rootroot00000000000000wrap-ansi-8.0.1/.editorconfig000066400000000000000000000002571411771271100161040ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 wrap-ansi-8.0.1/.gitattributes000066400000000000000000000000231411771271100163110ustar00rootroot00000000000000* text=auto eol=lf wrap-ansi-8.0.1/.github/000077500000000000000000000000001411771271100147635ustar00rootroot00000000000000wrap-ansi-8.0.1/.github/funding.yml000066400000000000000000000000651411771271100171410ustar00rootroot00000000000000github: [sindresorhus, Qix-] tidelift: npm/wrap-ansi wrap-ansi-8.0.1/.github/security.md000066400000000000000000000002631411771271100171550ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. wrap-ansi-8.0.1/.github/workflows/000077500000000000000000000000001411771271100170205ustar00rootroot00000000000000wrap-ansi-8.0.1/.github/workflows/main.yml000066400000000000000000000006451411771271100204740ustar00rootroot00000000000000name: CI on: - push - pull_request jobs: test: name: Node.js ${{ matrix.node-version }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: node-version: - 14 - 12 steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} - run: npm install - run: npm test wrap-ansi-8.0.1/.gitignore000066400000000000000000000000431411771271100154100ustar00rootroot00000000000000node_modules yarn.lock .nyc_output wrap-ansi-8.0.1/.npmrc000066400000000000000000000000231411771271100145360ustar00rootroot00000000000000package-lock=false wrap-ansi-8.0.1/index.js000077500000000000000000000132221411771271100150730ustar00rootroot00000000000000import stringWidth from 'string-width'; import stripAnsi from 'strip-ansi'; import ansiStyles from 'ansi-styles'; const ESCAPES = new Set([ '\u001B', '\u009B', ]); const END_CODE = 39; const ANSI_ESCAPE_BELL = '\u0007'; const ANSI_CSI = '['; const ANSI_OSC = ']'; const ANSI_SGR_TERMINATOR = 'm'; const ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`; const wrapAnsiCode = code => `${ESCAPES.values().next().value}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`; const wrapAnsiHyperlink = uri => `${ESCAPES.values().next().value}${ANSI_ESCAPE_LINK}${uri}${ANSI_ESCAPE_BELL}`; // Calculate the length of words split on ' ', ignoring // the extra characters added by ansi escape codes const wordLengths = string => string.split(' ').map(character => stringWidth(character)); // Wrap a long word across multiple rows // Ansi escape codes do not count towards length const wrapWord = (rows, word, columns) => { const characters = [...word]; let isInsideEscape = false; let isInsideLinkEscape = false; let visible = stringWidth(stripAnsi(rows[rows.length - 1])); for (const [index, character] of characters.entries()) { const characterLength = stringWidth(character); if (visible + characterLength <= columns) { rows[rows.length - 1] += character; } else { rows.push(character); visible = 0; } if (ESCAPES.has(character)) { isInsideEscape = true; isInsideLinkEscape = characters.slice(index + 1).join('').startsWith(ANSI_ESCAPE_LINK); } if (isInsideEscape) { if (isInsideLinkEscape) { if (character === ANSI_ESCAPE_BELL) { isInsideEscape = false; isInsideLinkEscape = false; } } else if (character === ANSI_SGR_TERMINATOR) { isInsideEscape = false; } continue; } visible += characterLength; if (visible === columns && index < characters.length - 1) { rows.push(''); visible = 0; } } // It's possible that the last row we copy over is only // ansi escape characters, handle this edge-case if (!visible && rows[rows.length - 1].length > 0 && rows.length > 1) { rows[rows.length - 2] += rows.pop(); } }; // Trims spaces from a string ignoring invisible sequences const stringVisibleTrimSpacesRight = string => { const words = string.split(' '); let last = words.length; while (last > 0) { if (stringWidth(words[last - 1]) > 0) { break; } last--; } if (last === words.length) { return string; } return words.slice(0, last).join(' ') + words.slice(last).join(''); }; // The wrap-ansi module can be invoked in either 'hard' or 'soft' wrap mode // // 'hard' will never allow a string to take up more than columns characters // // 'soft' allows long words to expand past the column length const exec = (string, columns, options = {}) => { if (options.trim !== false && string.trim() === '') { return ''; } let returnValue = ''; let escapeCode; let escapeUrl; const lengths = wordLengths(string); let rows = ['']; for (const [index, word] of string.split(' ').entries()) { if (options.trim !== false) { rows[rows.length - 1] = rows[rows.length - 1].trimStart(); } let rowLength = stringWidth(rows[rows.length - 1]); if (index !== 0) { if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) { // If we start with a new word but the current row length equals the length of the columns, add a new row rows.push(''); rowLength = 0; } if (rowLength > 0 || options.trim === false) { rows[rows.length - 1] += ' '; rowLength++; } } // In 'hard' wrap mode, the length of a line is never allowed to extend past 'columns' if (options.hard && lengths[index] > columns) { const remainingColumns = (columns - rowLength); const breaksStartingThisLine = 1 + Math.floor((lengths[index] - remainingColumns - 1) / columns); const breaksStartingNextLine = Math.floor((lengths[index] - 1) / columns); if (breaksStartingNextLine < breaksStartingThisLine) { rows.push(''); } wrapWord(rows, word, columns); continue; } if (rowLength + lengths[index] > columns && rowLength > 0 && lengths[index] > 0) { if (options.wordWrap === false && rowLength < columns) { wrapWord(rows, word, columns); continue; } rows.push(''); } if (rowLength + lengths[index] > columns && options.wordWrap === false) { wrapWord(rows, word, columns); continue; } rows[rows.length - 1] += word; } if (options.trim !== false) { rows = rows.map(row => stringVisibleTrimSpacesRight(row)); } const pre = [...rows.join('\n')]; for (const [index, character] of pre.entries()) { returnValue += character; if (ESCAPES.has(character)) { const {groups} = new RegExp(`(?:\\${ANSI_CSI}(?\\d+)m|\\${ANSI_ESCAPE_LINK}(?.*)${ANSI_ESCAPE_BELL})`).exec(pre.slice(index).join('')) || {groups: {}}; if (groups.code !== undefined) { const code = Number.parseFloat(groups.code); escapeCode = code === END_CODE ? undefined : code; } else if (groups.uri !== undefined) { escapeUrl = groups.uri.length === 0 ? undefined : groups.uri; } } const code = ansiStyles.codes.get(Number(escapeCode)); if (pre[index + 1] === '\n') { if (escapeUrl) { returnValue += wrapAnsiHyperlink(''); } if (escapeCode && code) { returnValue += wrapAnsiCode(code); } } else if (character === '\n') { if (escapeCode && code) { returnValue += wrapAnsiCode(escapeCode); } if (escapeUrl) { returnValue += wrapAnsiHyperlink(escapeUrl); } } } return returnValue; }; // For each newline, invoke the method separately export default function wrapAnsi(string, columns, options) { return String(string) .normalize() .replace(/\r\n/g, '\n') .split('\n') .map(line => exec(line, columns, options)) .join('\n'); } wrap-ansi-8.0.1/license000066400000000000000000000021351411771271100147710ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (https://sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. wrap-ansi-8.0.1/package.json000066400000000000000000000020441411771271100157110ustar00rootroot00000000000000{ "name": "wrap-ansi", "version": "8.0.1", "description": "Wordwrap a string with ANSI escape codes", "license": "MIT", "repository": "chalk/wrap-ansi", "funding": "https://github.com/chalk/wrap-ansi?sponsor=1", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, "type": "module", "exports": "./index.js", "engines": { "node": ">=12" }, "scripts": { "test": "xo && nyc ava" }, "files": [ "index.js" ], "keywords": [ "wrap", "break", "wordwrap", "wordbreak", "linewrap", "ansi", "styles", "color", "colour", "colors", "terminal", "console", "cli", "string", "tty", "escape", "formatting", "rgb", "256", "shell", "xterm", "log", "logging", "command-line", "text" ], "dependencies": { "ansi-styles": "^6.1.0", "string-width": "^5.0.1", "strip-ansi": "^7.0.1" }, "devDependencies": { "ava": "^3.15.0", "chalk": "^4.1.2", "coveralls": "^3.1.1", "has-ansi": "^5.0.1", "nyc": "^15.1.0", "xo": "^0.44.0" } } wrap-ansi-8.0.1/readme.md000066400000000000000000000046421411771271100152100ustar00rootroot00000000000000# wrap-ansi > Wordwrap a string with [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles) ## Install ``` $ npm install wrap-ansi ``` ## Usage ```js import chalk from 'chalk'; import wrapAnsi from 'wrap-ansi'; const input = 'The quick brown ' + chalk.red('fox jumped over ') + 'the lazy ' + chalk.green('dog and then ran away with the unicorn.'); console.log(wrapAnsi(input, 20)); ``` ## API ### wrapAnsi(string, columns, options?) Wrap words to the specified column width. #### string Type: `string` String with ANSI escape codes. Like one styled by [`chalk`](https://github.com/chalk/chalk). Newline characters will be normalized to `\n`. #### columns Type: `number` Number of columns to wrap the text to. #### options Type: `object` ##### hard Type: `boolean`\ Default: `false` By default the wrap is soft, meaning long words may extend past the column width. Setting this to `true` will make it hard wrap at the column width. ##### wordWrap Type: `boolean`\ Default: `true` By default, an attempt is made to split words at spaces, ensuring that they don't extend past the configured columns. If wordWrap is `false`, each column will instead be completely filled splitting words as necessary. ##### trim Type: `boolean`\ Default: `true` Whitespace on all lines is removed by default. Set this option to `false` if you don't want to trim. ## Related - [slice-ansi](https://github.com/chalk/slice-ansi) - Slice a string with ANSI escape codes - [cli-truncate](https://github.com/sindresorhus/cli-truncate) - Truncate a string to a specific width in the terminal - [chalk](https://github.com/chalk/chalk) - Terminal string styling done right - [jsesc](https://github.com/mathiasbynens/jsesc) - Generate ASCII-only output from Unicode strings. Useful for creating test fixtures. ## Maintainers - [Sindre Sorhus](https://github.com/sindresorhus) - [Josh Junon](https://github.com/qix-) - [Benjamin Coe](https://github.com/bcoe) ---
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
wrap-ansi-8.0.1/screenshot.png000066400000000000000000000261031411771271100163100ustar00rootroot00000000000000PNG  IHDRzB\}PLTE----,J+Hxͳr缓ܼ-,PלLָ-,DgM-,+Eʢ,&eY(C' ZTfϺbPxղQ?.J@!}|O>Vh+֒JWn֒L}ЀW%g眦ݤLG9u}Z|CȚgWPp`'ZZҘY\GK/0g1't0޺])۫Au҈gNcGu}#Z҃4Y9퟉="Iu%U;ӽ~޻j%"#A2vYˆKΈGĈqAQu}Zz6]Wg|. X0D)潤e%~WV[VZmBUkI9tW#m>˴eY9\@K253#>H:ǾKgjg Tܷ宷lJ$9:gq$;),T-Q'WhJ~t ΕsWi5}s {n/˟[Cc|n=_KTCZC8t[wh Gh΁j=7ZXeg}摖ZKPUKRe([mбAY')8YH==j>a2(L-y7rDѠZr~Aa*S&eLky-9\2-e6Jo"t#m)ZV< _~kS6'7PNgyT7{@͌@O;kJ-]_-S,5N֞{WFK.>y0H-jYw4;Mb#Zrr5O⩇hak޽>)Z*z<k$C a%%F=osQ] }6w#hYu3Me$3 @urM%WAPfq>_,G`rGUZjhI7[Z~Di*Dq35:pq]{g;;r.H9+7y tÉ "k8>Z10z2jE)-ar ] q-$0-7RcrY;:_L],Xy9d HK::zZ p%x7% JVUHOzׯV׿WNVOŹw 6NHKZh vx?j-1wD> fI_@%:>x1__ۚW&QL%kǼL4GђN*YYGK`͛̽B[%;@C64`t:Wy9h;H"4;XC9A;)3'ZsET<嫞ג6Yٴ9uKeXߵ䱐EGZ䉵j# Hu8hpH)6P-0'Gj' 5b,Z-&Au }-唇ma~u- k9o~TZ26<߬ )_dINK(8dZJ$גsk1҃h9}k'TFXˌc2:Ӳn4,>ZRNKѪ#6-+2asxYKU?W]9G:Z[| W24@ex-t:hYUKPP>Gkҳ}2LKa=y 8ThO G:ZM| SK~~598NB֒B -{YIz/ Yur r(gq9aRD9^г9rHK-8yVR3P61AqC%^277CՒ>F^%Z-9e ùSkSPuQDG-P:4 fcjY}* %$=Loz&NZ_TGLe --gx %8zg+3<-ѕ>uVjJֱg7MW]XNP!6%@NYmQiZ=%K3~9 Wf-,~($Cqc'l*<-E蓝%^l|r£28]+obW8)u Hy|enX87AЪ 钉G0kd% /5zPGXMZZzՒXݾ-y?Ǎ Z~`9*:S` qh)GAk fj kɿuAxZR/`Ő e3z򥱒/FqS@D&$-ep-7Pf -"?94v>n8Z~ SOG5?^gY7āPFN9:GKo[?T.'m40֧Rei}d֒0*7wSM%hGXNG&1r}Zi] [-cPk)+p1-~;sǢ`1\q%T,B痖og*h9HDKﶉG)\Kf-puXzXzXfLaaa9_22>͠k98^SdYS(J`gVf|jiY,r`nrcqj̮ћP))l)8h)EҖiR">ֿ2o)kmymC5VdVn PCRC{D[%cދ l/MZP?P>W MƆDY]WS֬o ]*EqjeT-lPKƆ!mC`K|r,qϋ%}Ra[sJkR7@K8te{rtP"*Xꐛ˅Jq]&6%K뻱4AЗ+_'vXہ t-%+ My`☹ p1a/\U)N.-\m0ŸӶأln|F=9e0:4p PkLb tۑϜhLcT B`K]p޺=\( n!QƆH7&ve}M43֍#]lL!RWm o,ѐh(g@ ~EhʨJRp1ua23)9Nd>L8^3]٧Q^ ]U3d4CCW<al_nɶn\QԵ:ꎥ6 b.C1RS:t$te+%.y QYVzIV(bKx[&R` T#T71j bqTb^Gj@C2T6Xųu˾3dC$y?3hGt}M_1}`I  K4 h<`p!75XºO}%SkXyGWbpHէv@$BK>na ,o'0T _h 7:hT]R=vpő5No/  ` ݌+ܑN&pڒaC!?8~;yRz t xRÃ=B,hKjmXV(bDp8S\Wf;=y]emU{dlp\pr MĒ L.FgZ Gː1O`;X Xz(W` 3cKI&((XpX{dCM&9,a#s|{g8q*kBjqDd=YM9D3AHQ^W/μuk]M/u2ޑ ˭7ΌYC:?zE;>oY\P"mw<ʤ7jZFO_}_\7ޙ|i?':^Ty^qo(fXhǀWzbk|Б,p\vD-wxs"~$YL}5d0!rpB-E1aBD&(䩛!(fCU1ppƒ,F:­7/f0ÕJFKZQjTs" Xpv!ʑǹ%sC!@R%.okK*5W L:,]Q#e8zb}` 7Wy)QpWk?K*eH~WPs4NCG] #Hm >h=:ѣ|65N73uj=tyhZJ"0F:,5Vm!.- ! Hf_ @Ci%UVuݴ#LE@(-ˡ4d(čG, hYmM9tB,}K2Lypqz%GM=yAΕ3_FTٚuykӭTL6-rpv2e?ʋ{IGޕ2 Dl kw蒮U*v F%@.%)eNFt:}Ǧevz&Y|/7YGir\LǚԂlck560u}h;bnELZV$hu-}'H7 ׍֭^NzTy2|qJz"S >SrzHsk}k'&=TGX-CiQ:p؋GV{%PPP)o{[s a ծVpu}9BǡewE݇C j?;L2qܡPe:> |qhY)ۡj Q[\i>]yp$2JVB#4(>I>F-%jiv.׶"R"܂lOFoO+µޜ:"-yكE>J}U jYPh(CZ -[nݙFZ-ޑS H]A#4(%IqhQ]ڦ~?{nc|*Z:py2|@-hflkG8IN֪#;?9Vtq+z2z0K9n6QkGFK&yh-k&^3R"ؒާO2_KQ#NGO`")޳rz+;,p 2~B!B!B!B!B!B!|lͲi#IR!$f?K2*ȊHZL6OdfSB!BNN >rcD^[ދZ~|dz@&$&ujꙒ/)sk"`G&b },t CϔlŲm]eN=c¦+gZ6,e&>u\=x(,' }3%[eO&ғZ|>ڞJ CcbBe9]:;\$)N-G1&SG'Fx˱}-i.!虒-Բ_Nh2L?J$8ZVP3=SZ]QK6[01L6j)v8Sh Z>j2=SZZG4ic a3%[eE(-ʌ4 @Z`C jٰd|?ئd꒙|%2Mnڋ"KXLrYTȁ?B!B!B!B!B!Q>6IENDB`wrap-ansi-8.0.1/test.js000077500000000000000000000216451411771271100147530ustar00rootroot00000000000000import test from 'ava'; import chalk from 'chalk'; import hasAnsi from 'has-ansi'; import stripAnsi from 'strip-ansi'; import wrapAnsi from './index.js'; chalk.level = 1; // When "hard" is false const fixture = 'The quick brown ' + chalk.red('fox jumped over ') + 'the lazy ' + chalk.green('dog and then ran away with the unicorn.'); const fixture2 = '12345678\n901234567890'; const fixture3 = '12345678\n901234567890 12345'; const fixture4 = '12345678\n'; const fixture5 = '12345678\n '; test('wraps string at 20 characters', t => { const result = wrapAnsi(fixture, 20); t.is(result, 'The quick brown \u001B[31mfox\u001B[39m\n\u001B[31mjumped over \u001B[39mthe lazy\n\u001B[32mdog and then ran\u001B[39m\n\u001B[32maway with the\u001B[39m\n\u001B[32municorn.\u001B[39m'); t.true(stripAnsi(result).split('\n').every(line => line.length <= 20)); }); test('wraps string at 30 characters', t => { const result = wrapAnsi(fixture, 30); t.is(result, 'The quick brown \u001B[31mfox jumped\u001B[39m\n\u001B[31mover \u001B[39mthe lazy \u001B[32mdog and then ran\u001B[39m\n\u001B[32maway with the unicorn.\u001B[39m'); t.true(stripAnsi(result).split('\n').every(line => line.length <= 30)); }); test('does not break strings longer than "cols" characters', t => { const result = wrapAnsi(fixture, 5, {hard: false}); t.is(result, 'The\nquick\nbrown\n\u001B[31mfox\u001B[39m\n\u001B[31mjumped\u001B[39m\n\u001B[31mover\u001B[39m\n\u001B[31m\u001B[39mthe\nlazy\n\u001B[32mdog\u001B[39m\n\u001B[32mand\u001B[39m\n\u001B[32mthen\u001B[39m\n\u001B[32mran\u001B[39m\n\u001B[32maway\u001B[39m\n\u001B[32mwith\u001B[39m\n\u001B[32mthe\u001B[39m\n\u001B[32municorn.\u001B[39m'); t.true(stripAnsi(result).split('\n').some(line => line.length > 5)); }); test('handles colored string that wraps on to multiple lines', t => { const result = wrapAnsi(chalk.green('hello world') + ' hey!', 5, {hard: false}); const lines = result.split('\n'); t.true(hasAnsi(lines[0])); t.true(hasAnsi(lines[1])); t.false(hasAnsi(lines[2])); }); test('does not prepend newline if first string is greater than "cols"', t => { const result = wrapAnsi(chalk.green('hello') + '-world', 5, {hard: false}); t.is(result.split('\n').length, 1); }); // When "hard" is true test('breaks strings longer than "cols" characters', t => { const result = wrapAnsi(fixture, 5, {hard: true}); t.is(result, 'The\nquick\nbrown\n\u001B[31mfox j\u001B[39m\n\u001B[31mumped\u001B[39m\n\u001B[31mover\u001B[39m\n\u001B[31m\u001B[39mthe\nlazy\n\u001B[32mdog\u001B[39m\n\u001B[32mand\u001B[39m\n\u001B[32mthen\u001B[39m\n\u001B[32mran\u001B[39m\n\u001B[32maway\u001B[39m\n\u001B[32mwith\u001B[39m\n\u001B[32mthe\u001B[39m\n\u001B[32munico\u001B[39m\n\u001B[32mrn.\u001B[39m'); t.true(stripAnsi(result).split('\n').every(line => line.length <= 5)); }); test('removes last row if it contained only ansi escape codes', t => { const result = wrapAnsi(chalk.green('helloworld'), 2, {hard: true}); t.true(stripAnsi(result).split('\n').every(x => x.length === 2)); }); test('does not prepend newline if first word is split', t => { const result = wrapAnsi(chalk.green('hello') + 'world', 5, {hard: true}); t.is(result.split('\n').length, 2); }); test('takes into account line returns inside input', t => { t.is(wrapAnsi(fixture2, 10, {hard: true}), '12345678\n9012345678\n90'); }); test('word wrapping', t => { t.is(wrapAnsi(fixture3, 15), '12345678\n901234567890\n12345'); }); test('no word-wrapping', t => { const result = wrapAnsi(fixture3, 15, {wordWrap: false}); t.is(result, '12345678\n901234567890 12\n345'); const result2 = wrapAnsi(fixture3, 5, {wordWrap: false}); t.is(result2, '12345\n678\n90123\n45678\n90 12\n345'); const rsult3 = wrapAnsi(fixture5, 5, {wordWrap: false}); t.is(rsult3, '12345\n678\n'); const result4 = wrapAnsi(fixture, 5, {wordWrap: false}); t.is(result4, 'The q\nuick\nbrown\n\u001B[31mfox j\u001B[39m\n\u001B[31mumped\u001B[39m\n\u001B[31mover\u001B[39m\n\u001B[31m\u001B[39mthe l\nazy \u001B[32md\u001B[39m\n\u001B[32mog an\u001B[39m\n\u001B[32md the\u001B[39m\n\u001B[32mn ran\u001B[39m\n\u001B[32maway\u001B[39m\n\u001B[32mwith\u001B[39m\n\u001B[32mthe u\u001B[39m\n\u001B[32mnicor\u001B[39m\n\u001B[32mn.\u001B[39m'); }); test('no word-wrapping and no trimming', t => { const result = wrapAnsi(fixture3, 13, {wordWrap: false, trim: false}); t.is(result, '12345678\n901234567890 \n12345'); const result2 = wrapAnsi(fixture4, 5, {wordWrap: false, trim: false}); t.is(result2, '12345\n678\n'); const result3 = wrapAnsi(fixture5, 5, {wordWrap: false, trim: false}); t.is(result3, '12345\n678\n '); const result4 = wrapAnsi(fixture, 5, {wordWrap: false, trim: false}); t.is(result4, 'The q\nuick \nbrown\n \u001B[31mfox \u001B[39m\njumpe\nd ove\nr \u001B[39mthe\n lazy\n \u001B[32mdog \u001B[39m\nand t\nhen r\nan aw\nay wi\nth th\ne uni\ncorn.\u001B[39m'); }); test('supports fullwidth characters', t => { t.is(wrapAnsi('안녕하세', 4, {hard: true}), '안녕\n하세'); }); test('supports unicode surrogate pairs', t => { t.is(wrapAnsi('a\uD83C\uDE00bc', 2, {hard: true}), 'a\n\uD83C\uDE00\nbc'); t.is(wrapAnsi('a\uD83C\uDE00bc\uD83C\uDE00d\uD83C\uDE00', 2, {hard: true}), 'a\n\uD83C\uDE00\nbc\n\uD83C\uDE00\nd\n\uD83C\uDE00'); }); test('#23, properly wraps whitespace with no trimming', t => { t.is(wrapAnsi(' ', 2, {trim: false}), ' \n '); t.is(wrapAnsi(' ', 2, {trim: false, hard: true}), ' \n '); }); test('#24, trims leading and trailing whitespace only on actual wrapped lines and only with trimming', t => { t.is(wrapAnsi(' foo bar ', 3), 'foo\nbar'); t.is(wrapAnsi(' foo bar ', 6), 'foo\nbar'); t.is(wrapAnsi(' foo bar ', 42), 'foo bar'); t.is(wrapAnsi(' foo bar ', 42, {trim: false}), ' foo bar '); }); test('#24, trims leading and trailing whitespace inside a color block only on actual wrapped lines and only with trimming', t => { t.is(wrapAnsi(chalk.blue(' foo bar '), 6), chalk.blue('foo\nbar')); t.is(wrapAnsi(chalk.blue(' foo bar '), 42), chalk.blue('foo bar')); t.is(wrapAnsi(chalk.blue(' foo bar '), 42, {trim: false}), chalk.blue(' foo bar ')); }); test('#25, properly wraps whitespace between words with no trimming', t => { t.is(wrapAnsi('foo bar', 3), 'foo\nbar'); t.is(wrapAnsi('foo bar', 3, {hard: true}), 'foo\nbar'); t.is(wrapAnsi('foo bar', 3, {trim: false}), 'foo\n \nbar'); t.is(wrapAnsi('foo bar', 3, {trim: false, hard: true}), 'foo\n \nbar'); }); test('#26, does not multiplicate leading spaces with no trimming', t => { t.is(wrapAnsi(' a ', 10, {trim: false}), ' a '); t.is(wrapAnsi(' a ', 10, {trim: false}), ' a '); }); test('#27, does not remove spaces in line with ansi escapes when no trimming', t => { t.is(wrapAnsi(chalk.bgGreen(` ${chalk.black('OK')} `), 100, {trim: false}), chalk.bgGreen(` ${chalk.black('OK')} `)); t.is(wrapAnsi(chalk.bgGreen(` ${chalk.black('OK')} `), 100, {trim: false}), chalk.bgGreen(` ${chalk.black('OK')} `)); t.is(wrapAnsi(chalk.bgGreen(' hello '), 10, {hard: true, trim: false}), chalk.bgGreen(' hello ')); }); test('#35, wraps hyperlinks, preserving clickability in supporting terminals', t => { const result1 = wrapAnsi('Check out \u001B]8;;https://www.example.com\u0007my website\u001B]8;;\u0007, it is \u001B]8;;https://www.example.com\u0007supercalifragilisticexpialidocious\u001B]8;;\u0007.', 16, {hard: true}); t.is(result1, 'Check out \u001B]8;;https://www.example.com\u0007my\u001B]8;;\u0007\n\u001B]8;;https://www.example.com\u0007website\u001B]8;;\u0007, it is\n\u001B]8;;https://www.example.com\u0007supercalifragili\u001B]8;;\u0007\n\u001B]8;;https://www.example.com\u0007sticexpialidocio\u001B]8;;\u0007\n\u001B]8;;https://www.example.com\u0007us\u001B]8;;\u0007.'); const result2 = wrapAnsi(`Check out \u001B]8;;https://www.example.com\u0007my \uD83C\uDE00 ${chalk.bgGreen('website')}\u001B]8;;\u0007, it ${chalk.bgRed('is \u001B]8;;https://www.example.com\u0007super\uD83C\uDE00califragilisticexpialidocious\u001B]8;;\u0007')}.`, 16, {hard: true}); t.is(result2, 'Check out \u001B]8;;https://www.example.com\u0007my 🈀\u001B]8;;\u0007\n\u001B]8;;https://www.example.com\u0007\u001B[42mwebsite\u001B[49m\u001B]8;;\u0007, it \u001B[41mis\u001B[49m\n\u001B[41m\u001B]8;;https://www.example.com\u0007super🈀califragi\u001B]8;;\u0007\u001B[49m\n\u001B[41m\u001B]8;;https://www.example.com\u0007listicexpialidoc\u001B]8;;\u0007\u001B[49m\n\u001B[41m\u001B]8;;https://www.example.com\u0007ious\u001B]8;;\u0007\u001B[49m.'); }); test('covers non-SGR/non-hyperlink ansi escapes', t => { t.is(wrapAnsi('Hello, \u001B[1D World!', 8), 'Hello,\u001B[1D\nWorld!'); t.is(wrapAnsi('Hello, \u001B[1D World!', 8, {trim: false}), 'Hello, \u001B[1D \nWorld!'); }); test('#39, normalizes newlines', t => { t.is(wrapAnsi('foobar\r\nfoobar\r\nfoobar\nfoobar', 3, {hard: true}), 'foo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar'); t.is(wrapAnsi('foo bar\r\nfoo bar\r\nfoo bar\nfoo bar', 3), 'foo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar'); });