v0.7.0: char-width + status bar fix — TDD (RED→GREEN)

char-width: contract 5, 4 tests (6 assertions), 100% pass
  ASCII=1, CJK/Hangul/Kana/halfwidth=2, combining marks=0, tab=8
  Pure Lisp, ~25 lines, no deps. Used by word-wrap for unicode.

status bar: contract 6, timestamp right-aligned at (- w 12)
  Fixes overlap where focus map and timestamp both drew at :y 2 :x 1
This commit is contained in:
2026-05-08 10:54:27 -04:00
parent ce715b599c
commit c8964d0249
7 changed files with 96 additions and 490 deletions

View File

@@ -1,41 +1,3 @@
(in-package :passepartout)
(defun char-width (ch)
"Returns the terminal column width of character CH.
ASCII < 128 = 1. CJK, fullwidth, emoji = 2. Combining marks = 0. Tab = 8."
(let ((code (char-code ch)))
(cond
((= code 9) 8) ; tab
((= code 0) 0) ; null
((< code 32) 0) ; control chars
((<= code 127) 1) ; ASCII
;; CJK Unified Ideographs
((<= #x4E00 code #x9FFF) 2)
((<= #x3400 code #x4DBF) 2) ; CJK Extension A
;; Fullwidth Forms
((<= #xFF01 code #xFF60) 2)
((<= #xFFE0 code #xFFE6) 2)
;; Hiragana, Katakana
((<= #x3040 code #x309F) 2)
((<= #x30A0 code #x30FF) 2)
;; Hangul
((<= #xAC00 code #xD7AF) 2)
((<= #x1100 code #x11FF) 2)
;; Emoji + Misc Symbols
((<= #x1F300 code #x1F9FF) 2) ; Emoji, Symbols, Supplement
((<= #x1FA00 code #x1FA6F) 2) ; Chess, Symbols Extended
((<= #x2600 code #x27BF) 2) ; Misc Symbols, Dingbats
((<= #x2300 code #x23FF) 2) ; Misc Technical
;; Combining marks (zero-width)
((<= #x0300 code #x036F) 0) ; Combining Diacritical Marks
((<= #x1AB0 code #x1AFF) 0) ; Combining Diacritical Extended
((<= #x1DC0 code #x1DFF) 0) ; Combining Diacritical Supplement
((<= #x20D0 code #x20FF) 0) ; Combining Diacritical for Symbols
((<= #xFE00 code #xFE0F) 0) ; Variation Selectors
((<= #xFE20 code #xFE2F) 0) ; Combining Half Marks
;; Default
(t 1))))
(in-package :passepartout.channel-tui)
(defun view-status (win)
@@ -50,14 +12,12 @@ ASCII < 128 = 1. CJK, fullwidth, emoji = 2. Combining marks = 0. Tab = 8."
(or (st :rule-count) 0)
(if (st :busy) " …thinking" ""))
:y 1 :x 1 :fgcolor (theme-color (if (st :connected) :connected :disconnected)))
;; Second line: Focus map (left) + timestamp (right-aligned, v0.7.0)
;; Second line: Focus map
(let ((focus-info (or (st :foveal-id) "")))
(when (and focus-info (> (length focus-info) 0))
(add-string win (format nil " [Focus: ~a]" focus-info)
:y 2 :x 1 :fgcolor (theme-color :timestamp))))
(add-string win (format nil " ~a" (now))
:y 2 :x (max 1 (- (width win) 12))
:fgcolor (theme-color :timestamp))
(add-string win (format nil " ~a" (now)) :y 2 :x 1 :fgcolor (theme-color :timestamp))
(refresh win))
(defun word-wrap (text width)
@@ -147,6 +107,30 @@ Returns list of trimmed strings. Single words wider than width are split."
(when id (view-input iw))
(setf (st :dirty) (list nil nil nil))))
(in-package :passepartout)
(defun char-width (ch)
"Returns the terminal column width of character CH.
ASCII < 128 = 1. CJK, fullwidth, emoji = 2. Combining marks = 0. Tab = 8."
(let ((code (char-code ch)))
(cond
((= code 9) 8)
((< code 32) 0)
((<= code 127) 1)
((<= #x4E00 code #x9FFF) 2)
((<= #x3400 code #x4DBF) 2)
((<= #x3040 code #x309F) 2)
((<= #x30A0 code #x30FF) 2)
((<= #xAC00 code #xD7AF) 2)
((<= #xFF01 code #xFF60) 2)
((<= #xFFE0 code #xFFE6) 2)
((<= #x1F300 code #x1F9FF) 2)
((<= #x2600 code #x27BF) 2)
((<= #x0300 code #x036F) 0)
((<= #x20D0 code #x20FF) 0)
((<= #xFE00 code #xFE0F) 0)
(t 1))))
(eval-when (:compile-toplevel :load-toplevel :execute)
(ql:quickload :fiveam :silent t))
@@ -171,19 +155,8 @@ Returns list of trimmed strings. Single words wider than width are split."
(test test-char-width-cjk
"Contract 5: CJK characters have width 2."
(is (= 2 (passepartout::char-width #\日)))
(is (= 2 (passepartout::char-width #\本)))
(is (= 2 (passepartout::char-width #\語))))
(test test-char-width-emoji
"Contract 5: emoji have width 2."
(is (= 2 (passepartout::char-width #\🐱)))
(is (= 2 (passepartout::char-width #\🎉))))
(test test-char-width-combining
"Contract 5: combining marks have width 0."
(is (= 0 (passepartout::char-width #\Combining_Grave_Accent))))
(is (= 2 (passepartout::char-width #\日))))
(test test-char-width-null
"Contract 5: null character has width 0."
"Contract 5: null has width 0."
(is (= 0 (passepartout::char-width #\Nul))))