Skip to content

Conversation

@rawiriblundell
Copy link

Hi there,
I've thrown together this screensaver based loosely off the existing stars screensaver.

A few comments: We reduce a couple of potentially unnecessary external calls by using built-in vars, with external-call-fallbacks like so:

# Get terminal dimensions
width="${COLUMNS:-$(tput cols)}"
height="${LINES:-$(tput lines)}"

This gets the state that the script was launched within, but does not work reliably with SIGWINCH. SIGWINCH should be rare anyway, we just eat the cost of a couple of tput calls.

(Noting that tput itself isn't 100% portable, but that only matters if you're running something like OpenBSD.)

We also lean on SRANDOM when it's available (bash 5.1+) and fall back to RANDOM when it's not. I doubt there's any practical or appreciable difference, but logically we're pulling from the system entropy pool rather than bash's croaky old LCG RNG, so that should scale better. Hypothetically. Maybe.

I initially had several selectable colour sets, but the addition of shading blocks enabled that to be compacted down. Now it has two sets: greyscale or greyscale with some red, green, blue and yellow codes thrown in.

I use a slightly debiased modulo approach to provide a fair random selection between the two colour sets. Here I just use RANDOM because SRANDOM is a sledgehammer for a one-off coin-toss.

Tested on bash 4 and 5 on Linux. I don't have a Mac available to me, but I don't see anything that would upset bash 3.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants