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 api)
(config licenses) (config licenses)
(config parser sexp) (config parser sexp)
(ice-9 exceptions)
(sloth common)
(sloth editor) (sloth editor)
(sloth interface) (sloth interface)
(ncurses curses)) (ncurses curses))
@ -45,7 +47,14 @@
"(Listof String) -> Int "(Listof String) -> Int
program entrypoint; handle commandline args and call appropriate procedures" program entrypoint; handle commandline args and call appropriate procedures"
(define options (getopt-config-auto args %configuration)) (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: ;;; Local Variables:
;;; mode: scheme ;;; mode: scheme

View File

@ -1,8 +1,9 @@
(define-module (sloth editor) (define-module (sloth editor)
#:use-module (ice-9 exceptions)
#:use-module (ice-9 textual-ports) #:use-module (ice-9 textual-ports)
#:use-module (oop goops) #:use-module (oop goops)
#:use-module (sloth interface)
#:use-module (sloth common) #:use-module (sloth common)
#:use-module (sloth interface)
#:use-module (ts) #:use-module (ts)
#:export (start-loop)) #:export (start-loop))

View File

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