init repo with utils file from cms project
This commit is contained in:
commit
a9c4cca71e
4 changed files with 68 additions and 0 deletions
47
src/gum_utils/core.clj
Normal file
47
src/gum_utils/core.clj
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
(ns gum-utils.core
|
||||
(:require
|
||||
[clojure.string :as str]
|
||||
[babashka.process :refer [shell]]))
|
||||
|
||||
(defn select
|
||||
"Select from a list of options using gum filter.
|
||||
Args:
|
||||
l list of {:item any :value string}"
|
||||
[l]
|
||||
(let [values (map :value l)
|
||||
selected-value (str/trim (:out (apply shell {:out :string} (concat '("gum" "filter") values))))
|
||||
selected-item (:item (first (filter #(= (:value %) selected-value) l)))]
|
||||
selected-item))
|
||||
|
||||
(defn color-print
|
||||
([text] (color-print text "5"))
|
||||
([text color]
|
||||
(shell (format "gum style --foreground %s \"%s\"" color text))))
|
||||
|
||||
(defn print-markdown [text]
|
||||
(shell (format "gum format \"%s\"" text)))
|
||||
|
||||
(defn prompt-for [placeholder & {:keys [prefill]}]
|
||||
(let [cmd (if prefill
|
||||
(format "gum input --placeholder='%s' --value='%s'" placeholder prefill)
|
||||
(format "gum input --placeholder='%s'" placeholder))]
|
||||
(str/trim (-> (shell {:out :string} cmd) :out))))
|
||||
|
||||
(defn prompt-for-many
|
||||
([placeholder]
|
||||
(let [val (prompt-for (str placeholder ", enter done to finish"))]
|
||||
(println val)
|
||||
(if (= val "done")
|
||||
nil
|
||||
(prompt-for-many placeholder `(~val)))))
|
||||
([placeholder carry]
|
||||
(let [val (prompt-for (str placeholder ", enter done to finish"))]
|
||||
(println val)
|
||||
(if (= val "done")
|
||||
carry
|
||||
(prompt-for-many placeholder (conj carry val))))))
|
||||
|
||||
(defn prompt-for-long-form [placeholder & {:keys [prefill]}]
|
||||
(if prefill
|
||||
(-> (shell {:out :string :extra-env {"GUM_WRITE_VALUE" prefill}} (format "gum write --placeholder='%s'" placeholder)) :out)
|
||||
(-> (shell {:out :string} (format "gum write --placeholder='%s'" placeholder)) :out)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue