2005-06-07 14:24:05 -04:00
|
|
|
(define-record-type app-window :app-window
|
2005-09-27 12:32:10 -04:00
|
|
|
(really-make-app-window x y width height curses-win)
|
2005-06-07 14:24:05 -04:00
|
|
|
app-window?
|
|
|
|
(x app-window-x)
|
|
|
|
(y app-window-y)
|
|
|
|
(width app-window-width)
|
|
|
|
(height app-window-height)
|
|
|
|
(curses-win app-window-curses-win set-app-window-curses-win!))
|
|
|
|
|
2005-09-27 12:32:10 -04:00
|
|
|
(define (make-app-window x y width height)
|
|
|
|
(really-make-app-window x y width height #f))
|
|
|
|
|
2005-06-07 14:24:05 -04:00
|
|
|
(define-record-discloser :app-window
|
|
|
|
(lambda (rec)
|
|
|
|
`(app-window
|
|
|
|
(x ,(app-window-x rec)) (y ,(app-window-y rec))
|
|
|
|
(w ,(app-window-width rec)) (h ,(app-window-height rec)))))
|
|
|
|
|
|
|
|
(define *bar-1* #f)
|
|
|
|
(define (bar-1) *bar-1*)
|
|
|
|
|
|
|
|
(define *active-command-window* #f)
|
|
|
|
(define (active-command-window) *active-command-window*)
|
|
|
|
|
|
|
|
(define *command-frame-window* #f)
|
|
|
|
(define (command-frame-window) *command-frame-window*)
|
|
|
|
|
|
|
|
(define *command-window* #f)
|
|
|
|
(define (command-window) *command-window*)
|
|
|
|
|
|
|
|
(define *result-window* #f)
|
|
|
|
(define (result-window) *result-window*)
|
|
|
|
|
|
|
|
(define *result-frame-window* #f)
|
|
|
|
(define (result-frame-window) *result-frame-window*)
|
|
|
|
|
2006-03-28 04:44:39 -05:00
|
|
|
(define *command-buffer* #f)
|
|
|
|
; (make-buffer '("pwd" "")
|
|
|
|
; 2 2 2 1 1
|
|
|
|
; 0 0
|
|
|
|
; #t 1))
|
|
|
|
|
|
|
|
(define (command-buffer)
|
|
|
|
(if *command-buffer*
|
|
|
|
*command-buffer*
|
|
|
|
(let ((buf (make-buffer (app-window-curses-win (command-window))
|
|
|
|
(lambda ()
|
|
|
|
(string-append (cwd) "> "))
|
|
|
|
0 0
|
|
|
|
(- (app-window-width (command-window)) 0)
|
|
|
|
(- (app-window-height (command-window)) 1))))
|
|
|
|
(set! *command-buffer* buf)
|
|
|
|
buf)))
|
2005-06-07 14:24:05 -04:00
|
|
|
|
|
|
|
(define *result-buffer*
|
|
|
|
(make-result-buffer 0 0 0 0
|
|
|
|
#f #f ; set in INIT-WINDOWS
|
|
|
|
'() '()))
|
|
|
|
|
|
|
|
(define (result-buffer) *result-buffer*)
|
|
|
|
|
|
|
|
(define *focus-buffer* 'command-buffer)
|
|
|
|
|
|
|
|
(define (focus-on-command-buffer?)
|
|
|
|
(eq? *focus-buffer* 'command-buffer))
|
|
|
|
|
|
|
|
(define (focus-command-buffer!)
|
|
|
|
(set! *focus-buffer* 'command-buffer))
|
|
|
|
|
|
|
|
(define (focus-on-result-buffer?)
|
|
|
|
(eq? *focus-buffer* 'result-buffer))
|
|
|
|
|
|
|
|
(define (focus-result-buffer!)
|
|
|
|
(set! *focus-buffer* 'result-buffer))
|
|
|
|
|
2005-06-14 07:20:30 -04:00
|
|
|
(define *untouched-tty* #f)
|
|
|
|
|
|
|
|
(define (save-initial-tty-info! port)
|
|
|
|
(set! *untouched-tty* (copy-tty-info (tty-info port))))
|
|
|
|
|
|
|
|
(define (restore-initial-tty-info! port)
|
|
|
|
(set-tty-info/now port *untouched-tty*))
|
|
|
|
|
2005-06-07 14:24:05 -04:00
|
|
|
(define (make-inlying-app-window outer-window)
|
|
|
|
(make-app-window (+ (app-window-x outer-window) 1)
|
|
|
|
(+ (app-window-y outer-window) 1)
|
|
|
|
(- (app-window-width outer-window) 2)
|
2005-09-27 12:32:10 -04:00
|
|
|
(- (app-window-height outer-window) 2)))
|
2005-06-07 14:24:05 -04:00
|
|
|
|
2005-09-27 12:32:10 -04:00
|
|
|
(define (app-window-init-curses-win! window)
|
2005-06-07 14:24:05 -04:00
|
|
|
(set-app-window-curses-win!
|
|
|
|
window
|
|
|
|
(newwin (app-window-height window) (app-window-width window)
|
|
|
|
(app-window-y window) (app-window-x window))))
|
|
|
|
|
2005-09-27 12:32:10 -04:00
|
|
|
(define (delete-app-window! window)
|
|
|
|
(delwin (app-window-curses-win window)))
|
|
|
|
|
2005-06-07 14:24:05 -04:00
|
|
|
(define (init-windows!)
|
2005-10-11 11:41:42 -04:00
|
|
|
(spawn-result-buffer-surveillant)
|
|
|
|
|
2005-06-07 14:24:05 -04:00
|
|
|
(set! *bar-1*
|
|
|
|
(make-app-window 1 1
|
2005-09-27 12:32:10 -04:00
|
|
|
(- (COLS) 2) 2))
|
2005-09-27 04:59:55 -04:00
|
|
|
(debug-message '*bar-1* *bar-1*)
|
2005-06-07 14:24:05 -04:00
|
|
|
(set! *active-command-window*
|
|
|
|
(make-app-window 1 (+ (round (/ (LINES) 3)) 2)
|
2005-09-27 12:32:10 -04:00
|
|
|
(- (COLS) 2) 3))
|
2005-09-27 04:59:55 -04:00
|
|
|
(debug-message '*active-command-window* *active-command-window*)
|
2005-06-07 14:24:05 -04:00
|
|
|
(set! *command-frame-window*
|
|
|
|
(make-app-window 1 2
|
2005-09-27 12:32:10 -04:00
|
|
|
(- (COLS) 2) (- (app-window-y (active-command-window)) 2)))
|
2005-09-27 04:59:55 -04:00
|
|
|
(debug-message '*command-frame-window* *command-frame-window*)
|
2005-06-07 14:24:05 -04:00
|
|
|
(set! *command-window*
|
|
|
|
(make-inlying-app-window (command-frame-window)))
|
2005-09-27 04:59:55 -04:00
|
|
|
(debug-message '*command-window* *command-window*)
|
2005-06-07 14:24:05 -04:00
|
|
|
(set! *result-frame-window*
|
|
|
|
(make-app-window 1 (+ (app-window-y (active-command-window)) 3)
|
|
|
|
(- (COLS) 2)
|
2005-09-27 12:32:10 -04:00
|
|
|
(- (- (LINES) 6) (app-window-height (command-frame-window)))))
|
2005-09-27 04:59:55 -04:00
|
|
|
(debug-message '*result-frame-window* *result-frame-window*)
|
2005-06-07 14:24:05 -04:00
|
|
|
(set! *result-window*
|
|
|
|
(make-inlying-app-window (result-frame-window)))
|
2005-09-27 04:59:55 -04:00
|
|
|
(debug-message '*result-window* *result-window*)
|
2005-06-07 14:24:05 -04:00
|
|
|
|
|
|
|
(let ((all-windows
|
|
|
|
(list (bar-1) (active-command-window)
|
|
|
|
(command-frame-window) (command-window)
|
|
|
|
(result-frame-window) (result-window))))
|
2005-09-27 12:32:10 -04:00
|
|
|
(for-each app-window-init-curses-win! all-windows)
|
2005-06-07 14:24:05 -04:00
|
|
|
|
|
|
|
(set-result-buffer-num-lines!
|
|
|
|
*result-buffer* (- (app-window-height (result-window)) 2))
|
|
|
|
(set-result-buffer-num-cols!
|
2005-09-27 04:59:55 -04:00
|
|
|
*result-buffer* (- (app-window-width (result-window)) 1))
|
2005-06-07 14:24:05 -04:00
|
|
|
|
2005-09-27 04:59:55 -04:00
|
|
|
(for-each wclear
|
2005-06-07 14:24:05 -04:00
|
|
|
(map app-window-curses-win all-windows))))
|
|
|
|
|
|
|
|
;; result-buffer-object-change-channel
|
|
|
|
|
|
|
|
(define result-buffer-changed-channel
|
|
|
|
(make-channel))
|
|
|
|
|
|
|
|
(define result-buffer-changes-subscribers
|
|
|
|
(make-channel))
|
|
|
|
|
|
|
|
(define (signal-result-buffer-object-change)
|
2005-09-27 05:00:33 -04:00
|
|
|
(let ((ack-channel (make-channel)))
|
|
|
|
(debug-message "signal-result-buffer-object-change")
|
|
|
|
(send result-buffer-changed-channel ack-channel)
|
|
|
|
(receive ack-channel)))
|
2005-06-07 14:24:05 -04:00
|
|
|
|
|
|
|
(define (spawn-result-buffer-surveillant)
|
|
|
|
(spawn
|
|
|
|
(lambda ()
|
|
|
|
(let lp ()
|
|
|
|
(select
|
|
|
|
(wrap (receive-rv result-buffer-changes-subscribers)
|
|
|
|
(lambda (answer-channel)
|
2005-06-14 07:20:30 -04:00
|
|
|
(debug-message "result-buffer-surveillant 1")
|
2005-09-27 05:00:33 -04:00
|
|
|
(sync (wrap
|
|
|
|
(receive-rv result-buffer-changed-channel)
|
|
|
|
(lambda (ack-channel)
|
|
|
|
(send answer-channel ack-channel))))
|
2005-06-07 14:24:05 -04:00
|
|
|
(lp)))
|
|
|
|
(wrap (receive-rv result-buffer-changed-channel)
|
2005-09-27 05:00:33 -04:00
|
|
|
(lambda (ack-channel)
|
|
|
|
(send ack-channel 'no-one-is-interested)
|
2005-06-14 07:20:30 -04:00
|
|
|
(debug-message "result-buffer-surveillant 2")
|
2005-06-07 14:24:05 -04:00
|
|
|
(lp))))))))
|
|
|
|
|
|
|
|
(define (result-buffer-other-object-has-focus-rv)
|
|
|
|
(let ((answer-channel (make-channel)))
|
|
|
|
(send result-buffer-changes-subscribers answer-channel)
|
2005-10-11 11:41:42 -04:00
|
|
|
(receive-rv answer-channel)))
|