terminal-keypress
v0.4.4
Published
Returns keypress events while enabling default input behavior
Downloads
13
Maintainers
Readme
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))