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:
parent
62cb3f81fe
commit
84fb07dd5a
@ -2,11 +2,12 @@
|
|||||||
|
|
||||||
(do
|
(do
|
||||||
|
|
||||||
(var *should-repl* :private false)
|
(var *should-repl* false)
|
||||||
(var *no-file* :private true)
|
(var *no-file* true)
|
||||||
(var *raw-stdin* :private false)
|
(var *quiet* false)
|
||||||
(var *handleopts* :private true)
|
(var *raw-stdin* false)
|
||||||
(var *exit-on-error* :private true)
|
(var *handleopts* true)
|
||||||
|
(var *exit-on-error* true)
|
||||||
|
|
||||||
# Flag handlers
|
# Flag handlers
|
||||||
(def handlers :private
|
(def handlers :private
|
||||||
@ -20,6 +21,7 @@
|
|||||||
-e Execute a string of janet
|
-e Execute a string of janet
|
||||||
-r Enter the repl after running all scripts
|
-r Enter the repl after running all scripts
|
||||||
-p Keep on executing if there is a top level error (persistent)
|
-p Keep on executing if there is a top level error (persistent)
|
||||||
|
-q Hide prompt, logo, and repl output (quiet)
|
||||||
-- Stop handling options`)
|
-- Stop handling options`)
|
||||||
(os/exit 0)
|
(os/exit 0)
|
||||||
1)
|
1)
|
||||||
@ -27,6 +29,7 @@
|
|||||||
"s" (fn [&] (set *raw-stdin* true) (set *should-repl* true) 1)
|
"s" (fn [&] (set *raw-stdin* true) (set *should-repl* true) 1)
|
||||||
"r" (fn [&] (set *should-repl* true) 1)
|
"r" (fn [&] (set *should-repl* true) 1)
|
||||||
"p" (fn [&] (set *exit-on-error* false) 1)
|
"p" (fn [&] (set *exit-on-error* false) 1)
|
||||||
|
"q" (fn [&] (set *quiet* true) 1)
|
||||||
"-" (fn [&] (set *handleopts* false) 1)
|
"-" (fn [&] (set *handleopts* false) 1)
|
||||||
"e" (fn [i &]
|
"e" (fn [i &]
|
||||||
(set *no-file* false)
|
(set *no-file* false)
|
||||||
@ -50,11 +53,19 @@
|
|||||||
(++ i))))
|
(++ i))))
|
||||||
|
|
||||||
(when (or *should-repl* *no-file*)
|
(when (or *should-repl* *no-file*)
|
||||||
(if *raw-stdin*
|
(if-not *quiet*
|
||||||
(repl nil (fn [x &] x))
|
(print "Janet " janet/version "-" janet/build " Copyright (C) 2017-2018 Calvin Rose"))
|
||||||
(do
|
(defn noprompt [_] "")
|
||||||
(print (string "Janet " janet/version "-" janet/build " Copyright (C) 2017-2018 Calvin Rose"))
|
(defn getprompt [p]
|
||||||
(repl (fn [buf p]
|
(def offset (parser/where p))
|
||||||
(def offset (parser/where p))
|
(string "janet:" offset ":" (parser/state p) "> "))
|
||||||
(def prompt (string "janet:" offset ":" (parser/state p) "> "))
|
(def prompter (if *quiet* noprompt getprompt))
|
||||||
(getline prompt buf)))))))
|
(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)))
|
||||||
|
Loading…
Reference in New Issue
Block a user