bat: Failure to use less from BusyBox

Describe the bug you encountered: Step to reproduce:

  1. scoop install busybox, bat
  2. bat .\yourfile.

Here is the result in my machine:

image

What did you expect to happen instead?

No error

How did you install bat?

scoop install bat


bat version and environment

version: bat 0.20.0 (0655ecf) OS: Window 11 lastest

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (6 by maintainers)

Most upvoted comments

I’d like to take this one on since nobody else has claimed it.

Nice investigation πŸ˜ƒ your approach sounds reasonable to me!

I personally would say not to bother checking older versions of busybox. And if a new version will be released which improves less, we can update bat to look at busybox versions then.

I’d vote for letting the grid lines stay as they are, but that’s just my personal opinion.

So looking at busybox less as it gets built with the default config, there’s no color support, but it can handle bat’s other formatting decorations (in somewhat reduced capacity). Example:

───────┬──────────────────────────────────────────────────────────────────────��
�─
       β”‚ File: applets/applets.c
       β”‚ Size: 350 B
───────┼──────────────────────────────────────────────────────────────────────��
�─
   1   β”‚ /* vi: set sw=4 ts=4: */
   2   β”‚ /*
   3   β”‚  * Stub for linking busybox binary against libbusybox.
   4   β”‚  *
   5   β”‚  * Copyright (C) 2007 Denys Vlasenko <vda.linux@googlemail.com>
   6   β”‚  *
   7   β”‚  * Licensed under GPLv2, see file LICENSE in this source tree.
   8   β”‚  */
   9   β”‚ #include "busybox.h"
  10   β”‚ 

So in less.rs the parse_less_version returns an Option<usize> due to less’s unconventional versioning, but busybox is on semantic versioning, so that return type gets messy if we try to account for busybox. It seems like we’re only doing that from output.rs (based on a quick grep -R in the source tree), so here’s my initial thinking.

  • Return an enum instead, something like:
pub enum LessVersion {
    less(usize),
    busybox,
    unknown,
  • Only turn off colored output for busybox less, but leave the other decorations. They’re kind of ugly, but usable, and there might well be environments where busybox less is the only pager - say Alpine probably.

If that sounds reasonable I can get something put together pretty quickly. I see a couple of tests that might affect, too, so I can take a look at those at the same time.

Questions

  • Should I check older versions of busybox for compatability?
  • If so, how far back?
  • The horizontal grid lines are ugly with busybox less. How much do we care? Enough to change how they’re drawn or possibly disable them? Or just let it go.

@nfisher1226 sounds great, thanks. Please let us know if you need any pointers πŸ˜ƒ

Actually, we already do quite extensive version checks on less when bat starts. Perhaps we could try to catch this case too and stop passing invalid args. I suggest we re-open this. Might also be suitable for a new contributor to take a look at. I’ll change the title since this does not appear to be a Windows-specific bug.

Try with --paging=never or setting BAT_PAGER to override the command line args passed to less - it looks likely that busybox includes some dodgy version of less