This commit is contained in:
Jay McCarthy 2018-08-17 13:15:07 -04:00
parent 90927c5e74
commit 205340bdc0
3 changed files with 31 additions and 21 deletions

View File

@ -8,7 +8,7 @@
(define-generics buffer (define-generics buffer
(buffer-resize! buffer rows cols) (buffer-resize! buffer rows cols)
(buffer-start! buffer rows cols) (buffer-start! buffer rows cols)
(buffer-commit! buffer)) (buffer-commit! buffer #:cursor? [cursor?]))
(define symbol->style (define symbol->style
`#hasheq([normal . ,A:style-normal] `#hasheq([normal . ,A:style-normal]
@ -91,9 +91,9 @@
(set! cur-c (add1 cur-c))) (set! cur-c (add1 cur-c)))
#t])))) #t]))))
(define (buffer-commit! buf) (define (buffer-commit! buf #:cursor? [cursor? #t])
(terminal-buffer-define buf) (terminal-buffer-define buf)
(display (A:show-cursor) op) (when cursor? (display (A:show-cursor) op))
(flush-output op))]) (flush-output op))])
(struct output-cell (s f b ch) #:mutable #:transparent) (struct output-cell (s f b ch) #:mutable #:transparent)
@ -154,7 +154,7 @@
(buffer-resize! buf draw-rows draw-cols) (buffer-resize! buf draw-rows draw-cols)
(clear-cells! cells) (clear-cells! cells)
(values draw-rows draw-cols (draw-cell! cells))) (values draw-rows draw-cols (draw-cell! cells)))
(define (buffer-commit! buf) (define (buffer-commit! buf #:cursor? [cursor? #t])
(output-buffer-define buf) (output-buffer-define buf)
(for/fold ([last-s 'normal] [last-f #f] [last-b #f]) (for/fold ([last-s 'normal] [last-f #f] [last-b #f])
([row (in-vector (cells-vec cells))]) ([row (in-vector (cells-vec cells))])
@ -218,7 +218,7 @@
(set! last-row r) (set! last-row r)
(set! last-col c) (set! last-col c)
(dc s f b r c ch)))) (dc s f b r c ch))))
(define (buffer-commit! buf) (define (buffer-commit! buf #:cursor? [cursor? #t])
(cached-buffer-define buf) (cached-buffer-define buf)
(define inner-buf (if clear-next? term-yclear term-nclear)) (define inner-buf (if clear-next? term-yclear term-nclear))
(set! clear-next? #f) (set! clear-next? #f)
@ -235,7 +235,7 @@
(match-define (output-cell s f b new-ch) new-cell) (match-define (output-cell s f b new-ch) new-cell)
(draw! s f b r c (or new-ch #\space))))) (draw! s f b r c (or new-ch #\space)))))
(draw! 'normal #f #f last-row last-col #f) (draw! 'normal #f #f last-row last-col #f)
(super-buffer-commit! inner-buf) (super-buffer-commit! inner-buf #:cursor? cursor?)
(swap! new-cells cur-cells))]) (swap! new-cells cur-cells))])
(define-syntax-rule (swap! x y) (define-syntax-rule (swap! x y)
@ -262,7 +262,7 @@
exact-nonnegative-integer? exact-nonnegative-integer? (or/c char? #f) exact-nonnegative-integer? exact-nonnegative-integer? (or/c char? #f)
boolean?)))] boolean?)))]
[buffer-commit! [buffer-commit!
(-> buffer? void?)] (->* (buffer?) (#:cursor? boolean?) void?)]
[make-terminal-buffer [make-terminal-buffer
(->* (exact-nonnegative-integer? exact-nonnegative-integer?) (->* (exact-nonnegative-integer? exact-nonnegative-integer?)
(#:clear? boolean? #:output output-port?) (#:clear? boolean? #:output output-port?)

View File

@ -34,6 +34,11 @@
;; ! : okay? (row col char -> void) row col -> bool ;; ! : okay? (row col char -> void) row col -> bool
(struct raart (w h !)) (struct raart (w h !))
(struct meta-raart raart (m))
(define (without-cursor x)
(match-define (raart w h !) x)
(meta-raart w h ! '(without-cursor)))
(define (draw buf x) (define (draw buf x)
(match-define (raart w h !) x) (match-define (raart w h !) x)
(define-values (define-values
@ -49,7 +54,9 @@
c r c r
(+ c w) (+ r h))) (+ c w) (+ r h)))
(! on-screen? draw-with-params 0 0) (! on-screen? draw-with-params 0 0)
(buffer-commit! buf)) (define without-cursor?
(memq 'without-cursor (if (meta-raart? x) (meta-raart-m x) '())))
(buffer-commit! #:cursor? (not without-cursor) buf))
(define (raart* w h !) (define (raart* w h !)
(raart w h (raart w h
@ -417,5 +424,7 @@
raart? raart?)] raart? raart?)]
[place-cursor-after [place-cursor-after
(-> raart? exact-nonnegative-integer? exact-nonnegative-integer? (-> raart? exact-nonnegative-integer? exact-nonnegative-integer?
raart?)]) raart?)]
[without-cursor
(-> raart? raart?)])
place-at*) place-at*)

View File

@ -53,18 +53,19 @@
["q" #f])) ["q" #f]))
(define (word-output w) (define (word-output w)
(hack-define w) (hack-define w)
(crop 0 cols 0 rows (without-cursor
(vappend (crop 0 cols 0 rows
#:halign 'left (vappend
(text (~a "Hello Jack! Enjoy the hacking! Press q to quit.")) #:halign 'left
(place-at* (text (~a "Hello Jack! Enjoy the hacking! Press q to quit."))
(for/fold ([c (blank world-cols world-rows)]) (place-at*
([o (in-list objs)]) (for/fold ([c (blank world-cols world-rows)])
(obj-define o) ([o (in-list objs)])
(place-at c oy ox (fg 'blue (char oc)))) (obj-define o)
[py px (fg 'red (char #\@))]) (place-at c oy ox (fg 'blue (char oc))))
(text (~a "Jack the Paren Hunter")) [py px (fg 'red (char #\@))])
(happend (text (~a "Steps: " steps " Score: " score)))))) (text (~a "Jack the Paren Hunter"))
(happend (text (~a "Steps: " steps " Score: " score)))))))
(define (word-return w) (define (word-return w)
(hack-define w) (hack-define w)
(~a "You got " score " parens in " steps " steps!"))]) (~a "You got " score " parens in " steps " steps!"))])