#!/bin/sh -e
#
# std - some nice shell functions to make life just a little bit easier
#
# usage: log <text>
#        log <module> <text>
#        log <module> <text> <prefix>
#
# ---
# see: https://github.com/kisslinux/kiss
# source: https://github.com/kiedtl/bin

log() (
  if tty -s; then
    lcol='\033[1;33m'
    lcol2='\033[1;36m'
    lclr='\033[m'

    printf "%b%s %b%s%b %s\n" \
      "${lcol}" "${3:-->}" "${lclr}${2:+${lcol2}}" \
      "$1" "${lclr}" "$2" >&2
  else
    printf "%s: %s%s%s %s\n" "${3:-$0}" \
      "${2:+[}" "$1" "${2:+]}" "$2"
  fi
)

# usage: die [text]
#        die [<module> <text>]
die() {
  log "$1" "$2" "ERROR"
  exit 1
}

# usage: pause [text]
#        pause [<module> <text>]
pause() {
  [ -z "$1" ] || log "$1" "$2"
  log "Press Enter to continue or Ctrl+C to abort here"
  read -r _
}
