Pug-like Semantics

Let the text have a purpose

Just because we are "printing text" in a terminal window, it doesn't mean that it have no meaning or purpose. Using some Pug inspired syntax, we can structure the output:

..src/bin.sh
use "std/fmt"

main() {
  h1 "I'm a bold, txtPrimary colored Title"
  hr "+" "-" # Fill the screen as ----+----
  text-center "Some centered text"
  br
  h2 "Normal, txtPrimary h2 Title"
  p "Some ${em}italic${x} text."
  br
  h3 "Like h2, but italic Title"
  p "${btnSuccess} Done! ${x} Well played."
  br
  em "check lib/std/fmt.sh"
}

# Load the main fn if no arguments
[[ "$#" == 0 ]] && main; exit 0

When writing some content that will be displayed in the terminal just like a webpage would do via Lynx or w3m browser, it could be nice to have an idea of the puprose of each line.

There are so far 8 tags, 8 text colors, 8 background colors and 4 font styles, plus some functions that we can mix toger to compose our output. See the reference section about functions and variables.

Custom styles via variables

In some custom library inside the SherpaCustomDir, we can go:

# lib/bob/style.sh

link="${txtBlue}${u}${em}"

then import the styles and use them:

# someBashBox/src/bin.sh

use "bob/style"

main() {
  # The url is now blue, underlined & italic
  p "Visit ${link}https://acme.com${x}" now!
}

Basically, ${link} apply the formating, that last until the first ${x} that normalize back the output. You can also use directly txt/bg/fontStyles combinations but it's convenient to have repeating pattern loaded like "css classes".

This would work too, without importing custom styles:

# someBashBox/src/bin.sh

use "std/fmt"

main() {
  # Make it bold & red to stand out.
  p "Here, some ${strong}${txtRed}BIG BOY${x} text."
}