2005-05-25 05:44:27 -04:00
|
|
|
(define-record-type plugin-state :plugin-state
|
|
|
|
(make-plugin-state processes selection-list cursor-x)
|
|
|
|
plugin-state?
|
|
|
|
(processes plugin-state-processes)
|
|
|
|
(selection-list plugin-state-selection-list)
|
|
|
|
(cursor-x plugin-state-cursor-x))
|
|
|
|
|
|
|
|
(define-record-discloser :plugin-state
|
|
|
|
(lambda (r)
|
|
|
|
`(plugin-state ,(plugin-state-selection-list r))))
|
|
|
|
|
2005-05-22 05:20:44 -04:00
|
|
|
(define (list-of-processes? thing)
|
|
|
|
(and (proper-list? thing)
|
|
|
|
(every process-info? thing)))
|
|
|
|
|
2005-05-25 05:44:27 -04:00
|
|
|
(define (string-take-max s nchars)
|
|
|
|
(if (>= nchars (string-length s))
|
|
|
|
s
|
|
|
|
(string-take s nchars)))
|
|
|
|
|
|
|
|
(define (layout-process width p)
|
|
|
|
(string-take-max
|
|
|
|
(apply format
|
|
|
|
(append
|
|
|
|
(list #f "~A ~A ~A ~A '~A ~A'~%")
|
|
|
|
(map (lambda (s) (s p))
|
|
|
|
(list process-info-pid
|
|
|
|
process-info-ppid
|
|
|
|
process-info-real-uid
|
|
|
|
process-info-%cpu
|
|
|
|
process-info-executable
|
|
|
|
process-info-command-line))))
|
|
|
|
width))
|
|
|
|
|
2005-05-25 07:36:12 -04:00
|
|
|
(define (make-process-selection-list num-cols num-lines processes)
|
|
|
|
(let ((layout (lambda (p) (layout-process num-cols p))))
|
2005-05-25 05:44:27 -04:00
|
|
|
(make-select-list
|
2005-05-26 07:33:38 -04:00
|
|
|
(map
|
|
|
|
(lambda (p)
|
|
|
|
(make-unmarked-element p #t (layout-process num-cols p)))
|
|
|
|
processes)
|
2005-05-25 07:36:12 -04:00
|
|
|
num-lines)))
|
2005-05-20 11:20:34 -04:00
|
|
|
|
|
|
|
(define (pps-receiver message)
|
2005-05-22 05:20:44 -04:00
|
|
|
(debug-message "pps-receiver " message)
|
2005-05-20 11:20:34 -04:00
|
|
|
(cond
|
2005-05-25 05:44:27 -04:00
|
|
|
|
2005-05-22 11:05:25 -04:00
|
|
|
((init-with-result-message? message)
|
2005-05-25 07:36:12 -04:00
|
|
|
(let* ((processes (init-with-result-message-result message))
|
|
|
|
(buffer (init-with-result-message-buffer message))
|
|
|
|
(num-cols (result-buffer-num-cols buffer))
|
|
|
|
(num-lines (result-buffer-num-lines buffer)))
|
2005-05-25 05:44:27 -04:00
|
|
|
(make-plugin-state
|
2005-05-25 07:36:12 -04:00
|
|
|
processes
|
|
|
|
(make-process-selection-list num-cols num-lines processes) 1)))
|
2005-05-25 05:44:27 -04:00
|
|
|
|
2005-05-20 11:20:34 -04:00
|
|
|
((print-message? message)
|
2005-05-25 05:44:27 -04:00
|
|
|
(paint-selection-list
|
|
|
|
(plugin-state-selection-list
|
|
|
|
(message-result-object message))))
|
|
|
|
|
2005-05-20 11:20:34 -04:00
|
|
|
((key-pressed-message? message)
|
2005-05-25 05:44:27 -04:00
|
|
|
(let ((old-state (message-result-object message)))
|
|
|
|
(make-plugin-state
|
|
|
|
(plugin-state-processes old-state)
|
|
|
|
(select-list-handle-key-press
|
|
|
|
(plugin-state-selection-list old-state)
|
|
|
|
message)
|
|
|
|
(plugin-state-cursor-x old-state))))
|
|
|
|
|
2005-05-20 11:20:34 -04:00
|
|
|
((restore-message? message)
|
|
|
|
(values))
|
2005-05-25 05:44:27 -04:00
|
|
|
|
2005-05-20 11:20:34 -04:00
|
|
|
((selection-message? message)
|
|
|
|
"'()")))
|
|
|
|
|
2005-05-22 11:05:25 -04:00
|
|
|
(register-plugin!
|
2005-05-23 08:47:41 -04:00
|
|
|
(make-view-plugin pps-receiver list-of-processes?))
|