From 90b9d770f0dfcfda334ac4eb934df0662eec4a98 Mon Sep 17 00:00:00 2001 From: Skylar Hill Date: Sun, 12 Nov 2023 00:42:45 -0600 Subject: [PATCH] Add simple error handling Now we don't have to deal with a completely obliterated terminal every time something breaks! \o/ --- scripts/sloth.in | 11 ++++++++++- sloth/editor.scm | 3 ++- sloth/ncurses.scm | 5 +++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/scripts/sloth.in b/scripts/sloth.in index 815dffb..75f8390 100644 --- a/scripts/sloth.in +++ b/scripts/sloth.in @@ -14,6 +14,8 @@ (config api) (config licenses) (config parser sexp) + (ice-9 exceptions) + (sloth common) (sloth editor) (sloth interface) (ncurses curses)) @@ -45,7 +47,14 @@ "(Listof String) -> Int program entrypoint; handle commandline args and call appropriate procedures" (define options (getopt-config-auto args %configuration)) - (start-loop (init-frontend 'ncurses) (option-ref options '(file) #f))) + (define frontend (init-frontend 'ncurses)) + (with-exception-handler + (lambda (err) + (when (error? err) + (end frontend) + (format (current-error-port) "An error occurred: ~a" err))) + (lambda () + (start-loop frontend (option-ref options '(file) #f))))) ;;; Local Variables: ;;; mode: scheme diff --git a/sloth/editor.scm b/sloth/editor.scm index 2c13b58..d1b5859 100644 --- a/sloth/editor.scm +++ b/sloth/editor.scm @@ -1,8 +1,9 @@ (define-module (sloth editor) + #:use-module (ice-9 exceptions) #:use-module (ice-9 textual-ports) #:use-module (oop goops) - #:use-module (sloth interface) #:use-module (sloth common) + #:use-module (sloth interface) #:use-module (ts) #:export (start-loop)) diff --git a/sloth/ncurses.scm b/sloth/ncurses.scm index b487f1a..d83b180 100644 --- a/sloth/ncurses.scm +++ b/sloth/ncurses.scm @@ -294,8 +294,9 @@ (move (get-main-win nc) y-real x-real)) (define-method (end (nc )) - (endwin) - (quit)) + (erase (get-main-win nc)) + (refresh (get-main-win nc)) + (endwin)) (define-method (write-buffer (nc ) buffer scroll) (define win (get-main-win nc))