()
| 8 | /[\u001b\u009b][[\]#;?()]*(?:(?:(?:[^\W_]*;?[^\W_]*)\u0007)|(?:(?:[0-9]{1,4}(;[0-9]{0,4})*)?[~0-9=<>cf-nqrtyA-PRZ]))/g |
| 9 | |
| 10 | const create = () => { |
| 11 | const colors = { enabled: true, visible: true, styles: {}, keys: {} } |
| 12 | |
| 13 | if (class="st">'FORCE_COLOR' in process.env) { |
| 14 | colors.enabled = process.env.FORCE_COLOR !== class="st">'0' |
| 15 | } |
| 16 | |
| 17 | const ansi = (style) => { |
| 18 | let open = (style.open = `\u001b[${style.codes[0]}m`) |
| 19 | let close = (style.close = `\u001b[${style.codes[1]}m`) |
| 20 | let regex = (style.regex = new RegExp(`\\u001b\\[${style.codes[1]}m`, class="st">'g')) |
| 21 | style.wrap = (input, newline) => { |
| 22 | if (input.includes(close)) input = input.replace(regex, close + open) |
| 23 | let output = open + input + close |
| 24 | class="cm">// see https://github.com/chalk/chalk/pull/92, thanks to the |
| 25 | class="cm">// chalk contributors for this fix. However, we've confirmed that |
| 26 | class="cm">// this issue is also present in Windows terminals |
| 27 | return newline ? output.replace(/\r*\n/g, `${close}$&${open}`) : output |
| 28 | } |
| 29 | return style |
| 30 | } |
| 31 | |
| 32 | const wrap = (style, input, newline) => { |
| 33 | return typeof style === class="st">'function' ? style(input) : style.wrap(input, newline) |
| 34 | } |
| 35 | |
| 36 | const style = (input, stack) => { |
| 37 | if (input === class="st">'' || input == null) return class="st">'' |
| 38 | if (colors.enabled === false) return input |
| 39 | if (colors.visible === false) return class="st">'' |
| 40 | let str = class="st">'' + input |
| 41 | let nl = str.includes(class="st">'\n') |
| 42 | let n = stack.length |
| 43 | if (n > 0 && stack.includes(class="st">'unstyle')) { |
| 44 | stack = [...new Set([class="st">'unstyle', ...stack])].reverse() |
| 45 | } |
| 46 | while (n-- > 0) str = wrap(colors.styles[stack[n]], str, nl) |
| 47 | return str |
| 48 | } |
| 49 | |
| 50 | const define = (name, codes, type) => { |
| 51 | colors.styles[name] = ansi({ name, codes }) |
| 52 | let keys = colors.keys[type] || (colors.keys[type] = []) |
| 53 | keys.push(name) |
| 54 | |
| 55 | Reflect.defineProperty(colors, name, { |
| 56 | configurable: true, |
| 57 | enumerable: true, |
| 58 | set(value) { |
| 59 | colors.alias(name, value) |
| 60 | }, |
| 61 | get() { |
| 62 | let color = (input) => style(input, color.stack) |
| 63 | Reflect.setPrototypeOf(color, colors) |
| 64 | color.stack = this.stack ? this.stack.concat(name) : [name] |
| 65 | return color |
| 66 | }, |
| 67 | }) |
no test coverage detected