How to use ansi-escapes - 10 common examples

To help you get started, we’ve selected a few ansi-escapes 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 heroku / cli / packages / ci-v5 / lib / render-test-runs.js View on Github external
function redraw (testRuns, watch, count = 15) {
  const arranged = limit(sort(testRuns), count)

  if (watch) {
    process.stdout.write(ansiEscapes.eraseDown)
  }

  const rows = arranged.map((testRun) => columns(testRun, testRuns))

  // this is a massive hack but I basically create a table that does not print so I can calculate its width if it were printed
  let width = 0
  function printLine (line) {
    width = line.length
  }

  cli.table(rows, {
    printLine: printLine,
    printHeader: false
  })

  const printRows = arranged.map((testRun) => columns(testRun, testRuns).concat([progressBar(testRun, testRuns, width)]))
github heroku / cli / packages / ci / src / utils / test-run.ts View on Github external
)
  })

  cli.table(data, {
    printHeader: undefined,
    columns: [
      {key: 'iconStatus', width: 1, label: ''}, // label '' is to make sure that widh is 1 character
      {key: 'number', label: ''},
      {key: 'branch'},
      {key: 'sha'},
      {key: 'status'}
    ]
  })

  if (watchOption) {
    process.stdout.write(ansiEscapes.cursorUp(latestTestRuns.length))
  }
}
github serverless / components / src / cli / index.js View on Github external
console.log(os.EOL) // eslint-disable-line

    // Write content
    let content = ' '
    if (this._.useTimer) {
      content += ` ${grey(this._.seconds + 's')}`
      content += ` ${grey(figures.pointerSmall)}`
    }
    content += ` ${stage}`
    content += ` ${grey(figures.pointerSmall)} ${this._.parentComponent}`
    content += ` ${grey(figures.pointerSmall)} ${message}`
    process.stdout.write(content)

    // Put cursor to starting position for next view
    console.log(os.EOL) // eslint-disable-line
    process.stdout.write(ansiEscapes.cursorLeft)
    process.stdout.write(ansiEscapes.cursorShow)

    if (reason === 'error') {
      process.exit(1)
    } else {
      process.exit(0)
    }
  }
github serverless / components / src / cli / index.js View on Github external
// Write content
    let content = ' '
    if (this._.useTimer) {
      content += ` ${grey(this._.seconds + 's')}`
      content += ` ${grey(figures.pointerSmall)}`
    }
    content += ` ${stage}`
    content += ` ${grey(figures.pointerSmall)} ${this._.parentComponent}`
    content += ` ${grey(figures.pointerSmall)} ${message}`
    process.stdout.write(content)

    // Put cursor to starting position for next view
    console.log(os.EOL) // eslint-disable-line
    process.stdout.write(ansiEscapes.cursorLeft)
    process.stdout.write(ansiEscapes.cursorShow)

    if (reason === 'error') {
      process.exit(1)
    } else {
      process.exit(0)
    }
  }
github serverless / components / src / cli / Context.js View on Github external
// Write content
    this.log()
    let content = ''
    if (this._.timer) {
      content += `${grey(this._.timerSeconds + 's')}`
      content += ` ${grey(figures.pointerSmall)} `
    }
    content += `${this._.entity} `
    content += `${grey(figures.pointerSmall)} ${message}`
    process.stdout.write(content)

    // Put cursor to starting position for next view
    console.log(os.EOL) // eslint-disable-line
    process.stdout.write(ansiEscapes.cursorLeft)
    process.stdout.write(ansiEscapes.cursorShow)

    if (reason === 'error') {
      process.exit(1)
    } else {
      process.exit(0)
    }
  }
