Skip to content
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
![Status](https://img.shields.io/badge/status-beta-blue)
[![Clojars Project](https://img.shields.io/clojars/v/de.timokramer/charm.clj.svg)](https://clojars.org/de.timokramer/charm.clj)
[![GitHub tag](https://img.shields.io/github/v/tag/TimoKramer/charm.clj?label=git%20tag)](https://github.com/TimoKramer/charm.clj/tags)
[![bb compatible](https://raw.githubusercontent.com/babashka/babashka/master/logo/badge.svg)](https://book.babashka.org#badges)

A Clojure TUI (Terminal User Interface) library inspired by [Bubble Tea](https://github.com/charmbracelet/bubbletea).

Expand Down
4 changes: 2 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{:paths ["src"]
:deps {org.clojure/clojure {:mvn/version "1.12.4"}
org.clojure/core.async {:mvn/version "1.8.741"}
org.jline/jline-terminal-ffm {:mvn/version "4.0.10"
org.jline/jline-terminal-ffm {:mvn/version "4.0.12"
:exclusions [org.jline/jline-native]}
org.jline/jline-reader {:mvn/version "4.0.10"}}
org.jline/jline-reader {:mvn/version "4.0.12"}}

:aliases {:test {:extra-paths ["test"]
:extra-deps {io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}}
Expand Down
33 changes: 24 additions & 9 deletions doc/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,53 @@
## Run examples

```
clj -M -m examples.pomodoro
bb cheatsheet
```
![cheatsheet gif](images/cheatsheet.gif)
```
bb pomodoro
```
![pomodoro gif](images/pomodoro.gif)
```
clj -M -m examples.download
bb download
```
![download gif](images/download.gif)
```
clj -M -m examples.spinner-demo
bb spinner
```
![spinner gif](images/spinner.gif)
```
clj -M -m examples.todos
bb todos
```
![todos gif](images/todos.gif)
```
clj -M -m examples.countdown
bb countdown
```
![countdown gif](images/countdown.gif)
```
clj -M -m examples.file-browser
bb file-browser
```
![file browser gif](images/file_browser.gif)
```
clj -M -m examples.form
bb form
```
![form gif](images/form.gif)
```
clj -M -m examples.counter
bb counter
```
![counter gif](images/counter.gif)
```
bb timer 5
```
![timer gif](images/timer.gif)
```
bb sketch
```
![sketch gif](images/sketch.gif)
```
bb emojis
```
![emojis gif](images/emojis.gif)

## native-image compilation

Expand All @@ -42,4 +58,3 @@ clj -T:build all
native-image -jar target/timer.jar -o timer
./timer -n Pomodoro 30m
```

28 changes: 23 additions & 5 deletions doc/examples/bb.edn
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
counter {:doc "Run counter example"
:task (exec 'examples.counter/-main)}

emoji-width {:doc "Run emoji width demo"
:task (exec 'examples.emoji-width/-main)}
emojis {:doc "Run emojis example"
:task (exec 'examples.emojis/-main)}

download {:doc "Run download example"
:task (exec 'examples.download/-main)}
Expand All @@ -24,11 +24,29 @@
pomodoro {:doc "Run pomodoro example"
:task (exec 'examples.pomodoro/-main)}

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

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

timer {:doc "Run timer example"
:task (exec 'examples.timer/-main)}
:requires ([examples.timer])
:task (apply examples.timer/-main *command-line-args*)}

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

recreate-gifs {:doc "Recreate all gifs with vhs"
:task (do (shell "vhs vhs/cheatsheet.tape")
(shell "vhs vhs/countdown.tape")
(shell "vhs vhs/counter.tape")
#_(shell "vhs vhs/emojis.tape")
(shell "vhs vhs/download.tape")
(shell "vhs vhs/file-browser.tape")
(shell "vhs vhs/form.tape")
(shell "vhs vhs/pomodoro.tape")
(shell "vhs vhs/sketch.tape")
(shell "vhs vhs/spinner.tape")
#_(shell "vhs vhs/timer.tape")
(shell "vhs vhs/todos.tape"))}}}
Binary file added doc/examples/images/cheatsheet.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/examples/images/countdown.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/examples/images/counter.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/examples/images/download.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/examples/images/emojis.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/examples/images/file_browser.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/examples/images/form.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/examples/images/pomodoro.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/examples/images/sketch.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/examples/images/spinner.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/examples/images/timer.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/examples/images/todos.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions doc/examples/src/examples/cheatsheet.clj
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@
(vec (map (fn [kw] (symbol (namespace kw) (name kw))) see-alsos)))))

(defn- open-overlay [state fn-sym]
(let [overlay-width (max 40 (min 60 (- (:width state) 10)))
(let [overlay-width (max 40 (- (:width state) 10))
content-width (- overlay-width 4)
content (build-overlay-content fn-sym content-width)
overlay-height (max 5 (min (- (:height state) 6) 20))
overlay-height (max 5 (- (:height state) 12))
see-alsos (or (extract-see-alsos fn-sym) [])]
(-> state
(assoc :mode :overlay)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
(ns examples.emoji-width
(ns examples.emojis
"Demonstrates grapheme cluster width handling with emoji in tables and borders.

Shows that ZWJ sequences, flags, and skin-tone emoji are measured correctly
when JLine 4 Mode 2027 is active (see ADR 006)."
when JLine 4 Mode 2027 is active (see ADR 007)."
(:require
[charm.core :as charm]
[charm.ansi.width :as w]))
[charm.components.table :as table]
[charm.message :as msg]
[charm.program :as program]
[charm.style.core :as style]))

;; ---------------------------------------------------------------------------
;; Data
Expand Down Expand Up @@ -34,28 +36,28 @@
;; ---------------------------------------------------------------------------

(def title-style
(charm/style :bold true :fg charm/magenta))
(style/style :bold true :fg style/magenta))

(def subtitle-style
(charm/style :fg charm/cyan :italic true))
(style/style :fg style/cyan :italic true))

(def box-style
(charm/style :border charm/rounded-border
(style/style :border style/rounded-border
:padding [0 1]
:border-fg charm/cyan))
:border-fg style/cyan))

(def header-style
(charm/style :bold true :fg charm/yellow))
(style/style :bold true :fg style/yellow))

(def cursor-style
(charm/style :bold true :fg charm/green))
(style/style :bold true :fg style/green))

;; ---------------------------------------------------------------------------
;; Init / Update / View
;; ---------------------------------------------------------------------------

(defn init []
(let [tbl (charm/table [{:title "Emoji" :width 6}
(let [tbl (table/table [{:title "Emoji" :width 6}
{:title "Name" :width 22}
{:title "Type" :width 34}
{:title "Expect" :width 6}
Expand All @@ -70,21 +72,21 @@

(defn update-fn [tbl msg]
(cond
(or (charm/key-match? msg "q")
(charm/key-match? msg "ctrl+c"))
[tbl charm/quit-cmd]
(or (msg/key-match? msg "q")
(msg/key-match? msg "ctrl+c"))
[tbl program/quit-cmd]

:else
(charm/table-update tbl msg)))
(table/table-update tbl msg)))

(defn view [tbl]
(let [rows (mapv (fn [[emoji name desc]]
[emoji name desc "2" (str (w/string-width emoji))])
[emoji name desc "2" (str (style/string-width emoji))])
emoji-rows)
tbl (assoc tbl :rows rows)]
(str (charm/render title-style "Grapheme Cluster Width Demo") "\n"
(charm/render subtitle-style "Emoji should align neatly if Mode 2027 is active") "\n\n"
(charm/render box-style (charm/table-view tbl {:separator " │ "}))
(str (style/render title-style "Grapheme Cluster Width Demo") "\n"
(style/render subtitle-style "Emoji should align neatly if Mode 2027 is active") "\n\n"
(style/render box-style (table/table-view tbl {:separator " │ "}))
"\n\n"
"j/k navigate q quit")))

Expand All @@ -93,7 +95,7 @@
;; ---------------------------------------------------------------------------

(defn -main [& _args]
(charm/run {:init init
:update update-fn
:view view
:alt-screen true}))
(program/run {:init init
:update update-fn
:view view
:alt-screen true}))
25 changes: 25 additions & 0 deletions doc/examples/vhs/cheatsheet.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Output images/cheatsheet.gif

Set Width 1200
Set Height 600
Set TypingSpeed 300ms
Set Shell bash

Type "bb cheatsheet"
Enter
Escape
Type "[?2027;2$y"
Escape
Type "jjjjllllll/walk"
Sleep 500ms
Escape
Type "[C"
Enter
Type "jjjjjjjjq"
Escape
Type "q"
Sleep 500ms
Backspace
Sleep 500ms
Escape
Type "q"
14 changes: 14 additions & 0 deletions doc/examples/vhs/emojis.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Output images/emojis.gif

Set Shell zsh
Set TypingSpeed 200ms
Set Width 2000
Set FontFamily "Fira Code"

Type "bb emojis"
Enter
Escape
Type "[?2027;2$y"
Escape
Type "jjjjjkkkjjjjjjjq"
Type "q"
Loading
Loading