コード例 #1
0
 it(`should use correct colors for seperator creation (${JSON.stringify(data)})`, function() {
     var segment = new SimpleBaseSegment("Some content", {foreground: "cyan", background: "blue", separator: data.name});
     var nextSegment = new MockedSegment("Some other content", "red", "green");
     var output = segment.render(nextSegment);
     var formatter = crayon.foreground(data.fg).background(data.bg);
     expect(output.substr(-31, 20).match(ansiRegex())).toEqual(formatter("").substr(0, 20).match(ansiRegex()));
 });
コード例 #2
0
ファイル: convert_ansi.js プロジェクト: marianmeres/jest
const toHumanReadableAnsi = text => {
  return text.replace(ansiRegex(), (match, offset, string) => {
    switch (match) {
      case style.red.close:
      case style.green.close:
      case style.cyan.close:
      case style.bgRed.close:
      case style.bgGreen.close:
      case style.bgCyan.close:
      case style.reset.open:
      case style.reset.close:
        return '</>';
      case style.red.open:
        return '<red>';
      case style.green.open:
        return '<green>';
      case style.cyan.open:
        return '<cyan>';
      case style.bgRed.open:
        return '<bgRed>';
      case style.bgGreen.open:
        return '<bgGreen>';
      case style.bgCyan.open:
        return '<bgCyan>';
      case style.dim.open:
        return '<dim>';
      case style.bold.open:
        return '<bold>';
      default:
        return '';
    }
  });
};
コード例 #3
0
ファイル: index.js プロジェクト: smallhelm/ansi-style-parser
module.exports = function(str){
  var r = [];
  var curr = str;
  var curr_style = [];
  var code;
  var e;
  while(e = ansiRegEx().exec(curr)){
    if(e.index > 0){
      r.push({
        styles: curr_style.slice(0),
        text: curr.substr(0, e.index)
      });
    }
    code = e[0];
    if(escape_codes[code]){
      each(escape_codes[code], function(o, code){
        removeElm(curr_style, code);
      });
    }
    if(code_to_style[code]){
      curr_style.push(code_to_style[code]);
    }
    curr = curr.substr(e.index + e[0].length);
  }
  if(curr.length > 0){
    r.push({
      styles: curr_style,
      text: curr
    });
  }
  return r;
};
コード例 #4
0
  function divide(data) {
    let tester = ansiRegex();
    let matcher = /.{1,139}/g;

    return data
      .split(/\n|\[K|\[[0-9]B|\[[1-9][0-9]B/)
      .reduce((arr, line) => {
        if (line.length < 140 || line.match(tester)) {
          arr.push(line);
        } else {
          arr.push(...line.match(matcher));
        }
        
        return arr;
      }, []);
  }
コード例 #5
0
                                          */const toHumanReadableAnsi = text => {const style = require('ansi-styles');return text.replace(ansiRegex(), (match, offset, string) => {switch (match) {case style.red.close:case style.green.close:case style.reset.open:
      case style.reset.close:
        return '</>';
      case style.red.open:
        return '<red>';
      case style.green.open:
        return '<green>';
      case style.dim.open:
        return '<dim>';
      case style.bold.open:
        return '<bold>';
      default:
        return '';}

  });
};
コード例 #6
0
ファイル: ConvertAnsi.js プロジェクト: abhishekkhandait/jest
const toHumanReadableAnsi = text =>
  text.replace(ansiRegex(), (match, offset, string) => {
    switch (match) {
      case style.red.close:
      case style.green.close:
      case style.cyan.close:
      case style.gray.close:
      case style.white.close:
      case style.yellow.close:
      case style.bgRed.close:
      case style.bgGreen.close:
      case style.bgYellow.close:
      case style.inverse.close:
      case style.dim.close:
      case style.bold.close:
      case style.reset.open:
      case style.reset.close:
        return '</>';
      case style.red.open:
        return '<red>';
      case style.green.open:
        return '<green>';
      case style.cyan.open:
        return '<cyan>';
      case style.gray.open:
        return '<gray>';
      case style.white.open:
        return '<white>';
      case style.yellow.open:
        return '<yellow>';
      case style.bgRed.open:
        return '<bgRed>';
      case style.bgGreen.open:
        return '<bgGreen>';
      case style.bgYellow.open:
        return '<bgYellow>';
      case style.inverse.open:
        return '<inverse>';
      case style.dim.open:
        return '<dim>';
      case style.bold.open:
        return '<bold>';
      default:
        return '';
    }
  });
コード例 #7
0
ファイル: base.js プロジェクト: brentpayne/Inquirer.js
 * @param  {String} [optionnal] String to concatenate to the prefix
 * @return {String} prompt prefix
 */

Prompt.prototype.prefix = function (str) {
  str || (str = '');
  return chalk.green('?') + ' ' + str;
};

/**
 * Return the prompt line suffix
 * @param  {String} [optionnal] String to concatenate to the suffix
 * @return {String} prompt suffix
 */

var reStrEnd = new RegExp('(?:' + ansiRegex().source + ')$|$');

Prompt.prototype.suffix = function (str) {
  str || (str = '');

  // make sure we get the `:` inside the styles
  if (str.length < 1 || /[a-z1-9]$/i.test(chalk.stripColor(str))) {
    str = str.replace(reStrEnd, ':$&');
  }

  return str.trim() + ' ';
};

/**
 * Generate the prompt question string
 * @return {String} prompt question string
コード例 #8
0
ファイル: index.js プロジェクト: AshKyd/es-modules-2016
/* */ 
'use strict';
var ansiRegex = require('ansi-regex');
var re = new RegExp(ansiRegex().source); // remove the `g` flag
module.exports = re.test.bind(re);
コード例 #9
0
ファイル: test_ansi-regex.js プロジェクト: mirek/flow-typed
 it('should be false boolean', () => {
   const bool: boolean = ansiRegex().test('cake');
   // => false
 });
コード例 #10
0
ファイル: test_ansi-regex.js プロジェクト: mirek/flow-typed
 it('should be false boolean 2', () => {
   const bool: boolean = ansiRegex({ onlyFirst: true }).test('cake');
   // => false
 });
コード例 #11
0
 it(`should render output with given background and foreground color (${JSON.stringify(data)})`, function() {
     var segment = new SimpleBaseSegment("Some content", {foreground: data.fg, background: data.bg});
     var output = segment.render(null);
     var expected = crayon.foreground(data.fg).background(data.bg)("");
     expect(output.match(ansiRegex())).toEqual(expected.match(ansiRegex()));
 });
コード例 #12
0
ファイル: base.js プロジェクト: 13hoop/toutiao
 * @return {String} prompt prefix
 */

Prompt.prototype.prefix = function( str ) {
  str || (str = "");
  return chalk.green("?") + " " + str;
};


/**
 * Return the prompt line suffix
 * @param  {String} [optionnal] String to concatenate to the suffix
 * @return {String} prompt suffix
 */

var reStrEnd = new RegExp("(?:" + ansiRegex().source + ")$|$");

Prompt.prototype.suffix = function( str ) {
  str || (str = "");
  return (str.length < 1 || /[a-z1-9]$/i.test(chalk.stripColor(str)) ?
          // make sure we get the `:` inside the styles
          str.replace(reStrEnd, ":$&") : str).trim() + " ";
};


/**
 * Generate the prompt question string
 * @return {String} prompt question string
 */

Prompt.prototype.getQuestion = function() {
コード例 #13
0
ファイル: ConvertAnsi.js プロジェクト: kentcdodds/jest
const test = (value: any) =>
  typeof value === 'string' && value.match(ansiRegex());
コード例 #14
0
"use strict";var ansiRegex=require("ansi-regex");var re=new RegExp(ansiRegex().source);module.exports=re.test.bind(re);
コード例 #15
0
module.exports = input => typeof input === 'string' ? input.replace(ansiRegex(), '') : input;
コード例 #16
0
ファイル: test_ansi-regex.js プロジェクト: mirek/flow-typed
 it('should be boolean', () => {
   // From the ansi-regex README.md
   const bool: boolean = ansiRegex().test('\u001B[4mcake\u001B[0m');
   // => true
 });
コード例 #17
0
ファイル: test_ansi-regex.js プロジェクト: mirek/flow-typed
 it('should be RegExp', () => {
   const regexp: RegExp = ansiRegex();
 });
コード例 #18
0
ファイル: test_ansi-regex.js プロジェクト: mirek/flow-typed
 it('should be RegExpMatchArray | null', () => {
   const array: ?Array<string> = '\u001B[4mcake\u001B[0m'.match(ansiRegex());
   // => ['\u001B[4m', '\u001B[0m']
 });
コード例 #19
0
ファイル: convert_ansi.js プロジェクト: amasad/jest
export const test = (val: any) =>
  typeof val === 'string' && val.match(ansiRegex());
コード例 #20
0
ファイル: test.js プロジェクト: kevmannn/chalk-form
test('`fn` prints given string with correct ansi code', t => {
  t.true(str.match(ansiRegex()).indexOf(ec) !== -1);
  t.true(hasAnsi(str));
})