Changeset e29cc2e for trip-planner-front/node_modules/wrap-ansi/index.js
- Timestamp:
- 11/25/21 22:08:24 (3 years ago)
- Branches:
- master
- Children:
- 8d391a1
- Parents:
- 59329aa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trip-planner-front/node_modules/wrap-ansi/index.js
r59329aa re29cc2e 11 11 const END_CODE = 39; 12 12 13 const ANSI_ESCAPE_BELL = '\u0007'; 14 const ANSI_CSI = '['; 15 const ANSI_OSC = ']'; 16 const ANSI_SGR_TERMINATOR = 'm'; 17 const ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`; 18 19 const wrapAnsi = code => `${ESCAPES.values().next().value}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`; 20 const wrapAnsiHyperlink = uri => `${ESCAPES.values().next().value}${ANSI_ESCAPE_LINK}${uri}${ANSI_ESCAPE_BELL}`; 13 const wrapAnsi = code => `${ESCAPES.values().next().value}[${code}m`; 21 14 22 15 // Calculate the length of words split on ' ', ignoring … … 29 22 const characters = [...word]; 30 23 31 let isInsideEscape = false; 32 let isInsideLinkEscape = false; 24 let insideEscape = false; 33 25 let visible = stringWidth(stripAnsi(rows[rows.length - 1])); 34 26 … … 44 36 45 37 if (ESCAPES.has(character)) { 46 isInsideEscape = true; 47 isInsideLinkEscape = characters.slice(index + 1).join('').startsWith(ANSI_ESCAPE_LINK); 38 insideEscape = true; 39 } else if (insideEscape && character === 'm') { 40 insideEscape = false; 41 continue; 48 42 } 49 43 50 if (isInsideEscape) { 51 if (isInsideLinkEscape) { 52 if (character === ANSI_ESCAPE_BELL) { 53 isInsideEscape = false; 54 isInsideLinkEscape = false; 55 } 56 } else if (character === ANSI_SGR_TERMINATOR) { 57 isInsideEscape = false; 58 } 59 44 if (insideEscape) { 60 45 continue; 61 46 } … … 77 62 78 63 // Trims spaces from a string ignoring invisible sequences 79 const stringVisibleTrimSpacesRight = str ing=> {80 const words = str ing.split(' ');64 const stringVisibleTrimSpacesRight = str => { 65 const words = str.split(' '); 81 66 let last = words.length; 82 67 … … 90 75 91 76 if (last === words.length) { 92 return str ing;77 return str; 93 78 } 94 79 … … 96 81 }; 97 82 98 // The wrap-ansi module can be invoked in either 'hard' or 'soft' wrap mode 83 // The wrap-ansi module can be invoked 84 // in either 'hard' or 'soft' wrap mode 99 85 // 100 // 'hard' will never allow a string to take up more than columns characters 86 // 'hard' will never allow a string to take up more 87 // than columns characters 101 88 // 102 89 // 'soft' allows long words to expand past the column length … … 106 93 } 107 94 108 let returnValue = ''; 95 let pre = ''; 96 let ret = ''; 109 97 let escapeCode; 110 let escapeUrl;111 98 112 99 const lengths = wordLengths(string); … … 115 102 for (const [index, word] of string.split(' ').entries()) { 116 103 if (options.trim !== false) { 117 rows[rows.length - 1] = rows[rows.length - 1].trim Start();104 rows[rows.length - 1] = rows[rows.length - 1].trimLeft(); 118 105 } 119 106 … … 133 120 } 134 121 135 // In 'hard' wrap mode, the length of a line is never allowed to extend past 'columns' 122 // In 'hard' wrap mode, the length of a line is 123 // never allowed to extend past 'columns' 136 124 if (options.hard && lengths[index] > columns) { 137 125 const remainingColumns = (columns - rowLength); … … 167 155 } 168 156 169 const pre = [...rows.join('\n')];157 pre = rows.join('\n'); 170 158 171 for (const [index, character] of pre.entries()) {172 ret urnValue+= character;159 for (const [index, character] of [...pre].entries()) { 160 ret += character; 173 161 174 162 if (ESCAPES.has(character)) { 175 const {groups} = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`).exec(pre.slice(index).join('')) || {groups: {}}; 176 if (groups.code !== undefined) { 177 const code = Number.parseFloat(groups.code); 178 escapeCode = code === END_CODE ? undefined : code; 179 } else if (groups.uri !== undefined) { 180 escapeUrl = groups.uri.length === 0 ? undefined : groups.uri; 181 } 163 const code = parseFloat(/\d[^m]*/.exec(pre.slice(index, index + 4))); 164 escapeCode = code === END_CODE ? null : code; 182 165 } 183 166 184 167 const code = ansiStyles.codes.get(Number(escapeCode)); 185 168 186 if (pre[index + 1] === '\n') { 187 if (escapeUrl) { 188 returnValue += wrapAnsiHyperlink(''); 189 } 190 191 if (escapeCode && code) { 192 returnValue += wrapAnsi(code); 193 } 194 } else if (character === '\n') { 195 if (escapeCode && code) { 196 returnValue += wrapAnsi(escapeCode); 197 } 198 199 if (escapeUrl) { 200 returnValue += wrapAnsiHyperlink(escapeUrl); 169 if (escapeCode && code) { 170 if (pre[index + 1] === '\n') { 171 ret += wrapAnsi(code); 172 } else if (character === '\n') { 173 ret += wrapAnsi(escapeCode); 201 174 } 202 175 } 203 176 } 204 177 205 return ret urnValue;178 return ret; 206 179 }; 207 180 … … 210 183 return String(string) 211 184 .normalize() 212 .replace(/\r\n/g, '\n')213 185 .split('\n') 214 186 .map(line => exec(line, columns, options))
Note:
See TracChangeset
for help on using the changeset viewer.