From d1816df4c029447f94963355cbdce5c434063ee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Sun, 24 Aug 2025 19:50:56 -0300 Subject: Add cursors --- cursor.lisp | 31 +++++++++++++++++++++++++++++++ package.lisp | 10 ++++++++++ utils.asd | 5 +++-- 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 cursor.lisp 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)))) diff --git a/package.lisp b/package.lisp index d170039..e6ed7b5 100644 --- a/package.lisp +++ b/package.lisp @@ -1,3 +1,13 @@ +(defpackage #:cursor + (:use #:cl) + (:export #:text + #:index + #:data + #:has-data? + #:peek + #:advance + #:distance)) + (defpackage #:color (:use #:cl) (:export #:hsl->rgb)) diff --git a/utils.asd b/utils.asd index 4a126d6..f4974e0 100644 --- a/utils.asd +++ b/utils.asd @@ -1,4 +1,4 @@ -(defsystem #:utils +(defsystem "utils" :serial nil :components ((:file "package") @@ -6,4 +6,5 @@ (:file "char") (:file "symbol") (:file "color") - (:file "str"))) + (:file "str") + (:file "cursor"))) -- cgit v1.2.3