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

View File

@ -34,6 +34,11 @@
;; ! : okay? (row col char -> void) row col -> bool
(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)
(match-define (raart w h !) x)
(define-values
@ -49,7 +54,9 @@
c r
(+ c w) (+ r h)))
(! 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 !)
(raart w h
@ -417,5 +424,7 @@
raart? raart?)]
[place-cursor-after
(-> raart? exact-nonnegative-integer? exact-nonnegative-integer?
raart?)])
raart?)]
[without-cursor
(-> raart? raart?)])
place-at*)

View File

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