From 31fa68324c6af5719d8901acd58c67847e915921 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Mon, 23 Jun 2025 02:24:02 -0300 Subject: Create cursed text --- cursed.lisp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'cursed.lisp') 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~a~a~}" + (str:context-window (data obj) + (index obj) + :side-length 10)) + "END OF DATA"))) + (substitute #\↲ #\Newline str)))) -- cgit v1.2.3