From 07cea571ef775131e7378abd11830a8a29750f82 Mon Sep 17 00:00:00 2001 From: Amr Gharbeia Date: Wed, 13 May 2026 16:29:50 -0400 Subject: [PATCH] fix: add backend-clear method for raw 2D arrays Same pattern as the draw-text array fix. Application code may call backend-clear with a framebuffer array instead of a backend instance. The array method clears all cells to default blank state. --- org/framebuffer.org | 12 ++++++++++++ src/rendering/framebuffer.lisp | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/org/framebuffer.org b/org/framebuffer.org index 1296526..2055157 100644 --- a/org/framebuffer.org +++ b/org/framebuffer.org @@ -382,6 +382,18 @@ framebuffer without wrapping it in a ~framebuffer-backend~. :bold bold :italic italic :underline underline))))) #+end_src +*** backend-clear (raw array) + +Allow clearing a raw 2D framebuffer array directly (same type as returned by +~make-framebuffer~). Resets all cells to blank defaults. + +#+begin_src lisp :tangle ../src/rendering/framebuffer.lisp +(defmethod backend-clear ((fb array)) + (dotimes (y (array-dimension fb 0)) + (dotimes (x (array-dimension fb 1)) + (setf (aref fb y x) (make-cell))))) +#+end_src + *** draw-rect Fill a rectangular region with space characters and an optional background diff --git a/src/rendering/framebuffer.lisp b/src/rendering/framebuffer.lisp index a4541a1..7485212 100644 --- a/src/rendering/framebuffer.lisp +++ b/src/rendering/framebuffer.lisp @@ -93,6 +93,11 @@ :fg fg :bg bg :bold bold :italic italic :underline underline))))) +(defmethod backend-clear ((fb array)) + (dotimes (y (array-dimension fb 0)) + (dotimes (x (array-dimension fb 1)) + (setf (aref fb y x) (make-cell))))) + (defmethod draw-rect ((fb framebuffer-backend) x y w h &key bg) (dotimes (row h) (dotimes (col w)