Liking cljdoc? Tell your friends :D

charm.ansi.width

Text width calculation for terminal display.

Handles:

  • ANSI escape sequences (zero width)
  • Wide characters (CJK, emojis = 2 cells)
  • Combining characters (zero width)
  • Grapheme clusters (emoji sequences)
Text width calculation for terminal display.

Handles:
- ANSI escape sequences (zero width)
- Wide characters (CJK, emojis = 2 cells)
- Combining characters (zero width)
- Grapheme clusters (emoji sequences)
raw docstring

pad-leftclj

(pad-left s width & {:keys [char] :or {char \space}})

Pad a string on the left to reach a target display width.

Pad a string on the left to reach a target display width.
sourceraw docstring

pad-rightclj

(pad-right s width & {:keys [char] :or {char \space}})

Pad a string on the right to reach a target display width.

Pad a string on the right to reach a target display width.
sourceraw docstring

string-widthclj

(string-width s)

Measure the display width of a string in terminal cells.

  • ANSI escape sequences have zero width
  • Wide characters (CJK, emojis) count as 2 cells
  • Combining characters count as 0 cells

Example: (string-width "hello") ; => 5 (string-width "你好") ; => 4 (2 wide chars) (string-width "\033[31mhi") ; => 2 (ANSI ignored)

Measure the display width of a string in terminal cells.

- ANSI escape sequences have zero width
- Wide characters (CJK, emojis) count as 2 cells
- Combining characters count as 0 cells

Example:
  (string-width "hello")     ; => 5
  (string-width "你好")       ; => 4 (2 wide chars)
  (string-width "\033[31mhi") ; => 2 (ANSI ignored)
sourceraw docstring

strip-ansiclj

(strip-ansi s)

Remove ANSI escape sequences from a string.

Remove ANSI escape sequences from a string.
sourceraw docstring

truncateclj

(truncate s width & {:keys [tail] :or {tail "..."}})

Truncate a string to fit within a given display width.

Options: :tail - String to append when truncated (default "...")

The tail is included in the width calculation.

Example: (truncate "hello world" 8) ; => "hello..." (truncate "hello world" 8 :tail "…") ; => "hello w…"

Truncate a string to fit within a given display width.

Options:
  :tail - String to append when truncated (default "...")

The tail is included in the width calculation.

Example:
  (truncate "hello world" 8)           ; => "hello..."
  (truncate "hello world" 8 :tail "…") ; => "hello w…"
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close