summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2022-11-05 12:04:02 +0100
committerEkaitz Zarraga <ekaitz@elenq.tech>2022-11-05 12:04:02 +0100
commit395b51b37fb8c226384b09793be16304a8f94dd8 (patch)
tree439f5f0c50742f8f41360fd777ca8119da73941e
parent1d6a79a98c8810b2e05087d978dc963c8d23fc7e (diff)
Better IO that stops with messages
-rw-r--r--depre/main.scm12
1 files changed, 8 insertions, 4 deletions
diff --git a/depre/main.scm b/depre/main.scm
index b59c5c9..525f685 100644
--- a/depre/main.scm
+++ b/depre/main.scm
@@ -1,5 +1,6 @@
; https://xn--rpa.cc/irl/term.html
-(define-module (depre main))
+(define-module (depre main)
+ #:use-module (ice-9 textual-ports))
;; Code makes heavy use of functional code and parameters for state.
(define max-100 (lambda (x) (if (> x 100) 100 x)))
@@ -40,8 +41,9 @@
;; Simple I/O
(define (answer message)
(lambda ()
+ (newline)
(display message)
- (newline)))
+ (get-line (current-input-port))))
(define (bar percent)
"A simple 12 character bar for life-like variable representation"
@@ -55,6 +57,8 @@
(else #\space)))
len))
+(define (read-number)
+ (string->number (get-line (current-input-port))))
;; Basic state representation and creation: A state is a function that knows
;; how to jump to other states through a menu.
@@ -75,12 +79,12 @@
(newline))
menu (iota (length menu) 1))
(display "You choose > ")
- (let loop ((chosen (read)))
+ (let loop ((chosen (read-number)))
(if (and (number? chosen) (<= chosen (length menu)))
((cdr (nth chosen menu)))
(begin
(display "Wrong answer. Try again > ")
- (loop (read)))))))
+ (loop (read-number)))))))
;; States: