Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DietPi-Banner | Add color to large hostname #6173

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

matellis
Copy link
Contributor

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

@MichaIng MichaIng added the Visual 🌹 Issues affecting only the beauty of menus and output, but not the functionality label Feb 18, 2023
@MichaIng
Copy link
Owner

MichaIng commented Feb 18, 2023

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 MichaIng changed the title Add color to large banner DietPi-Banner | Add color to large hostname Feb 18, 2023
@matellis
Copy link
Contributor Author

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?

@MichaIng
Copy link
Owner

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
  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.

@Fourdee
Copy link
Collaborator

Fourdee commented Apr 9, 2023

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].

@MichaIng
Copy link
Owner

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.

@Fourdee
Copy link
Collaborator

Fourdee commented Apr 10, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Visual 🌹 Issues affecting only the beauty of menus and output, but not the functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants