Extract zc-logo into autoloaded function

This commit is contained in:
Sebastian Gniazdowski 2016-09-13 22:11:50 +02:00
parent 4a17b6d4bc
commit 3b46453d48
2 changed files with 37 additions and 37 deletions

36
zc-logo Normal file
View file

@ -0,0 +1,36 @@
# Prints a graphical "logo" with ID and NAME
setopt localoptions extendedglob
integer halfl=$(( LINES / 2 )) halfc=$(( COLUMNS / 2 ))
integer hlen tlen
local text headerline=" Zconvey" headerline2=""
__zconvey_get_name_of_id "$ZCONVEY_ID"
if [ -z "$REPLY" ]; then
text="ID: <$ZCONVEY_ID> NAME: (no name assigned)"
else
text="ID: <$ZCONVEY_ID> NAME: $REPLY"
fi
tlen="${#text}"
hlen=tlen+4
headerline="${(r:hlen:: :)headerline}"
headerline="${headerline/Zconvey/\033[1;34mZconvey\033[0m\033[1;44m}"
headerline2="${(r:hlen:: :)headerline2}"
text="${text/(#b)(<[[:digit:]]#>)/\033[1;32m${match[1]}\033[1;33m}"
text="${text/(#b)NAME: (?#)/NAME: \033[1;32m${match[1]}\033[0m}"
[ "$1" != "echo" ] && {
echotc sc
echotc cm $(( halfl - 3 )) $(( halfc - hlen/2 ))
print -n "\033[1;44m$headerline\033[0m"
echotc cm $(( halfl - 2 )) $(( halfc - hlen/2 ))
print -n "\033[1;44m \033[0m \033[1;33m$text\033[0m \033[1;44m \033[0m"
echotc cm $(( halfl - 1 )) $(( halfc - hlen/2 ))
print -n "\033[1;44m$headerline2\033[0m"
echotc rc
} || {
print "\033[1;44m$headerline\033[0m\n\033[1;44m \033[0m \033[1;33m$text\033[0m \033[1;44m \033[0m\n\033[1;44m$headerline2\033[0m"
}
# vim:ft=zsh

View file

@ -22,7 +22,7 @@ fi
#
# Autoloads
#
autoload zc zc-rename zc-take zc-ls
autoload zc zc-rename zc-take zc-ls zc-logo
#
# Global variables
@ -124,42 +124,6 @@ function zc-id() {
fi
}
# Prints a graphical "logo" with ID and NAME
function zc-logo() {
setopt localoptions extendedglob
integer halfl=$(( LINES / 2 )) halfc=$(( COLUMNS / 2 ))
integer hlen tlen
local text headerline=" Zconvey" headerline2=""
__zconvey_get_name_of_id "$ZCONVEY_ID"
if [ -z "$REPLY" ]; then
text="ID: <$ZCONVEY_ID> NAME: (no name assigned)"
else
text="ID: <$ZCONVEY_ID> NAME: $REPLY"
fi
tlen="${#text}"
hlen=tlen+4
headerline="${(r:hlen:: :)headerline}"
headerline="${headerline/Zconvey/\033[1;34mZconvey\033[0m\033[1;44m}"
headerline2="${(r:hlen:: :)headerline2}"
text="${text/(#b)(<[[:digit:]]#>)/\033[1;32m${match[1]}\033[1;33m}"
text="${text/(#b)NAME: (?#)/NAME: \033[1;32m${match[1]}\033[0m}"
[ "$1" != "echo" ] && {
echotc sc
echotc cm $(( halfl - 3 )) $(( halfc - hlen/2 ))
print -n "\033[1;44m$headerline\033[0m"
echotc cm $(( halfl - 2 )) $(( halfc - hlen/2 ))
print -n "\033[1;44m \033[0m \033[1;33m$text\033[0m \033[1;44m \033[0m"
echotc cm $(( halfl - 1 )) $(( halfc - hlen/2 ))
print -n "\033[1;44m$headerline2\033[0m"
echotc rc
} || {
print "\033[1;44m$headerline\033[0m\n\033[1;44m \033[0m \033[1;33m$text\033[0m \033[1;44m \033[0m\n\033[1;44m$headerline2\033[0m"
}
}
function zc-logo-all() {
setopt localoptions extendedglob clobber
integer idx is_locked counter=0