m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-09-11 16:21:52 -0400
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-09-11 16:28:54 -0400
commit26de1b9f0646bdd495a9457923a8146120704f1a (patch)
treed2b6d32ec776a84976851e0b014798a77e4b28f3 /bin
parentfbe048df52cf52323086727acfd2861c93e8e913 (diff)
Add ability to exit IO loop
Diffstat (limited to 'bin')
-rwxr-xr-xbin/dicebag.js8
1 files changed, 7 insertions, 1 deletions
diff --git a/bin/dicebag.js b/bin/dicebag.js
index f7b0921..6e88ae6 100755
--- a/bin/dicebag.js
+++ b/bin/dicebag.js
@@ -24,7 +24,7 @@ const parseArgs = () => {
const rollDie = (string, roller) => {
try {
- const die = parse(string.trim())
+ const die = parse(string)
console.log(roller(die))
} catch (error) {
console.log(error.message)
@@ -32,8 +32,14 @@ const rollDie = (string, roller) => {
}
const runIoLoop = (roller) => {
+ console.log("Type 'quit' or 'exit' to exit")
process.stdin.setEncoding('utf8')
process.stdin.on('data', (string) => {
+ string = string.trim()
+ if (string === 'exit' || string === 'quit') {
+ process.exit(0)
+ }
+
rollDie(string, roller)
})
}