Text width calculation for terminal display.
Handles:
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)
(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.
(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.
(string-width s)Measure the display width of a string in terminal 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)
(strip-ansi s)Remove ANSI escape sequences from a string.
Remove ANSI escape sequences from a string.
(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…"
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 |