Created
May 11, 2019 06:22
-
-
Save carsonfarmer/09852d4b53e362cb467d78aa415a8647 to your computer and use it in GitHub Desktop.
Adding some interactivity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/index.js b/index.js | |
index 11b46ac..4cf1473 100644 | |
--- a/index.js | |
+++ b/index.js | |
@@ -1,6 +1,7 @@ | |
#!/usr/bin/env node | |
const cli = require('cac')('txtl') | |
+var readline = require('readline') | |
const { log } = console | |
@@ -8,6 +9,19 @@ const { log } = console | |
cli.command('', 'Starts an interactive chat session in a thread.') | |
.action((opts) => { | |
log('do something') | |
+ // Specify our readline interface | |
+ const rl = readline.createInterface({ | |
+ input: process.stdin, | |
+ output: process.stdout, | |
+ terminal: false | |
+ }) | |
+ // Run callback for each input on stdin | |
+ rl.on('line', (line) => { | |
+ if (line !== '') { | |
+ log(line) | |
+ rl.prompt() | |
+ } | |
+ }) | |
}) | |
.option('--thread [thread]', 'Thread ID. Omit to use the \'default\' thread.', { | |
default: 'default', |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment