mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 4/9] lib: term: factor out single cdev handling from term_getsize
Date: Fri,  1 May 2026 08:53:58 +0200	[thread overview]
Message-ID: <20260501070625.952091-5-a.fatoum@barebox.org> (raw)
In-Reply-To: <20260501070625.952091-1-a.fatoum@barebox.org>

The logic is easier to follow with the per-cdev code split off.

No functional change intended.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 include/term.h |  5 +++++
 lib/term.c     | 42 +++++++++++++++++++++++++++---------------
 2 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/include/term.h b/include/term.h
index e53fcffcfc28..4845aad6ec66 100644
--- a/include/term.h
+++ b/include/term.h
@@ -2,7 +2,12 @@
 #ifndef __TERM_H
 #define __TERM_H
 
+struct console_device;
+
 void term_setpos(int x, int y);
 int term_getsize(int *screenwidth, int *screenheight);
 
+int term_cdev_get_size(struct console_device *cdev,
+		       int *screenwidth, int *screenheight);
+
 #endif /* __LIBBB_H */
diff --git a/lib/term.c b/lib/term.c
index 96fdb0737d31..3949aeb45136 100644
--- a/lib/term.c
+++ b/lib/term.c
@@ -72,29 +72,41 @@ static int term_cdev_read_reply(struct console_device *cdev,
 	return 0;
 }
 
+int term_cdev_get_size(struct console_device *cdev,
+		       int *screenwidth, int *screenheight)
+{
+	const char esc[] = "\e7" "\e[r" "\e[999;999H" "\e[6n";
+	int ret, params[2];
+
+	if (!(cdev->f_active & CONSOLE_STDIN))
+		return -ENOENT;
+	if (!(cdev->f_active & CONSOLE_STDOUT))
+		return -ENOENT;
+
+	term_cdev_drain(cdev);
+
+	console_puts(cdev, esc);
+
+	ret = term_cdev_read_reply(cdev, params, 2, 'R');
+	if (ret)
+		return ret;
+
+	*screenheight = params[0];
+	*screenwidth = params[1];
+
+	return 0;
+}
+
 int term_getsize(int *screenwidth, int *screenheight)
 {
 	int width = INT_MAX, height = INT_MAX;
 	bool found = false;
-	const char esc[] = "\e7" "\e[r" "\e[999;999H" "\e[6n";
 
 	for_each_console(cdev) {
-		int w, h, params[2];
+		int w, h;
 
-		if (!(cdev->f_active & CONSOLE_STDIN))
+		if (term_cdev_get_size(cdev, &w, &h))
 			continue;
-		if (!(cdev->f_active & CONSOLE_STDOUT))
-			continue;
-
-		term_cdev_drain(cdev);
-
-		console_puts(cdev, esc);
-
-		if (term_cdev_read_reply(cdev, params, 2, 'R'))
-			continue;
-
-		h = params[0];
-		w = params[1];
 
 		width = min(w, width);
 		height = min(h, height);
-- 
2.47.3




  parent reply	other threads:[~2026-05-01  7:07 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-01  6:53 [PATCH 0/9] lib: term: fix fbconsole cursor desynchronization Ahmad Fatoum
2026-05-01  6:53 ` [PATCH 1/9] lib: term: avoid printing NUL with new new console_puts API Ahmad Fatoum
2026-05-01  6:53 ` [PATCH 2/9] lib: term: return error code from term_getsize() Ahmad Fatoum
2026-05-01  6:53 ` [PATCH 3/9] lib: term: add per-console terminal response parser Ahmad Fatoum
2026-05-01  6:53 ` Ahmad Fatoum [this message]
2026-05-01  6:53 ` [PATCH 5/9] lib: term: fix term_getsize cursor restore Ahmad Fatoum
2026-05-01  6:54 ` [PATCH 6/9] console: add get_size callback for direct size reporting Ahmad Fatoum
2026-05-01  6:54 ` [PATCH 7/9] video: fbconsole: implement get_size Ahmad Fatoum
2026-05-01  6:54 ` [PATCH 8/9] console: add per-console terminal.size parameter Ahmad Fatoum
2026-05-01  7:19 ` [PATCH 9/9] efi: reimplement query_console_serial using term_getsize Ahmad Fatoum
2026-05-07 10:38 ` [PATCH 0/9] lib: term: fix fbconsole cursor desynchronization Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260501070625.952091-5-a.fatoum@barebox.org \
    --to=a.fatoum@barebox.org \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox