Add quiet option to main client.
(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
-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)
"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)
(++ 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]
+ (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))
- (def prompt (string "janet:" offset ":" (parser/state p) "> "))
- (getline prompt buf)))))))
+ (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)))
