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: 5 days 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 (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-03-31T14:40:14.000Z (over 6 years ago)
- Last Synced: 2024-10-03T23:53:42.355Z (about 1 month 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).
[![npm version](https://img.shields.io/npm/v/cli-on-key.svg)](https://www.npmjs.com/package/derhuerst/cli-on-key)
![ISC-licensed](https://img.shields.io/github/license/derhuerst/cli-on-key.svg)
[![chat with me on Gitter](https://img.shields.io/badge/chat%20with%20me-on%20gitter-512e92.svg)](https://gitter.im/derhuerst)
[![support me on Patreon](https://img.shields.io/badge/support%20me-on%20patreon-fa7664.svg)](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).