2005-10-11 11:45:14 -04:00
|
|
|
(define-option 'job 'fg-key (char->ascii #\f))
|
|
|
|
(define-option 'job 'bg-key (char->ascii #\b))
|
|
|
|
(define-option 'job 'stop-job-key (char->ascii #\s))
|
|
|
|
(define-option 'job 'refresh-key (char->ascii #\g))
|
|
|
|
(define-option 'job 'kill-job-key (char->ascii #\k))
|
2005-09-13 09:20:30 -04:00
|
|
|
|
2005-06-04 07:22:44 -04:00
|
|
|
(define (job-name->string name)
|
|
|
|
(let ((port (open-output-string)))
|
|
|
|
(display name port)
|
|
|
|
(get-output-string port)))
|
|
|
|
|
|
|
|
(define (short-date date)
|
|
|
|
(fill-up-string 10
|
|
|
|
(format-date "~H:~M:~S" date)))
|
|
|
|
|
|
|
|
(define (format-job-run-state job)
|
|
|
|
(fill-up-string 12
|
|
|
|
(cond
|
|
|
|
((job-running? job) "running")
|
|
|
|
((job-ready? job) "ready")
|
2005-08-21 12:56:31 -04:00
|
|
|
((job-waiting-for-input? job) "wait/input")
|
|
|
|
((job-has-new-output? job) "wait/output")
|
2005-06-14 07:20:30 -04:00
|
|
|
((job-stopped? job) "stopped")
|
2005-06-04 07:22:44 -04:00
|
|
|
(else "run/output"))))
|
|
|
|
|
|
|
|
(define (format-job job num-cols)
|
|
|
|
(cut-to-size num-cols
|
|
|
|
(string-append
|
|
|
|
(fill-up-string
|
|
|
|
20 (job-name->string (job-name job)))
|
|
|
|
" "
|
|
|
|
(format-job-run-state job)
|
|
|
|
" "
|
|
|
|
(short-date (job-start-time job))
|
|
|
|
" "
|
|
|
|
(if (job-end-time job)
|
|
|
|
(short-date (job-end-time job))
|
|
|
|
(fill-up-string 12 "-"))
|
|
|
|
" "
|
|
|
|
(fill-up-string
|
|
|
|
6 (if (job-end-time job)
|
|
|
|
(number->string (job-status job))
|
|
|
|
"-")))))
|
|
|
|
|
|
|
|
(define (make-joblist-headline num-cols)
|
|
|
|
(cut-to-size
|
|
|
|
num-cols
|
|
|
|
(string-append
|
|
|
|
(fill-up-string 20 "NAME")
|
|
|
|
" "
|
|
|
|
(fill-up-string 12 "RUN STATUS")
|
|
|
|
" "
|
|
|
|
(fill-up-string 10 "START")
|
|
|
|
" "
|
|
|
|
(fill-up-string 10 "END")
|
|
|
|
" "
|
|
|
|
(fill-up-string 6 "STATUS"))))
|
|
|
|
|
2005-10-11 11:45:14 -04:00
|
|
|
(define (make-jobs-select-list jobs lines width)
|
|
|
|
(make-select-list
|
|
|
|
(map (lambda (job)
|
|
|
|
(make-unmarked-text-element
|
|
|
|
job #t (format-job job width)))
|
|
|
|
jobs)
|
|
|
|
lines))
|
|
|
|
|
|
|
|
|
2005-06-04 07:22:44 -04:00
|
|
|
(define (make-joblist-viewer jobs buffer)
|
|
|
|
(let* ((jobs jobs)
|
|
|
|
(num-cols (- (result-buffer-num-cols buffer) 1))
|
|
|
|
(headline (make-joblist-headline num-cols))
|
|
|
|
(select-list
|
2005-10-11 11:45:14 -04:00
|
|
|
(make-jobs-select-list
|
|
|
|
jobs
|
|
|
|
(- (result-buffer-num-lines buffer) 2)
|
|
|
|
(- num-cols 2))))
|
2005-06-04 07:22:44 -04:00
|
|
|
|
2005-07-06 04:57:44 -04:00
|
|
|
(define get-selection-as-ref
|
|
|
|
(make-get-selection-as-ref-method select-list))
|
2005-06-04 07:22:44 -04:00
|
|
|
|
2005-07-06 04:57:44 -04:00
|
|
|
(define (get-selection-as-text self for-scheme-mode? focus-object-table)
|
2005-06-04 07:22:44 -04:00
|
|
|
(if for-scheme-mode?
|
2005-07-06 04:57:44 -04:00
|
|
|
(send self 'get-selection-as-ref focus-object-table)
|
2005-09-27 04:08:15 -04:00
|
|
|
(let ((marked (select-list-get-marked select-list)))
|
2005-06-04 07:22:44 -04:00
|
|
|
(if (null? marked)
|
|
|
|
(number->string
|
|
|
|
(proc:pid (job-proc (select-list-selected-entry select-list))))
|
|
|
|
(string-join (map (lambda (job)
|
|
|
|
(number->string
|
|
|
|
(proc:pid (job-proc job))))
|
|
|
|
marked))))))
|
|
|
|
|
|
|
|
(lambda (message)
|
|
|
|
|
|
|
|
(case message
|
|
|
|
|
|
|
|
((paint)
|
|
|
|
(lambda (self win buffer have-focus?)
|
|
|
|
(mvwaddstr win 0 0 headline)
|
|
|
|
(paint-selection-list-at
|
2005-09-27 12:31:54 -04:00
|
|
|
select-list 0 1 win (result-buffer-num-cols buffer)
|
|
|
|
have-focus?)))
|
2005-06-04 07:22:44 -04:00
|
|
|
|
|
|
|
((key-press)
|
|
|
|
(lambda (self key control-x-pressed?)
|
2005-09-13 09:20:30 -04:00
|
|
|
(cond
|
2005-10-11 11:45:14 -04:00
|
|
|
((= key (config 'job 'fg-key))
|
|
|
|
(continue-job-in-foreground
|
|
|
|
(select-list-selected-entry select-list)))
|
|
|
|
((= key (config 'job 'bg-key))
|
|
|
|
(continue-job-in-background
|
|
|
|
(select-list-selected-entry select-list)))
|
|
|
|
((= key (config 'job 'stop-job-key))
|
2005-09-13 09:20:30 -04:00
|
|
|
(stop-job (select-list-selected-entry select-list)))
|
2005-10-11 11:45:14 -04:00
|
|
|
|
|
|
|
((= key (config 'job 'kill-job-key))
|
|
|
|
(signal-job signal/kill
|
|
|
|
(select-list-selected-entry select-list)))
|
|
|
|
|
|
|
|
((= key (config 'job 'refresh-key))
|
|
|
|
(send self 'refresh))
|
2005-09-13 09:20:30 -04:00
|
|
|
(else
|
|
|
|
(set! select-list
|
|
|
|
(select-list-handle-key-press select-list key))))
|
2005-06-04 07:22:44 -04:00
|
|
|
self))
|
|
|
|
|
2005-07-06 04:57:44 -04:00
|
|
|
((get-selection-as-text) get-selection-as-text)
|
2005-06-04 07:22:44 -04:00
|
|
|
|
2005-07-06 04:57:44 -04:00
|
|
|
((get-selection-as-ref) get-selection-as-ref)
|
2005-06-04 07:22:44 -04:00
|
|
|
|
2005-10-11 11:45:14 -04:00
|
|
|
((refresh)
|
|
|
|
(lambda (self)
|
|
|
|
(set! select-list
|
|
|
|
(make-jobs-select-list
|
|
|
|
jobs
|
|
|
|
(- (result-buffer-num-lines buffer) 2)
|
|
|
|
(- num-cols 2)))))
|
2005-06-04 07:22:44 -04:00
|
|
|
(else
|
|
|
|
(error "joblist-viewer unknown message" message))))))
|
|
|
|
|
|
|
|
(define (list-of-jobs? thing)
|
|
|
|
(and (proper-list? thing) (every job? thing)))
|
|
|
|
|
|
|
|
(register-plugin!
|
|
|
|
(make-view-plugin make-joblist-viewer list-of-jobs?))
|
2005-06-07 14:24:05 -04:00
|
|
|
|
2005-08-11 10:50:36 -04:00
|
|
|
(define format-signal-no
|
|
|
|
(let ((signal/name-alist
|
|
|
|
`((,signal/alrm . signal/alrm)
|
|
|
|
(,signal/int . signal/int)
|
|
|
|
(,signal/chld . signal/chld)
|
|
|
|
(,signal/cont . signal/cont)
|
|
|
|
(,signal/hup . signal/hup)
|
|
|
|
(,signal/quit . signal/quit)
|
|
|
|
(,signal/term . signal/term)
|
|
|
|
(,signal/tstp . signal/tstp)
|
|
|
|
(,signal/usr1 . signal/usr1)
|
|
|
|
(,signal/usr2 . signal/usr2)
|
|
|
|
(,signal/stop . signal/stop)
|
|
|
|
(,signal/kill . signal/kill)
|
|
|
|
(,signal/abrt . signal/abrt)
|
|
|
|
(,signal/fpe . signal/fpe)
|
|
|
|
(,signal/ill . signal/ill)
|
|
|
|
(,signal/pipe . signal/pipe)
|
|
|
|
(,signal/segv . signal/segv)
|
|
|
|
(,signal/ttin . signal/ttin)
|
|
|
|
(,signal/ttou . signal/ttou))))
|
|
|
|
(lambda (no)
|
|
|
|
(cond
|
|
|
|
((assoc no signal/name-alist)
|
|
|
|
=> (lambda (p)
|
|
|
|
(symbol->string (cdr p))))
|
|
|
|
(else "some non-POSIX signal")))))
|
|
|
|
|
|
|
|
(define (format-job-status job)
|
|
|
|
(let ((status (job-status job)))
|
|
|
|
(debug-message "format-job-status " status)
|
|
|
|
(cond
|
|
|
|
((status:exit-val status)
|
|
|
|
=> (lambda (code)
|
|
|
|
(string-append "exited normally with code "
|
|
|
|
(number->string code))))
|
|
|
|
((status:stop-sig status)
|
|
|
|
=> (lambda (signal-no)
|
|
|
|
(string-append "suspended by signal "
|
|
|
|
(format-signal-no signal-no))))
|
|
|
|
((status:term-sig status)
|
|
|
|
=> (lambda (signal-no)
|
|
|
|
(string-append "terminated by signal "
|
|
|
|
(format-signal-no signal-no)))))))
|
|
|
|
|
2005-06-07 14:24:05 -04:00
|
|
|
;;; viewer for a single job viewer
|
|
|
|
|
|
|
|
(define (make-job-viewer job buffer)
|
|
|
|
(let ((select-list #f)
|
|
|
|
(num-cols
|
2005-07-06 04:57:44 -04:00
|
|
|
(- (result-buffer-num-cols buffer) 1))
|
|
|
|
(console-viewer
|
|
|
|
(if (job-with-console? job)
|
|
|
|
(make-console-viewer (job-console job) buffer)
|
|
|
|
#f)))
|
2005-06-07 14:24:05 -04:00
|
|
|
|
|
|
|
(define (make-job-select-list job)
|
|
|
|
(make-select-list
|
|
|
|
(map
|
|
|
|
(lambda (args)
|
2005-09-27 12:29:34 -04:00
|
|
|
(make-unmarked-text-element
|
2005-06-07 14:24:05 -04:00
|
|
|
(car args) #f
|
|
|
|
(cut-to-size
|
|
|
|
num-cols
|
|
|
|
(apply string-append
|
|
|
|
(append
|
|
|
|
(list (fill-up-string 15 (cadr args)))
|
|
|
|
(cddr args))))))
|
2005-08-21 12:56:31 -04:00
|
|
|
`((,job
|
2005-06-14 07:20:30 -04:00
|
|
|
"name:" ,(job-name->string (job-name job)))
|
2005-08-11 10:50:36 -04:00
|
|
|
|
|
|
|
(,(if (job-end-time job) (job-status job) #f)
|
|
|
|
"status:"
|
2005-08-12 09:28:54 -04:00
|
|
|
,(if (job-end-time job)
|
|
|
|
(format-job-status job)
|
|
|
|
"n/a"))
|
2005-08-11 10:50:36 -04:00
|
|
|
|
2005-06-14 07:20:30 -04:00
|
|
|
(,(job-start-time job)
|
|
|
|
"start:"
|
|
|
|
,(short-date (job-start-time job)))
|
|
|
|
(,(job-end-time job)
|
|
|
|
"end:"
|
|
|
|
,(if (job-end-time job)
|
|
|
|
(short-date (job-end-time job))
|
|
|
|
"-"))
|
|
|
|
(#f "run status:"
|
|
|
|
,(format-job-run-state job))
|
2005-09-27 04:59:07 -04:00
|
|
|
,@(if (job-with-console? job)
|
|
|
|
`((,console-viewer "<View Console>" ""))
|
|
|
|
'())))
|
2005-09-27 04:59:55 -04:00
|
|
|
(- (result-buffer-num-lines buffer) 3)))
|
2005-06-07 14:24:05 -04:00
|
|
|
|
|
|
|
(define (handle-key-press self key control-x-pressed?)
|
|
|
|
(cond
|
2005-10-11 11:45:14 -04:00
|
|
|
((= key (config 'job 'fg-key))
|
2005-09-27 04:58:06 -04:00
|
|
|
(continue-job-in-foreground job)
|
|
|
|
self)
|
2005-10-11 11:45:14 -04:00
|
|
|
((= key (config 'job 'bg-key))
|
2005-09-27 04:58:06 -04:00
|
|
|
(continue-job-in-background job)
|
|
|
|
self)
|
2005-10-11 11:45:14 -04:00
|
|
|
((= key (config 'job 'refresh-key))
|
2005-09-27 04:58:06 -04:00
|
|
|
(set! select-list (make-job-select-list job))
|
|
|
|
self)
|
2005-10-11 11:45:14 -04:00
|
|
|
((= key (config 'job 'stop-job-key))
|
2005-09-27 04:58:06 -04:00
|
|
|
(stop-job job)
|
|
|
|
self)
|
2005-10-11 11:45:14 -04:00
|
|
|
((= key (config 'job 'kill-job-key))
|
|
|
|
(signal-job signal/kill job)
|
|
|
|
self)
|
2005-09-27 04:58:06 -04:00
|
|
|
((and (= key 10)
|
|
|
|
(procedure? (select-list-selected-entry select-list)))
|
|
|
|
(select-list-selected-entry select-list))
|
2005-06-07 14:24:05 -04:00
|
|
|
(else
|
|
|
|
(set! select-list
|
2005-09-27 04:58:06 -04:00
|
|
|
(select-list-handle-key-press select-list key))
|
|
|
|
self)))
|
2005-06-07 14:24:05 -04:00
|
|
|
|
|
|
|
(set! select-list (make-job-select-list job))
|
|
|
|
|
|
|
|
(lambda (message)
|
|
|
|
(case message
|
|
|
|
|
|
|
|
((paint)
|
|
|
|
(lambda (self win buffer have-focus?)
|
|
|
|
(mvwaddstr
|
2005-08-11 10:50:36 -04:00
|
|
|
win 0 0 (cut-to-size num-cols "Viewing job"))
|
2005-06-07 14:24:05 -04:00
|
|
|
(paint-selection-list-at
|
2005-09-27 12:31:54 -04:00
|
|
|
select-list 0 1 win (result-buffer-num-cols buffer)
|
|
|
|
have-focus?)))
|
2005-06-07 14:24:05 -04:00
|
|
|
|
|
|
|
((key-press) handle-key-press)
|
|
|
|
|
2005-08-21 12:56:31 -04:00
|
|
|
((get-selection-as-ref)
|
2005-07-06 04:57:44 -04:00
|
|
|
(make-get-selection-as-ref-method select-list))
|
2005-06-07 14:24:05 -04:00
|
|
|
|
2005-08-21 12:56:31 -04:00
|
|
|
((get-selection-as-text)
|
|
|
|
(lambda (self focus? focus-table)
|
|
|
|
((make-get-selection-as-ref-method select-list)
|
|
|
|
self focus-table)))
|
2005-06-07 14:24:05 -04:00
|
|
|
|
|
|
|
(else
|
|
|
|
(error "job viewer unknown message" message))))))
|
|
|
|
|
|
|
|
(register-plugin!
|
|
|
|
(make-view-plugin make-job-viewer job?))
|