2005-05-22 05:20:44 -04:00
|
|
|
(define (list-of-processes? thing)
|
|
|
|
(and (proper-list? thing)
|
|
|
|
(every process-info? thing)))
|
|
|
|
|
2005-09-27 12:30:57 -04:00
|
|
|
(define (make-header-line)
|
2005-09-27 12:30:23 -04:00
|
|
|
(make-select-line
|
|
|
|
(list
|
2005-09-27 12:30:57 -04:00
|
|
|
(make-unmarked-text-element 'pid #f (right-align-string 6 "PID "))
|
|
|
|
(make-unmarked-text-element 'ppid #f (right-align-string 6 "PPID "))
|
|
|
|
(make-unmarked-text-element 'user #f (left-align-string 9 "USER "))
|
2005-09-27 12:32:36 -04:00
|
|
|
(make-unmarked-text-element '%cpu #f (right-align-string 6 "%CPU "))
|
2005-09-27 12:30:57 -04:00
|
|
|
(make-unmarked-text-element 'command #f "COMMAND"))))
|
2005-05-25 05:44:27 -04:00
|
|
|
|
2005-09-27 12:32:26 -04:00
|
|
|
|
|
|
|
(define (column->opertions column)
|
|
|
|
(case column
|
|
|
|
((pid) (values < = > process-info-pid))
|
|
|
|
((ppid) (values < = > process-info-ppid))
|
|
|
|
((user) (values string<? string=? string>?
|
|
|
|
process-info-logname))
|
|
|
|
((time) (values < = > process-info-time))
|
2005-09-27 12:32:36 -04:00
|
|
|
((%cpu) (values < = > process-info-%cpu))
|
2005-09-27 12:32:26 -04:00
|
|
|
((command) (values string<? string=? string>?
|
|
|
|
process-info-executable))
|
|
|
|
(else
|
|
|
|
(error "unknown column" column))))
|
|
|
|
|
2005-05-25 05:44:27 -04:00
|
|
|
(define (layout-process width p)
|
2005-05-31 15:31:38 -04:00
|
|
|
(cut-to-size
|
|
|
|
width
|
|
|
|
(string-append
|
2005-09-27 04:59:21 -04:00
|
|
|
(right-align-string 5 (number->string (process-info-pid p)))
|
2005-05-31 15:31:38 -04:00
|
|
|
" "
|
2005-09-27 04:59:21 -04:00
|
|
|
(right-align-string 5 (number->string (process-info-ppid p)))
|
2005-05-31 15:31:38 -04:00
|
|
|
" "
|
2005-09-27 04:59:21 -04:00
|
|
|
(left-align-string 8 (process-info-logname p))
|
2005-09-27 04:58:18 -04:00
|
|
|
" "
|
2005-09-27 12:32:36 -04:00
|
|
|
(right-align-string 5 (number->string (process-info-%cpu p)))
|
2005-05-31 15:31:38 -04:00
|
|
|
" "
|
2005-09-27 12:30:23 -04:00
|
|
|
(left-align-string 100 (string-append
|
2005-09-27 04:59:21 -04:00
|
|
|
(process-info-executable p)
|
|
|
|
" "
|
|
|
|
(string-join
|
|
|
|
(process-info-command-line p)))))))
|
|
|
|
|
2005-09-27 12:30:23 -04:00
|
|
|
(define (make-process-selection-list num-cols num-lines
|
|
|
|
processes)
|
2005-05-25 07:36:12 -04:00
|
|
|
(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)
|
2005-09-27 12:30:23 -04:00
|
|
|
(make-unmarked-text-element p #t (layout-process num-cols p)))
|
2005-05-26 07:33:38 -04:00
|
|
|
processes)
|
2005-05-25 07:36:12 -04:00
|
|
|
num-lines)))
|
2005-05-20 11:20:34 -04:00
|
|
|
|
2005-09-27 12:32:26 -04:00
|
|
|
(define (make-filter-window list-viewer entries
|
|
|
|
compare-val select-val)
|
2005-09-27 12:36:44 -04:00
|
|
|
(define header-line "Filter by")
|
|
|
|
(define header-length (string-length header-line))
|
2005-09-27 12:32:26 -04:00
|
|
|
(let* ((vals
|
|
|
|
(delete-duplicates
|
|
|
|
(map select-val entries) compare-val))
|
|
|
|
(val-strings
|
|
|
|
(map display-to-string vals))
|
2005-09-27 12:36:44 -04:00
|
|
|
(lines 10)
|
|
|
|
(inner-width
|
|
|
|
(min (apply max header-length
|
|
|
|
(map string-length val-strings))
|
|
|
|
(COLS)))
|
|
|
|
(dialog (make-app-window (- (quotient (COLS) 2)
|
|
|
|
(quotient inner-width 2))
|
|
|
|
5
|
|
|
|
(+ 4 inner-width)
|
|
|
|
lines)))
|
2005-09-27 12:32:26 -04:00
|
|
|
(app-window-init-curses-win! dialog)
|
|
|
|
(let* ((dialog-win (app-window-curses-win dialog))
|
|
|
|
(select-list
|
|
|
|
(make-select-list
|
|
|
|
(map (lambda (val str)
|
|
|
|
(make-unmarked-text-element
|
|
|
|
val #f str))
|
|
|
|
vals val-strings)
|
2005-09-27 12:36:44 -04:00
|
|
|
(- lines 3))))
|
2005-09-27 12:32:26 -04:00
|
|
|
|
|
|
|
(define (paint)
|
|
|
|
(werase dialog-win)
|
|
|
|
(box dialog-win
|
|
|
|
(ascii->char 0) (ascii->char 0))
|
2005-09-27 12:36:44 -04:00
|
|
|
(mvwaddstr dialog-win
|
|
|
|
0
|
|
|
|
(+ 1 (quotient (- inner-width header-length) 2))
|
|
|
|
header-line)
|
|
|
|
(paint-selection-list-at select-list 2 1 dialog-win inner-width #t)
|
2005-09-27 12:32:26 -04:00
|
|
|
(wrefresh dialog-win))
|
|
|
|
|
|
|
|
(paint)
|
|
|
|
(lambda (key)
|
|
|
|
(cond ((= key 27)
|
|
|
|
(delete-app-window! dialog)
|
|
|
|
(close-modal-window!)
|
|
|
|
#t)
|
|
|
|
((select-list-key? key)
|
|
|
|
(set! select-list
|
|
|
|
(select-list-handle-key-press select-list key))
|
|
|
|
(paint)
|
|
|
|
#f)
|
|
|
|
((= key 10)
|
|
|
|
(let* ((val (select-list-selected-entry select-list))
|
|
|
|
(new-entries
|
|
|
|
(filter (lambda (entry)
|
|
|
|
(compare-val (select-val entry)
|
|
|
|
val)) entries)))
|
|
|
|
(send list-viewer 'set-entries! new-entries))
|
|
|
|
(delete-app-window! dialog)
|
|
|
|
#t)
|
|
|
|
(else #f))))))
|
|
|
|
|
2005-09-27 04:59:34 -04:00
|
|
|
(define-option 'ps 'kill-key (char->ascii #\k))
|
|
|
|
(define-option 'ps 'refresh-key (char->ascii #\g))
|
2005-09-27 12:30:57 -04:00
|
|
|
(define-option 'ps 'sort-up-key (char->ascii #\s))
|
|
|
|
(define-option 'ps 'sort-down-key (char->ascii #\S))
|
2005-09-27 12:32:26 -04:00
|
|
|
(define-option 'ps 'filter-key (char->ascii #\f))
|
2005-09-27 04:58:43 -04:00
|
|
|
|
2005-05-31 09:15:31 -04:00
|
|
|
(define (make-pps-viewer processes buffer)
|
2005-09-27 12:30:23 -04:00
|
|
|
(let* ((processes processes)
|
2005-09-27 12:30:57 -04:00
|
|
|
(header-line (make-header-line))
|
2005-09-27 12:30:23 -04:00
|
|
|
(select-list
|
|
|
|
(make-process-selection-list
|
|
|
|
(result-buffer-num-cols buffer)
|
|
|
|
(result-buffer-num-lines buffer)
|
|
|
|
processes)))
|
2005-06-01 07:49:56 -04:00
|
|
|
|
2005-07-06 04:57:44 -04:00
|
|
|
(define (get-selection-as-text self for-scheme-mode? focus-object-table)
|
2005-09-27 04:08:15 -04:00
|
|
|
(let* ((marked (select-list-get-marked select-list)))
|
2005-07-06 04:57:44 -04:00
|
|
|
(cond
|
|
|
|
((null? marked)
|
|
|
|
(number->string
|
|
|
|
(process-info-pid
|
|
|
|
(select-list-selected-entry select-list))))
|
|
|
|
(for-scheme-mode?
|
|
|
|
(string-append
|
2005-09-27 04:46:34 -04:00
|
|
|
"'" (write-to-string (map process-info-pid marked))))
|
2005-07-06 04:57:44 -04:00
|
|
|
(else
|
|
|
|
(string-join
|
|
|
|
(map number->string
|
|
|
|
(map process-info-pid marked)))))))
|
2005-06-01 07:49:56 -04:00
|
|
|
|
2005-05-30 15:19:36 -04:00
|
|
|
(lambda (message)
|
2005-05-31 15:31:38 -04:00
|
|
|
(case message
|
|
|
|
|
2005-09-27 12:30:57 -04:00
|
|
|
((paint)
|
|
|
|
(lambda (self win buffer have-focus?)
|
|
|
|
(paint-select-line-at header-line 0 0 win buffer)
|
|
|
|
(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-05-31 15:31:38 -04:00
|
|
|
|
2005-09-27 12:30:57 -04:00
|
|
|
((key-press)
|
|
|
|
(lambda (self key control-x-pressed?)
|
|
|
|
(cond
|
|
|
|
((or (= key (config 'ps 'sort-up-key))
|
|
|
|
(= key (config 'ps 'sort-down-key)))
|
|
|
|
(let ((column (select-line-selected-entry header-line)))
|
2005-09-27 12:32:26 -04:00
|
|
|
(receive (compare-up compare-equal compare-down select)
|
|
|
|
(column->opertions column)
|
2005-09-27 12:30:57 -04:00
|
|
|
(let ((compare (if (= key (config 'ps 'sort-up-key))
|
|
|
|
compare-up
|
|
|
|
compare-down)))
|
2005-09-27 12:32:26 -04:00
|
|
|
(send self 'set-processes!
|
|
|
|
(list-sort
|
|
|
|
(lambda (p1 p2)
|
|
|
|
(compare (select p1) (select p2)))
|
|
|
|
processes))
|
2005-09-27 12:30:57 -04:00
|
|
|
self))))
|
2005-09-27 12:32:26 -04:00
|
|
|
((= key (config 'ps 'filter-key))
|
|
|
|
(receive (compare-up compare-equal compare-down select)
|
|
|
|
(column->opertions
|
|
|
|
(select-line-selected-entry header-line))
|
|
|
|
(set-modal-window!
|
|
|
|
(make-filter-window self processes compare-equal select))
|
|
|
|
self))
|
2005-09-27 12:30:57 -04:00
|
|
|
((= key (config 'ps 'kill-key))
|
|
|
|
(let ((infos
|
|
|
|
(select-list-get-selection select-list)))
|
|
|
|
(for-each
|
|
|
|
(cut signal-process <> signal/term)
|
|
|
|
(map process-info-pid infos)))
|
|
|
|
self)
|
|
|
|
((= key (config 'ps 'refresh-key))
|
2005-09-27 12:32:26 -04:00
|
|
|
(send self 'set-processes! (pps))
|
2005-09-27 12:30:57 -04:00
|
|
|
self)
|
|
|
|
((select-list-key? key)
|
|
|
|
(set! select-list
|
|
|
|
(select-list-handle-key-press select-list key))
|
|
|
|
self)
|
|
|
|
((select-line-key? key)
|
|
|
|
(select-line-handle-key-press! header-line key)
|
|
|
|
self)
|
|
|
|
(else self))))
|
2005-06-01 07:49:56 -04:00
|
|
|
|
2005-09-27 12:30:57 -04:00
|
|
|
((get-selection-as-text) get-selection-as-text)
|
2005-06-01 07:49:56 -04:00
|
|
|
|
2005-09-27 12:30:57 -04:00
|
|
|
((get-selection-as-ref)
|
|
|
|
(make-get-selection-as-ref-method select-list))
|
2005-09-27 12:32:26 -04:00
|
|
|
|
|
|
|
((set-entries!)
|
|
|
|
(lambda (self processes)
|
|
|
|
(send self 'set-processes! processes)))
|
|
|
|
|
|
|
|
((set-processes!)
|
|
|
|
(lambda (self new-processes)
|
|
|
|
(set! processes new-processes)
|
|
|
|
(set! select-list
|
|
|
|
(make-process-selection-list
|
|
|
|
(result-buffer-num-cols buffer)
|
|
|
|
(- (result-buffer-num-lines buffer) 1)
|
|
|
|
new-processes))))
|
2005-09-27 12:30:57 -04:00
|
|
|
(else
|
|
|
|
(error "pps-viewer unknown message" message))))))
|
2005-05-20 11:20:34 -04:00
|
|
|
|
2005-05-22 11:05:25 -04:00
|
|
|
(register-plugin!
|
2005-05-30 15:19:36 -04:00
|
|
|
(make-view-plugin make-pps-viewer list-of-processes?))
|