[PATCH 6/9] console: add get_size callback for direct size reporting
Ahmad Fatoum
a.fatoum at barebox.org
Thu Apr 30 23:54:00 PDT 2026
Add an optional get_size callback to struct console_device that allows
consoles to report their dimensions directly without requiring escape
sequence queries.
Update term_getsize() to try get_size first for consoles that implement
it. These consoles only need CONSOLE_STDOUT to participate in size
detection. Consoles without get_size still require both CONSOLE_STDIN
and CONSOLE_STDOUT for the escape sequence query path.
This enables output-only consoles like fbconsole to report their size
to commands like edit and watch.
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
include/console.h | 1 +
lib/term.c | 8 ++++++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/include/console.h b/include/console.h
index 1dfaa66d9266..f2b8da1546ef 100644
--- a/include/console.h
+++ b/include/console.h
@@ -43,6 +43,7 @@ struct console_device {
int (*set_mode)(struct console_device *cdev, enum console_mode mode);
int (*open)(struct console_device *cdev);
int (*close)(struct console_device *cdev);
+ int (*get_size)(struct console_device *cdev, int *width, int *height);
const char *devname;
int devid;
diff --git a/lib/term.c b/lib/term.c
index 0a656d79e725..382250c70ddf 100644
--- a/lib/term.c
+++ b/lib/term.c
@@ -79,11 +79,15 @@ int term_cdev_get_size(struct console_device *cdev,
const char restore[] = "\e8";
int ret, params[2];
- if (!(cdev->f_active & CONSOLE_STDIN))
- return -ENOENT;
if (!(cdev->f_active & CONSOLE_STDOUT))
return -ENOENT;
+ if (cdev->get_size)
+ return cdev->get_size(cdev, screenwidth, screenheight);
+
+ if (!(cdev->f_active & CONSOLE_STDIN))
+ return -ENOENT;
+
term_cdev_drain(cdev);
console_puts(cdev, esc);
--
2.47.3
More information about the barebox
mailing list