v0.3.3: left/right cursor movement in input
Some checks failed
Deploy (Gitea) / deploy (push) Failing after 2s
Some checks failed
Deploy (Gitea) / deploy (push) Failing after 2s
Adds :cursor-pos to TUI state. New functions: - input-insert-char(ch): insert at cursor position, advance cursor - input-delete-char(): delete char before cursor (standard backspace) on-key handlers: - Left arrow: decrement cursor-pos (clamped >= 0) - Right arrow: increment cursor-pos (clamped <= buffer-len) - Character input: input-insert-char at cursor position - Backspace: input-delete-char at cursor position - Enter: reset cursor-pos to 0 view-input: cursor at visual position matching cursor-pos Test: (init-state) → (input-insert-char #\h) → (input-insert-char #\i) → (setf cursor-pos 1) → (input-insert-char #\X) → 'hXi' at pos 2
This commit is contained in:
@@ -115,10 +115,12 @@ Returns list of trimmed strings. Single words wider than width are split."
|
||||
(defun view-input (win)
|
||||
(let* ((text (input-string))
|
||||
(w (or (width win) 78))
|
||||
(clip (min (length text) (1- w))))
|
||||
(pos (or (st :cursor-pos) 0))
|
||||
(display-start (max 0 (- pos (1- w))))
|
||||
(visible (subseq text display-start (min (length text) (+ display-start w)))))
|
||||
(clear win)
|
||||
(add-string win (format nil "~a " text) :y 0 :x 0 :n (1- w) :fgcolor (theme-color :input))
|
||||
(setf (cursor-position win) (list 0 clip)))
|
||||
(add-string win (format nil "~a " visible) :y 0 :x 0 :n (1- w) :fgcolor (theme-color :input))
|
||||
(setf (cursor-position win) (list 0 (min (- pos display-start) (1- w)))))
|
||||
(refresh win))
|
||||
#+end_src
|
||||
|
||||
|
||||
Reference in New Issue
Block a user