Skip to content

Instantly share code, notes, and snippets.

@carsonfarmer
Created May 11, 2019 06:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carsonfarmer/09852d4b53e362cb467d78aa415a8647 to your computer and use it in GitHub Desktop.
Save carsonfarmer/09852d4b53e362cb467d78aa415a8647 to your computer and use it in GitHub Desktop.
Adding some interactivity
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