How to use the ansi-escapes.cursorBackward 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 zeit / now / src / providers / sh / util / etc / input / text.js View on Github external
if (valid) {
      stdout.write(label)
    } else {
      const _label = label.replace('-', '✖')
      stdout.write(chalk.red(_label))
    }

    value = initialValue
    stdout.write(initialValue)

    if (mask) {
      if (!value) {
        value = chalk.gray(placeholder)
        caretOffset = 0 - stripAnsi(value).length
        stdout.write(value)
        stdout.write(ansiEscapes.cursorBackward(Math.abs(caretOffset)))
      }

      regex = placeholder
        .split('')
        .reduce((prev, curr) => {
          if (curr !== ' ' && !prev.includes(curr)) {
            if (curr === '/') {
              prev.push(' / ')
            } else {
              prev.push(curr)
            }
          }
          return prev
        }, [])
        .join('|')
      regex = new RegExp(`(${regex})`, 'g')
github zeit / now / src / providers / sh / util / etc / input / text.js View on Github external
caretOffset += formattedData.length
            }
          } else if (/\s/.test(data) && caretOffset < 0) {
            caretOffset++
            tmp = value
          } else {
            return stdout.write(ansiEscapes.beep)
          }
          value = tmp
        } else if (validateKeypress(data, value)) {
          value = tmp
          if (caretOffset === 0) {
            const completion = await autoComplete(value)
            if (completion) {
              suggestion = chalk.gray(completion)
              suggestion += ansiEscapes.cursorBackward(completion.length)
            } else {
              suggestion = ''
            }
          }
        } else {
          return stdout.write(ansiEscapes.beep)
        }
      }

      if (mask === 'cc' || mask === 'ccv') {
        value = formatCC(value)
        value = value.replace(regex, chalk.gray('$1'))
      } else if (mask === 'expDate') {
        value = value.replace(regex, chalk.gray('$1'))
      }
github zeit / now / lib / utils / input / text.js View on Github external
caretOffset += formattedData.length
            }
          } else if (/\s/.test(data) && caretOffset < 0) {
            caretOffset++
            tmp = value
          } else {
            return stdout.write(ansiEscapes.beep)
          }
          value = tmp
        } else if (validateKeypress(data, value)) {
          value = tmp
          if (caretOffset === 0) {
            const completion = await autoComplete(value)
            if (completion) {
              suggestion = chalk.gray(completion)
              suggestion += ansiEscapes.cursorBackward(completion.length)
            } else {
              suggestion = ''
            }
          }
        } else {
          return stdout.write(ansiEscapes.beep)
        }
      }

      if (mask === 'cc' || mask === 'ccv') {
        value = formatCC(value)
        value = value.replace(regex, chalk.gray('$1'))
      } else if (mask === 'expDate') {
        value = value.replace(regex, chalk.gray('$1'))
      }
github zeit / email-prompt / index.js View on Github external
val.substr(val.length + caretOffset)
        }

        const parts = val.split('@')
        if (parts.length === 2 && parts[1].length > 0) {
          const [, _host] = parts
          const host = _host.toLowerCase()
          for (const domain of _domains) {
            if (host === domain) {
              break
            }

            if (host === domain.substr(0, host.length)) {
              suggestion = domain.substr(host.length)
              completion = chalk[suggestionColor](suggestion)
              completion += ansi.cursorBackward(domain.length - host.length)
              break
            }
          }
        }

        if (completion.length === 0) {
          suggestion = ''
        }
      }

      process.stdout.write(ansi.eraseLines(1) + start + val + completion)
      if (caretOffset) {
        process.stdout.write(ansi.cursorBackward(Math.abs(caretOffset)))
      }
    }
github zeit / now / packages / now-cli / src / util / input / text.ts View on Github external
caretOffset += formattedData.length;
            }
          } else if (/\s/.test(data) && caretOffset < 0) {
            caretOffset++;
            tmp = value;
          } else {
            return stdout.write(ansiEscapes.beep);
          }
          value = tmp;
        } else if (validateKeypress(data, value)) {
          value = tmp;
          if (caretOffset === 0) {
            const completion = await autoComplete(value);
            if (completion) {
              suggestion = chalk.gray(completion);
              suggestion += ansiEscapes.cursorBackward(completion.length);
            } else {
              suggestion = '';
            }
          }
        } else {
          return stdout.write(ansiEscapes.beep);
        }
      }

      if (mask === 'cc' || mask === 'ccv') {
        value = formatCC(value);
        value = value.replace(regex, chalk.gray('$1'));
      } else if (mask === 'expDate') {
        value = value.replace(regex, chalk.gray('$1'));
      }
github dylang / observatory / lib / observatory.js View on Github external
function update() {
        var output = task.render();
        var change = currentLine - task.line;
        out.write(position.cursorUp(change));
        out.write(output);
        out.write(position.cursorDown(change - (out.height(output) - 1)));
        out.write(position.cursorBackward(out.ln(output)));
        return task;
    }
github SBoudrias / Inquirer.js / packages / inquirer / lib / utils / readline.js View on Github external
exports.left = function(rl, x) {
  rl.output.write(ansiEscapes.cursorBackward(x));
};
github SBoudrias / Inquirer.js / packages / core / lib / readline.js View on Github external
exports.left = function(rl, x) {
  rl.output.write(ansiEscapes.cursorBackward(x));
};
github reimertz / wcal / src / bin / helpers / ask-for-input.js View on Github external
} 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)))
      }
    }
github jdxcode / password-prompt / index.js View on Github external
function backspace () {
        if (input.length === 0) return
        input = input.substr(0, input.length - 1)
        stderr.write(ansi.cursorBackward(1))
        stderr.write(ansi.eraseEndLine)
      }