Add simple error handling

Now we don't have to deal with a completely obliterated terminal every time
something breaks! \o/
This commit is contained in:
Skylar Hill 2023-11-12 00:42:45 -06:00
parent 34e57d8dcc
commit 90b9d770f0
3 changed files with 15 additions and 4 deletions

View file

@ -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

View file

@ -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))

View file

@ -294,8 +294,9 @@
(move (get-main-win nc) y-real x-real))
(define-method (end (nc <ncurses-frontend>))
(endwin)
(quit))
(erase (get-main-win nc))
(refresh (get-main-win nc))
(endwin))
(define-method (write-buffer (nc <ncurses-frontend>) buffer scroll)
(define win (get-main-win nc))