[PATCH 13/20] fbconsole: add new clear_chars helper

Ahmad Fatoum a.fatoum at barebox.org
Sun May 3 01:33:15 PDT 2026


fbc_parse_csi() implements partial line clearing by printing spaces as
that's an easy way to do background-color aware clearing.

Wrap that idiom in a new clear_chars helper that can be used to clear
between everything between two cells in the future as well.

Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
 drivers/video/fbconsole.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index fb6a7d3e5809..f586aabdae43 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -285,6 +285,18 @@ static void drawchar(struct fbc_priv *priv, int x, int y, int c)
 	fb_blit_area(priv, x, y);
 }
 
+static void clear_chars(struct fbc_priv *priv,
+			int start_x, int start_y, int end_x, int end_y)
+{
+	for (int y = start_y; y <= end_y; y++) {
+		int xs = (y == start_y) ? start_x : 0;
+		int xe = (y == end_y) ? end_x : (int)priv->cols - 1;
+
+		for (int x = xs; x <= xe; x++)
+			drawchar(priv, x, y, ' ');
+	}
+}
+
 static void video_invertchar(struct fbc_priv *priv, int x, int y)
 {
 	int startx, starty, width, height, fw, fh;
@@ -592,7 +604,7 @@ static bool fbc_parse_csi(struct fbc_priv *priv)
 {
 	char *end;
 	unsigned char last;
-	int pos, i;
+	int pos;
 
 	last = priv->csi[priv->csipos - 1];
 
@@ -670,12 +682,12 @@ static bool fbc_parse_csi(struct fbc_priv *priv)
 		toggle_cursor_visibility(priv);
 		switch (pos) {
 		case 0:
-			for (i = priv->cur.x; i < priv->cols; i++)
-				drawchar(priv, i, priv->cur.y, ' ');
+			clear_chars(priv, priv->cur.x, priv->cur.y,
+				    priv->cols - 1, priv->cur.y);
 			break;
 		case 1:
-			for (i = 0; i <= priv->cur.x; i++)
-				drawchar(priv, i, priv->cur.y, ' ');
+			clear_chars(priv, 0, priv->cur.y,
+				    priv->cur.x, priv->cur.y);
 			break;
 		}
 		toggle_cursor_visibility(priv);
-- 
2.47.3




More information about the barebox mailing list