DietPi icon indicating copy to clipboard operation
DietPi copied to clipboard

DietPi-Banner | Add color to large hostname

Open matellis opened this issue 3 years ago • 6 comments

Simple addition of lolcat to make large prompts colorful. I had a dilemma here:

  • lolcat is found in the ubuntu repo but relies on ruby and is very slow
  • A fork of lolcat, re-written in C and has a snap package available but is bigger (50k) than lolcat-cc
  • lolcat-cc is very quick and the smallest standalone binary (30k) but not found in any repo

I went with the smallest, fastest package, which was lolcat-cc

This is a frivolous upgrade, which just looks really nice in a modern terminal. I understand if there's no appetite for bloating DietPi by 30k for eye candy reasons.

image

matellis avatar Feb 18 '23 01:02 matellis

Many thanks for your PR.

bloating DietPi by 30k for eye candy reasons

Yeah, to be honest, that was my first thought, especially with a pre-compiled binary where we cannot know for sure what is inside (unless we can reproduce the build exactly).

But more importantly: this binary will only work with the exact platform you compiled it on, at least only on that exact architecture and a range of glibc versions. So we'd need a minimum of 4 (soon 5 => RISC-V) binaries, probably 12 (15) if we need/want dedicated ones for each supported Debian version (using latest glibc on each).

A possible approach would be to add lolcat-cc as dietpi-software option, or at least to our CI builds and host packages for all architectures and Debian versions on our server and installed on demand. It can then be used more flexible with just lolcat-cc from console, and if present, could be invoked by dietpi-banner as well for the large hostname and possible other parts in DietPi.

in a modern terminal

This is btw another reason why it should be optional in any case: Simple boot consoles usually support only a very minimal 8 color set, so there it won't work well or look ugly, as long as the tool isn't smart to use a different color set depending on terminal capabilities. Can be tested of course.

MichaIng avatar Feb 18 '23 01:02 MichaIng

Can you point me at a way to do the optional software builds? That's what I intended to do first but couldn't grok it just by looking at the repo.

I like the colors because they make it much clearer which host I'm logging into, so it's not just eye candy (really!).

If I can make it a software option, then how should that work? When you install lolcat-cc it automatically colors the banner, or selecting colorful banner automatically installs the package?

matellis avatar Feb 18 '23 22:02 matellis

You can have a look into how we do for Gogs:

  1. Actual build script: https://github.com/MichaIng/DietPi/blob/dev/.build/software/gogs/build.bash
    • Ah, we do not packaging there, to align with upstream archives which we use in all cases but ARMv6. However, packaging is trivial for a single binary, see how we do here: https://github.com/MichaIng/DietPi/blob/dev/.build/software/raspberrypi-sys-mods/build.bash
  2. A script which sets up and starts a build container, where the first script is called within: https://github.com/MichaIng/DietPi/blob/dev/.build/software/gogs/container_build.bash 3 A GitHub Actions workflow which calls the build container script and uploads the final packages to our server: https://github.com/MichaIng/DietPi/blob/dev/.github/workflows/gogs.yml

If I can make it a software option, then how should that work? When you install lolcat-cc it automatically colors the banner, or selecting colorful banner automatically installs the package?

At least it should be possible to select it for install directly from the dietpi-banner menu, otherwise no one will see it. And since dietpi-banner is currently a checkbox menu, I'd not implement this different, so it is possible enable/disable it. When enabled, the script could still check for the lolcat-cc executable to be available for calling it, just to not throw errors if it was uninstalled manually while the banner option not de-selected.

MichaIng avatar Feb 19 '23 22:02 MichaIng

Just thinking out aloud here.

Could probably code this in bash, although, could be a massive performance hit?

  • Assign each letter to pre-defined array using a eg: 6x6 grid (Really bad h)
aLetter[0]='
|    
|    
  -
|    |
|    |'
  • Then do a sed replace for colours based on length of Input_String='HostName'. Would probably need a 2D array on aLetter[iLetter][iLine].

Fourdee avatar Apr 09 '23 14:04 Fourdee

Here is the script we use for the large letters: https://github.com/MichaIng/DietPi/blob/master/dietpi/func/dietpi-print_large

In theory every letter could made an associative array with x,y index. Then based on additional overall X (including all letters) and y, each sub-character could be prepended with a colour code. A little nasty is that all letters have different widths, so another associative array is needed to hold that info for each letter, or alternatively checking for every sub-character declaration before prepending the colour code + printing it.

External command calls are "expensive" as well, so probably it would be still faster. Just wondering how much if would affect the non-colour variant and how to nicely detect which colour codes are actually supported by a particular terminal or whether to simply always use the \e[rr,gg,bbm codes (which does not work well on all terminals/SSH etc.

MichaIng avatar Apr 10 '23 07:04 MichaIng

Here is the script we use for the large letters: https://github.com/MichaIng/DietPi/blob/master/dietpi/func/dietpi-print_large

@MichaIng

Lol, sorry, I had no idea this existed. Very nice!

Fourdee avatar Apr 10 '23 12:04 Fourdee