summaryrefslogtreecommitdiff
path: root/cursor.lisp
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2025-08-24 19:50:56 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2025-08-24 19:50:56 -0300
commitd1816df4c029447f94963355cbdce5c434063ee6 (patch)
treee4ff17ff8c2d4159a85bb34f3935f843f6bdce4c /cursor.lisp
parent97f8b6d2a990fe2e93704460fcdf08701616d7e4 (diff)
downloadutils-main.tar.gz
utils-main.zip
Add cursorsHEADmain
Diffstat (limited to 'cursor.lisp')
-rw-r--r--cursor.lisp31
1 files changed, 31 insertions, 0 deletions
diff --git a/cursor.lisp b/cursor.lisp
new file mode 100644
index 0000000..d3012ab
--- /dev/null
+++ b/cursor.lisp
@@ -0,0 +1,31 @@
+(in-package #:cursor)
+
+(defclass text ()
+ ((data :type simple-string :initarg :data :reader data :initform "")
+ (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~a~a~}"
+ (str:context-window (data obj)
+ (index obj)
+ :side-length 10))
+ "END OF DATA")))
+ (substitute #\↲ #\Newline str))))