How to use ansi-regex - 9 common examples

To help you get started, we’ve selected a few ansi-regex examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github taskcluster / taskcluster-tools / src / lib / ui / terminalview.jsx View on Github external
{frame.map(line => {
            // Check if there are any ansi colors/styles
            const doubleSpace = line.match(/ {2}/g);

            if (ansiRegex().test(line)) {
              const newLine = ansiUp.ansi_to_html(line);

              return doubleSpace && doubleSpace.length ? (
                  <div>
                ) :
                <div>;
            } else if (doubleSpace &amp;&amp; doubleSpace.length) {
              return <div>{line}</div>;
            }

            return <div>{line}</div>;
          })}
        </div></div>
github DonJayamanne / pythonVSCode / src / datascience-ui / interactive-common / cell.tsx View on Github external
// Stream output needs to be wrapped in xmp so it
            // show literally. Otherwise &lt; chars start a new html element.
            mimeType = 'text/html';
            isText = true;
            isError = false;
            renderWithScrollbars = true;
            const stream = copy as nbformat.IStream;
            const formatted = concatMultilineString(stream.text);
            copy.data = {
                'text/html': formatted.includes('&lt;') ? `` : `<div>${formatted}</div>`
            };

            // Output may have goofy ascii colorization chars in it. Try
            // colorizing if we don't have html that needs 
github taskcluster / taskcluster-tools / src / push-inspector / components / terminalView.jsx View on Github external
frame.map(line =&gt; {
              // Check if there are any ansi colors/styles
              if (ansiRegex().test(line)) {
                const newLine = ansiUp.ansi_to_html(line);
                return <div></div>;
              }

              return <div>{line}</div>;
            })
          }
github DonJayamanne / pythonVSCode / src / datascience-ui / interactive-common / cellOutput.tsx View on Github external
// Stream output needs to be wrapped in xmp so it
            // show literally. Otherwise &lt; chars start a new html element.
            mimeType = 'text/html';
            isText = true;
            isError = false;
            renderWithScrollbars = true;
            const stream = copy as nbformat.IStream;
            const formatted = concatMultilineStringOutput(stream.text);
            copy.data = {
                'text/html': formatted.includes('&lt;') ? `` : `<div>${formatted}</div>`
            };

            // Output may have goofy ascii colorization chars in it. Try
            // colorizing if we don't have html that needs 
github taskcluster / taskcluster-tools / src / lib / ui / log-fetcher.js View on Github external
const divide = data =&gt; {
  const tester = ansiRegex();
  const matcher = /.{1,139}/g;

  return data
    .split(/\n|\[K|\[[0-9]B|\[[1-9][0-9]B/)
    .reduce((arr, line) =&gt; {
      if (line.length &lt; 140 || line.match(tester)) {
        arr.push(line);
      } else {
        arr.push(...line.match(matcher));
      }

      return arr;
    }, []);
};
github postlight / lux / src / packages / logger / utils / write.js View on Github external
tryCatch(async () => {
    message = message.replace(ansiRegex(), '');
    await fs.appendFileAsync(path, message, 'utf8');
  }, err => {
    console.error(err);
github zeit / now / packages / now-cli / src / util / input / text.ts View on Github external
value = value.replace(regex, chalk.gray('$1'));
          } else if (mask === 'expDate') {
            value = value.replace(regex, chalk.gray('$1'));
          }

          const l = chalk.red(label.replace('-', '✖'));
          stdout.write(eraseLines(1));
          stdout.write(l + value + ansiEscapes.beep);
          if (caretOffset) {
            process.stdout.write(
              ansiEscapes.cursorBackward(Math.abs(caretOffset))
            );
          }
        }
        return;
      } else if (!ansiRegex().test(data)) {
        let tmp =
          value.substr(0, value.length + caretOffset) +
          data +
          value.substr(value.length + caretOffset);

        if (mask) {
          if (/\d/.test(data) && caretOffset !== 0) {
            let formattedData = data;

            if (mask === 'cc' || mask === 'ccv') {
              formattedData = formatCC(data);
            }

            if (value[value.length + caretOffset + 1] === ' ') {
              tmp =
                value.substr(0, value.length + caretOffset) +
github facebook / jest / packages / pretty-format / src / plugins / ConvertAnsi.js View on Github external
const toHumanReadableAnsi = text =&gt; {
  return text.replace(ansiRegex(), (match, offset, string) =&gt; {
    switch (match) {
      case style.red.close:
      case style.green.close:
      case style.reset.open:
      case style.reset.close:
        return '';
      case style.red.open:
        return '';
      case style.green.open:
        return '';
      case style.dim.open:
        return '';
      case style.bold.open:
        return '';
      default:
        return '';
github expo / expo-cli / packages / expo-cli / src / PackageManager.ts View on Github external
import ansiRegex from 'ansi-regex';
import { isUsingYarn } from '@expo/config';
import spawnAsync, { SpawnOptions } from '@expo/spawn-async';
import split from 'split';
import { Transform } from 'stream';
import npmPackageArg from 'npm-package-arg';
import fs from 'fs-extra';
import path from 'path';
import detectIndent from 'detect-indent';
import detectNewline from 'detect-newline';

import log from './log';

const ansi = `(?:${ansiRegex().source})*`;
const npmPeerDependencyWarningPattern = new RegExp(
  `${ansi}npm${ansi} ${ansi}WARN${ansi}.+You must install peer dependencies yourself\\.\n`,
  'g'
);
const yarnPeerDependencyWarningPattern = new RegExp(
  `${ansi}warning${ansi} "[^"]+" has (?:unmet|incorrect) peer dependency "[^"]+"\\.\n`,
  'g'
);

class NpmStderrTransform extends Transform {
  _transform(
    chunk: Buffer,
    encoding: string,
    callback: (error?: Error | null, data?: any) => void
  ) {
    this.push(chunk.toString().replace(npmPeerDependencyWarningPattern, ''));

ansi-regex

Regular expression for matching ANSI escape codes

MIT
Latest version published 3 years ago

Package Health Score

74 / 100
Full package analysis

Popular ansi-regex functions