(zilch core statusbar): small cleanups
This commit is contained in:
parent
ac7dec3064
commit
cab43001e6
1 changed files with 10 additions and 3 deletions
|
|
@ -10,6 +10,8 @@
|
||||||
statusbar-logger)
|
statusbar-logger)
|
||||||
|
|
||||||
(begin
|
(begin
|
||||||
|
; Creates a buffered port, which buffers up to one line (terminated by a newline character)
|
||||||
|
; and calls redraw-status-bar after a write that prints a newline.
|
||||||
(define (buffered-port mutex write-output-line redraw-status-bar close-this-port)
|
(define (buffered-port mutex write-output-line redraw-status-bar close-this-port)
|
||||||
(define line-buffer (make-bytevector 1024 0))
|
(define line-buffer (make-bytevector 1024 0))
|
||||||
(define line-buffer-location 0)
|
(define line-buffer-location 0)
|
||||||
|
|
@ -40,18 +42,23 @@
|
||||||
(make-output-port (lambda (str) (mutex-lock! mutex) (write-data (string->utf8 str) 0)) close-this-port))
|
(make-output-port (lambda (str) (mutex-lock! mutex) (write-data (string->utf8 str) 0)) close-this-port))
|
||||||
|
|
||||||
(define (statusbar-logger out-port err-port print-logs)
|
(define (statusbar-logger out-port err-port print-logs)
|
||||||
|
; Current status bar text
|
||||||
(define status-bar "[0/0 builds, 0 running] ...")
|
(define status-bar "[0/0 builds, 0 running] ...")
|
||||||
(define terminal-width 80)
|
(define terminal-width 80)
|
||||||
(define-values (rows cols) (terminal-size err-port))
|
(define-values (rows cols) (terminal-size err-port))
|
||||||
(when (> cols 0) (set! terminal-width cols))
|
(when (> cols 0) (set! terminal-width cols))
|
||||||
|
|
||||||
(define (terminal-width-thread-thunk handler)
|
(define (terminal-width-thread-thunk handler)
|
||||||
(handler #t)
|
; Lock the output mutex whilst setting the terminal size.
|
||||||
(mutex-lock! out-mutex)
|
|
||||||
(define-values (rows cols) (terminal-size err-port))
|
(define-values (rows cols) (terminal-size err-port))
|
||||||
|
(mutex-lock! out-mutex)
|
||||||
(when (> cols 0) (set! terminal-width cols))
|
(when (> cols 0) (set! terminal-width cols))
|
||||||
(mutex-unlock! out-mutex)
|
(mutex-unlock! out-mutex)
|
||||||
|
|
||||||
|
; Wait until the next SIGWINCH, then loop
|
||||||
|
(handler #t)
|
||||||
(terminal-width-thread-thunk handler))
|
(terminal-width-thread-thunk handler))
|
||||||
|
|
||||||
(define terminal-width-thread (make-thread (lambda () (terminal-width-thread-thunk (make-signal-handler signal/winch)))))
|
(define terminal-width-thread (make-thread (lambda () (terminal-width-thread-thunk (make-signal-handler signal/winch)))))
|
||||||
|
|
||||||
(define (draw-status-bar)
|
(define (draw-status-bar)
|
||||||
|
|
@ -92,7 +99,7 @@
|
||||||
(begin
|
(begin
|
||||||
(set! last-activity-start-id #f)
|
(set! last-activity-start-id #f)
|
||||||
(set! last-activity-start (utf8->string (bytevector-copy buf start end)))
|
(set! last-activity-start (utf8->string (bytevector-copy buf start end)))
|
||||||
(set! need-redraw #t))))
|
(draw-status-bar))))
|
||||||
|
|
||||||
(define (write-out-line buf start end)
|
(define (write-out-line buf start end)
|
||||||
(unless need-redraw
|
(unless need-redraw
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue