summaryrefslogtreecommitdiff
path: root/scripts/prompt.scm
blob: 738cd423fd70a4eb3f9acf67916e8bc42c42cad2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(define prompt-active #f)
(define prompt-box (make-rect 0 0 800 20))
(define prompt-text "")

(define (prompt-update)
  (let ((key-pressed (rl-get-key-pressed)))
    
    
    (if (eq? key-pressed 161)
	(set! prompt-active (not prompt-active))
	)
    
    (if prompt-active
	(begin
	  (let ((key (rl-get-char-pressed)))
	    (cond ((and (>= key 32) (<= key 125))
		   (set! prompt-text
			 (string-append prompt-text (string (integer->char key)))))
		  ))
	  
	  (if (rl-is-key-down KEY_ENTER)
	      (begin
		(eval-string prompt-text)
		(set! prompt-text "")
		))
	  
	  (if (eq? key-pressed KEY_BACKSPACE)
	      (let ((n (string-length prompt-text)))
		(cond ((>= n 1)
		       (set! prompt-text (substring prompt-text 0 (- n 1))))
		      )))
	  
	  ))
    )
  )

(define (prompt-draw)
  (if prompt-active
      (begin
	(rl-draw-rectangle
	 (rect-x prompt-box)
	 (rect-y prompt-box)
	 (rect-width prompt-box)
	 (rect-height prompt-box)
	 (make-color 190 100 255))
	(rl-draw-text prompt-text 0 0 20 (make-color 0 0 0))
	))
  )