Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/derhuerst/cli-on-key
Read command line key presses from process.stdin. Based on TooTallNate/keypress.
https://github.com/derhuerst/cli-on-key
cli command-line key keypress stdin
Last synced: about 1 month ago
JSON representation
Read command line key presses from process.stdin. Based on TooTallNate/keypress.
- Host: GitHub
- URL: https://github.com/derhuerst/cli-on-key
- Owner: derhuerst
- License: isc
- Created: 2018-03-31T14:38:50.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-31T14:40:14.000Z (almost 7 years ago)
- Last Synced: 2024-12-25T00:31:10.345Z (about 2 months ago)
- Topics: cli, command-line, key, keypress, stdin
- Language: JavaScript
- Homepage: https://github.com/derhuerst/cli-on-key#cli-on-key
- Size: 5.86 KB
- Stars: 7
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# cli-on-key
**Read command line key presses from process.stdin.** Based on [`TooTallNate/keypress`](https://github.com/TooTallNate/keypress).
[](https://www.npmjs.com/package/derhuerst/cli-on-key)

[](https://gitter.im/derhuerst)
[](https://patreon.com/derhuerst)## Installing
```shell
npm install @derhuerst/cli-on-key
```## Usage
`listen` will switch the stream to [raw mode](https://nodejs.org/api/tty.html#tty_readstream_israw), `stopListening` will revert to the previous value.
```js
const listen = require('cli-on-key')const stopListening = listen(process.stdin, (key) => {
if (key.ctrl && key.name === 'c') {
stopListening() // stop on Ctrl + C
} else console.log(key)
})
```## Contributing
If you have a question or have difficulties using `cli-on-key`, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, refer to [the issues page](https://github.com/derhuerst/cli-on-key/issues).