shell dot on steroids https://pagure.io/shellfu

_pretty_color.sh 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/bash
  2. shellfu import termcolors
  3. _PRETTY_COLOR_DEBUG=""
  4. _PRETTY_COLOR_DIE=""
  5. _PRETTY_COLOR_USAGE_IS=""
  6. _PRETTY_COLOR_THINK=""
  7. _PRETTY_COLOR_WARN=""
  8. _PRETTY_COLOR_OFF=""
  9. __shellfu__pretty_color__init() {
  10. test -t 2 || return 0 # stderr is a pipe/file; refrain from colors
  11. _PRETTY_COLOR_DEBUG="${TERMCOLORS_LBLUE}"
  12. _PRETTY_COLOR_DIE="${TERMCOLORS_LRED}"
  13. _PRETTY_COLOR_USAGE_IS="${TERMCOLORS_YELLOW}"
  14. _PRETTY_COLOR_THINK="${TERMCOLORS_LBLACK}"
  15. _PRETTY_COLOR_WARN="${TERMCOLORS_LRED}"
  16. _PRETTY_COLOR_OFF="${TERMCOLORS_NONE}"
  17. }
  18. _pretty__debug() {
  19. local decor="()"
  20. local caller_is_main=${caller_is_main:-false}
  21. local caller=${caller:-UNKNOWN}
  22. $caller_is_main && decor=
  23. while IFS= read -r line;
  24. do echo -ne "${_PRETTY_COLOR_DEBUG}debug:$caller$decor:$_PRETTY_COLOR_OFF"
  25. echo "$line"; done
  26. }
  27. _pretty__die() {
  28. echo -ne "$_PRETTY_COLOR_DIE"
  29. while IFS= read -r line;
  30. do echo "$line"; done
  31. echo -ne "$_PRETTY_COLOR_OFF"
  32. }
  33. _pretty__mkhelp() {
  34. echo -ne "$_PRETTY_COLOR_USAGE_IS"
  35. while IFS= read -r line;
  36. do echo -e "$line"; done
  37. echo -ne "$_PRETTY_COLOR_OFF"
  38. }
  39. _pretty__mkusage() {
  40. echo -ne "$_PRETTY_COLOR_USAGE_IS"
  41. while IFS= read -r line;
  42. do echo -e "$line"; done
  43. echo -ne "$_PRETTY_COLOR_OFF"
  44. }
  45. _pretty__think() {
  46. echo -ne "$_PRETTY_COLOR_THINK"
  47. while IFS= read -r line;
  48. do echo "$line"; done
  49. echo -ne "$_PRETTY_COLOR_OFF"
  50. }
  51. _pretty__warn() {
  52. echo -ne "$_PRETTY_COLOR_WARN"
  53. while IFS= read -r line;
  54. do echo "$line"; done
  55. echo -ne "$_PRETTY_COLOR_OFF"
  56. }