diff options
-rw-r--r-- | cursed.asd | 2 | ||||
-rw-r--r-- | cursed.lisp | 30 | ||||
-rw-r--r-- | package.lisp | 9 |
3 files changed, 39 insertions, 2 deletions
@@ -1,6 +1,6 @@ (defsystem #:cursed :serial t - :depends-on () + :depends-on (#:utils) :components ((:file "package") (:file "cursed"))) diff --git a/cursed.lisp b/cursed.lisp index ee0dfa1..b3fedd7 100644 --- a/cursed.lisp +++ b/cursed.lisp @@ -1 +1,31 @@ (in-package #:cursed) + +(defclass text () + ((data :type 'simple-string :initarg :data :reader data :initform nil) + (index :type '(unsigned-byte 44) :initarg :index :accessor index :initform 0))) + +(defun has-data? (cursor) + (< (index cursor) (length (data cursor)))) + +(defun peek (cursor) + (char (data cursor) + (index cursor))) + +(defun advance (cursor) + (make-instance 'text + :data (data cursor) + :index (+ (index cursor) 1))) + +(defun distance (from to) + (- (index to) + (index from))) + +(defmethod print-object ((obj text) stream) + (print-unreadable-object (obj stream :type t) + (let ((str (if (has-data? obj) + (format nil "~{~a[4;33m~a[m~a~}" + (str:context-window (data obj) + (index obj) + :side-length 10)) + "END OF DATA"))) + (substitute #\↲ #\Newline str)))) diff --git a/package.lisp b/package.lisp index 9137d9d..1dd2728 100644 --- a/package.lisp +++ b/package.lisp @@ -1,2 +1,9 @@ (defpackage #:cursed - (:use #:cl)) + (:use #:cl) + (:export #:text + #:index + #:data + #:has-data? + #:peek + #:advance + #:distance)) |