2005-06-07 14:24:05 -04:00
|
|
|
(define-record-type console :console
|
|
|
|
(really-make-console pty-in pty-out
|
|
|
|
pause-channel resume-channel
|
|
|
|
window terminal-buffer)
|
|
|
|
console?
|
|
|
|
(pty-in console-pty-in)
|
|
|
|
(pty-out console-pty-out)
|
|
|
|
(pause-channel console-pause-channel)
|
|
|
|
(resume-channel console-resume-channel)
|
|
|
|
(window console-window)
|
|
|
|
(terminal-buffer console-terminal-buffer))
|
|
|
|
|
|
|
|
(define (make-console pty-in pty-out window terminal-buffer)
|
|
|
|
(let ((pause-channel (make-channel))
|
|
|
|
(resume-channel (make-channel)))
|
|
|
|
(spawn-console-loop
|
|
|
|
pause-channel resume-channel window terminal-buffer
|
|
|
|
(make-channel-for-pty-out pty-in))
|
|
|
|
(really-make-console
|
|
|
|
pty-in pty-out pause-channel resume-channel
|
|
|
|
window terminal-buffer)))
|
|
|
|
|
|
|
|
(define (make-channel-for-pty-out pty)
|
|
|
|
(let ((channel (make-channel)))
|
|
|
|
(spawn
|
|
|
|
(lambda ()
|
|
|
|
(debug-message "make-channel-for-pty-out " pty)
|
|
|
|
(let lp ((c (read-char pty)))
|
|
|
|
(if (not (eof-object? c))
|
|
|
|
(begin
|
|
|
|
(send channel c)
|
|
|
|
(lp (read-char pty)))))))
|
|
|
|
channel))
|
|
|
|
|
|
|
|
(define (spawn-console-loop
|
|
|
|
pause-channel resume-channel
|
|
|
|
window terminal-buffer pty-channel)
|
|
|
|
(spawn
|
|
|
|
(lambda ()
|
2005-07-06 04:57:44 -04:00
|
|
|
(let lp ((paint? #f))
|
2005-06-07 14:24:05 -04:00
|
|
|
(select
|
|
|
|
(wrap (receive-rv pause-channel)
|
|
|
|
(lambda (ignore)
|
|
|
|
(lp #f)))
|
|
|
|
(wrap (receive-rv resume-channel)
|
|
|
|
(lambda (ignore)
|
|
|
|
(lp #t)))
|
|
|
|
(wrap (receive-rv pty-channel)
|
|
|
|
(lambda (char)
|
|
|
|
(cond
|
|
|
|
((eof-object? char)
|
|
|
|
(lp paint?))
|
|
|
|
(else
|
|
|
|
(terminal-buffer-add-char terminal-buffer char)
|
|
|
|
(if paint?
|
2005-06-07 16:03:04 -04:00
|
|
|
(begin
|
|
|
|
(curses-paint-terminal-buffer
|
|
|
|
terminal-buffer window)
|
|
|
|
(wrefresh window)))
|
2005-06-07 14:24:05 -04:00
|
|
|
(lp paint?))))))))))
|
|
|
|
|
|
|
|
(define (pause-console-output console)
|
2005-06-07 16:52:49 -04:00
|
|
|
(debug-message "pause-console-output")
|
2005-06-07 14:24:05 -04:00
|
|
|
(send (console-pause-channel console) 'ignore))
|
|
|
|
|
|
|
|
(define (resume-console-output console)
|
2005-06-07 16:52:49 -04:00
|
|
|
(debug-message "resume-console-output")
|
2005-06-07 14:24:05 -04:00
|
|
|
(send (console-resume-channel console) 'ignore))
|
|
|
|
|
|
|
|
(define (view-console console)
|
|
|
|
(debug-message "view-console " console)
|
|
|
|
(curses-paint-terminal-buffer/complete
|
|
|
|
(console-terminal-buffer console)
|
|
|
|
(console-window console))
|
|
|
|
(resume-console-output console)
|
|
|
|
(spawn
|
|
|
|
(lambda ()
|
|
|
|
(sync
|
|
|
|
(wrap (result-buffer-other-object-has-focus-rv)
|
2005-09-27 05:00:33 -04:00
|
|
|
(lambda (ack-channel)
|
|
|
|
(pause-console-output console)
|
|
|
|
(send ack-channel 'ignore)))))))
|
2005-06-07 14:24:05 -04:00
|
|
|
|
|
|
|
(define (make-console-viewer console buffer)
|
|
|
|
(lambda (message)
|
|
|
|
(case message
|
|
|
|
((paint)
|
|
|
|
(lambda (self win buffer have-focus?)
|
|
|
|
(view-console console)))
|
|
|
|
(else
|
|
|
|
(lambda (self . more)
|
|
|
|
self)))))
|
|
|
|
|
|
|
|
(register-plugin!
|
|
|
|
(make-view-plugin make-console-viewer console?))
|