diff --git a/scripts/sloth.in b/scripts/sloth.in index 17b2a17..1e6fd5b 100644 --- a/scripts/sloth.in +++ b/scripts/sloth.in @@ -45,7 +45,7 @@ "(Listof String) -> Int program entrypoint; handle commandline args and call appropriate procedures" (define options (getopt-config-auto args %configuration)) - (core-loop)) + (start-loop #:file (option-ref options '(file) #f))) ;;; Local Variables: ;;; mode: scheme diff --git a/sloth/editor.scm b/sloth/editor.scm index 54737f0..6db469c 100644 --- a/sloth/editor.scm +++ b/sloth/editor.scm @@ -2,11 +2,17 @@ #:use-module (sloth interface) #:use-module (ncurses curses) #:use-module (ts) - #:export (core-loop)) + #:use-module (ice-9 textual-ports) + #:export (start-loop)) (define modes '(#:normal-mode #:insert-mode)) -(define* (core-loop #:optional (win (init-win)) (mode #:normal-mode)) +(define* (start-loop #:key (win (init-win)) + (file #f)) + (if file (find-file win file)) + (core-loop win)) + +(define* (core-loop win #:optional (mode #:normal-mode)) (define process-result (case mode ((#:normal-mode) (normal-mode-process-input win (getch win))) @@ -50,3 +56,8 @@ ((eqv? key #\q) (endwin) (quit)))) + +(define (find-file win file) + (when (file-exists? file) + (addstr win (call-with-input-file file get-string-all)) + (refresh win)))