console.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # -*- mode: sh; tab-width: 4; coding: utf-8 -*-
  2. # vim: ts=4 noet ai ft=sh
  3. # Console logging helper functions
  4. # This file is part of JPM.sh.
  5. # Copyright (C) 2016 the Desktopd developers
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. # TODO: Colors not good
  20. TERM_OKBLUE='\033[2;94m' #'\033[94m'
  21. TERM_OKGREEN='\033[2;3;32m'
  22. TERM_WARNING='\033[2;7;93m' #'\033[4;33m'
  23. TERM_FAIL='\033[101;97m' #'\033[4;91m'
  24. TERM_UNIMPORTANT='\033[95m'
  25. TERM_IMPORTANT='\033[1;35m'
  26. TERM_BOLD='\033[1m'
  27. TERM_BOLDLINE='\033[1;4m'
  28. TERM_ENDC='\033[0m'
  29. # @deprecated
  30. progressFilter () {
  31. [ -t 2 ] && tr '\n' '\r' >&2 || cat >&2
  32. }
  33. jpmConsoleLog () {
  34. [ "$JPM_SILENT" ] && return
  35. [ -t 2 ] && [ -z "$ZOMBIE_NOCOLOR" ] && {
  36. printf "${TERM_UNIMPORTANT}[%s]${TERM_ENDC} ${TERM_OKBLUE}%s${TERM_ENDC}\n" "`date`" "$@" >&2
  37. :;} || {
  38. echo "[`date`] $@" >&2
  39. }
  40. }
  41. jpmConsoleNotice () {
  42. [ -t 2 ] && [ -z "$JPMSH_NOCOLOR" ] && {
  43. printf "${TERM_UNIMPORTANT}[%s]${TERM_ENDC} ${TERM_BOLD}Notice:${TERM_ENDC} ${TERM_OKGREEN}%s${TERM_ENDC}\n" "`date`" "$@" >&2
  44. :;} || {
  45. echo "[`date`] Notice: $@" >&2
  46. }
  47. }
  48. jpmConsoleWarn () {
  49. [ -t 2 ] && [ -z "$JPMSH_NOCOLOR" ] && {
  50. printf "${TERM_IMPORTANT}[%s]${TERM_ENDC} ${TERM_WARNING} Warning: ${TERM_ENDC} ${TERM_BOLD}%s${TERM_ENDC}\n" "`date`" "$@" >&2
  51. :;} || {
  52. echo "[`date`] Warning: $@" >&2
  53. }
  54. }
  55. jpmConsoleError () {
  56. [ -t 2 ] && [ -z "$JPMSH_NOCOLOR" ] && {
  57. printf "${TERM_IMPORTANT}[%s]${TERM_ENDC} ${TERM_FAIL} Error: ${TERM_ENDC} ${TERM_BOLDLINE}%s${TERM_ENDC}\n" "`date`" "$@" >&2
  58. :;} || {
  59. echo "[`date`] Error: $@" >&2
  60. }
  61. }