Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
cider/cider-nrepl {:mvn/version "0.58.0"}}
:main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware]"]}

:examples {:extra-paths ["doc"]}
:examples {:extra-deps {charm/examples {:local/root "doc/examples"}}}

:user {:extra-paths ["user"]}

Expand Down
19 changes: 17 additions & 2 deletions doc/examples/bb.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{:paths ["src" "../../src"]
{:paths ["src" "../../src" "resources"]
:deps {djblue/portal {:mvn/version "0.58.5"}}
:tasks
{cheatsheet {:doc "Run cheatsheet example"
:task (exec 'examples.cheatsheet/-main)}
Expand All @@ -21,6 +22,9 @@
form {:doc "Run form example"
:task (exec 'examples.form/-main)}

talk {:doc "Run talk example"
:task (exec 'examples.talk/-main)}

pomodoro {:doc "Run pomodoro example"
:task (exec 'examples.pomodoro/-main)}

Expand Down Expand Up @@ -49,4 +53,15 @@
(shell "vhs vhs/sketch.tape")
(shell "vhs vhs/spinner.tape")
#_(shell "vhs vhs/timer.tape")
(shell "vhs vhs/todos.tape"))}}}
(shell "vhs vhs/todos.tape"))}

portal {:doc "Start nREPL server with portal + tap> wired up"
:requires ([babashka.nrepl.server :as nrepl]
[portal.api :as p])
:task (do
(p/open)
(add-tap p/submit)
(println "Portal opened. nREPL on localhost:1667")
(nrepl/start-server! {:port 1667})
(deref (promise)))}}}

2 changes: 1 addition & 1 deletion doc/examples/deps.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{:paths ["src"]
{:paths ["src" "resources"]
:deps {de.timokramer/charm.clj {:local/root "../../"}
com.github.clj-easy/graal-build-time {:mvn/version "1.0.5"}}
:aliases
Expand Down
13 changes: 13 additions & 0 deletions doc/examples/resources/talk/slide01.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
__ __ _ _ _ _
\ \ / / __(_) |_ ___ ___| |__ __ _ _ __ _ __ ___ (_)_ __ __ _
\ \ /\ / / '__| | __/ _ \ / __| '_ \ / _` | '__| '_ ` _ \| | '_ \ / _` |
\ V V /| | | | || __/ | (__| | | | (_| | | | | | | | | | | | | (_| |
\_/\_/ |_| |_|\__\___| \___|_| |_|\__,_|_| |_| |_| |_|_|_| |_|\__, |
|___/
_____ _ _ ___ _ _ _ _ _
|_ _| | | |_ _|___ (_)_ __ | |__ __ _| |__ __ _ ___| |__ | | ____ _
| | | | | || |/ __| | | '_ \ | '_ \ / _` | '_ \ / _` / __| '_ \| |/ / _` |
| | | |_| || |\__ \ | | | | | | |_) | (_| | |_) | (_| \__ \ | | | < (_| |
|_| \___/|___|___/ |_|_| |_| |_.__/ \__,_|_.__/ \__,_|___/_| |_|_|\_\__,_|

by Timo Kramer
6 changes: 6 additions & 0 deletions doc/examples/resources/talk/slide02.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
_____ _ _ _ _
|_ _| |__ ___ | |__ ___ __ _(_)_ __ _ __ (_)_ __ __ _
| | | '_ \ / _ \ | '_ \ / _ \/ _` | | '_ \| '_ \| | '_ \ / _` |
| | | | | | __/ | |_) | __/ (_| | | | | | | | | | | | | (_| |
|_| |_| |_|\___| |_.__/ \___|\__, |_|_| |_|_| |_|_|_| |_|\__, |
|___/ |___/
13 changes: 13 additions & 0 deletions doc/examples/resources/talk/slide03.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
_ _ _ _
(_) (_)_ __ ___ __ _ _ __ __| |
| | | | '_ \ / _ \ / _` | '_ \ / _` |
| | | | | | | __/ | (_| | | | | (_| |
_/ |_|_|_| |_|\___| \__,_|_| |_|\__,_|
|__/
_ _ _ _
___| |__ __ _ _ __ _ __ ___ | |__ _ __ __ _ ___ ___| | ___| |_
/ __| '_ \ / _` | '__| '_ ` _ \| '_ \| '__/ _` |/ __/ _ \ |/ _ \ __|
| (__| | | | (_| | | | | | | | | |_) | | | (_| | (_| __/ | __/ |_
\___|_| |_|\__,_|_| |_| |_| |_|_.__/|_| \__,_|\___\___|_|\___|\__|

😈😊🏳️‍🌈🙂‍↔️👨‍👩‍👧🇳🇱👍🏿
12 changes: 12 additions & 0 deletions doc/examples/resources/talk/slide04.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
____ _ _ _
| __ ) __ _| |_| |_ ___ _ __(_) ___ ___
| _ \ / _` | __| __/ _ \ '__| |/ _ \/ __|
| |_) | (_| | |_| || __/ | | | __/\__ \
|____/ \__,_|\__|\__\___|_| |_|\___||___/

_ _ _ _
(_)_ __ ___| |_ _ __| | ___ __| |
| | '_ \ / __| | | | |/ _` |/ _ \/ _` |
| | | | | (__| | |_| | (_| | __/ (_| |
|_|_| |_|\___|_|\__,_|\__,_|\___|\__,_|

12 changes: 12 additions & 0 deletions doc/examples/resources/talk/slide05.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
____ _____ ____ _
| _ \| ____| _ \| |
| |_) | _| | |_) | |
| _ <| |___| __/| |___
|_| \_\_____|_| |_____|

_ _ _
__| | _____ _____| | ___ _ __ _ __ ___ ___ _ __ | |_
/ _` |/ _ \ \ / / _ \ |/ _ \| '_ \| '_ ` _ \ / _ \ '_ \| __|
| (_| | __/\ V / __/ | (_) | |_) | | | | | | __/ | | | |_
\__,_|\___| \_/ \___|_|\___/| .__/|_| |_| |_|\___|_| |_|\__|
|_|
7 changes: 7 additions & 0 deletions doc/examples/resources/talk/slide06.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
___ _
/ _ \__ _____ _ __| | __ _ _ _
| | | \ \ / / _ \ '__| |/ _` | | | |
| |_| |\ V / __/ | | | (_| | |_| |
\___/ \_/ \___|_| |_|\__,_|\__, |
|___/

6 changes: 6 additions & 0 deletions doc/examples/resources/talk/slide07.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
_ _ _ _
/ \ _ __ (_)_ __ ___ __ _| |_(_) ___ _ __ ___
/ _ \ | '_ \| | '_ ` _ \ / _` | __| |/ _ \| '_ \/ __|
/ ___ \| | | | | | | | | | (_| | |_| | (_) | | | \__ \
/_/ \_\_| |_|_|_| |_| |_|\__,_|\__|_|\___/|_| |_|___/

6 changes: 6 additions & 0 deletions doc/examples/resources/talk/slide08.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
____ _ _ _
| _ \ __ _ __ _(_)_ __ __ _| |_(_) ___ _ __
| |_) / _` |/ _` | | '_ \ / _` | __| |/ _ \| '_ \
| __/ (_| | (_| | | | | | (_| | |_| | (_) | | | |
|_| \__,_|\__, |_|_| |_|\__,_|\__|_|\___/|_| |_|
|___/
6 changes: 6 additions & 0 deletions doc/examples/resources/talk/slide09.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
_____ _ _
| ____|_ __ ___ ___ (_|_)___
| _| | '_ ` _ \ / _ \| | / __|
| |___| | | | | | (_) | | \__ \
|_____|_| |_| |_|\___// |_|___/
|__/
50 changes: 17 additions & 33 deletions doc/examples/src/examples/pomodoro.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
[charm.components.timer :as timer]
[charm.message :as msg]
[charm.program :as program]
[charm.style.core :as style]
[clojure.string :as str])
[charm.style.core :as style])
(:gen-class))

;; ---------------------------------------------------------------------------
Expand Down Expand Up @@ -96,11 +95,12 @@
(style/render hint-style "↑/↓ to select, Enter to start, q to quit"))))

;; ---------------------------------------------------------------------------
;; View - Timer Running
;; View - Timer
;; ---------------------------------------------------------------------------

(defn view-running [state]
(let [{:keys [phase timer total-ms cycle-count]} state
(defn view-timer [state]
(let [{:keys [phase timer total-ms cycle-count screen]} state
paused? (= screen :paused)
remaining (max 0 (timer/timeout timer))
elapsed (- total-ms remaining)
p (if (pos? total-ms) (/ elapsed total-ms) 0.0)
Expand All @@ -112,48 +112,24 @@
:empty-style (style/style :fg (gradient-color p phase true)))]
(str (style/render (phase-style phase) phase-label)
(style/render hint-style (str " (cycle " cycle-count ")"))
(when paused? " ")
(when paused? (style/render (style/style :fg (style/rgb 255 200 100) :bold true) "PAUSED"))
"\n\n"
(progress/progress-view bar)
" "
(style/render time-style (format-remaining remaining))
"\n\n"
(style/render hint-style "p to pause/resume, q to quit"))))

;; ---------------------------------------------------------------------------
;; View - Paused
;; ---------------------------------------------------------------------------

(defn view-paused [state]
(let [{:keys [phase timer total-ms cycle-count]} state
remaining (max 0 (timer/timeout timer))
elapsed (- total-ms remaining)
p (if (pos? total-ms) (/ elapsed total-ms) 0.0)
phase-label (if (= phase :work) "WORK" "BREAK")
bar (progress/progress-bar :width 30
:percent p
:bar-style :thick
:full-style (style/style :fg (gradient-color p phase))
:empty-style (style/style :fg (gradient-color p phase true)))]
(str (style/render (phase-style phase) phase-label)
(style/render hint-style (str " (cycle " cycle-count ")"))
" "
(style/render (style/style :fg (style/rgb 255 200 100) :bold true) "PAUSED")
"\n\n"
(progress/progress-view bar)
" "
(style/render time-style (format-remaining remaining))
"\n\n"
(style/render hint-style "p to resume, q to quit"))))

;; ---------------------------------------------------------------------------
;; Main View
;; ---------------------------------------------------------------------------

(defn view [state]
(case (:screen state)
:selecting (view-selecting state)
:running (view-running state)
:paused (view-paused state)))
:running (view-timer state)
:paused (view-timer state)))

;; ---------------------------------------------------------------------------
;; Timer Helpers
Expand All @@ -180,6 +156,7 @@
;; ---------------------------------------------------------------------------

(defn update-fn [state msg]
(tap> state)
(let [{:keys [screen]} state]
(cond
;; Global quit
Expand Down Expand Up @@ -269,3 +246,10 @@
:alt-screen false
:hide-cursor true})
(println))))

(comment
(def app (program/run-async {:init init
:update #'update-fn
:view #'view
:alt-screen false
:hide-cursor true})))
Loading
Loading