(ns examples.counter "Simple counter example - demonstrates basic Elm architecture. Mirrors bubbletea's simple example." (:require [tui.core :as tui])) ;; === Model === (def initial-model {:count 0}) ;; === Update === (defn update-model [model msg] (cond ;; Quit on q or ctrl+c (or (tui/key= msg "q") (tui/key= msg [:ctrl \c])) [model tui/quit] ;; Increment on up/k (or (tui/key= msg :up) (tui/key= msg "k")) [(update model :count inc) nil] ;; Decrement on down/j (or (tui/key= msg :down) (tui/key= msg "j")) [(update model :count dec) nil] ;; Reset on r (tui/key= msg "r") [(assoc model :count 0) nil] :else [model nil])) ;; === View === (defn view [{:keys [count]}] [:col {:gap 1} [:box {:border :rounded :padding [0 1]} [:col [:text {:bold true} "Counter"] [:text ""] [:text {:fg (cond (pos? count) :green (neg? count) :red :else :default)} (str "Count: " count)]]] [:text {:fg :gray} "j/k or up/down: change value"] [:text {:fg :gray} "r: reset q: quit"]]) ;; === Main === (defn -main [& _args] (println "Starting counter...") (let [final-model (tui/run {:init initial-model :update update-model :view view})] (println "Final count:" (:count final-model))))