當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。