Skip to content

Commit

Permalink
update venice console script
Browse files Browse the repository at this point in the history
  • Loading branch information
juerg committed Jan 16, 2024
1 parent c3386fb commit 9dc0213
Showing 1 changed file with 33 additions and 47 deletions.
80 changes: 33 additions & 47 deletions src/main/resources/com/github/jlangch/venice/venice.venice
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
(import :com.github.jlangch.venice.EofException)



(defonce logo
"""
__ __ _
\\ \\ / /__ _ __ (_) ___ ___
\\ \\/ / _ \\ '_ \\| |/ __/ _ \\
\\ / __/ | | | | (_| __/
\\/ \\___|_| |_|_|\\___\\___|
""" )

(defonce COLORS {
:light { :logo "[38;5;33m"
:status "[38;5;64m"
Expand Down Expand Up @@ -73,7 +83,7 @@
;; "--debug"
"-Dorg.gradle.java.home=\"~{java-home}\""])

(defonce display-status? false)
(defonce display-status-bar? false)



Expand Down Expand Up @@ -106,14 +116,10 @@
"-PsonatypeUsername=\"~{sonatype-user}\""
"-PsonatypePassword=\"~{sonatype-pwd}\""))



;; -----------------------------------------------------------------------------
;; Gradle utils -
;; -----------------------------------------------------------------------------

(defn gradle-tasks [& args]
(apply gradlew/run* proj-home println warning
(apply gradlew/run* proj-home
(partial (printlnc :stdout))
(partial (printlnc :stderr))
(concat gradle-std-options args)))


Expand Down Expand Up @@ -148,48 +154,31 @@
;; Util -
;; -----------------------------------------------------------------------------

(def logo
"""
__ __ _
\\ \\ / /__ _ __ (_) ___ ___
\\ \\/ / _ \\ '_ \\| |/ __/ _ \\
\\ / __/ | | | | (_| __/
\\/ \\___|_| |_|_|\\___\\___|
""" )

(defn fatal-error-and-exit [msg]
(println)
(error msg)
(printlnc :error msg)
(println)
(sleep 5000) ;; give the user time to read the error message
(throw (ex :EofException msg)))

(defn status [msg]
(println (ansi/style (str msg) (color :status))))

(defn error [msg]
(println (ansi/style (str msg) (color :error))))

(defn warning [msg]
(println (ansi/style (str msg) (color :warning))))

(defn invalid-cmd [msg]
(println (ansi/style (str msg) (color :warning))))
(printlnc :warning msg))

(defn display-welcome-msg []
(docoll #(println (ansi/style % :bold (color :logo)))
(str/split-lines logo)))
(docoll #(printlnc-bold :logo %) (str/split-lines logo)))

(defn show-color-theme []
(doseq [code [:logo :status :result :stdout :stderr :warning :error]]
(println (ansi/style (name code) (color code)))))
(printlnc code (name code))))

(defn printlnc [color-code text]
(println (ansi/style (str text) (ansi-color color-code))))

(defn color [code]
(-> (*repl-color-theme* COLORS (:light COLORS))
(code :stdout)))
(defn printlnc-bold [color-code text]
(println (ansi/style (str text) :bold (ansi-color color-code))))

(defn color-theme []
*repl-color-theme*)
(defn ansi-color [code]
(code (*repl-color-theme* COLORS (:light COLORS)) :stdout))

(defn help []
(println
Expand Down Expand Up @@ -230,13 +219,13 @@
"""))


(defn display-status []
(when display-status?
(defn display-status-bar []
(when display-status-bar?
(let [cols (repl/term-cols)
left (str/format "%s" (java-version))
right ""
delim (str/repeat "-" (- cols 8 (count left) (count right)))]
(status (str/format "-- %s %s %s --" left delim right)))))
(printlnc :status (str/format "-- %s %s %s --" left delim right)))))


(defn run-command [cmd & args]
Expand All @@ -258,10 +247,7 @@
(match? cmd "h|help") (help)
(match? cmd "x|exit") (exit)
(match? cmd "q|quit") (exit)
:else (invalid-cmd (str "Invalid command: "
cmd
" "
(str/join " " args)))))
:else (printlnc :warning "Invalid command: ~{cmd}")))

(defn split-command [cmd]
(let [c (str/trim-to-nil cmd)]
Expand All @@ -276,13 +262,13 @@
(defn handle-command [cmd]
(try
(apply run-command (split-command cmd))
(display-status)
(display-status-bar)
(catch :EofException ex
(error "Terminating shell...")
(printlnc :error "Terminating shell...")
(sleep 1000)
(throw ex))
(catch :java.lang.Exception ex
(error (str "Error: " (:message ex))))))
(printlnc :error (str "Error: " (:message ex))))))



Expand All @@ -305,4 +291,4 @@
(repl/handler handle-command)

(display-welcome-msg)
(display-status)
(display-status-bar)

0 comments on commit 9dc0213

Please sign in to comment.