-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide unified functions for formatting text output
`text` plugin provides all needed for making beautiful logging. It provides several functions which produce formatted and colored output. The `box` function (a previous primary method of logging) is replaced with the new one. #167
- Loading branch information
Showing
16 changed files
with
173 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,6 @@ MESSAGE | |
} | ||
|
||
default() { | ||
boxtee git init | ||
git-verbose init | ||
git elegant acquire-repository | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/env bash | ||
|
||
# 8 ANSI colors | ||
TEXT_COLOR_BLACK=30 | ||
TEXT_COLOR_RED=31 | ||
TEXT_COLOR_GREEN=32 | ||
TEXT_COLOR_BROWN=33 | ||
TEXT_COLOR_BLUE=34 | ||
TEXT_COLOR_PURPLE=35 | ||
TEXT_COLOR_CYAN=36 | ||
TEXT_COLOR_GRAY=37 | ||
TEXT_COLOR_DEFAULT=0 | ||
|
||
# 4 ANSI text formats | ||
TEXT_FORMAT_NORMAL=0 | ||
TEXT_FORMAT_BOLD=1 | ||
TEXT_FORMAT_UNDERLINE=4 | ||
TEXT_FORMAT_BLINKING=5 | ||
|
||
--colored-text() { | ||
# usage: --colored-text <format> <color> <message>... | ||
local COLOR="" | ||
local RESET="" | ||
if [[ -t 1 ]]; then | ||
COLOR="\e[${1};${2}m" | ||
RESET="\e[m" | ||
fi | ||
shift; shift | ||
printf "${COLOR}" | ||
local prefix="" | ||
for part in "$@"; do | ||
printf "%s" "${prefix}${part}" | ||
prefix=" " | ||
done | ||
printf "${RESET}" | ||
printf "\n" | ||
} | ||
|
||
command-text() { | ||
# Display a CLI command | ||
local COLOR="" | ||
local RESET="" | ||
if [[ -t 1 ]]; then | ||
COLOR="\e[${TEXT_FORMAT_BOLD};${TEXT_COLOR_GREEN}m" | ||
RESET="\e[m" | ||
fi | ||
printf "${COLOR}==>> ${RESET}" | ||
--colored-text ${TEXT_FORMAT_BOLD} ${TEXT_COLOR_BLUE} "$@" | ||
} | ||
|
||
info-text() { | ||
# Display a regular message | ||
--colored-text ${TEXT_FORMAT_NORMAL} ${TEXT_COLOR_GREEN} "$@" | ||
} | ||
|
||
--box-text(){ | ||
local LAYOUT=${1} | ||
shift | ||
t="$@xxxxxx" | ||
c=${replace:-=} | ||
${LAYOUT} ${t//?/$c} | ||
${LAYOUT} "$c$c $@ $c$c" | ||
${LAYOUT} ${t//?/$c} | ||
} | ||
|
||
info-box() { | ||
# Display an important message | ||
--box-text info-text "$@" | ||
} | ||
|
||
error-text() { | ||
# Display an error message within a single-line log | ||
--colored-text ${TEXT_FORMAT_BOLD} ${TEXT_COLOR_RED} "$@" | ||
} | ||
|
||
error-box() { | ||
# Display an error message within a multi-line log | ||
--box-text error-text "$@" | ||
} |
Oops, something went wrong.