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
34 changes: 34 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
## 3.10.0 -- UNRELEASED

Add new functions to `clj-commons.pretty.annotations`
to streamline the typical usage; new functions:

* `create-annotation-set`
* `add-callout`
* `render-annotation-set'

With the new functions, it is possible to set a width
for annotations, which will word-wrap as needed.
Further, if there is insufficient horizontal space for the annotation (by default, at least 30 characters
for the actual text),
then the annotations offsets will be rerouted:

```text
102: (around the tower *)
103: (name *) Base of the Tower
┯ ┯━━━
┌┘ │
│ ┌──────┘
│ └╴ All your base are
│ belong to us
└╴ Mark your time
104: (look *)
105: Behind the concrete building a steel girder rises from the sand
```

This avoids the case where the annotation could be
output as a single tall column of words.
The above example was triggered by having a narrow overall width (30).

Currently, long input lines are not word wrapped; they are output exactly as is.

## 3.9.0 -- 6 Sep 2026

* `clj-commons.ansi/wrap` splits a composed string into a sequence of composed strings for soft or hard wrapping
Expand Down
1 change: 1 addition & 0 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{:extra-paths ["test" "test-resources"]
:extra-deps {org.clojure/core.async {:mvn/version "1.9.865"}
nubank/matcher-combinators {:mvn/version "3.10.1"}
expound/expound {:mvn/version "0.9.0"}
org.clojure/test.check {:mvn/version "1.1.3"}
io.github.cognitect-labs/test-runner {:git/tag "v0.5.1"
:git/sha "dfb30dd"}}
Expand Down
24 changes: 13 additions & 11 deletions src/clj_commons/ansi.clj
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,12 @@
(if (>= i n)
acc
(let [ws? (whitespace-char? (.charAt s i))
j (loop [k (inc i)]
(if (and (< k n)
(= ws? (whitespace-char? (.charAt s k))))
(recur (inc k))
k))]
j (long
(loop [k (inc i)]
(if (and (< k n)
(= ws? (whitespace-char? (.charAt s k))))
(recur (inc k))
k)))]
(recur j (conj acc {:kind (if ws? :ws :word)
:fonts fonts
:text (subs s i j)})))))))
Expand Down Expand Up @@ -472,7 +473,7 @@
(recur (seq more) state)))))))

(defn- wrap-hard
[runs width]
[runs ^long width]
(loop [runs (seq runs)
i 0
line []
Expand All @@ -485,20 +486,21 @@
(recur (next runs) 0 [] (conj lines line) 0)
(let [fonts (:fonts item)
^String text (:text item)
n (.length text)]
n (long (.length text))]
(cond
(>= i n)
(recur (next runs) 0 line lines col)

(= col width)
(let [i (if (whitespace-char? (.charAt text i))
(skip-whitespace text i)
i)]
(let [i (long
(if (whitespace-char? (.charAt text i))
(skip-whitespace text i)
i))]
(recur runs i [] (conj lines line) 0))

:else
(let [fits (- width col)
take-n (min fits (- n i))
take-n (long (min fits (- n i)))
chunk (subs text i (+ i take-n))]
(recur runs
(+ i take-n)
Expand Down
Loading
Loading