125 lines
3.1 KiB
Bash
125 lines
3.1 KiB
Bash
|
#!/bin/bash
|
|||
|
# https://gist.github.com/anthonyaxenov/b17c6fbd7895c6049e1ceddc7c54bb5b
|
|||
|
# source: https://misc.flogisoft.com/bash/tip_colors_and_formatting
|
|||
|
|
|||
|
########################################################
|
|||
|
# Иконки
|
|||
|
########################################################
|
|||
|
|
|||
|
IINFO="[ i ]"
|
|||
|
INOTE="[ * ]"
|
|||
|
IWARN="[ # ]"
|
|||
|
IERROR="[ ! ]"
|
|||
|
IFATAL="[ @ ]"
|
|||
|
ISUCCESS="[ ! ]"
|
|||
|
IASK="[ ? ]"
|
|||
|
|
|||
|
########################################################
|
|||
|
# Атрибуты текста (форматирование)
|
|||
|
########################################################
|
|||
|
|
|||
|
BOLD="\e[1m" # жирный
|
|||
|
DIM="\e[2m" # приглушённый
|
|||
|
# UNDERL="\e[4m" # подчёркнутый
|
|||
|
# BLINK="\e[5m" # мигающий
|
|||
|
# INV="\e[7m" # инвертированный
|
|||
|
# HIDDEN="\e[8m" # скрытый
|
|||
|
|
|||
|
_BOLD="\e[21m" # нежирный
|
|||
|
_DIM="\e[22m" # неприглушённый
|
|||
|
# _BLINK="\e[25m" # немигающий
|
|||
|
# _UNDERL="\e[24m" # неподчёркнутый
|
|||
|
# _INV="\e[27m" # неинвертированный
|
|||
|
# _HIDDEN="\e[28m" # нескрытый
|
|||
|
|
|||
|
NORMAL="\e[20m" # сброс всех атрибутов
|
|||
|
RESET="\e[0m" # сброс всех атрибутов и цветов (вообще)
|
|||
|
|
|||
|
########################################################
|
|||
|
# Цвет текста
|
|||
|
########################################################
|
|||
|
|
|||
|
FRESET="\e[39m" # сброс цвета
|
|||
|
FBLACK="\e[30m"
|
|||
|
FWHITE="\e[97m"
|
|||
|
FRED="\e[31m"
|
|||
|
FGREEN="\e[32m"
|
|||
|
FYELLOW="\e[33m"
|
|||
|
FBLUE="\e[34m"
|
|||
|
FLRED="\e[91m"
|
|||
|
FLGREEN="\e[92m"
|
|||
|
FLYELLOW="\e[93m"
|
|||
|
FLBLUE="\e[94m"
|
|||
|
|
|||
|
########################################################
|
|||
|
# Цвет фона текста
|
|||
|
########################################################
|
|||
|
|
|||
|
BRESET="\e[49m" # сброс цвета
|
|||
|
BBLACK="\e[40m"
|
|||
|
BWHITE="\e[107m"
|
|||
|
BRED="\e[41m"
|
|||
|
BGREEN="\e[42m"
|
|||
|
BYELLOW="\e[43m"
|
|||
|
BBLUE="\e[44m"
|
|||
|
BLRED="\e[101m"
|
|||
|
BLGREEN="\e[102m"
|
|||
|
BLYELLOW="\e[103m"
|
|||
|
BLBLUE="\e[104m"
|
|||
|
|
|||
|
########################################################
|
|||
|
# Функции для вывода текста
|
|||
|
########################################################
|
|||
|
|
|||
|
print() {
|
|||
|
echo -e "$*${RESET}"
|
|||
|
}
|
|||
|
|
|||
|
ask() {
|
|||
|
IFS= read -rp "$(dt)$(print ${BOLD}${BBLUE}${FWHITE}${IASK}${BRESET}\ ${BOLD}$1 ): " $2
|
|||
|
}
|
|||
|
|
|||
|
dbg() {
|
|||
|
print "${DIM}$*"
|
|||
|
}
|
|||
|
|
|||
|
info() {
|
|||
|
print "$(dt)${BOLD}${FWHITE}${IINFO}${RESET}${FWHITE} $1 "
|
|||
|
}
|
|||
|
|
|||
|
note() {
|
|||
|
print "$(dt)${BOLD}${DIM}${FWHITE}${INOTE}${RESET} $1 "
|
|||
|
}
|
|||
|
|
|||
|
success() {
|
|||
|
print "$(dt)${BOLD}${BGREEN}${FWHITE}${ISUCCESS}${BRESET}$FGREEN $1 "
|
|||
|
}
|
|||
|
|
|||
|
warn() {
|
|||
|
print "$(dt)${BOLD}${BYELLOW}${FBLACK}${IWARN}${BRESET}${FYELLOW} Warning:${RESET} $1 " >&2
|
|||
|
}
|
|||
|
|
|||
|
error() {
|
|||
|
print "$(dt)${BOLD}${BLRED}${FWHITE}${IERROR} Error: ${BRESET}${FLRED} $1 " >&2
|
|||
|
}
|
|||
|
|
|||
|
fatal() {
|
|||
|
print "$(dt)${BOLD}${BRED}${FWHITE}${IFATAL} FATAL: $1 " >&2
|
|||
|
}
|
|||
|
|
|||
|
########################################################
|
|||
|
# Тестирование
|
|||
|
########################################################
|
|||
|
|
|||
|
# print
|
|||
|
# print "print test"
|
|||
|
# print
|
|||
|
# ask "ask test" test
|
|||
|
# dbg "debug test: answer is $test"
|
|||
|
# info "info test"
|
|||
|
# note "note test"
|
|||
|
# success "success test"
|
|||
|
# warn "warn test"
|
|||
|
# error "error test"
|
|||
|
# fatal "fatal test"
|