This can still be pretty ragged because it just leaves space for the longest name at the end of each line rather than measuring the name that actually comes next, but at least with this change we never over-run.
I noticed this because ConnectBot on my current device gives me a 60-column terminal. busybox seems to do this, though it seems to actually measure, judging by how close it gets to the margin. That doesn't seem worth the effort though? --- main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
From 50e1d011a8d198b421d3ce971cd66d5528343958 Mon Sep 17 00:00:00 2001 From: Elliott Hughes <e...@google.com> Date: Thu, 13 Aug 2020 09:19:11 -0700 Subject: [PATCH] toybox: fit list of commands in terminal width. This can still be pretty ragged because it just leaves space for the longest name at the end of each line rather than measuring the name that actually comes next, but at least with this change we never over-run. I noticed this because ConnectBot on my current device gives me a 60-column terminal. busybox seems to do this, though it seems to actually measure, judging by how close it gets to the margin. That doesn't seem worth the effort though? --- main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index ffa735e3..ced2a65b 100644 --- a/main.c +++ b/main.c @@ -178,6 +178,7 @@ void toybox_main(void) { char *toy_paths[] = {"usr/", "bin/", "sbin/", 0}, *s = toys.argv[1]; int i, len = 0; + unsigned width = 80; // fast path: try to exec immediately. // (Leave toys.which null to disable suid return logic.) @@ -195,7 +196,8 @@ void toybox_main(void) if (toys.argv[1] && strcmp(toys.argv[1], "--long")) unknown(toys.argv[1]); - // Output list of command. + // Output list of commands. + terminal_size(&width, 0); for (i = 1; i<ARRAY_LEN(toy_list); i++) { int fl = toy_list[i].flags; if (fl & TOYMASK_LOCATION) { @@ -205,7 +207,7 @@ void toybox_main(void) if (fl & (1<<j)) len += printf("%s", toy_paths[j]); } len += printf("%s",toy_list[i].name); - if (++len > 65) len = 0; + if (++len > width-15) len = 0; xputc(len ? ' ' : '\n'); } } -- 2.28.0.220.ged08abb693-goog
_______________________________________________ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net