Present completions in modal window

part of darcs patch Fri Sep 23 12:32:41 EEST 2005  Martin Gasbichler <gasbichl@informatik.uni-tuebingen.de>
This commit is contained in:
eknauel 2005-09-27 16:37:05 +00:00
parent c9bd3f8209
commit de78de0050
2 changed files with 71 additions and 60 deletions

View File

@ -413,6 +413,7 @@
(maybe-modal-window (maybe-modal-window
(if (maybe-modal-window ch) (if (maybe-modal-window ch)
(begin (begin
(close-modal-window!)
(paint) (paint)
(when (current-history-item) (when (current-history-item)
(paint-result-window (entry-data (current-history-item))) (paint-result-window (entry-data (current-history-item)))
@ -422,10 +423,6 @@
((= ch key-control-x) ((= ch key-control-x)
(loop (wait-for-input) #t completion-selector)) (loop (wait-for-input) #t completion-selector))
((and (focus-on-result-buffer?) completion-selector)
(let ((new-selector (completion-selector ch)))
(loop (wait-for-input) c-x-pressed? new-selector)))
;; tab pressed twice, select completion using select-list ;; tab pressed twice, select completion using select-list
((and (focus-on-command-buffer?) ((and (focus-on-command-buffer?)
completion-selector completion-selector
@ -437,9 +434,8 @@
((and (focus-on-command-buffer?) ((and (focus-on-command-buffer?)
(command-buffer-in-command-mode?) (command-buffer-in-command-mode?)
(= ch key-tab)) (= ch key-tab))
(let ((maybe-selector (offer-completions (last (buffer-text (command-buffer))))
(offer-completions (last (buffer-text (command-buffer)))))) (loop (wait-for-input) #f #f))
(loop (wait-for-input) #f maybe-selector)))
((and (focus-on-command-buffer?) ((and (focus-on-command-buffer?)
(command-buffer-in-command-mode?) (command-buffer-in-command-mode?)
@ -803,17 +799,15 @@
(move-cursor (command-buffer) (result-buffer)) (move-cursor (command-buffer) (result-buffer))
(refresh-command-window)) (refresh-command-window))
(define (paint-completion-select-list select-list command) (define (paint-completion-select-list win width select-list command)
(let ((win (app-window-curses-win (result-window))))
(wclear win) (wclear win)
(wattron win (A-BOLD)) (wattron win (A-BOLD))
(mvwaddstr win 0 0 (mvwaddstr win 0 0
(string-append "Possible completions for " command)) (string-append "Possible completions for " command))
(wattrset win (A-NORMAL)) (wattrset win (A-NORMAL))
(paint-selection-list-at select-list 0 2 (paint-selection-list-at select-list 0 2
win (result-buffer-num-cols (result-buffer)) win width #t)
(focus-on-result-buffer?)) (wrefresh win))
(refresh-result-window)))
(define (current-cursor-index) (define (current-cursor-index)
;; #### No, I will not comment on this. ;; #### No, I will not comment on this.
@ -838,29 +832,50 @@
((null? completions) ((null? completions)
#f) #f)
((list? completions) ((list? completions)
(let* ((select-list (set-modal-window!
(completions->select-list (make-completions-window command completions cmdln to-complete)))
completions
(- (result-buffer-num-lines (result-buffer)) 3)))
(selector
(make-completion-selector select-list completions
cmdln to-complete)))
(paint-completion-select-list select-list command)
(move-cursor (command-buffer) (result-buffer))
(refresh-command-window)
selector))
(else (else
(error "COMPLETE returned an unexpected value" (error "COMPLETE returned an unexpected value"
completions))))))) completions)))))))
(define (make-completion-selector select-list completions (define (make-completions-window command completions
cmdln to-complete) cmdln to-complete)
(define header-line "Select completion")
(define header-length (string-length header-line))
(let* ((lines 10)
(inner-width
(min (apply max header-length
(map string-length completions))
(COLS)))
(dialog (make-app-window (- (quotient (COLS) 2)
(quotient inner-width 2))
5
(+ 4 inner-width)
lines)))
(app-window-init-curses-win! dialog)
(let* ((dialog-win (app-window-curses-win dialog))
(select-list
(completions->select-list
completions
(- lines 3))))
(define (paint)
(werase dialog-win)
(box dialog-win
(ascii->char 0) (ascii->char 0))
(mvwaddstr dialog-win
0
(+ 1 (quotient (- inner-width header-length) 2))
header-line)
(paint-completion-select-list dialog-win inner-width select-list command)
(wrefresh dialog-win))
(paint)
(lambda (key) (lambda (key)
(cond (cond
((= key 10) ((= key 10)
(let ((completion (let ((completion
(select-list-selected-entry select-list))) (select-list-selected-entry select-list)))
(focus-command-buffer!)
;; #### No, I will not comment on this. ;; #### No, I will not comment on this.
(call-with-values (call-with-values
(lambda () (lambda ()
@ -870,16 +885,13 @@
(lambda (completed-line new-cursor-pos) (lambda (completed-line new-cursor-pos)
(display-completed-line completed-line (display-completed-line completed-line
(+ 2 new-cursor-pos)))) (+ 2 new-cursor-pos))))
#f)) (delete-app-window! dialog)
#t))
((select-list-key? key) ((select-list-key? key)
(let ((new-select-list (set! select-list
(select-list-handle-key-press select-list key))) (select-list-handle-key-press select-list key))
(paint-completion-select-list (paint)
new-select-list (last (buffer-text (command-buffer)))) #f)
(make-completion-selector
new-select-list completions cmdln to-complete)))
(else (else
;; #### FIXME we loose a character this way #f))))))
(focus-command-buffer!)
#f))))

View File

@ -112,7 +112,6 @@
val)) entries))) val)) entries)))
(send list-viewer 'set-entries! new-entries)) (send list-viewer 'set-entries! new-entries))
(delete-app-window! dialog) (delete-app-window! dialog)
(close-modal-window!)
#t) #t)
(else #f)))))) (else #f))))))