2005-05-22 05:20:44 -04:00
|
|
|
(define-syntax when
|
|
|
|
(syntax-rules ()
|
|
|
|
((_ ?test ?do-this ...)
|
|
|
|
(if ?test
|
|
|
|
(begin ?do-this ... (values))
|
|
|
|
(values)))))
|
2004-10-10 09:22:25 -04:00
|
|
|
|
2005-06-04 05:43:22 -04:00
|
|
|
(define-syntax with-lock
|
|
|
|
(syntax-rules ()
|
|
|
|
((_ lock exp ...)
|
|
|
|
(begin
|
|
|
|
(obtain-lock lock)
|
|
|
|
(let ((val (begin exp ...)))
|
|
|
|
(release-lock lock)
|
|
|
|
val)))))
|
2005-05-30 11:21:40 -04:00
|
|
|
|
2005-05-23 09:03:45 -04:00
|
|
|
;; mode of the command buffer
|
|
|
|
(define *command-buffer-mode* 'scheme)
|
|
|
|
|
|
|
|
(define (command-buffer-in-scheme-mode?)
|
|
|
|
(eq? *command-buffer-mode* 'scheme))
|
|
|
|
|
|
|
|
(define (command-buffer-in-command-mode?)
|
|
|
|
(eq? *command-buffer-mode* 'command))
|
|
|
|
|
|
|
|
(define (enter-scheme-mode!)
|
|
|
|
(set! *command-buffer-mode* 'scheme))
|
|
|
|
|
|
|
|
(define (enter-command-mode!)
|
|
|
|
(set! *command-buffer-mode* 'command))
|
|
|
|
|
2005-06-07 14:24:05 -04:00
|
|
|
(define executable-completions-lock (make-lock))
|
|
|
|
(define executable-completions #f)
|
|
|
|
|
|
|
|
(define key-control-x 24)
|
|
|
|
(define key-o 111)
|
|
|
|
(define key-tab 9)
|
|
|
|
|
2005-05-22 05:20:44 -04:00
|
|
|
;; History
|
2004-09-20 04:09:54 -04:00
|
|
|
|
|
|
|
(define history-pos 0)
|
2005-05-22 05:20:44 -04:00
|
|
|
(define the-history (make-empty-history))
|
|
|
|
|
|
|
|
(define (history) the-history)
|
|
|
|
|
|
|
|
(define *current-history-item* #f)
|
2004-09-20 04:09:54 -04:00
|
|
|
|
2005-05-22 05:20:44 -04:00
|
|
|
(define (current-history-item)
|
|
|
|
*current-history-item*)
|
|
|
|
|
|
|
|
(define-record-type history-entry :history-entry
|
2005-05-30 15:19:36 -04:00
|
|
|
(make-history-entry command args viewer)
|
2004-10-03 05:13:30 -04:00
|
|
|
history-entry?
|
|
|
|
(command history-entry-command)
|
2005-05-22 05:20:44 -04:00
|
|
|
(args history-entry-args)
|
2005-05-30 15:19:36 -04:00
|
|
|
(viewer history-entry-viewer set-history-entry-viewer!))
|
2004-10-03 05:13:30 -04:00
|
|
|
|
2005-05-22 05:20:44 -04:00
|
|
|
(define (current-history-entry-selector-maker selector)
|
|
|
|
(lambda ()
|
|
|
|
(cond
|
|
|
|
((current-history-item)
|
|
|
|
=> (lambda (entry)
|
|
|
|
(selector (entry-data entry))))
|
|
|
|
(else #f))))
|
2004-09-20 04:09:54 -04:00
|
|
|
|
2005-05-22 05:20:44 -04:00
|
|
|
(define active-command
|
|
|
|
(current-history-entry-selector-maker history-entry-command))
|
2004-10-10 09:22:25 -04:00
|
|
|
|
2005-05-22 05:20:44 -04:00
|
|
|
(define active-command-arguments
|
|
|
|
(current-history-entry-selector-maker history-entry-args))
|
|
|
|
|
2005-05-30 15:19:36 -04:00
|
|
|
(define current-viewer
|
|
|
|
(current-history-entry-selector-maker history-entry-viewer))
|
2005-05-22 05:20:44 -04:00
|
|
|
|
2005-05-30 15:19:36 -04:00
|
|
|
(define (update-current-viewer! new-viewer)
|
2005-05-22 05:20:44 -04:00
|
|
|
(cond
|
|
|
|
((current-history-item)
|
|
|
|
=> (lambda (entry)
|
2005-05-30 15:19:36 -04:00
|
|
|
(set-history-entry-viewer! (entry-data entry) new-viewer)))
|
2005-05-22 05:20:44 -04:00
|
|
|
(else (values))))
|
|
|
|
|
|
|
|
(define (append-to-history! history-entry)
|
|
|
|
(append-history-item! the-history history-entry)
|
|
|
|
(set! *current-history-item*
|
|
|
|
(history-last-entry the-history)))
|
|
|
|
|
|
|
|
;; one step back in the history
|
|
|
|
(define (history-back!)
|
|
|
|
(cond
|
|
|
|
((and (current-history-item)
|
|
|
|
(history-prev-entry (current-history-item)))
|
|
|
|
=> (lambda (prev)
|
|
|
|
(set! *current-history-item* prev)))
|
|
|
|
(else (values))))
|
|
|
|
|
|
|
|
;; one step forward
|
|
|
|
(define (history-forward!)
|
|
|
|
(cond
|
|
|
|
((and *current-history-item*
|
|
|
|
(history-next-entry *current-history-item*))
|
|
|
|
=> (lambda (next)
|
|
|
|
(set! *current-history-item* next)))
|
|
|
|
(else (values))))
|
2004-10-03 05:13:30 -04:00
|
|
|
|
2004-10-10 09:22:25 -04:00
|
|
|
;;active keyboard-interrupt:
|
|
|
|
;;after each input this is set to #f.
|
|
|
|
;;If a keyboard-interrupt occurs this can be checked by looking-up this box
|
|
|
|
(define active-keyboard-interrupt #f)
|
2004-10-03 05:13:30 -04:00
|
|
|
|
2005-05-20 11:20:34 -04:00
|
|
|
|
2004-10-06 09:00:59 -04:00
|
|
|
;;The "user" (who extends the functionality of NUIT) has to inform NUIT
|
|
|
|
;;about which function is meant to be the receiver, when a certain
|
|
|
|
;;command is active
|
2004-10-10 09:22:25 -04:00
|
|
|
|
2004-09-14 07:54:00 -04:00
|
|
|
;;*************************************************************************
|
2004-10-06 09:00:59 -04:00
|
|
|
;;Actions
|
2004-09-14 07:54:00 -04:00
|
|
|
|
2004-10-10 09:22:25 -04:00
|
|
|
;;start the whole thing
|
2005-05-10 15:37:54 -04:00
|
|
|
(define (nuit)
|
2005-05-18 11:25:16 -04:00
|
|
|
(let ((tty-name (init-tty-debug-output!)))
|
2005-07-06 04:57:44 -04:00
|
|
|
(if tty-name
|
|
|
|
(begin
|
|
|
|
(display "Debug messages will be on ")
|
|
|
|
(display tty-name)
|
|
|
|
(newline))))
|
2005-05-17 05:22:07 -04:00
|
|
|
(with-inspecting-handler
|
|
|
|
8888
|
|
|
|
(lambda (condition)
|
|
|
|
(with-current-output-port*
|
|
|
|
(error-output-port)
|
|
|
|
(lambda ()
|
|
|
|
(display "starting remote handler for condition")
|
|
|
|
(display condition)
|
|
|
|
(newline)
|
|
|
|
(display "Please connect to port 8888")
|
|
|
|
(newline)
|
|
|
|
#t)))
|
|
|
|
run))
|
2004-10-10 09:22:25 -04:00
|
|
|
|
2005-05-22 05:20:44 -04:00
|
|
|
(define (toggle-buffer-focus)
|
|
|
|
(cond
|
|
|
|
((focus-on-command-buffer?)
|
|
|
|
(focus-result-buffer!)
|
|
|
|
(refresh-result-window))
|
|
|
|
(else
|
|
|
|
(focus-command-buffer!)
|
2005-06-07 14:24:05 -04:00
|
|
|
(move-cursor (command-buffer) (result-buffer))
|
2005-05-22 05:20:44 -04:00
|
|
|
(refresh-command-window))))
|
|
|
|
|
2005-05-23 09:03:45 -04:00
|
|
|
(define (toggle-command/scheme-mode)
|
|
|
|
(cond
|
|
|
|
((command-buffer-in-command-mode?)
|
|
|
|
(enter-scheme-mode!))
|
|
|
|
((command-buffer-in-scheme-mode?)
|
|
|
|
(enter-command-mode!)))
|
|
|
|
(paint-command-frame-window)
|
|
|
|
(paint-command-window-contents)
|
2005-06-07 14:24:05 -04:00
|
|
|
(move-cursor (command-buffer) (result-buffer))
|
2005-05-23 09:03:45 -04:00
|
|
|
(refresh-command-window))
|
|
|
|
|
2005-05-23 09:22:16 -04:00
|
|
|
(define (handle-return-key)
|
2005-06-07 14:24:05 -04:00
|
|
|
(let ((command-line (cadr (reverse (buffer-text (command-buffer))))))
|
2005-05-31 09:55:54 -04:00
|
|
|
(debug-message "command-line " command-line)
|
2005-05-23 09:22:16 -04:00
|
|
|
(cond
|
2005-05-23 12:03:26 -04:00
|
|
|
((string=? command-line "")
|
2005-05-23 09:22:16 -04:00
|
|
|
(values))
|
|
|
|
((command-buffer-in-scheme-mode?)
|
2005-05-23 12:03:26 -04:00
|
|
|
(eval-command-in-scheme-mode command-line))
|
2005-05-23 09:22:16 -04:00
|
|
|
((command-buffer-in-command-mode?)
|
2005-05-31 09:39:40 -04:00
|
|
|
(eval-command-in-command-mode command-line))
|
|
|
|
(else
|
|
|
|
(error "Cannot handle return key" command-line)))))
|
2005-05-23 09:22:16 -04:00
|
|
|
|
2005-05-23 10:52:03 -04:00
|
|
|
(define (find-command-plugin command)
|
|
|
|
(or (find (lambda (p)
|
|
|
|
(string=? (command-plugin-command p) command))
|
|
|
|
(command-plugin-list))
|
|
|
|
standard-command-plugin))
|
|
|
|
|
2005-05-23 12:03:26 -04:00
|
|
|
(define (eval-command-in-command-mode command-line)
|
|
|
|
(let* ((tokens (split-command-line command-line))
|
|
|
|
(command (car tokens))
|
|
|
|
(args (cdr tokens))
|
2005-05-30 15:19:36 -04:00
|
|
|
(command-plugin (find-command-plugin command))
|
|
|
|
(viewer
|
|
|
|
(find/init-plugin-for-result
|
|
|
|
(with-errno-handler
|
|
|
|
((errno data)
|
|
|
|
(else data))
|
|
|
|
((command-plugin-evaluater command-plugin) command args))))
|
|
|
|
(new-entry
|
|
|
|
(make-history-entry command args viewer)))
|
|
|
|
;; FIXME, use insert here
|
2005-05-31 09:55:54 -04:00
|
|
|
(append-to-history! new-entry)
|
2005-06-07 14:24:05 -04:00
|
|
|
(signal-result-buffer-object-change)
|
2005-06-04 05:43:22 -04:00
|
|
|
(obtain-lock paint-lock)
|
2005-05-31 09:55:54 -04:00
|
|
|
(paint-result-window new-entry)
|
2005-05-31 10:32:16 -04:00
|
|
|
(refresh-result-window)
|
2005-06-07 14:24:05 -04:00
|
|
|
(move-cursor (command-buffer) (result-buffer))
|
2005-06-04 05:43:22 -04:00
|
|
|
(refresh-command-window)
|
|
|
|
(release-lock paint-lock)))
|
2005-05-23 12:03:26 -04:00
|
|
|
|
2005-08-10 15:46:13 -04:00
|
|
|
(define (display-error-and-continue condition more)
|
|
|
|
(let ((win (app-window-curses-win (result-window))))
|
|
|
|
(wclear win)
|
|
|
|
(wattron win (A-BOLD))
|
|
|
|
(mvwaddstr win 0 0
|
|
|
|
(string-append "I'm sorry " (user-login-name) ", "
|
|
|
|
"I'm afraid I can't do that. "
|
|
|
|
"The following error occured:"))
|
|
|
|
(wattrset win (A-NORMAL))
|
|
|
|
(let ((string-port (open-output-string)))
|
|
|
|
(display condition string-port)
|
|
|
|
(display " " string-port)
|
|
|
|
(display more)
|
|
|
|
(mvwaddstr win 5 0 (get-output-string string-port)))
|
|
|
|
(refresh-result-window)))
|
|
|
|
|
2005-05-23 12:03:26 -04:00
|
|
|
(define (eval-command-in-scheme-mode command-line)
|
2005-08-10 15:46:13 -04:00
|
|
|
(with-fatal-error-handler*
|
|
|
|
display-error-and-continue
|
|
|
|
(lambda ()
|
|
|
|
(let ((viewer
|
|
|
|
(find/init-plugin-for-result
|
|
|
|
(eval-string command-line))))
|
|
|
|
(let* ((tokens (split-command-line command-line))
|
|
|
|
(command (car tokens))
|
|
|
|
(args (cdr tokens))
|
|
|
|
(new-entry
|
|
|
|
(make-history-entry command args viewer)))
|
|
|
|
;; #### shouldn't we use some kind of insertion here?
|
|
|
|
(append-to-history! new-entry)
|
|
|
|
(signal-result-buffer-object-change)
|
|
|
|
(obtain-lock paint-lock)
|
|
|
|
(paint-result-window new-entry)
|
|
|
|
(refresh-result-window)
|
|
|
|
(move-cursor (command-buffer) (result-buffer))
|
|
|
|
(refresh-command-window)
|
|
|
|
(release-lock paint-lock))))))
|
|
|
|
|
|
|
|
;; #### crufty, and a very dumb idea
|
2005-05-23 12:03:26 -04:00
|
|
|
(define split-command-line string-tokenize)
|
2005-05-23 09:22:16 -04:00
|
|
|
|
2005-06-01 06:04:21 -04:00
|
|
|
(define (paste-selection/refresh viewer)
|
|
|
|
(add-string-to-command-buffer
|
2005-06-04 07:22:44 -04:00
|
|
|
(send (current-viewer)
|
2005-07-06 04:57:44 -04:00
|
|
|
'get-selection-as-text
|
2005-06-04 07:22:44 -04:00
|
|
|
(command-buffer-in-scheme-mode?) (focus-table)))
|
2005-06-07 14:24:05 -04:00
|
|
|
(print-command-buffer (app-window-curses-win (command-window))
|
|
|
|
(command-buffer))
|
|
|
|
(move-cursor (command-buffer) (result-buffer))
|
2005-08-10 14:47:26 -04:00
|
|
|
(refresh-command-window)
|
|
|
|
(refresh-result-window))
|
2005-06-01 06:04:21 -04:00
|
|
|
|
|
|
|
(define (paste-focus-object/refresh viewer)
|
|
|
|
(add-string-to-command-buffer
|
|
|
|
(if (command-buffer-in-command-mode?)
|
2005-06-04 07:22:44 -04:00
|
|
|
(send (current-viewer)
|
2005-07-06 04:57:44 -04:00
|
|
|
'get-selection-as-text
|
2005-06-04 07:22:44 -04:00
|
|
|
(command-buffer-in-scheme-mode?)
|
|
|
|
(focus-table))
|
2005-07-06 04:57:44 -04:00
|
|
|
(send (current-viewer) 'get-selection-as-ref (focus-table))))
|
2005-06-07 14:24:05 -04:00
|
|
|
(print-command-buffer (app-window-curses-win (command-window))
|
|
|
|
(command-buffer))
|
|
|
|
(move-cursor (command-buffer) (result-buffer))
|
2005-08-10 14:47:26 -04:00
|
|
|
(refresh-command-window)
|
|
|
|
(refresh-result-window))
|
2005-06-01 06:04:21 -04:00
|
|
|
|
2005-06-14 07:20:30 -04:00
|
|
|
;; #### implement me
|
|
|
|
(define terminal-input-handler
|
|
|
|
(lambda ignore
|
|
|
|
'terminal-input))
|
|
|
|
|
|
|
|
;; #### implement me
|
|
|
|
(define terminal-output-handler
|
|
|
|
(lambda ignore
|
|
|
|
'terminal-output))
|
|
|
|
|
|
|
|
(define (install-signal-handlers)
|
|
|
|
(for-each
|
|
|
|
(lambda (signal)
|
|
|
|
(set-interrupt-handler signal #f))
|
2005-06-14 09:44:09 -04:00
|
|
|
(list interrupt/int
|
|
|
|
;interrupt/quit
|
|
|
|
interrupt/tstp))
|
2005-06-14 07:20:30 -04:00
|
|
|
(set-interrupt-handler signal/ttin terminal-input-handler)
|
|
|
|
(set-interrupt-handler signal/ttou terminal-output-handler))
|
|
|
|
|
|
|
|
(define (enable-tty-output-control! port)
|
|
|
|
(let ((info (copy-tty-info (tty-info port))))
|
|
|
|
(set-tty-info:local-flags
|
|
|
|
info
|
2005-06-14 09:44:09 -04:00
|
|
|
(bitwise-ior (tty-info:local-flags info)
|
2005-06-14 07:20:30 -04:00
|
|
|
ttyl/ttou-signal))
|
|
|
|
(set-tty-info/now port info)))
|
|
|
|
|
|
|
|
(define (process-group-leader?)
|
|
|
|
(= (process-group) (pid)))
|
|
|
|
|
2005-05-22 05:20:44 -04:00
|
|
|
;; handle input
|
2005-05-10 15:37:54 -04:00
|
|
|
(define (run)
|
2005-06-14 07:20:30 -04:00
|
|
|
(save-initial-tty-info! (current-input-port))
|
2005-06-14 09:44:09 -04:00
|
|
|
|
|
|
|
(autoreap-policy #f)
|
|
|
|
|
2005-06-07 14:24:05 -04:00
|
|
|
(init-screen)
|
2005-05-18 11:47:28 -04:00
|
|
|
(init-windows!)
|
2005-06-07 14:24:05 -04:00
|
|
|
(clear)
|
|
|
|
|
2005-06-14 07:20:30 -04:00
|
|
|
(if (not (process-group-leader?))
|
|
|
|
(become-session-leader))
|
|
|
|
|
|
|
|
(set-tty-process-group (current-input-port) (pid))
|
|
|
|
|
2005-05-30 05:33:07 -04:00
|
|
|
(init-executables-completion-set!)
|
2005-06-14 07:20:30 -04:00
|
|
|
(enable-tty-output-control! (current-output-port))
|
2005-05-30 05:33:07 -04:00
|
|
|
|
2005-06-03 07:44:53 -04:00
|
|
|
;; init joblist
|
|
|
|
(let ((statistics-channel (spawn-joblist-surveillant)))
|
|
|
|
(spawn
|
|
|
|
(lambda ()
|
|
|
|
(let lp ((stats (cml-receive statistics-channel)))
|
|
|
|
(debug-message "statistics update " stats)
|
2005-06-04 05:43:22 -04:00
|
|
|
(obtain-lock paint-lock)
|
|
|
|
(paint-command-frame-window)
|
|
|
|
(paint-job-status-list stats)
|
|
|
|
(paint-command-window-contents)
|
2005-06-07 14:24:05 -04:00
|
|
|
(wrefresh (app-window-curses-win (command-frame-window)))
|
|
|
|
(move-cursor (command-buffer) (result-buffer))
|
2005-06-04 05:43:22 -04:00
|
|
|
(refresh-command-window)
|
|
|
|
(release-lock paint-lock)
|
2005-06-03 07:44:53 -04:00
|
|
|
(lp (cml-receive statistics-channel))))))
|
|
|
|
|
2005-05-10 15:37:54 -04:00
|
|
|
;;Loop
|
|
|
|
(paint)
|
2005-05-30 05:33:07 -04:00
|
|
|
(let loop ((ch (wait-for-input)) (c-x-pressed? #f)
|
2005-05-30 10:08:41 -04:00
|
|
|
(completion-selector #f))
|
2005-05-30 05:33:07 -04:00
|
|
|
|
2005-05-10 15:37:54 -04:00
|
|
|
(cond
|
2005-05-22 05:20:44 -04:00
|
|
|
|
|
|
|
;; Ctrl-x -> wait for next input
|
|
|
|
((= ch key-control-x)
|
2005-05-30 10:08:41 -04:00
|
|
|
(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)))
|
2005-05-30 05:33:07 -04:00
|
|
|
|
|
|
|
;; tab pressed twice, select completion using select-list
|
|
|
|
((and (focus-on-command-buffer?)
|
2005-05-30 10:08:41 -04:00
|
|
|
completion-selector
|
2005-05-30 05:33:07 -04:00
|
|
|
(= ch key-tab))
|
|
|
|
(focus-result-buffer!)
|
2005-05-30 10:08:41 -04:00
|
|
|
(loop (wait-for-input) #f completion-selector))
|
2005-05-22 05:20:44 -04:00
|
|
|
|
2005-05-30 05:33:07 -04:00
|
|
|
;; tab is pressed in the first place, offer completions
|
2005-05-28 08:08:23 -04:00
|
|
|
((and (focus-on-command-buffer?)
|
|
|
|
(= ch key-tab))
|
2005-05-30 10:08:41 -04:00
|
|
|
(let ((maybe-selector
|
2005-06-07 14:24:05 -04:00
|
|
|
(offer-completions (last (buffer-text (command-buffer))))))
|
2005-05-30 10:08:41 -04:00
|
|
|
(loop (wait-for-input) #f maybe-selector)))
|
2005-05-23 10:52:03 -04:00
|
|
|
|
2005-05-23 09:03:45 -04:00
|
|
|
;; F7 toggle scheme-mode / command-mode (FIXME: find a better key)
|
2005-06-01 04:07:48 -04:00
|
|
|
((= ch key-f7)
|
2005-05-23 09:03:45 -04:00
|
|
|
(toggle-command/scheme-mode)
|
2005-05-30 05:33:07 -04:00
|
|
|
(loop (wait-for-input) #f #f))
|
2005-05-23 09:03:45 -04:00
|
|
|
|
2005-05-27 12:02:39 -04:00
|
|
|
((= ch key-f8)
|
|
|
|
(show-shell-screen)
|
|
|
|
(paint)
|
2005-05-30 05:33:07 -04:00
|
|
|
(loop (wait-for-input) #f #f))
|
2005-05-27 12:02:39 -04:00
|
|
|
|
2005-05-22 05:20:44 -04:00
|
|
|
;; C-x o --- toggle buffer focus
|
|
|
|
((and c-x-pressed? (= ch key-o))
|
|
|
|
(toggle-buffer-focus)
|
2005-05-30 05:33:07 -04:00
|
|
|
(loop (wait-for-input) #f #f))
|
2005-05-22 05:20:44 -04:00
|
|
|
|
2005-05-27 12:02:39 -04:00
|
|
|
;; C-x p --- insert selection
|
2005-06-01 06:04:21 -04:00
|
|
|
((and c-x-pressed? (current-history-item)
|
2005-05-27 12:02:39 -04:00
|
|
|
(= ch 112))
|
2005-06-01 06:04:21 -04:00
|
|
|
(paste-selection/refresh (current-viewer))
|
2005-06-01 05:15:43 -04:00
|
|
|
(loop (wait-for-input) #f #f))
|
|
|
|
|
2005-06-01 06:04:21 -04:00
|
|
|
;; C-x P --- insert focus object(s)
|
|
|
|
((and c-x-pressed? (current-history-item)
|
|
|
|
(= ch 80))
|
|
|
|
(paste-focus-object/refresh (current-viewer))
|
2005-05-30 05:33:07 -04:00
|
|
|
(loop (wait-for-input) #f #f))
|
2005-05-27 12:02:39 -04:00
|
|
|
|
2005-05-22 05:20:44 -04:00
|
|
|
((and c-x-pressed? (focus-on-result-buffer?))
|
2005-05-30 15:19:36 -04:00
|
|
|
(update-current-viewer!
|
|
|
|
(send (current-viewer)
|
|
|
|
'key-press ch key-control-x))
|
|
|
|
(loop (wait-for-input) #f #f))
|
2005-05-22 05:20:44 -04:00
|
|
|
|
|
|
|
;; C-x r --- redo
|
|
|
|
((and c-x-pressed? (focus-on-command-buffer?)
|
|
|
|
(= ch 114))
|
|
|
|
(debug-message "Eric should re-implement redo..."))
|
|
|
|
|
2005-05-10 15:37:54 -04:00
|
|
|
((= ch key-f1)
|
2005-05-22 05:20:44 -04:00
|
|
|
(endwin))
|
2005-05-10 15:37:54 -04:00
|
|
|
|
|
|
|
((= ch key-f2)
|
2005-05-22 05:20:44 -04:00
|
|
|
(paint)
|
2005-05-30 05:33:07 -04:00
|
|
|
(loop (wait-for-input) c-x-pressed? #f))
|
2005-05-19 09:59:52 -04:00
|
|
|
|
2005-05-10 15:37:54 -04:00
|
|
|
;; forward in result history
|
|
|
|
((= ch key-npage)
|
2005-05-22 05:20:44 -04:00
|
|
|
(history-forward!)
|
2005-06-04 05:43:22 -04:00
|
|
|
(obtain-lock paint-lock)
|
2005-05-22 05:20:44 -04:00
|
|
|
(when (current-history-item)
|
|
|
|
(paint-active-command-window)
|
2005-06-07 14:24:05 -04:00
|
|
|
(signal-result-buffer-object-change)
|
2005-05-22 05:20:44 -04:00
|
|
|
(paint-result-window (entry-data (current-history-item))))
|
2005-05-19 09:59:52 -04:00
|
|
|
(refresh-result-window)
|
2005-06-04 05:43:22 -04:00
|
|
|
(release-lock paint-lock)
|
2005-05-30 05:33:07 -04:00
|
|
|
(loop (wait-for-input) c-x-pressed? #f))
|
2005-05-10 15:37:54 -04:00
|
|
|
|
|
|
|
;; back in result history
|
|
|
|
((= ch key-ppage)
|
2005-05-22 05:20:44 -04:00
|
|
|
(history-back!)
|
2005-06-04 05:43:22 -04:00
|
|
|
(obtain-lock paint-lock)
|
2005-05-22 05:20:44 -04:00
|
|
|
(when (current-history-item)
|
|
|
|
(paint-active-command-window)
|
2005-06-07 14:24:05 -04:00
|
|
|
(signal-result-buffer-object-change)
|
2005-05-22 05:20:44 -04:00
|
|
|
(paint-result-window (entry-data (current-history-item))))
|
2005-05-19 09:59:52 -04:00
|
|
|
(refresh-result-window)
|
2005-06-04 05:43:22 -04:00
|
|
|
(release-lock paint-lock)
|
2005-05-30 05:33:07 -04:00
|
|
|
(loop (wait-for-input) c-x-pressed? #f))
|
2005-05-22 05:20:44 -04:00
|
|
|
|
2005-05-26 07:34:35 -04:00
|
|
|
((and (focus-on-command-buffer?) (= ch 10))
|
2005-06-07 14:24:05 -04:00
|
|
|
(input (command-buffer) ch)
|
2005-06-04 05:43:22 -04:00
|
|
|
(obtain-lock paint-lock)
|
2005-06-07 14:24:05 -04:00
|
|
|
(werase (app-window-curses-win (command-window)))
|
|
|
|
(print-command-buffer (app-window-curses-win (command-window))
|
|
|
|
(command-buffer))
|
|
|
|
(move-cursor (command-buffer) (result-buffer))
|
2005-05-31 08:41:42 -04:00
|
|
|
(refresh-command-window)
|
2005-06-04 05:43:22 -04:00
|
|
|
(release-lock paint-lock)
|
2005-05-23 09:22:16 -04:00
|
|
|
(handle-return-key)
|
2005-05-30 05:33:07 -04:00
|
|
|
(loop (wait-for-input) c-x-pressed? #f))
|
2005-05-22 05:20:44 -04:00
|
|
|
|
|
|
|
(else
|
2005-05-22 11:05:25 -04:00
|
|
|
(cond
|
|
|
|
((focus-on-result-buffer?)
|
|
|
|
(when (current-history-item)
|
2005-05-30 15:19:36 -04:00
|
|
|
(update-current-viewer!
|
|
|
|
(send (current-viewer)
|
|
|
|
'key-press ch c-x-pressed?))
|
2005-06-04 05:43:22 -04:00
|
|
|
(obtain-lock paint-lock)
|
2005-05-22 11:05:25 -04:00
|
|
|
(paint-result-window (entry-data (current-history-item)))
|
2005-06-07 14:24:05 -04:00
|
|
|
(move-cursor (command-buffer) (result-buffer))
|
2005-06-04 05:43:22 -04:00
|
|
|
(refresh-result-window)
|
|
|
|
(release-lock paint-lock))
|
2005-05-30 05:33:07 -04:00
|
|
|
(loop (wait-for-input) #f #f))
|
2005-05-22 11:05:25 -04:00
|
|
|
(else
|
2005-06-07 14:24:05 -04:00
|
|
|
(input (command-buffer) ch)
|
2005-06-04 05:43:22 -04:00
|
|
|
(obtain-lock paint-lock)
|
2005-06-07 14:24:05 -04:00
|
|
|
(werase (app-window-curses-win (command-window)))
|
|
|
|
(print-command-buffer (app-window-curses-win (command-window))
|
|
|
|
(command-buffer))
|
|
|
|
(move-cursor (command-buffer) (result-buffer))
|
2005-05-22 11:05:25 -04:00
|
|
|
(refresh-command-window)
|
2005-06-04 05:43:22 -04:00
|
|
|
(release-lock paint-lock)
|
2005-05-30 05:33:07 -04:00
|
|
|
(loop (wait-for-input) c-x-pressed? #f)))))))
|
2005-05-10 15:37:54 -04:00
|
|
|
|
2005-05-30 05:33:07 -04:00
|
|
|
(define (get-path-list)
|
|
|
|
(cond
|
|
|
|
((getenv "PATH")
|
|
|
|
=> (lambda (str)
|
|
|
|
(string-tokenize
|
|
|
|
str (char-set-difference char-set:full (char-set #\:)))))
|
|
|
|
(else
|
|
|
|
'("/usr/bin" "/bin" "/usr/sbin" "/sbin"))))
|
|
|
|
|
|
|
|
(define (init-executables-completion-set!)
|
2005-05-30 11:21:40 -04:00
|
|
|
(spawn
|
|
|
|
(lambda ()
|
|
|
|
(with-lock executable-completions-lock
|
2005-06-04 05:43:22 -04:00
|
|
|
(set! executable-completions
|
|
|
|
(make-completion-set-for-executables (get-path-list)))))))
|
2005-05-30 05:33:07 -04:00
|
|
|
|
2005-05-10 15:37:54 -04:00
|
|
|
(define (paint-bar-1)
|
2005-07-06 04:57:44 -04:00
|
|
|
(mvwaddstr (app-window-curses-win (bar-1)) 0 1 "Commander S")
|
2005-06-07 14:24:05 -04:00
|
|
|
(wrefresh (app-window-curses-win (bar-1))))
|
2005-05-10 15:37:54 -04:00
|
|
|
|
2005-05-23 09:03:45 -04:00
|
|
|
(define (paint-command-buffer-mode-indicator)
|
|
|
|
(let ((mode-string
|
|
|
|
(string-append
|
|
|
|
"[ "
|
|
|
|
(if (command-buffer-in-command-mode?)
|
|
|
|
"Command"
|
|
|
|
"Scheme")
|
|
|
|
" ]")))
|
|
|
|
(mvwaddstr
|
2005-06-07 14:24:05 -04:00
|
|
|
(app-window-curses-win (command-frame-window))
|
2005-05-23 09:03:45 -04:00
|
|
|
0
|
2005-06-07 14:24:05 -04:00
|
|
|
(- (- (app-window-width (command-frame-window))
|
2005-05-23 09:03:45 -04:00
|
|
|
(string-length mode-string))
|
|
|
|
2)
|
|
|
|
mode-string)))
|
|
|
|
|
2005-05-17 11:02:01 -04:00
|
|
|
(define (paint-command-frame-window)
|
2005-06-07 14:24:05 -04:00
|
|
|
(box (app-window-curses-win (command-frame-window))
|
2005-05-17 11:02:01 -04:00
|
|
|
(ascii->char 0) (ascii->char 0))
|
2005-05-23 09:03:45 -04:00
|
|
|
(paint-command-buffer-mode-indicator)
|
2005-06-03 07:44:53 -04:00
|
|
|
(paint-job-status-list)
|
2005-06-07 14:24:05 -04:00
|
|
|
(wrefresh (app-window-curses-win (command-frame-window))))
|
2005-05-10 15:37:54 -04:00
|
|
|
|
2005-06-03 07:44:53 -04:00
|
|
|
(define paint-job-status-list
|
|
|
|
(let ((latest-statistics (initial-job-statistics)))
|
|
|
|
(lambda args
|
|
|
|
(let-optionals args
|
|
|
|
((statistics latest-statistics))
|
|
|
|
(let* ((stat-item (lambda (text number)
|
|
|
|
(string-append text (number->string number))))
|
|
|
|
(stat
|
|
|
|
(string-join
|
|
|
|
(map
|
|
|
|
(lambda (status.count)
|
|
|
|
(case (car status.count)
|
|
|
|
((running) (stat-item "run:" (cdr status.count)))
|
|
|
|
((ready) (stat-item "ready:" (cdr status.count)))
|
2005-06-14 07:20:30 -04:00
|
|
|
((stopped) (stat-item "stop:" (cdr status.count)))
|
2005-06-03 07:44:53 -04:00
|
|
|
((new-output) (stat-item "out:" (cdr status.count)))
|
|
|
|
((waiting-for-input) (stat-item "in:" (cdr status.count)))))
|
|
|
|
statistics)))
|
|
|
|
(line (string-append "[ " stat " ]")))
|
|
|
|
(set! latest-statistics statistics)
|
|
|
|
(mvwaddstr
|
2005-06-07 14:24:05 -04:00
|
|
|
(app-window-curses-win (command-frame-window))
|
|
|
|
(- (app-window-height (command-frame-window)) 1)
|
|
|
|
(- (- (app-window-width (command-frame-window))
|
2005-06-03 07:44:53 -04:00
|
|
|
(string-length line))
|
|
|
|
2)
|
|
|
|
line))))))
|
|
|
|
|
2005-05-10 15:37:54 -04:00
|
|
|
(define (paint-command-window-contents)
|
2005-06-07 14:24:05 -04:00
|
|
|
(set-buffer-num-lines! (command-buffer)
|
|
|
|
(- (app-window-height (command-window)) 2))
|
|
|
|
(set-buffer-num-cols! (command-buffer)
|
|
|
|
(- (app-window-width (command-window)) 3))
|
|
|
|
(werase (app-window-curses-win (command-window)))
|
|
|
|
(print-command-buffer (app-window-curses-win (command-window))
|
|
|
|
(command-buffer)))
|
2005-05-18 14:55:51 -04:00
|
|
|
|
|
|
|
(define (refresh-command-window)
|
2005-06-07 14:24:05 -04:00
|
|
|
(wrefresh (app-window-curses-win (command-window))))
|
2005-05-10 15:37:54 -04:00
|
|
|
|
2005-05-19 09:59:52 -04:00
|
|
|
(define (paint-result-frame-window)
|
2005-06-07 14:24:05 -04:00
|
|
|
(let ((win (app-window-curses-win (result-frame-window))))
|
2005-05-19 09:59:52 -04:00
|
|
|
(wclear win)
|
|
|
|
(box win (ascii->char 0) (ascii->char 0))
|
|
|
|
(wrefresh win)))
|
|
|
|
|
2005-05-22 05:20:44 -04:00
|
|
|
(define (paint-result-window entry)
|
2005-06-07 14:24:05 -04:00
|
|
|
(let ((win (app-window-curses-win (result-window))))
|
2005-05-30 15:19:36 -04:00
|
|
|
(wclear win)
|
|
|
|
(send (history-entry-viewer entry)
|
2005-06-07 14:24:05 -04:00
|
|
|
'paint win (result-buffer) (focus-on-result-buffer?))))
|
2005-05-19 09:59:52 -04:00
|
|
|
|
|
|
|
(define (refresh-result-window)
|
2005-06-07 14:24:05 -04:00
|
|
|
(wrefresh (app-window-curses-win (result-window))))
|
2004-10-10 09:22:25 -04:00
|
|
|
|
2005-05-23 09:22:16 -04:00
|
|
|
(define (paint-result/command-buffer history-entry)
|
|
|
|
(paint-result-window history-entry)
|
|
|
|
(paint-active-command-window)
|
|
|
|
(scroll-command-buffer)
|
|
|
|
(paint-command-window-contents)
|
2005-06-07 14:24:05 -04:00
|
|
|
(move-cursor (command-buffer) (result-buffer))
|
2005-05-23 09:22:16 -04:00
|
|
|
(refresh-result-window)
|
|
|
|
(refresh-command-window))
|
|
|
|
|
2005-05-10 15:37:54 -04:00
|
|
|
(define (paint)
|
|
|
|
(paint-bar-1)
|
2005-05-17 11:02:01 -04:00
|
|
|
(paint-command-frame-window)
|
2005-05-10 15:37:54 -04:00
|
|
|
(paint-command-window-contents)
|
2005-05-22 05:20:44 -04:00
|
|
|
(paint-active-command-window)
|
2005-05-19 09:59:52 -04:00
|
|
|
(paint-result-frame-window)
|
2005-05-22 05:20:44 -04:00
|
|
|
;(paint-result-window)
|
2005-06-07 14:24:05 -04:00
|
|
|
(move-cursor (command-buffer) (result-buffer))
|
2005-05-19 09:59:52 -04:00
|
|
|
(refresh-command-window)
|
|
|
|
(refresh-result-window))
|
2005-05-10 12:06:06 -04:00
|
|
|
|
|
|
|
(define (wait-for-input)
|
|
|
|
(noecho)
|
2005-06-07 14:24:05 -04:00
|
|
|
(keypad (app-window-curses-win (bar-1)) #t)
|
2005-05-10 12:06:06 -04:00
|
|
|
(set! active-keyboard-interrupt #f)
|
2005-06-07 14:24:05 -04:00
|
|
|
(let ((ch (wgetch (app-window-curses-win (bar-1)))))
|
2005-05-10 12:06:06 -04:00
|
|
|
(echo)
|
|
|
|
ch))
|
2004-10-03 05:13:30 -04:00
|
|
|
|
2005-05-23 10:52:03 -04:00
|
|
|
(define (find/init-plugin-for-result result)
|
|
|
|
(cond
|
2005-07-06 04:57:44 -04:00
|
|
|
;; #### a hack
|
|
|
|
((null? result)
|
|
|
|
(make-standard-viewer result (result-buffer)))
|
2005-05-23 10:52:03 -04:00
|
|
|
((determine-plugin-by-type result)
|
2005-05-30 15:19:36 -04:00
|
|
|
=> (lambda (view-plugin)
|
2005-05-31 09:14:55 -04:00
|
|
|
((view-plugin-constructor view-plugin)
|
2005-06-07 14:24:05 -04:00
|
|
|
result (result-buffer))))
|
2005-05-23 10:52:03 -04:00
|
|
|
(else
|
2005-06-07 14:24:05 -04:00
|
|
|
(make-standard-viewer result (result-buffer)))))
|
2004-10-10 09:22:25 -04:00
|
|
|
|
2004-10-06 09:00:59 -04:00
|
|
|
;;scroll buffer after one command was entered
|
2005-05-11 09:30:51 -04:00
|
|
|
(define (scroll-command-buffer)
|
2005-06-07 14:24:05 -04:00
|
|
|
(set-buffer-pos-line! (command-buffer)
|
|
|
|
(+ (buffer-pos-line (command-buffer)) 1))
|
|
|
|
(set-buffer-pos-col! (command-buffer) 2))
|
2004-09-20 04:09:54 -04:00
|
|
|
|
2005-05-22 05:20:44 -04:00
|
|
|
|
2005-05-22 11:05:25 -04:00
|
|
|
(define (determine-plugin-by-type result)
|
2005-05-20 11:20:34 -04:00
|
|
|
(find (lambda (r)
|
2005-05-23 08:47:41 -04:00
|
|
|
((view-plugin-type-predicate r) result))
|
|
|
|
(view-plugin-list)))
|
2005-05-22 05:20:44 -04:00
|
|
|
|
2004-10-06 09:00:59 -04:00
|
|
|
;;Management of the upper buffer
|
|
|
|
;;add a char to the buffer
|
2005-05-11 09:30:51 -04:00
|
|
|
(define (add-to-command-buffer ch)
|
2005-06-07 14:24:05 -04:00
|
|
|
(let* ((text (buffer-text (command-buffer)))
|
2005-05-11 09:30:51 -04:00
|
|
|
(last-pos (- (length text) 1))
|
|
|
|
(old-last-el (list-ref text last-pos))
|
|
|
|
(old-rest (sublist text 0 last-pos))
|
|
|
|
(before-ch (substring old-last-el 0
|
2005-06-07 16:54:22 -04:00
|
|
|
(max 0 (- (buffer-pos-col (command-buffer)) 2))))
|
2005-05-11 09:30:51 -04:00
|
|
|
(after-ch (substring old-last-el
|
2005-06-07 14:24:05 -04:00
|
|
|
(max 0 (- (buffer-pos-col (command-buffer)) 2))
|
2005-05-11 09:30:51 -04:00
|
|
|
(string-length old-last-el)))
|
|
|
|
(new-last-el (string-append before-ch
|
|
|
|
(string (ascii->char ch))
|
|
|
|
after-ch)))
|
2005-06-07 14:24:05 -04:00
|
|
|
(set-buffer-text! (command-buffer)
|
2005-05-11 09:30:51 -04:00
|
|
|
(append old-rest (list new-last-el)))
|
2005-06-07 14:24:05 -04:00
|
|
|
(set-buffer-pos-col! (command-buffer)
|
|
|
|
(+ (buffer-pos-col (command-buffer)) 1))))
|
2004-09-14 07:54:00 -04:00
|
|
|
|
2004-10-06 09:00:59 -04:00
|
|
|
;;add a string to the buffer
|
2005-05-17 16:19:53 -04:00
|
|
|
(define (add-string-to-command-buffer string)
|
|
|
|
(let loop ((str string))
|
|
|
|
(if (string=? str "")
|
|
|
|
(values)
|
|
|
|
(let ((first-ch (string-ref str 0)))
|
|
|
|
(add-to-command-buffer (char->ascii first-ch))
|
|
|
|
(loop (substring str 1 (string-length str)))))))
|
2004-10-03 05:13:30 -04:00
|
|
|
|
2005-05-22 05:20:44 -04:00
|
|
|
;;; FIXME: I guess s48 knows a better way to do this (see ,inspect)
|
|
|
|
(define (maybe-shorten-string string width)
|
|
|
|
(if (> (string-length string) width)
|
|
|
|
(string-append (substring string 0 (- width 3))
|
|
|
|
"...")
|
|
|
|
string))
|
|
|
|
|
|
|
|
(define (paint-active-command-window)
|
2005-06-07 14:24:05 -04:00
|
|
|
(let ((win (app-window-curses-win (active-command-window)))
|
|
|
|
(width (app-window-width (active-command-window))))
|
2005-05-22 05:20:44 -04:00
|
|
|
(wclear win)
|
|
|
|
(box win (ascii->char 0) (ascii->char 0))
|
|
|
|
(cond
|
|
|
|
((current-history-item)
|
|
|
|
=> (lambda (entry)
|
|
|
|
(mvwaddstr win 1 2
|
|
|
|
(maybe-shorten-string
|
|
|
|
(history-entry-command (entry-data entry)) width)))))
|
|
|
|
(wrefresh win)))
|
|
|
|
|
2004-10-03 05:13:30 -04:00
|
|
|
;;Cursor
|
2004-10-06 09:00:59 -04:00
|
|
|
;;move cursor to the corrct position
|
2005-05-25 05:44:27 -04:00
|
|
|
(define (move-cursor command-buffer result-buffer)
|
|
|
|
(cond
|
|
|
|
((focus-on-command-buffer?)
|
|
|
|
(cursor-right-pos
|
2005-06-07 14:24:05 -04:00
|
|
|
(app-window-curses-win (command-window))
|
2005-05-25 05:44:27 -04:00
|
|
|
command-buffer))
|
|
|
|
(else
|
|
|
|
(compute-y-x result-buffer)
|
2005-06-07 14:24:05 -04:00
|
|
|
(wmove (app-window-curses-win (result-window))
|
2005-05-25 05:44:27 -04:00
|
|
|
(result-buffer-y result-buffer)
|
|
|
|
(result-buffer-x result-buffer))
|
2005-06-07 14:24:05 -04:00
|
|
|
(wrefresh (app-window-curses-win (result-window))))))
|
2004-09-14 07:54:00 -04:00
|
|
|
|
2004-10-06 09:00:59 -04:00
|
|
|
;;compue pos-x and pos-y
|
2005-05-25 05:44:27 -04:00
|
|
|
(define (compute-y-x result-buffer)
|
|
|
|
(let ((pos-result (result-buffer-line result-buffer))
|
|
|
|
(pos-result-col (result-buffer-column result-buffer))
|
|
|
|
(result-lines (result-buffer-num-lines result-buffer)))
|
|
|
|
(if (>= pos-result result-lines)
|
|
|
|
(set-result-buffer-y! result-buffer result-lines)
|
|
|
|
(set-result-buffer-y! result-buffer pos-result))
|
|
|
|
(set-result-buffer-x! result-buffer pos-result-col)))
|
2004-09-14 07:54:00 -04:00
|
|
|
|
2005-05-17 16:19:53 -04:00
|
|
|
(define (sublist l pos k)
|
|
|
|
(let ((tmp (list-tail l pos)))
|
|
|
|
(reverse (list-tail (reverse tmp)
|
|
|
|
(- (length tmp) k)))))
|
2004-10-03 05:13:30 -04:00
|
|
|
|
2004-10-10 09:22:25 -04:00
|
|
|
;;When NUIT is closed the state has to be restored, in order to let the
|
|
|
|
;;user start again from scratch
|
2005-05-17 16:19:53 -04:00
|
|
|
(define (restore-state)
|
|
|
|
(set! history '())
|
|
|
|
(set! history-pos 0)
|
|
|
|
(set! active-keyboard-interrupt #f))
|
2004-10-10 09:22:25 -04:00
|
|
|
|
2005-05-22 11:05:25 -04:00
|
|
|
(define (get-param-as-str param-lst)
|
|
|
|
(let loop ((lst param-lst)
|
|
|
|
(str ""))
|
|
|
|
(if (null? lst)
|
|
|
|
str
|
|
|
|
(loop (cdr lst)
|
|
|
|
(string-append str " " (car lst))))))
|
2004-10-10 09:22:25 -04:00
|
|
|
|
2005-05-30 05:33:07 -04:00
|
|
|
(define (completions->select-list completions num-lines)
|
2005-05-28 08:08:23 -04:00
|
|
|
(debug-message "possible completions " completions)
|
|
|
|
(make-select-list
|
|
|
|
(map (lambda (s) (make-unmarked-element s #f s))
|
|
|
|
completions)
|
2005-05-30 05:33:07 -04:00
|
|
|
num-lines))
|
|
|
|
|
|
|
|
(define (command-contains-path? command)
|
|
|
|
(or (string-contains command "/")
|
|
|
|
(string-contains command "~")
|
|
|
|
(string-contains command "..")))
|
|
|
|
|
2005-05-30 10:08:41 -04:00
|
|
|
(define (files-in-dir file-filter dir)
|
2005-05-30 05:33:07 -04:00
|
|
|
(with-cwd dir
|
|
|
|
(filter-map
|
|
|
|
(lambda (file)
|
2005-05-30 10:08:41 -04:00
|
|
|
(and (file-filter file)
|
2005-05-30 05:33:07 -04:00
|
|
|
(absolute-file-name file dir)))
|
|
|
|
(directory-files))))
|
|
|
|
|
|
|
|
(define (complete-path path)
|
|
|
|
(let ((dir (file-name-directory path)))
|
|
|
|
(map (lambda (p)
|
|
|
|
(if (string-prefix? "/" p)
|
|
|
|
p
|
|
|
|
(string-append dir p)))
|
|
|
|
(glob (string-append path "*")))))
|
|
|
|
|
2005-05-30 10:08:41 -04:00
|
|
|
(define (complete-with-filesystem-objects filter partial-name)
|
|
|
|
(if (and (file-exists? partial-name) (file-directory? partial-name))
|
|
|
|
(files-in-dir filter partial-name)
|
|
|
|
(complete-path partial-name)))
|
|
|
|
|
|
|
|
(define (complete-executables/path partial-name)
|
|
|
|
(complete-with-filesystem-objects
|
|
|
|
(lambda (file)
|
|
|
|
(or (file-executable? file) (file-directory? file)))
|
|
|
|
partial-name))
|
2005-05-30 05:33:07 -04:00
|
|
|
|
2005-05-30 10:08:41 -04:00
|
|
|
(define (complete-files/path partial-name)
|
|
|
|
(complete-with-filesystem-objects
|
|
|
|
(lambda (file) #t) partial-name))
|
|
|
|
|
2005-06-01 04:07:48 -04:00
|
|
|
(define (command-completer command prefix args args-pos)
|
2005-05-30 10:08:41 -04:00
|
|
|
(debug-message "command-mode-completer" prefix "|" args "|" args-pos)
|
2005-05-30 05:33:07 -04:00
|
|
|
(cond
|
2005-05-30 10:08:41 -04:00
|
|
|
((command-contains-path? prefix)
|
|
|
|
;; #### FIXME ignore errors here?
|
2005-06-01 04:07:48 -04:00
|
|
|
(complete-executables/path (expand-file-name prefix (cwd))))
|
2005-05-30 05:33:07 -04:00
|
|
|
(else
|
|
|
|
(append
|
2005-05-30 10:08:41 -04:00
|
|
|
(completions-for (command-completions) prefix)
|
2005-05-30 11:21:40 -04:00
|
|
|
(with-lock executable-completions-lock
|
2005-06-04 05:43:22 -04:00
|
|
|
(completions-for-executables executable-completions prefix))))))
|
2005-05-30 10:08:41 -04:00
|
|
|
|
2005-06-01 04:07:48 -04:00
|
|
|
(define (file-completer command prefix args args-pos)
|
|
|
|
(if (zero? (string-length prefix))
|
|
|
|
(complete-files/path prefix)
|
|
|
|
(complete-files/path (expand-file-name prefix (cwd)))))
|
|
|
|
|
2005-05-30 10:08:41 -04:00
|
|
|
(define (assemble-line-with-completion command arg arg-pos completion)
|
|
|
|
(debug-message "assemble-line-with-completion "
|
|
|
|
command "," arg "," arg-pos "," completion)
|
|
|
|
(let ((string-append* (lambda (s t)
|
|
|
|
(if (string=? s "")
|
|
|
|
t
|
|
|
|
(string-append s " " t)))))
|
|
|
|
(let lp ((tokens (cons command arg))
|
|
|
|
(arg-count 0)
|
|
|
|
(cursor-pos 0)
|
|
|
|
(line ""))
|
|
|
|
(cond
|
|
|
|
((null? tokens)
|
|
|
|
(values line (+ 2 cursor-pos)))
|
|
|
|
((= arg-count arg-pos)
|
|
|
|
(lp (cdr tokens)
|
|
|
|
(+ arg-count 1)
|
|
|
|
(+ cursor-pos (string-length completion))
|
|
|
|
(string-append* line completion)))
|
|
|
|
(else
|
|
|
|
(lp (cdr tokens)
|
|
|
|
(+ arg-count 1)
|
|
|
|
(+ 1 (+ cursor-pos (string-length (car tokens))))
|
|
|
|
(string-append* line (car tokens))))))))
|
|
|
|
|
|
|
|
(define (display-completed-line line cursor-pos)
|
|
|
|
(debug-message "display-completed-line " line "," cursor-pos)
|
2005-06-07 14:24:05 -04:00
|
|
|
(set-buffer-pos-col! (command-buffer) cursor-pos)
|
|
|
|
(set-buffer-text! (command-buffer)
|
2005-05-30 10:08:41 -04:00
|
|
|
(append
|
2005-06-07 14:24:05 -04:00
|
|
|
(drop-right (buffer-text (command-buffer)) 1)
|
2005-05-30 10:08:41 -04:00
|
|
|
(list line)))
|
2005-06-07 14:24:05 -04:00
|
|
|
(wclrtoeol (app-window-curses-win (command-window)))
|
|
|
|
(print-command-buffer (app-window-curses-win (command-window))
|
|
|
|
(command-buffer))
|
|
|
|
(move-cursor (command-buffer) (result-buffer))
|
2005-05-30 10:08:41 -04:00
|
|
|
(refresh-command-window))
|
2005-05-28 08:08:23 -04:00
|
|
|
|
2005-05-30 05:33:07 -04:00
|
|
|
(define (paint-completion-select-list select-list command)
|
2005-06-07 14:24:05 -04:00
|
|
|
(let ((win (app-window-curses-win (result-window))))
|
2005-05-30 05:33:07 -04:00
|
|
|
(wclear win)
|
|
|
|
(wattron win (A-BOLD))
|
|
|
|
(mvwaddstr win 0 0
|
|
|
|
(string-append "Possible completions for " command))
|
|
|
|
(wattrset win (A-NORMAL))
|
2005-05-31 11:14:45 -04:00
|
|
|
(paint-selection-list-at select-list 0 2
|
2005-06-07 14:24:05 -04:00
|
|
|
win (result-buffer) (focus-on-result-buffer?))
|
2005-05-28 08:08:23 -04:00
|
|
|
(refresh-result-window)))
|
|
|
|
|
2005-05-30 10:08:41 -04:00
|
|
|
(define (completer-function-for-command command)
|
2005-06-13 07:04:49 -04:00
|
|
|
(let ((alist
|
|
|
|
(map (lambda (p)
|
|
|
|
(cons (command-plugin-command p)
|
|
|
|
(command-plugin-completer p)))
|
|
|
|
(command-plugin-list))))
|
|
|
|
(cond
|
|
|
|
((assoc command alist) => cdr)
|
|
|
|
(else #f))))
|
2005-05-30 10:08:41 -04:00
|
|
|
|
|
|
|
(define (call-completer command args prefix arg-pos)
|
|
|
|
(cond
|
|
|
|
((= 0 arg-pos)
|
2005-06-01 04:07:48 -04:00
|
|
|
(command-completer command prefix args arg-pos))
|
2005-05-30 10:08:41 -04:00
|
|
|
((completer-function-for-command command)
|
|
|
|
=> (lambda (completer)
|
|
|
|
(completer command prefix args arg-pos)))
|
|
|
|
(else
|
2005-06-01 04:07:48 -04:00
|
|
|
(file-completer command prefix args arg-pos))))
|
2005-05-30 10:08:41 -04:00
|
|
|
|
2005-05-30 05:33:07 -04:00
|
|
|
(define (offer-completions command)
|
|
|
|
(let* ((tokens/cursor-list (tokenize-command command))
|
2005-05-30 10:08:41 -04:00
|
|
|
(args (map car (cdr tokens/cursor-list)))
|
2005-05-30 05:33:07 -04:00
|
|
|
(command (caar tokens/cursor-list)))
|
|
|
|
(call-with-values
|
|
|
|
(lambda ()
|
|
|
|
(find-token-with-cursor tokens/cursor-list))
|
|
|
|
(lambda (prefix arg-pos)
|
2005-05-30 10:08:41 -04:00
|
|
|
;; #### FIXME
|
|
|
|
(if (not prefix)
|
|
|
|
(error "could not determine token with cursor position"
|
|
|
|
tokens/cursor-list command
|
2005-06-07 14:24:05 -04:00
|
|
|
(- (buffer-pos-col (command-buffer)) 2)))
|
2005-05-30 10:08:41 -04:00
|
|
|
(let ((completions
|
|
|
|
(call-completer command args
|
|
|
|
prefix arg-pos)))
|
2005-05-30 05:33:07 -04:00
|
|
|
(if (= (length completions) 1)
|
|
|
|
(begin
|
2005-05-30 10:08:41 -04:00
|
|
|
(call-with-values
|
|
|
|
(lambda ()
|
|
|
|
(assemble-line-with-completion
|
|
|
|
command args arg-pos (car completions)))
|
|
|
|
display-completed-line)
|
2005-05-30 05:33:07 -04:00
|
|
|
#f)
|
2005-05-30 10:08:41 -04:00
|
|
|
(let* ((select-list
|
|
|
|
(completions->select-list
|
|
|
|
completions
|
2005-06-07 14:24:05 -04:00
|
|
|
(- (result-buffer-num-lines (result-buffer)) 3)))
|
2005-05-30 10:08:41 -04:00
|
|
|
(selector
|
|
|
|
(make-completion-selector
|
|
|
|
select-list completions
|
|
|
|
command args arg-pos)))
|
2005-05-30 05:33:07 -04:00
|
|
|
(paint-completion-select-list select-list command)
|
2005-06-07 14:24:05 -04:00
|
|
|
(move-cursor (command-buffer) (result-buffer))
|
2005-05-30 10:08:41 -04:00
|
|
|
(refresh-command-window)
|
|
|
|
selector)))))))
|
|
|
|
|
|
|
|
(define (make-completion-selector select-list completions
|
|
|
|
command arg arg-pos)
|
|
|
|
(lambda (key)
|
|
|
|
(cond
|
|
|
|
((= key 10)
|
|
|
|
(focus-command-buffer!)
|
|
|
|
(call-with-values
|
|
|
|
(lambda ()
|
|
|
|
(assemble-line-with-completion
|
|
|
|
command arg arg-pos
|
|
|
|
(select-list-selected-entry select-list)))
|
|
|
|
display-completed-line)
|
|
|
|
#f)
|
2005-05-30 11:38:13 -04:00
|
|
|
((or (select-list-navigation-key? key)
|
|
|
|
(select-list-marking-key? key))
|
|
|
|
(let ((new-select-list
|
2005-05-30 15:19:36 -04:00
|
|
|
(select-list-handle-key-press select-list key)))
|
2005-05-30 11:38:13 -04:00
|
|
|
(paint-completion-select-list
|
2005-06-07 14:24:05 -04:00
|
|
|
new-select-list (last (buffer-text (command-buffer))))
|
2005-05-30 11:38:13 -04:00
|
|
|
(make-completion-selector
|
|
|
|
new-select-list completions command arg arg-pos)))
|
|
|
|
(else
|
|
|
|
;; #### FIXME we loose a character this way
|
|
|
|
(focus-command-buffer!)
|
|
|
|
#f))))
|
2005-05-30 05:33:07 -04:00
|
|
|
|
|
|
|
(define (find-token-with-cursor tokens/cursor-list)
|
2005-05-30 10:08:41 -04:00
|
|
|
(debug-message "find-token-with-cursor " tokens/cursor-list)
|
2005-05-30 05:33:07 -04:00
|
|
|
(let lp ((lst tokens/cursor-list) (i 0))
|
|
|
|
(cond
|
|
|
|
((null? lst)
|
|
|
|
(values #f i))
|
|
|
|
((cdar lst)
|
|
|
|
(values (caar lst) i))
|
|
|
|
(else
|
|
|
|
(lp (cdr lst) (+ i 1))))))
|
|
|
|
|
|
|
|
(define (command-token-delimiter? c)
|
|
|
|
(char-set-contains? char-set:whitespace c))
|
|
|
|
|
|
|
|
(define (skip-delimters delimiter? chars)
|
|
|
|
(let lp ((chars chars) (i 0))
|
|
|
|
(cond
|
|
|
|
((null? chars) (values '() i))
|
|
|
|
((delimiter? (car chars))
|
|
|
|
(lp (cdr chars) (+ i 1)))
|
|
|
|
(else (values chars i)))))
|
|
|
|
|
|
|
|
(define (tokenize-command command)
|
2005-06-07 14:24:05 -04:00
|
|
|
(let ((cursor-pos (- (buffer-pos-col (command-buffer)) 2))) ;; don't ask
|
2005-05-30 05:33:07 -04:00
|
|
|
(let lp ((chars (string->list command))
|
|
|
|
(token "")
|
|
|
|
(tokens '())
|
|
|
|
(i 0))
|
|
|
|
(cond
|
|
|
|
((null? chars)
|
|
|
|
(reverse (cons (cons token (= i cursor-pos)) tokens)))
|
|
|
|
((command-token-delimiter? (car chars))
|
|
|
|
(call-with-values
|
|
|
|
(lambda ()
|
|
|
|
(skip-delimters command-token-delimiter? chars))
|
|
|
|
(lambda (rest skipped)
|
|
|
|
(lp rest "" (cons (cons token (= i cursor-pos)) tokens)
|
|
|
|
(+ i skipped)))))
|
|
|
|
(else
|
|
|
|
(lp (cdr chars) (string-append token (string (car chars)))
|
|
|
|
tokens (+ i 1)))))))
|
|
|
|
|