diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2025-06-23 02:24:02 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2025-06-23 02:24:02 -0300 |
commit | 31fa68324c6af5719d8901acd58c67847e915921 (patch) | |
tree | 3f51b77ca857761246a98d39d8c10bc0f5e653a0 /cursed.lisp | |
parent | 9e44b49ef3313e2970dad1fcfc5b936e5a52840f (diff) | |
download | cursed-31fa68324c6af5719d8901acd58c67847e915921.tar.gz cursed-31fa68324c6af5719d8901acd58c67847e915921.zip |
Create cursed text
Diffstat (limited to 'cursed.lisp')
-rw-r--r-- | cursed.lisp | 30 |
1 files changed, 30 insertions, 0 deletions
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)))) |