[PATCH 15/20] fbconsole: support ESC[0J and ESC[1J partial screen clear

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


The ESC[J handler always called cls() which clears the entire screen,
regardless of the parameter. Per ECMA-48, the parameter selects the
region to clear:

  - 0 (or omitted): from cursor to end of screen
  - 1: from start of screen to cursor
  - 2: entire screen

Add a clear_chars() helper that clears a partial specified region by
drawing spaces (respecting the current background color), and parse
the ESC[J parameter to dispatch to the appropriate clearing mode.

Link: https://terminalguide.namepad.de/seq/csi_cj-0/
Link: https://terminalguide.namepad.de/seq/csi_cj-1/
Link: https://terminalguide.namepad.de/seq/csi_cj-2/
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
 drivers/video/fbconsole.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index c67e3817ca13..6cca3faa9615 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -641,7 +641,20 @@ static bool fbc_parse_csi(struct fbc_priv *priv)
 		}
 		break;
 	case 'J':
-		cls(priv);
+		pos = simple_strtoul(priv->csi, &end, 10);
+		toggle_cursor_visibility(priv);
+		switch (pos) {
+		case 0: /* clear from cursor to end of screen */
+			clear_chars(priv, priv->cur.x, priv->cur.y,
+				    priv->cols - 1, priv->rows - 1);
+			break;
+		case 1: /* clear from start of screen to cursor */
+			clear_chars(priv, 0, 0, priv->cur.x, priv->cur.y);
+			break;
+		case 2: /* clear entire screen */
+			cls(priv);
+			break;
+		}
 		toggle_cursor_visibility(priv);
 		return true;
 	case 'H':
-- 
2.47.3




More information about the barebox mailing list