How to use the ansi-escapes.eraseLines 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 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 zeit / now / src / providers / sh / util / etc / input / text.js View on Github external
// Until the first keypress
    valid = true,
    // Can be:
    // - `false`, which does nothing
    // - `cc`, for credit cards
    // - `date`, for dates in the mm / yyyy format
    mask = false,
    placeholder = '',
    abortSequences = new Set(['\x03']),
    eraseSequences = new Set([ESCAPES.BACKSPACE, ESCAPES.CTRL_H]),
    resolveChars = new Set([ESCAPES.CARRIAGE]),
    stdin = process.stdin,
    stdout = process.stdout,
    // Char to print before resolving/rejecting the promise
    // If `false`, nothing will be printed
    trailing = ansiEscapes.eraseLines(1),
    // Gets called on each keypress;
    // `data` contains the current keypress;
    // `futureValue` contains the current value + the
    // Keypress in the correct place
    validateKeypress = (data, futureValue) => true, // eslint-disable-line no-unused-vars
    // Get's called before the promise is resolved
    // Returning `false` here will prevent the user from submiting the value
    validateValue = data => true, // eslint-disable-line no-unused-vars
    // Receives the value of the input and should return a string
    // Or false if no autocomplion is available
    autoComplete = value => false, // eslint-disable-line no-unused-vars
    // Tab
    // Right arrow
    autoCompleteChars = new Set(['\t', '\x1b[C']),
    // If true, converts everything the user types to to lowercase
    forceLowerCase = false
github zeit / now / packages / now-cli / src / commands / billing / add.js View on Github external
if (clear) {
        const linesToClear = state.error ? 15 : 14;
        process.stdout.write(ansiEscapes.eraseLines(linesToClear));
      }

      console.log(
        success(
          `${state.cardNumber.brand ||
            state.cardNumber.card.brand} ending in ${res.last4 ||
            res.card.last4} was added to ${chalk.bold(contextName)}`
        )
      );
    } catch (err) {
      stopSpinner();
      const linesToClear = state.error ? 15 : 14;
      process.stdout.write(ansiEscapes.eraseLines(linesToClear));
      state.error = `${chalk.red(
        '> Error!'
      )} ${err.message} Please make sure the info is correct`;
      await render();
    }
  }
github mgrip / react-cli / src / index.js View on Github external
function writeToConsole(output: string) {
  process.stdout.write(ansiEscapes.eraseLines(previousLineCount) + output);
  previousLineCount = output.split("\n").length;
}
github cloud-annotations / training / src / utils / picker.js View on Github external
rl.input.on('keypress', (_, key) => {
      if (key.name === 'up') {
        index = Math.max(0, index - 1)
        process.stdout.write(eraseLines(delegate.windowSize))
        renderItems(items, delegate, index)
      } else if (key.name === 'down') {
        index = Math.min(items.length - 1, index + 1)
        process.stdout.write(eraseLines(delegate.windowSize))
        renderItems(items, delegate, index)
      } else if (key.name === 'return') {
        resolve(index)
      }
    })
  })
github cloud-annotations / training / src / utils / input.js View on Github external
rl.input.on('keypress', (_, key) => {
      if (key.name === 'tab' && charCount === 0) {
        process.stdout.write(eraseLines(1))
        rl.setPrompt(question)
        rl.prompt()
      } else if (key.name === 'backspace' && charCount === 0) {
        process.stdout.write(eraseLines(1))
        rl.setPrompt(prompt)
        rl.prompt()
      } else if (key.name === 'backspace') {
        charCount--
      } else {
        charCount++
      }
    })
github SBoudrias / Inquirer.js / packages / core / lib / readline.js View on Github external
exports.clearLine = function(rl, len) {
  rl.output.write(ansiEscapes.eraseLines(len));
};
github vadimdemedes / ink / src / vendor / log-update.js View on Github external
render.clear = () => {
		stream.write(ansiEscapes.eraseLines(prevLineCount));
		prevLineCount = 0;
	};
github zeit / now / src / providers / sh / util / etc / output / erase-lines.js View on Github external
module.exports = n => process.stdout.write(ansiEscapes.eraseLines(n))
github reimertz / wcal / src / bin / helpers / ask-for-input.js View on Github external
val.substr(0, val.length + caretOffset - 1) +
          val.substr(val.length + caretOffset)
      } else {
        if (resolveChars.has(s)) {
          restore()
          return resolve(val)
        }

        const add = forceLowerCase ? s.toLowerCase() : s
        val =
          val.substr(0, val.length + caretOffset) +
          add +
          val.substr(val.length + caretOffset)
      }

      process.stdout.write(ansi.eraseLines(1) + chalk.dim(question) + val)
      if (caretOffset) {
        process.stdout.write(ansi.cursorBackward(Math.abs(caretOffset)))
      }
    }