summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2024-01-16 01:13:39 +0100
committerEkaitz Zarraga <ekaitz@elenq.tech>2024-01-18 22:48:57 +0100
commiteb0d091771fa39dcb2a5b4793a1c10abcec0dc5e (patch)
tree658d5e56eba8c64d724653f2c1bef2c5416a136d
parent13c0512b2644d3b0292fe505cc62dc035932d0e2 (diff)
world: organize and layout guile too
-rw-r--r--main.scm6
-rw-r--r--world/guile-tty.sld14
-rw-r--r--world/tty-commands.scm4
-rw-r--r--world/tty-commands.sld4
-rw-r--r--world/ui.scm19
-rw-r--r--world/ui.sld6
6 files changed, 36 insertions, 17 deletions
diff --git a/main.scm b/main.scm
new file mode 100644
index 0000000..9a9a391
--- /dev/null
+++ b/main.scm
@@ -0,0 +1,6 @@
+(cond-expand
+ (chibi (import (world ui)
+ (scheme small)))
+ (guile (import (world ui))))
+
+(run (command-line))
diff --git a/world/guile-tty.sld b/world/guile-tty.sld
new file mode 100644
index 0000000..5194a61
--- /dev/null
+++ b/world/guile-tty.sld
@@ -0,0 +1,14 @@
+(define-library (world guile-tty)
+ (import (scheme base))
+ (cond-expand
+ (guile (import (system foreign)))
+ (else (error 'not-supported)))
+ (begin
+ (error 'TODO)
+
+ ;; https://www.gnu.org/software/guile//manual/html_node/More-Foreign-Functions.html
+ (define _openpty
+ (foreign-library-function "tcgetattr"
+ #:return-type int
+ #:arg-types (list 'int '*)))
+ ))
diff --git a/world/tty-commands.scm b/world/tty-commands.scm
index a5f50db..4ce4212 100644
--- a/world/tty-commands.scm
+++ b/world/tty-commands.scm
@@ -25,9 +25,9 @@
number respectively. In ttys, cursor starts at 1,1"
(csi-command! (number->string (+ y 1)) ";" (number->string (+ 1 x)) "H"))
-(define (ui-initialize!)
+(define (tui-initialize!)
(enable-alternate-buffer!)
(move-cursor! 0 0))
-(define (ui-deinitialize!)
+(define (tui-deinitialize!)
(disable-alternate-buffer!))
diff --git a/world/tty-commands.sld b/world/tty-commands.sld
index 503b6bb..1ec5588 100644
--- a/world/tty-commands.sld
+++ b/world/tty-commands.sld
@@ -1,7 +1,7 @@
(define-library (world tty-commands)
(import (scheme base))
- (export ui-initialize!
- ui-deinitialize!
+ (export tui-initialize!
+ tui-deinitialize!
move-cursor!
erase-screen!)
(include "tty-commands.scm"))
diff --git a/world/ui.scm b/world/ui.scm
index 40d4e69..757e7dd 100644
--- a/world/ui.scm
+++ b/world/ui.scm
@@ -1,8 +1,5 @@
-
-
-(define (echo-char)
+(define (tui-loop)
(define table (make-piece-table "hola"))
- (ui-initialize!)
(let loop ((char (read-char)))
(move-cursor! 0 0)
(cond
@@ -10,11 +7,13 @@
(else (piece-table-insert! table 4 "hola" 'normal)
(erase-screen!)
(write-string (piece-table->string table))
- (loop (read-char)))))
- (ui-deinitialize!))
+ (loop (read-char))))))
-(define (start arguments)
- (with-raw-io (current-input-port) echo-char))
+(define (call-with-tui thunk)
+ (dynamic-wind
+ tui-initialize!
+ (lambda () (with-raw-io (current-input-port) thunk))
+ tui-deinitialize!))
-;; Extend `with-raw-io` with the initialization functions and just move to a
-;; `with-tui` function that calls the provided thunk in the proper mode
+(define (run arguments)
+ (call-with-tui tui-loop))
diff --git a/world/ui.sld b/world/ui.sld
index 1f2eda9..b59401e 100644
--- a/world/ui.sld
+++ b/world/ui.sld
@@ -4,7 +4,7 @@
(par piece-table)) ;; Remove the piece table from here later, and move to main
(cond-expand
(chibi (import (chibi stty)))
- (guile (import ()))) ; we fail now, but in the future i can build
- ; a simple wrapper around termios
- (export start)
+ (guile (import (world guile-tty)))) ; we fail now, but in the future i can build
+ ; a simple wrapper around termios
+ (export run)
(include "ui.scm"))