(ns sydnix-cli.prelude
  (:require
   [clojure.core.match :refer [match]]))

(defn y-or-n?
  [prompt
   & {:keys [default]
      :or {default :n}
      :as opts}]
  (let [y-n-indicator (case default
                        :y " [Y/n] "
                        :n " [y/N] ")]
    (print (str prompt y-n-indicator))
    (flush))
  (let [line (read-line)]
    (match line
           "" (case default :y true :n false)
           (:or "y" "Y") true
           (:or "n" "N") false
           _ (do (println "Please enter y or n.")
                 (recur prompt opts)))))
