- read-event, line-read and the editor loop work in both colours. The leaf is read-bytes, a defbjouble: a bjoroutine awaits the glue's read, other code blocks. with-raw-mode takes a body of either colour. - Cancelling the scope of a waiting line-read ends it and restores the terminal modes. The glue runs reads one at a time. - The key decoder is (bjoterm keys), and widths, prompt escapes, search and common prefixes are (bjoterm text). Clusters and categories come from (std unicode grapheme) and (std unicode chars). - Keys.cs and Text.cs are removed. The glue is termios, signals, poll and read. - New tests: tests/async.bjo and tests/text.bjo. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
32 lines
1.6 KiB
Text
32 lines
1.6 KiB
Text
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
;; Clusters and widths of (bjoterm text).
|
|
;;
|
|
;; bjo test tests/text.bjo
|
|
|
|
(import (std prelude))
|
|
(import (std simpletest))
|
|
(import (bjoterm text))
|
|
|
|
(defun (main args)
|
|
(expect "e and a combining accent is one cluster" (vec-length (text-clusters "e\u{301}x")) 2)
|
|
(expect "an emoji with a skin tone is one cluster" (vec-length (text-clusters "👍🏽")) 1)
|
|
(expect "CR LF is one cluster" (vec-length (text-clusters "\r\n")) 1)
|
|
(expect "ASCII is 1 column" (text-width "abc") 3)
|
|
(expect "CJK is 2 columns" (text-width "中文") 4)
|
|
(expect "a combining accent is 0 columns" (text-width "e\u{301}") 1)
|
|
(expect "a zero-width joiner is 0 columns" (cluster-width "\u{200D}") 0)
|
|
(expect "the soft hyphen is 1 column" (cluster-width "\u{AD}") 1)
|
|
(expect "an emoji is 2 columns" (text-width "👍🏽") 2)
|
|
(expect "a flag is 2 columns" (text-width "🇸🇪") 2)
|
|
(expect "a control is ^X, 2 columns" (cluster-width "\u{1}") 2)
|
|
(expect "escape sequences in a prompt are 0 columns" (text-width "\u{1B}[1mλ>\u{1B}[0m ") 3)
|
|
(expect-true "a letter is part of a word" (word-cluster? "ä"))
|
|
(expect-true "a digit is part of a word" (word-cluster? "7"))
|
|
(expect-true "_ is part of a word" (word-cluster? "_"))
|
|
(expect-true "a bracket is not" (not (word-cluster? "(")))
|
|
(expect "find-clusters does not match inside a cluster" (find-clusters "e\u{301}" "e") -1)
|
|
(expect "common-prefix keeps whole clusters" (common-prefix ["e\u{301}a" "e\u{301}b"]) "e\u{301}")
|
|
0)
|