lispyclouds / bblgum

An extremely tiny and simple wrapper around charmbracelet/gum

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Difficulties with joining complex style statements

Eanilsen opened this issue · comments

I would like to first extend my gratitude for this library, it is very cool and easy to work with.

However, I have been having issues when using :style with multi-line return values.
I am going through the gum demo and implementing it using bblgum, but I can't figure out how I should handle the last :join statement as it is combining two multi-line :style results.

If I am not joining, the solution posted by the author in this issue works fine. But alas, not when joining.

The following snippet is what I am trying to recreate. I have added some variables so that it can be copy/pasted into a bash environment to test. The complete script is available at the link provided in a previous paragraph.
Also I removed an exclamation mark, as it was causing issues directly in the terminal, but that is besides the point.

NAME="Foo" 
GUM="Bar" 
NICE_MEETING_YOU=$(gum style --height 5 --width 25 --padding '1 3' --border double --border-foreground 57 "Well, it was nice meeting you, $(gum style --foreground 212 "$NAME"). Hope to see you soon.") 
CHEW_BUBBLE_GUM=$(gum style --width 25 --padding '1 3' --border double --border-foreground 212 "Don't forget to chew some $(gum style --foreground "#04B575" "$GUM") bubble gum.") 
gum join --horizontal "$NICE_MEETING_YOU" "$CHEW_BUBBLE_GUM"

Any assistance appreciated.

You know what, I think posting this issue was enough to figure it out by myself. I simply used clojure.string/join and there you have it.

(let [name (first (:result (b/gum :style ["Foo"] :foreground 212)))
      gum (first (:result (b/gum :style ["Bar"] :foreground "#04B575")))
      nice (str/join "\n"
                     (:result (b/gum :style [(format "Well, it was nice meeting you, %s. Hope to see you soon!" name)]
                                     :height 5
                                     :width 25
                                     :padding "1 3"
                                     :border "double"
                                     :border-foreground 57)))
      chew (str/join "\n"
                     (:result (b/gum :style [(format "Don't forget to chew some %s bubble gum." gum)]
                                     :width 25
                                     :padding "1 3"
                                     :border "double"
                                     :border-foreground 212)))]
  (b/gum :join [nice chew] :horizontal true :as :ignored))

Hopefully this can help someone else.

There is not such function in the library, but it might be helpful to define something like this for extensive scripting:

(defn gumrf 
  "Run a b/gum and return first result"  
  [& args]
  (->> args (apply b/gum) :result first))

Define this on top of the file and save yourself a lot of boilerplate.