Main styling API.
Create styles as maps and apply them to text.
Example: (def my-style (style :fg (rgb 255 0 0) :bold true :padding [1 2])) (render my-style "Hello!") ; => styled text
Main styling API. Create styles as maps and apply them to text. Example: (def my-style (style :fg (rgb 255 0 0) :bold true :padding [1 2])) (render my-style "Hello!") ; => styled text
(attributed-string style-map text)Create a JLine AttributedString with the given style applied.
This avoids the ANSI parse/unparse cycle when building content that will be rendered directly via JLine's Display.
For single lines without layout (padding, border, margin): (attributed-string my-style "Hello!")
For multiple parts with different styles: (-> (AttributedStringBuilder.) (.styled (style->attributed-style style1) "part1") (.styled (style->attributed-style style2) "part2") (.toAttributedString))
Create a JLine AttributedString with the given style applied.
This avoids the ANSI parse/unparse cycle when building content
that will be rendered directly via JLine's Display.
For single lines without layout (padding, border, margin):
(attributed-string my-style "Hello!")
For multiple parts with different styles:
(-> (AttributedStringBuilder.)
(.styled (style->attributed-style style1) "part1")
(.styled (style->attributed-style style2) "part2")
(.toAttributedString))(frame-size {:keys [padding margin border]})Calculate the frame size (padding + border + margin) of a style. Returns [width height].
Calculate the frame size (padding + border + margin) of a style. Returns [width height].
(merge-style s & {:as opts})A copy of s with the named options changed.
style fills in every key, so (merge base variant) overwrites the base with
the variant's defaults - nil colors, false attributes - instead of
inheriting them. This changes only the options given, which is what building a
variant of a base style wants:
(def base (style :fg 240 :padding [0 1])) (def selected (merge-style base :fg :white :bold true))
Because the options are named rather than taken from another style map, there
is no guessing about which keys were meant: (merge-style base :bold false)
turns bold off.
A copy of `s` with the named options changed. `style` fills in every key, so `(merge base variant)` overwrites the base with the variant's *defaults* - nil colors, false attributes - instead of inheriting them. This changes only the options given, which is what building a variant of a base style wants: (def base (style :fg 240 :padding [0 1])) (def selected (merge-style base :fg :white :bold true)) Because the options are named rather than taken from another style map, there is no guessing about which keys were meant: `(merge-style base :bold false)` turns bold off.
(render style & strings)Render text with a style applied.
(render style "text") (render style "multiple" "strings")
Render text with a style applied. (render style "text") (render style "multiple" "strings")
(style & {:as opts})Create a style map.
Options: ;; Colors (a color map, an ANSI 256 int like 240, an ANSI 16 ;; name keyword like :red, or a hex string like "#ff8000") :fg - Foreground color :bg - Background color
;; Text attributes :bold - Bold text :italic - Italic text :underline - Underline text :blink - Blinking text :faint - Faint/dim text :reverse - Reverse video :strikethrough - Strikethrough text
;; Dimensions :width - Fixed width (pads/truncates) :height - Fixed height
;; Alignment :align - Horizontal alignment (:left :center :right) :valign - Vertical alignment (:top :center :bottom)
;; Spacing (1-4 values in CSS order, or a bare number for all sides) :padding - Padding [top right bottom left] :margin - Margin [top right bottom left]
;; Border :border - Border style (from charm.style.border) :border-fg - Border foreground color :border-bg - Border background color
;; Rendering :inline - Remove newlines when true
Create a style map. Options: ;; Colors (a color map, an ANSI 256 int like 240, an ANSI 16 ;; name keyword like :red, or a hex string like "#ff8000") :fg - Foreground color :bg - Background color ;; Text attributes :bold - Bold text :italic - Italic text :underline - Underline text :blink - Blinking text :faint - Faint/dim text :reverse - Reverse video :strikethrough - Strikethrough text ;; Dimensions :width - Fixed width (pads/truncates) :height - Fixed height ;; Alignment :align - Horizontal alignment (:left :center :right) :valign - Vertical alignment (:top :center :bottom) ;; Spacing (1-4 values in CSS order, or a bare number for all sides) :padding - Padding [top right bottom left] :margin - Margin [top right bottom left] ;; Border :border - Border style (from charm.style.border) :border-fg - Border foreground color :border-bg - Border background color ;; Rendering :inline - Remove newlines when true
(style->attributed-style {:keys [fg bg bold italic underline blink faint reverse
strikethrough]})Convert style map to JLine AttributedStyle.
Useful for direct AttributedString construction: (AttributedString. text (style->attributed-style my-style))
Convert style map to JLine AttributedStyle. Useful for direct AttributedString construction: (AttributedString. text (style->attributed-style my-style))
(styled text & style-opts)Apply style directly to text. Shorthand for (render (style opts...) text).
(styled "hello" :fg (rgb 255 0 0) :bold true)
Apply style directly to text. Shorthand for (render (style opts...) text). (styled "hello" :fg (rgb 255 0 0) :bold true)
(with-align s align)Set horizontal alignment.
Set horizontal alignment.
(with-margin s margin)Set margin. Accepts [t r b l] or single value.
Set margin. Accepts [t r b l] or single value.
(with-padding s padding)Set padding. Accepts [t r b l] or single value.
Set padding. Accepts [t r b l] or single value.
(with-valign s valign)Set vertical alignment.
Set vertical alignment.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |