How to use the ansi-escapes.cursorLeft function in ansi-escapes

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 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 / 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)
github serverless / components / src / utils / getCli.js View on Github external
render: async (frame = 0) => {
        const nextFrame = ++frame
        const second = String(Math.floor(nextFrame / 10) + 1) // cause we're running at 10 frames per second
        let coloredStage

        if (['dev', 'development'].includes(stage)) {
          coloredStage = chalk.green(stage)
        } else if (['prod', 'production'].includes(stage)) {
          coloredStage = chalk.red(stage)
        } else {
          coloredStage = chalk.yellow(stage)
        }

        cli.write(
          `${ansiEscapes.cursorHide +
            ansiEscapes.cursorLeft +
            ansiEscapes.eraseDown}\n  ${chalk.grey(
            `${second}s ${figures.pointerSmall}`
          )} ${coloredStage} ${chalk.grey(figures.pointerSmall)} ${componentName} ${chalk.grey(
            figures.pointerSmall
          )} ${chalk.yellow(cli.msg)}\n${ansiEscapes.cursorLeft + ansiEscapes.cursorUp(2)}`
        )
        if (!cli.running) {
          cli.write(
            `${ansiEscapes.cursorShow + ansiEscapes.cursorLeft + ansiEscapes.cursorDown(2)}\n`
          )
          return
        }
        await sleep(100)
        cli.render(nextFrame)
      },
      write: process.stdout.write.bind(process.stdout)
github Akryum / monorepo-run / src / run.js View on Github external
if (clearingLine) {
        process.stdout.write('\n')
      }
    }

    process.stdout.write(data)
    lastOutputClearedLine = clearingLine ? folder : false
    lastOutputFolder = folder
  }

  // Data chunk processing

  const regEraseLine = new RegExp(escapeAnsiEscapeSeq(ansiEscapes.eraseLine), 'g')
  const regMoveCursor = new RegExp(`(${[
    '\r',
    escapeAnsiEscapeSeq(ansiEscapes.cursorLeft),
    escapeAnsiEscapeSeq(ansiEscapes.cursorTo(0)),
    escapeAnsiEscapeSeq(ansiEscapes.cursorTo(1)),
  ].join('|')})+`, 'g')
  const regNewLine = /(\n)/g
  const fakePrintBorder = '__print_border__'
  const fakePrintBorderReg = new RegExp(fakePrintBorder, 'g')
  const printBorder = `${ansiEscapes.cursorTo(0)}${border}${ansiEscapes.cursorTo(2)}`
  const printEraseLine = `${ansiEscapes.eraseLine}${fakePrintBorder}`
  const printReplaceNewLine = `$&${fakePrintBorder}`

  /**
   * Process text to print border and move all output 2 charaters to the right
   * @param {string} data
   */
  const processOutput = (data) => {
    data = data.replace(regEraseLine, printEraseLine)
github heroku / heroku-cli-util / lib / prompt.js View on Github external
return new Promise(function (resolve, reject) {
    let stdin = process.stdin
    let stderr = process.stderr
    let input = ''
    stdin.setEncoding('utf8')
    stderr.write(ansi.eraseLine)
    stderr.write(ansi.cursorLeft)
    cli.console.writeError(options.prompt)
    stdin.resume()
    stdin.setRawMode(true)

    function stop () {
      if (!options.hide) {
        stderr.write(
          ansi.cursorHide +
            ansi.cursorLeft +
            options.prompt +
            input.replace(/./g, '*') +
            '\n' +
            ansi.cursorShow)
      } else {
        stderr.write('\n')
      }
github heroku / heroku-cli-util / lib / prompt.js View on Github external
return new Promise(function (resolve, reject) {
    let stdin = process.stdin
    let stderr = process.stderr
    let input = ''
    stdin.setEncoding('utf8')
    stderr.write(ansi.eraseLine)
    stderr.write(ansi.cursorLeft)
    cli.console.writeError(options.prompt)
    stdin.resume()
    stdin.setRawMode(true)

    function stop () {
      if (!options.hide) {
        stderr.write(
          ansi.cursorHide +
            ansi.cursorLeft +
            options.prompt +
            input.replace(/./g, '*') +
            '\n' +
            ansi.cursorShow)
      } else {
        stderr.write('\n')
      }
github jest-community / jest-watch-typeahead / src / shared / pattern_prompt.js View on Github external
_onChange(pattern: string, options: ScrollOptions) {
    this._pipe.write(ansiEscapes.eraseLine);
    this._pipe.write(ansiEscapes.cursorLeft);
  }
}
github serverless / components / src / utils / getCli.js View on Github external
if (['dev', 'development'].includes(stage)) {
          coloredStage = chalk.green(stage)
        } else if (['prod', 'production'].includes(stage)) {
          coloredStage = chalk.red(stage)
        } else {
          coloredStage = chalk.yellow(stage)
        }

        cli.write(
          `${ansiEscapes.cursorHide +
            ansiEscapes.cursorLeft +
            ansiEscapes.eraseDown}\n  ${chalk.grey(
            `${second}s ${figures.pointerSmall}`
          )} ${coloredStage} ${chalk.grey(figures.pointerSmall)} ${componentName} ${chalk.grey(
            figures.pointerSmall
          )} ${chalk.yellow(cli.msg)}\n${ansiEscapes.cursorLeft + ansiEscapes.cursorUp(2)}`
        )
        if (!cli.running) {
          cli.write(
            `${ansiEscapes.cursorShow + ansiEscapes.cursorLeft + ansiEscapes.cursorDown(2)}\n`
          )
          return
        }
        await sleep(100)
        cli.render(nextFrame)
      },
      write: process.stdout.write.bind(process.stdout)