[Toybox] [PATCH] more.c: More stuff, down cursor key scrolls down. Also stuff about less

Oliver Webb aquahobbyist at proton.me
Tue Mar 19 22:02:11 PDT 2024


I spotted the more implementation in pending. Looking at it, it's missing quite a lot of stuff, 
Such as the ability to go back in a file. It's built in a way where nothing is accumulated, Which 
means that support for that would require a half-rewrite.

What does POSIX specify as far as options? Looking at the man page, quite a bit. None of which I've
ever seen used before.

Looking at the other keybindings GNU more provides which I can implement, There's "=" (prints current
line number) ":f" (print filename and line), as well as being able to use the down arrow to go down 
(with the added side effect of any escape key doing so too, not the end of the world, especially
since we can't scroll up) That are Implemented them in the attached patch.

There is also a testing problem. vi.c doesn't do TEST_HOST because it needs a -s option
to pass in scripts to test with. less and more are _worse_ since they don't change anything.
Manually testing often introduces regressions, so I dunno what the solution is here

This patch improves things for now, but if we are planning on doing a future less implementation. 
We could probably merge more into that and make them share a common base either as 2 functions in
the same file, or just make more a OLDTOY pointing to less like how [ points to [[.

(The rest of this email is about less, not more)

Seeing if this is possible, what does GNU less implement:

$ man less
[...]
       less [-[+]aABcCdeEfFgGiIJKLmMnNqQrRsSuUVwWX~]
            [-b space] [-h lines] [-j line] [-k keyfile]
            [-{oO} logfile] [-p pattern] [-P prompt] [-t tag]
            [-T tagsfile] [-x tab,...] [-y lines] [-[z] lines]
            [-# shift] [+[+]cmd] [--] [filename]...

Oh. Busybox has a less implementation, what does it implement:

        -E      Quit once the end of a file is reached
        -F      Quit if entire file fits on first screen
        -I      Ignore case in all searches
        -M,-m   Display status line with line numbers and percentage through the file
        -N      Prefix line number to each line
        -S      Truncate long lines
        -R      Remove color escape codes in input
        -~      Suppress ~s displayed past EOF

That's more reasonable. Although I've used less -R before and that is the exact opposite of
what it is for. Plus no keybinding list and "h" isn't showing them... Which means I'd
have to look at and study the GPLv2 source code, whee! Using this "when in doubt; look at what busybox does"
approach to more gives me what looks like the exact same implementation that is in toybox, internal help text and all.

less seems moderately easy (Read lines into list, show lines, scroll down and read more lines,
scroll up and go back in list.) Especially since we already have vi.c which does almost all the stuff
less does at it's core, there's a lot of potential code-sharing (To which file though, lib/tty.c?).
But I have to ask the question "If it's so easy, why isn't it in toybox yet?" Is it just because
other TODO items taking up time, or is it because it's harder to implement than it seems.

-   Oliver Webb <aquahobbyist at proton.me>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-more.c-More-stuff-f-n-down-arrow-goes-down.patch
Type: text/x-patch
Size: 2931 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20240320/24196b20/attachment.bin>


More information about the Toybox mailing list