1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-18 14:44:48 +00:00

Add quiet option to main client.

This commit is contained in:
Calvin Rose 2019-01-10 17:10:12 -05:00
parent 62cb3f81fe
commit 84fb07dd5a

View File

@ -2,11 +2,12 @@
(do
(var *should-repl* :private false)
(var *no-file* :private true)
(var *raw-stdin* :private false)
(var *handleopts* :private true)
(var *exit-on-error* :private true)
(var *should-repl* false)
(var *no-file* true)
(var *quiet* false)
(var *raw-stdin* false)
(var *handleopts* true)
(var *exit-on-error* true)
# Flag handlers
(def handlers :private
@ -20,6 +21,7 @@
-e Execute a string of janet
-r Enter the repl after running all scripts
-p Keep on executing if there is a top level error (persistent)
-q Hide prompt, logo, and repl output (quiet)
-- Stop handling options`)
(os/exit 0)
1)
@ -27,6 +29,7 @@
"s" (fn [&] (set *raw-stdin* true) (set *should-repl* true) 1)
"r" (fn [&] (set *should-repl* true) 1)
"p" (fn [&] (set *exit-on-error* false) 1)
"q" (fn [&] (set *quiet* true) 1)
"-" (fn [&] (set *handleopts* false) 1)
"e" (fn [i &]
(set *no-file* false)
@ -50,11 +53,19 @@
(++ i))))
(when (or *should-repl* *no-file*)
(if *raw-stdin*
(repl nil (fn [x &] x))
(do
(print (string "Janet " janet/version "-" janet/build " Copyright (C) 2017-2018 Calvin Rose"))
(repl (fn [buf p]
(def offset (parser/where p))
(def prompt (string "janet:" offset ":" (parser/state p) "> "))
(getline prompt buf)))))))
(if-not *quiet*
(print "Janet " janet/version "-" janet/build " Copyright (C) 2017-2018 Calvin Rose"))
(defn noprompt [_] "")
(defn getprompt [p]
(def offset (parser/where p))
(string "janet:" offset ":" (parser/state p) "> "))
(def prompter (if *quiet* noprompt getprompt))
(defn getstdin [prompt buf]
(file/write stdout prompt)
(file/flush stdout)
(file/read stdin :line buf))
(def getter (if *raw-stdin* getstdin getline))
(defn getchunk [buf p]
(getter (prompter p) buf))
(def onsig (if *quiet* (fn [x &] x) nil))
(repl getchunk onsig)))