0.4.4 • Published 7 years ago

terminal-keypress v0.4.4

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

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))
0.4.4

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.1

8 years ago

0.1.0

8 years ago