From 1db39c1348de281d7a3baf1b2ab1ff387138ba2d Mon Sep 17 00:00:00 2001 From: Skylar Date: Fri, 3 Nov 2023 22:15:11 -0500 Subject: [PATCH] Create a basic ncurses buffer that can be edited --- scripts/sloth.in | 20 ++++++++++++++++++-- sloth/editor.scm | 9 +++++++++ sloth/interface.scm | 12 ++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 sloth/editor.scm create mode 100644 sloth/interface.scm diff --git a/scripts/sloth.in b/scripts/sloth.in index c167e37..2a09799 100644 --- a/scripts/sloth.in +++ b/scripts/sloth.in @@ -13,7 +13,10 @@ (use-modules (config) (config api) (config licenses) - (config parser sexp)) + (config parser sexp) + (sloth interface) + (sloth editor) + (ncurses curses)) ;; Commandline handling @@ -30,7 +33,7 @@ (arguments (list (argument (name 'file) - (handle file-exists?) + (test file-exists?) (synopsis "The file to open") (example "./file.txt")))) (directory (in-home ".config/")) @@ -43,6 +46,19 @@ program entrypoint; handle commandline args and call appropriate procedures" (define options (getopt-config-auto args %configuration)) (display (full-command options)) (newline) + (init-screen) + (let test-loop () + (let ((ch (getch screen)) + (yx (getyx screen))) + (cond + ((eq? #\backspace ch) (begin + (delch screen))) + ((eq? KEY_LEFT ch) (move screen (car yx) (- (cadr yx) 1))) + ((eq? KEY_RIGHT ch) (move screen (car yx) (+ (cadr yx) 1))) + ((eq? KEY_UP ch) (move screen (- (car yx) 1) (cadr yx))) + ((eq? KEY_DOWN ch) (move screen (+ (car yx) 1) (cadr yx))) + ((char? ch) (insert-char ch)))) + (test-loop)) #; (match (full-command options) ; ((_ file) ; diff --git a/sloth/editor.scm b/sloth/editor.scm new file mode 100644 index 0000000..24e69c3 --- /dev/null +++ b/sloth/editor.scm @@ -0,0 +1,9 @@ +(define-module (sloth editor) + #:use-module (ncurses curses) + #:use-module (ts) + #:use-module (sloth interface) + #:export (insert-char)) + +(define (insert-char c) + (addch screen (normal c)) + (refresh screen)) diff --git a/sloth/interface.scm b/sloth/interface.scm new file mode 100644 index 0000000..9d43e6a --- /dev/null +++ b/sloth/interface.scm @@ -0,0 +1,12 @@ +(define-module (sloth interface) + #:use-module (ncurses curses) + #:export (screen + init-screen)) + +(define screen '()) + +(define (init-screen) + (set! screen (initscr)) + (raw!) + (noecho!) + (keypad! screen #t))