[PATCH 1/2] video: Allow querying the font size
Simon Glass
sjg at chromium.org
Mon Jan 8 01:14:54 CET 2024
All the font size to be queried using the 'font size' command.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
cmd/font.c | 17 +++++++++--------
doc/usage/cmd/font.rst | 6 ++++--
test/cmd/font.c | 9 +++++++++
3 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/cmd/font.c b/cmd/font.c
index cb39c88063f..c7fe2a70a49 100644
--- a/cmd/font.c
+++ b/cmd/font.c
@@ -56,9 +56,6 @@ static int do_font_size(struct cmd_tbl *cmdtp, int flag, int argc,
uint size;
int ret;
- if (argc != 2)
- return CMD_RET_USAGE;
-
if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev))
return CMD_RET_FAILURE;
ret = vidconsole_get_font_size(dev, &font_name, &size);
@@ -67,12 +64,16 @@ static int do_font_size(struct cmd_tbl *cmdtp, int flag, int argc,
return CMD_RET_FAILURE;
}
- size = dectoul(argv[1], NULL);
+ if (argc < 2) {
+ printf("%d\n", size);
+ } else {
+ size = dectoul(argv[1], NULL);
- ret = vidconsole_select_font(dev, font_name, size);
- if (ret) {
- printf("Failed (error %d)\n", ret);
- return CMD_RET_FAILURE;
+ ret = vidconsole_select_font(dev, font_name, size);
+ if (ret) {
+ printf("Failed (error %d)\n", ret);
+ return CMD_RET_FAILURE;
+ }
}
return 0;
diff --git a/doc/usage/cmd/font.rst b/doc/usage/cmd/font.rst
index 8ba149d7599..fea0df3f745 100644
--- a/doc/usage/cmd/font.rst
+++ b/doc/usage/cmd/font.rst
@@ -10,7 +10,7 @@ Synopis
font list
font select <name> [<size>]
- font size <size>
+ font size [<size>]
Description
-----------
@@ -31,7 +31,7 @@ This selects a new font and optionally changes the size.
font size
~~~~~~~~~
-This changes the font size only.
+This changes the font size only. With no argument it shows the current size.
Examples
--------
@@ -41,6 +41,8 @@ Examples
=> font list
nimbus_sans_l_regular
cantoraone_regular
+ => font size
+ 30
=> font size 40
=> font select cantoraone_regular 20
=>
diff --git a/test/cmd/font.c b/test/cmd/font.c
index 1fe05c1ead5..9c1eebf799e 100644
--- a/test/cmd/font.c
+++ b/test/cmd/font.c
@@ -60,10 +60,19 @@ static int font_test_base(struct unit_test_state *uts)
ut_assertok(vidconsole_get_font_size(dev, &name, &size));
ut_asserteq_str("cantoraone_regular", name);
ut_asserteq(40, size);
+ ut_assertok(ut_check_console_end(uts));
+
+ ut_assertok(run_command("font size", 0));
+ ut_assert_nextline("40");
+ ut_assertok(ut_check_console_end(uts));
ut_assertok(run_command("font size 30", 0));
ut_assertok(ut_check_console_end(uts));
+ ut_assertok(run_command("font size", 0));
+ ut_assert_nextline("30");
+ ut_assertok(ut_check_console_end(uts));
+
ut_assertok(vidconsole_get_font_size(dev, &name, &size));
ut_asserteq_str("cantoraone_regular", name);
ut_asserteq(30, size);
--
2.34.1
More information about the U-Boot
mailing list