line-read: Tab lists the candidates when it can add nothing; 0.2.1

As fish does: a second Tab is no longer needed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Linus Björnstam 2026-12-01 13:59:37 +01:00
parent 2b7749013d
commit 03382ff236
2 changed files with 13 additions and 16 deletions

View file

@ -1,6 +1,6 @@
(package (package
(name (bjoterm)) (name (bjoterm))
(version "0.2.0") (version "0.2.1")
(description "The terminal for Bjolang programs: raw mode, key events and escape sequences. Linux.") (description "The terminal for Bjolang programs: raw mode, key events and escape sequences. Linux.")
(license "MPL-2.0") (license "MPL-2.0")

View file

@ -106,13 +106,10 @@
;; - `killing?`: the last key killed text, so the next kill adds to `kill`. ;; - `killing?`: the last key killed text, so the next kill adds to `kill`.
;; - `hist-at`: the history entry shown; the history's length for the ;; - `hist-at`: the history entry shown; the history's length for the
;; input being written, which is kept in `draft` meanwhile. ;; input being written, which is kept in `draft` meanwhile.
;; - `tabbed?`: the last key was Tab and completed nothing more, so the next
;; Tab lists the candidates.
(type (: State (Record (: text (Vec string)) (: cursor int) (type (: State (Record (: text (Vec string)) (: cursor int)
(: kill string) (: killing? bool) (: kill string) (: killing? bool)
(: hist-at int) (: draft (Vec string)) (: hist-at int) (: draft (Vec string))
(: search (Option Search)) (: search (Option Search)))))
(: tabbed? bool))))
;; What one key does. ;; What one key does.
(type (: Step (Union (: Edited State) (type (: Step (Union (: Edited State)
@ -235,8 +232,9 @@
;; M-d (the word after); C-y yanks. C-t swaps two characters. ;; M-d (the word after); C-y yanks. C-t swaps two characters.
;; - History: Up and Down on the first and last line, C-p, C-n; C-r ;; - History: Up and Down on the first and last line, C-p, C-n; C-r
;; searches back, again C-r for an older match, C-g ends the search. ;; searches back, again C-r for an older match, C-g ends the search.
;; - Tab completes with `#:completer`, and a second Tab lists the ;; - Tab completes with `#:completer`: it inserts the candidates' common
;; candidates. Without a completer it inserts a tab. ;; prefix, or lists them when that adds nothing, as fish does. Without
;; a completer it inserts a tab.
;; - A suggestion from `#:suggester`: at the end of the input, Right, C-f, ;; - A suggestion from `#:suggester`: at the end of the input, Right, C-f,
;; End and C-e accept all of it; M-f, C-Right and M-Right one word. ;; End and C-e accept all of it; M-f, C-Right and M-Right one word.
;; - Enter accepts (see `#:input-done?`), M-Enter and C-j start a new line, ;; - Enter accepts (see `#:input-done?`), M-Enter and C-j start a new line,
@ -282,7 +280,7 @@
(def text (clusters initial)) (def text (clusters initial))
(State (text text) (cursor (vec-length text)) (kill "") (killing? #f) (State (text text) (cursor (vec-length text)) (kill "") (killing? #f)
(hist-at (vec-length (record-ref ed history))) (draft []) (hist-at (vec-length (record-ref ed history))) (draft [])
(search None) (tabbed? #f))) (search None)))
(: (-> LineEditor Terminal string string (Option (-> (Vec string))) string LineResult)) (: (-> LineEditor Terminal string string (Option (-> (Vec string))) string LineResult))
(defun (edit-loop ed term prompt cont notices initial) (defun (edit-loop ed term prompt cont notices initial)
@ -386,7 +384,7 @@
(_ unit)) (_ unit))
result)))) result))))
;; The list of candidates that a second Tab writes, each row ended by "\n". ;; The list of candidates that Tab writes, each row ended by "\n".
;; - Without descriptions: in columns, as `columns`. ;; - Without descriptions: in columns, as `columns`.
;; - With descriptions: one candidate a row, its description after it, ;; - With descriptions: one candidate a row, its description after it,
;; dimmed and cut to fit `width`. The candidates' column is as wide as ;; dimmed and cut to fit `width`. The candidates' column is as wide as
@ -821,8 +819,8 @@
(Finished st (LineText text)) (Finished st (LineText text))
(Edited (insert st "\n")))) (Edited (insert st "\n"))))
(: (-> LineEditor State bool Step)) (: (-> LineEditor State Step))
(defun (complete ed st tabbed?) (defun (complete ed st)
(match (record-ref ed completer) (match (record-ref ed completer)
(None (Edited (insert st "\t"))) (None (Edited (insert st "\t")))
((Some completer) ((Some completer)
@ -841,8 +839,7 @@
(def common (common-prefix candidates)) (def common (common-prefix candidates))
(cond (cond
((> (vec-length (clusters common)) k) (Edited (replace-with common))) ((> (vec-length (clusters common)) k) (Edited (replace-with common)))
(tabbed? (ShowList st candidates (record-ref c descriptions))) (else (ShowList st candidates (record-ref c descriptions)))))))))
(else (Bell (record-set st (tabbed? #t))))))))))
;; The next older match of `query` from history index `from` down, or None. ;; The next older match of `query` from history index `from` down, or None.
(: (-> LineEditor string int (Option (Tuple int int)))) (: (-> LineEditor string int (Option (Tuple int int))))
@ -905,7 +902,7 @@
(: (-> LineEditor State TermEvent Step)) (: (-> LineEditor State TermEvent Step))
(defun (editing ed prev ev) (defun (editing ed prev ev)
;; The flags hold only for the key after the one that set them. ;; The flags hold only for the key after the one that set them.
(def st (record-set prev (killing? #f) (tabbed? #f))) (def st (record-set prev (killing? #f)))
(def killing? (record-ref prev killing?)) (def killing? (record-ref prev killing?))
(def cursor (record-ref st cursor)) (def cursor (record-ref st cursor))
(def n (vec-length (record-ref st text))) (def n (vec-length (record-ref st text)))
@ -986,8 +983,8 @@
(def text (vec-set (vec-set (record-ref st text) (- i 1) b) i a)) (def text (vec-set (vec-set (record-ref st text) (- i 1) b) i a))
(Edited (record-set st (text text) (cursor (+ i 1))))))) (Edited (record-set st (text text) (cursor (+ i 1)))))))
;; Completion, the screen, and the program. ;; Completion, the screen, and the program.
((Tuple KeyTab (Tuple #f #f)) (complete ed st (record-ref prev tabbed?))) ((Tuple KeyTab (Tuple #f #f)) (complete ed st))
((Tuple (KeyChar #\i) (Tuple #t #f)) (complete ed st (record-ref prev tabbed?))) ((Tuple (KeyChar #\i) (Tuple #t #f)) (complete ed st))
((Tuple (KeyChar #\l) (Tuple #t #f)) (ClearScreen st)) ((Tuple (KeyChar #\l) (Tuple #t #f)) (ClearScreen st))
((Tuple (KeyChar #\z) (Tuple #t #f)) (if (record-ref ed suspend?) (SuspendNow st) (Bell st))) ((Tuple (KeyChar #\z) (Tuple #t #f)) (if (record-ref ed suspend?) (SuspendNow st) (Bell st)))
(_ (Bell st)))))) (_ (Bell st))))))