npm

Need private packages and team management tools?Check out npm Orgs. »

terminal-keypress

0.4.4 • Public • Published

terminal-keypress

  $ npm install --save terminal-keypress

Fires keypress events for terminal applications. Unfortunately, this seems to be possible only via process.stdin.setRawMode(true), which kills the default input behavior. terminal-keypress aims to fire keypress events while enabling default input behavior.

Usage

Require it:

  const keypress = require('terminal-keypress')
  // sets raw mode true and enables default behavior
  keypress.init()

Add callbacks for keypress events:

  keypress.on('keypress', (char, key) => {
    if (key.sequence === 'a') {
      console.log('You typed an "a"!')
    }
  })

  keypress.once('return', () => {
    let input = keypress.input()
    console.log(input)
  })

Easily color the user's input using chalk:

  const chalk = require('chalk')
  keypress.color(letter => chalk.red(letter))

install

npm i terminal-keypress

Downloadsweekly downloads

12

version

0.4.4

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability