line-read: #:highlighter draws parts of the input styled; 0.2.3

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Linus Björnstam 2026-12-01 14:58:26 +01:00
parent 4eef978b6b
commit 3f6ccc3c39
3 changed files with 69 additions and 12 deletions

View file

@ -308,6 +308,20 @@
(simulate-line (make-line-editor) (keys [(typed "!") [enter]]) #:initial "hi")
(Tuple (Some (LineText "hi!")) "hi!"))
;; Highlighting.
(expect "a highlight styles its characters, the last one winning"
(cluster-styles (make-line-editor #:highlighter
(Some (fun (text)
[(Highlight (start 0) (end 3) (style [StyleBold]))
(Highlight (start 1) (end 2) (style [StyleUnderline]))])))
["a" "b" "c" "d"])
[[StyleBold] [StyleUnderline] [StyleBold] []])
(expect "offsets count characters, not clusters"
(cluster-styles (make-line-editor #:highlighter
(Some (fun (text) [(Highlight (start 2) (end 3) (style [StyleBold]))])))
["e\u{301}" "x"])
[[] [StyleBold]])
;; The list of candidates.
(expect "without descriptions, in columns" (completion-listing ["ab" "cd" "ef"] [] 20) "ab cd ef\n")
(expect "with them, one a row"