当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript strip-ansi类代码示例

本文整理汇总了TypeScript中strip-ansi的典型用法代码示例。如果您正苦于以下问题:TypeScript strip-ansi类的具体用法?TypeScript strip-ansi怎么用?TypeScript strip-ansi使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了strip-ansi类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: buildTableOutput

export function buildTableOutput(
  rows: TableRow[],
  {separators = '  ' as string | string[], indent = 0 as string | number} = {},
): string {
  let maxTextLengths: number[] = [];

  for (let row of rows) {
    let lastNoneEmptyIndex = 0;

    for (let i = 0; i < row.length; i++) {
      let text = row[i] || '';
      let textLength = stripAnsi(text).length;

      if (textLength) {
        lastNoneEmptyIndex = i;
      }

      if (maxTextLengths.length > i) {
        maxTextLengths[i] = Math.max(maxTextLengths[i], textLength);
      } else {
        maxTextLengths[i] = textLength;
      }
    }

    row.splice(lastNoneEmptyIndex + 1);
  }

  let indentStr =
    typeof indent === 'string' ? indent : new Array(indent + 1).join(' ');

  return (
    // tslint:disable-next-line:prefer-template
    rows
      .map(row => {
        let line = indentStr;

        for (let i = 0; i < row.length; i++) {
          let text = row[i] || '';
          let textLength = stripAnsi(text).length;

          let maxLength = maxTextLengths[i];

          line += text;
          line += new Array(maxLength - textLength + 1).join(' ');

          if (i < row.length - 1) {
            if (typeof separators === 'string') {
              line += separators;
            } else {
              line += separators[i];
            }
          }
        }

        return line;
      })
      .join('\n') + '\n'
  );
}
开发者ID:vilic,项目名称:clime,代码行数:59,代码来源:string.ts

示例2: writeLine

 //#endregion
 /**
  * adds the text to the reporters output stream
  * 
  * @param {string} text 
  */
 protected writeLine(text: string): void {
     if (text) {
         if (!this.mochaOptions.useColors) {
             // colors are added by default, setting chalk.level can affect other reporters
             // so remove colors if no-color specified
             text = strip(text);
         }
         console.log(text);
     }
 }
开发者ID:dotnetprofessional,项目名称:LiveDoc,代码行数:16,代码来源:LiveDocReporter.ts

示例3: write

 /**
  * adds the text to the reporters output stream
  * without a line return
  * 
  * @param {string} text 
  */
 protected write(text: string): void {
     if (text) {
         if (!this.mochaOptions.useColors) {
             // colors are added by default, setting chalk.level can affect other reporters
             // so remove colors if no-color specified
             text = strip(text);
         }
         // Output without a line return
         process.stdout.write(text);
     }
 }
开发者ID:dotnetprofessional,项目名称:LiveDoc,代码行数:17,代码来源:LiveDocReporter.ts

示例4: stripAnsi

      .map(row => {
        let line = indentStr;

        for (let i = 0; i < row.length; i++) {
          let text = row[i] || '';
          let textLength = stripAnsi(text).length;

          let maxLength = maxTextLengths[i];

          line += text;
          line += new Array(maxLength - textLength + 1).join(' ');

          if (i < row.length - 1) {
            if (typeof separators === 'string') {
              line += separators;
            } else {
              line += separators[i];
            }
          }
        }

        return line;
      })
开发者ID:vilic,项目名称:clime,代码行数:23,代码来源:string.ts

示例5: stripAnsi

 _lines(s: string): number {
   return stripAnsi(s)
     .split('\n')
     .map(l => Math.ceil(l.length / this.width))
     .reduce((c, i) => c + i, 0)
 }
开发者ID:nunsie,项目名称:prisma,代码行数:6,代码来源:SpinnerAction.ts

示例6: pad

  function pad(str: string, length: number) {
    const visibleLength = stripAnsi(str).length
    const diff = length - visibleLength

    return str + ' '.repeat(Math.max(0, diff))
  }
开发者ID:dhruvcodeword,项目名称:prisma,代码行数:6,代码来源:table.ts

示例7: calcWidth

 function calcWidth(cell) {
   const lines = stripAnsi(cell).split(/[\r\n]+/)
   const lineLengths = lines.map(property('length'))
   return Math.max.apply(Math, lineLengths)
 }
开发者ID:dhruvcodeword,项目名称:prisma,代码行数:5,代码来源:table.ts

示例8: it

 it('List PRs `gh pr --detailed`', done => {
     // strip ansi characters so it doesn't fail on Travis
     expect(stripAnsi(runCmd('gh pr  --detailed'))).toMatchSnapshot()
     done()
 })
开发者ID:node-gh,项目名称:gh,代码行数:5,代码来源:pull-request.test.ts


注:本文中的strip-ansi类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。