From 2232786316accd01b6ed36ea98195f0460296aa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Tue, 4 Apr 2023 14:41:13 +0200 Subject: [PATCH] Handle process and terminal correctly. --- src/Makefile | 2 +- src/ansi.scm | 6 ++++++ src/environment.scm | 11 +++++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Makefile b/src/Makefile index c96edb4..6939b15 100644 --- a/src/Makefile +++ b/src/Makefile @@ -225,7 +225,7 @@ WEB-STATIC-SOURCES=web-static.scm member-record.import.scm \ web-static.o: web-static.import.scm web-static.import.scm: $(WEB-STATIC-SOURCES) -ENVIRONMENT-SOURCES=environment.scm +ENVIRONMENT-SOURCES=environment.scm ansi.import.scm environment.o: environment.import.scm environment.import.scm: $(ENVIRONMENT-SOURCES) diff --git a/src/ansi.scm b/src/ansi.scm index 4a11b12..67007b8 100644 --- a/src/ansi.scm +++ b/src/ansi.scm @@ -39,6 +39,7 @@ ansi-string-length ansi-paragraph-format ansi-string + clrscr ansi-tests! ) @@ -211,6 +212,11 @@ (cons arg res) (cons arg (cons (apply ansi (reverse kws)) res)))))))))) + ;; Clears the entire screen and positions cursor in the upper-left + ;; corner. + (define (clrscr) + (display "\x1b[0m\x1b[2J\x1b[0;0H")) + ;; Performs ANSI module self-tests. (define (ansi-tests!) (run-tests diff --git a/src/environment.scm b/src/environment.scm index e20c56d..829f40f 100644 --- a/src/environment.scm +++ b/src/environment.scm @@ -34,14 +34,17 @@ (import scheme (chicken base) (chicken process-context) - (chicken process)) + (chicken process) + ansi) ;; Starts an editor on given file (define (edit-file file-path) (print "Editing...") (let* ((edvar (get-environment-variable "EDITOR")) - (editor (or edvar "editor"))) - (process-run editor (list file-path)) - )) + (editor (or edvar "editor")) + (pid (process-run editor (list file-path)))) + (process-wait pid) + (clrscr) + (flush-output))) )