github webiny / webiny-js / packages / cli / sls / execute.js View on Github external
if (debug) {
        process.env.DEBUG = "webiny*";
        context.debug = require("debug")("webiny");
    }
    const Template = require("./template/serverless.js");
    const component = new Template(`Webiny.${env}`, context);
    await component.init();

    const output = await component[method]({ env, debug, alias });
    if (debug) {
        // Add an empty line after debug output for nicer output
        console.log();
    }
    context._.status.running = false;
    process.stdout.write(ansiEscapes.cursorLeft);
    process.stdout.write(ansiEscapes.eraseDown);
    process.stdout.write(ansiEscapes.cursorShow);
    process.chdir(cwd);

    return { output, duration: context._.seconds };
};
github cloud-annotations / training / src / commands / loginSSO.js View on Github external
let iObjectStorage = 0
  if (objectStorageResources.resources.length > 1) {
    iObjectStorage = await picker(
      `${bold('Object Storage Instances')} ${dim(
        '(Use arrow keys and enter to choose)'
      )}`,
      objectStorageResources.resources.map(a => a.name),
      {
        default: 0,
        returnIndex: true
      }
    )
  }

  const objectStorage = objectStorageResources.resources[iObjectStorage]
  process.stdout.write(eraseLines(2))
  console.log(`Object Storage Instance ${cyan.bold(objectStorage.name)}`)

  console.log()
  spinner.start()
  const machineLearningResources = await request({
    url: machineLearningResourcesEndpoint,
    method: 'GET',
    headers: {
      Authorization: 'bearer ' + upgradedToken.access_token
    },
    json: true
  })
  spinner.stop()

  if (machineLearningResources.next_url) {
    // TODO: check if there are more accounts
github serverless / components / src / cli / index.js View on Github external
if (this._.useTimer) {
      content += ` ${grey(this._.seconds + 's')}`
      content += ` ${grey(figures.pointerSmall)}`
    }
    content += ` ${green(this._.stage)}`
    content += ` ${grey(figures.pointerSmall)} ${this._.parentComponent}`
    content += ` ${grey(figures.pointerSmall)} ${grey(this._.status.message)}`
    content += ` ${grey(this._.status.loadingDots)}`
    process.stdout.write(content)
    console.log() // eslint-disable-line

    // Get cursor starting position according to terminal & content width
    const startingPosition = this.getRelativeVerticalCursorPosition(content)

    // Put cursor to starting position for next view
    process.stdout.write(ansiEscapes.cursorUp(startingPosition))
    process.stdout.write(ansiEscapes.cursorLeft)
  }
github serverless / components / src / cli / Context.js View on Github external
// Write status content
      console.log() // eslint-disable-line
      let content = ''
      if (this._.timer) {
        content += `${grey(this._.timerSeconds + 's')} `
        content += `${grey(figures.pointerSmall)} `
      }
      content += `${this._.entity} `
      content += `${grey(figures.pointerSmall)} ${grey(this._.status)}`
      content += ` ${grey(this._.loadingDots)}`
      process.stdout.write(content)
      console.log() // eslint-disable-line

      // Put cursor to starting position for next view
      const startingPosition = this._getRelativeVerticalCursorPosition(content)
      process.stdout.write(ansiEscapes.cursorUp(startingPosition))
      process.stdout.write(ansiEscapes.cursorLeft)
    }

    await sleep(100)
    return this._renderEngine()
  }
github serverless / components / src / cli / Context.js View on Github external
close(reason, message) {
    if (reason === 'error') {
      message = red(message)
    }
    if (reason === 'cancel') {
      message = red('Canceled')
    }
    if (reason === 'done') {
      message = green(message || 'Done')
    }

    // Clear any existing content
    process.stdout.write(ansiEscapes.cursorLeft)
    process.stdout.write(ansiEscapes.eraseDown)

    // Write content
    this.log()
    let content = ''
    if (this._.timer) {
      content += `${grey(this._.timerSeconds + 's')}`
      content += ` ${grey(figures.pointerSmall)} `
    }
    content += `${this._.entity} `
    content += `${grey(figures.pointerSmall)} ${message}`
    process.stdout.write(content)

    // Put cursor to starting position for next view
    console.log(os.EOL) // eslint-disable-line
    process.stdout.write(ansiEscapes.cursorLeft)