Merge pull request #437 from dylanaraps/ascii2

Ascii: Cleanup ascii functions
This commit is contained in:
Dylan Araps 2016-11-13 21:45:54 +11:00 committed by GitHub
commit 9612632048
6 changed files with 198 additions and 229 deletions

View file

@ -1,19 +1,19 @@
${c1} `.-/::/-``
${c2} `.-/::/-``
.-/osssssssso/.
:osyysssssssyyys+-
`.+yyyysssssssssyyyyy+.
`/syyyyyssssssssssyyyyys-`
`/yhyyyyysss${c2}++${c1}ssosyyyyhhy/`
.ohhhyyyys${c2}o++/+o${c1}so${c2}+${c1}syy${c2}+${c1}shhhho.
.shhhhys${c2}oo++//+${c1}sss${c2}+++${c1}yyy${c2}+s${c1}hhhhs.
-yhhhhs${c2}+++++++o${c1}ssso${c2}+++${c1}yyy${c2}s+o${c1}hhddy:
-yddhhy${c2}o+++++o${c1}syyss${c2}++++${c1}yyy${c2}yooy${c1}hdddy-
.yddddhs${c2}o++o${c1}syyyyys${c2}+++++${c1}yyhh${c2}sos${c1}hddddy`
`odddddhyosyhyyyyyy${c2}++++++${c1}yhhhyosddddddo
.dmdddddhhhhhhhyyyo${c2}+++++${c1}shhhhhohddddmmh.
ddmmdddddhhhhhhhso${c2}++++++${c1}yhhhhhhdddddmmdy
dmmmdddddddhhhyso${c2}++++++${c1}shhhhhddddddmmmmh
-dmmmdddddddhhys${c2}o++++o${c1}shhhhdddddddmmmmd-
`/yhyyyyysss${c1}++${c2}ssosyyyyhhy/`
.ohhhyyyys${c1}o++/+o${c2}so${c1}+${c2}syy${c1}+${c2}shhhho.
.shhhhys${c1}oo++//+${c2}sss${c1}+++${c2}yyy${c1}+s${c2}hhhhs.
-yhhhhs${c1}+++++++o${c2}ssso${c1}+++${c2}yyy${c1}s+o${c2}hhddy:
-yddhhy${c1}o+++++o${c2}syyss${c1}++++${c2}yyy${c1}yooy${c2}hdddy-
.yddddhs${c1}o++o${c2}syyyyys${c1}+++++${c2}yyhh${c1}sos${c2}hddddy`
`odddddhyosyhyyyyyy${c1}++++++${c2}yhhhyosddddddo
.dmdddddhhhhhhhyyyo${c1}+++++${c2}shhhhhohddddmmh.
ddmmdddddhhhhhhhso${c1}++++++${c2}yhhhhhhdddddmmdy
dmmmdddddddhhhyso${c1}++++++${c2}shhhhhddddddmmmmh
-dmmmdddddddhhys${c1}o++++o${c2}shhhhdddddddmmmmd-
.smmmmddddddddhhhhhhhhhdddddddddmmmms.
`+ydmmmdddddddddddddddddddmmmmdy/.
`.:+ooyyddddddddddddyyso+:.`

View file

@ -7,9 +7,9 @@ ${c1} -`
`/:-:++oooo+:
`/++++/+++++++:
`/++++++++++++++:
`/+++o${c2}oooooooo${c1}oooo/`
./${c2}ooosssso++osssssso${c1}+`
${c2} .oossssso-````/ossssss+`
`/+++ooooooooooooo/`
./ooosssso++osssssso+`
.oossssso-````/ossssss+`
-osssssso. :ssssssso.
:osssssss/ osssso+++.
/ossssssss/ +ssssooo/-

View file

@ -7,8 +7,8 @@ M- ,=;;;#:, ,:#;;:=, ,@
:# :#.=/++++/=.$= #=
,#; #/:+/;,,/++:+/ ;+.
,+/. ,;@+, ,#H;, ,/+,
;+;;/= @. ${c2}.H${c3}#${c2}#X ${c1}-X :///+;
;+=;;;.@, ${c3}.X${c2}M${c3}@$. ${c1}=X.//;=#/.
;+;;/= @. ${c3}.H${c2}#${c3}#X ${c1}-X :///+;
;+=;;;.@, ${c2}.X${c3}M${c2}@$. ${c1}=X.//;=#/.
,;: :@#= =$H: .+#-
,#= #;-///==///-// =#,
;+ :#-;;;:;;;;-X- +:

View file

@ -250,24 +250,24 @@ block_height=1
# Progress bar character
# --progress_char elapsed_char total_char
progress_char_elapsed="-"
progress_char_total="="
bar_char_elapsed="-"
bar_char_total="="
# Progress border
# --progress_border on, off
progress_border="on"
bar_border="on"
# Progress bar length in spaces
# Number of chars long to make the progress bars.
# --progress_length num
progress_length="15"
bar_length="15"
# Progress bar colors
# When set to distro, uses your distro's logo colors
# Takes: num, "distro"
# --progress_colors col col
progress_color_elapsed="distro"
progress_color_total="distro"
bar_color_elapsed="distro"
bar_color_total="distro"
# Customize how the info is displayed.
# bar: Only the progress bar is displayed.

355
neofetch
View file

@ -19,6 +19,9 @@ export LANG=C
# Set no case match.
shopt -s nocasematch
# Reset colors/bold
reset="\033[0m"
# DETECT INFORMATION
get_os() {
@ -1063,7 +1066,7 @@ get_memory() {
esac
memory="${memused}MB / ${memtotal}MB"
# Progress bars
# Bars
case "$memory_display" in
"bar") memory="$(bar "${memused}" "${memtotal}")" ;;
"infobar") memory="${memory} $(bar "${memused}" "${memtotal}")" ;;
@ -1849,18 +1852,6 @@ get_image_backend() {
esac
}
get_image_program() {
if [[ -n "$ITERM_PROFILE" ]]; then
image_program="iterm2"
elif [[ "$(tycat 2>/dev/null)" ]]; then
image_program="tycat"
else
image_program="w3m"
fi
}
get_ascii() {
if [[ ! -f "$ascii" || "$ascii" == "distro" ]]; then
# Error message
@ -1932,6 +1923,18 @@ get_ascii() {
export LC_ALL=C
}
get_image_program() {
if [[ -n "$ITERM_PROFILE" ]]; then
image_program="iterm2"
elif [[ "$(tycat 2>/dev/null)" ]]; then
image_program="tycat"
else
image_program="w3m"
fi
}
get_w3m_img_path() {
if [[ -x "$w3m_img_path" ]]; then
return
@ -2300,13 +2303,13 @@ info() {
err "Info: Couldn't detect $subtitle." && return
case "$1" in
title)
"title")
string="${title_color}${bold}${output}"
string="${string/@/${at_color}@${title_color}${bold}}"
length="${#output}"
;;
underline) string="${underline_color}${output}" ;;
"underline") string="${underline_color}${output}" ;;
*)
string="${subtitle_color}${bold}${subtitle}${reset}"
@ -2367,196 +2370,188 @@ get_underline() {
fi
}
colors() {
# Reset colors/bold
reset="\033[0m"
get_line_break() {
line_break=" "
# Change color of logo based on distro
# Calculate info height
info_height="$((info_height+=1))"
}
get_bold() {
case "$ascii_bold" in
"on") ascii_bold="\033[1m" ;;
"off") ascii_bold="" ;;
esac
case "$bold" in
"on") bold="\033[1m" ;;
"off") bold="" ;;
esac
}
trim() {
# When a string is passed to 'echo' all trailing and leading
# whitespace is removed and inside the string multiple spaces are
# condensed into single spaces.
#
# The 'set -f/+f' is here so that 'echo' doesn't cause any expansion
# of special characters.
#
# The whitespace trim doesn't work with multiline strings so we use
# '${1//[[:space:]]/ }' to remove newlines beofre we trim the whitespace.
set -f
builtin echo -E ${1//[[:space:]]/ }
set +f
}
# COLORS
get_distro_colors() {
# This function sets the text colors according
# to your OS/Distro's logo colors.
#
# $ascii_distro is the same as $distro
case "$ascii_distro" in
"Arch"* | "Antergos"*)
setcolors 6 4
;;
"BlankOn"* | "DracOS"*)
setcolors 1 7
"Arch"* | "Kogaion"* | "Elementary"* | "GalliumOS"* | "Rosa"* | "OpenWrt"* | "Netrunner"* | "PCLinuxOS"* | "Slackware"* | "KaOS"* | "Kubuntu"* | "Lubuntu"* | "Xubuntu"* | "OpenIndiana"* | "Fedora"* | "Korora"* | "Sabayon"* | "Frugalware"* | "Exherbo"* | "Scientific"* | "Solus"*)
set_colors 4 7 1
;;
"CentOS"*)
setcolors 3 2 4 5 7
set_colors 3 2 4 5 7
;;
"CRUX"* | "Chakra"* | "gNewSense"* | "SailfishOS"* | "Alpine"* | "Ubuntu-GNOME"* | "Qubes"*)
setcolors 4 5 7 6
set_colors 4 5 7 6
;;
"Chrom"*)
setcolors 2 1 3 4 7
set_colors 2 1 3 4 7
ascii_distro="chrome"
;;
"Debian"* | "Ubuntu"* | "DragonFly"* | "PacBSD"* | "Oracle"*)
setcolors 1 7 3
"Raspbian"*)
set_colors 2 1
;;
"Red Star"* | "Redstar")
setcolors 1 7 3
ascii_distro="redstar"
"Debian"* | "Ubuntu"* | "DragonFly"* | "PacBSD"* | "Oracle" | "BlankOn"* | "DracOS"* | "Peppermint"*)
set_colors 1 7 3
;;
"FreeBSD"* | "PCBSD"*)
setcolors 1 7 3
set_colors 1 7 3
ascii_distro="freebsd"
;;
"Red Star"* | "Redstar")
set_colors 1 7 3
ascii_distro="redstar"
;;
"Red"*)
setcolors 1 7 3
set_colors 1 7 3
ascii_distro="redhat"
;;
"Pardus"*)
setcolors 3 7
;;
"Kogaion"* | "Elementary"* | "GalliumOS"* | "Rosa"* | "OpenWrt"* | "Netrunner"*)
setcolors 4 7
;;
"Fedora"* | "Korora"* | "Sabayon"* | "Frugalware"* | "Exherbo"*)
setcolors 4 7 1
;;
"Gentoo"* | "Funtoo"* | "SteamOS"* | "Devuan"*)
setcolors 5 7
;;
"KDE"*)
setcolors 2 7
ascii_distro="kde"
;;
"Kali"*)
setcolors 4 8
set_colors 4 8
;;
"BunsenLabs"*)
setcolors 8 7
set_colors 8 7
;;
*"OS X"* | *"iOS"* | "Mac" | *"macOS"*)
setcolors 2 3 1 1 5 4
set_colors 2 3 1 1 5 4
ascii_distro="mac"
;;
"OpenMandriva"*)
setcolors 4 3
set_colors 4 3
;;
"Mageia"* | "Porteus"*)
setcolors 6 7
"NetBSD"* | "Parabola"* | "Tails"* | "BLAG"* | "Gentoo"* | "Funtoo"* | "SteamOS"* | "Devuan"*)
set_colors 5 7
;;
"Peppermint"*)
setcolors 1 7
"OpenBSD"* | "GuixSD"* | "Pardus"*)
set_colors 3 7 6 1 8
;;
*"Mint"*)
setcolors 2 7
ascii_distro="mint"
*"SUSE"* | "Manjaro"* | "Deepin"* |"LMDE"* | "Chapeau"* | "Bitrig"*)
set_colors 2 7
;;
"LMDE"* | "Chapeau"* | "Bitrig"*)
setcolors 2 7
"KDE"*)
set_colors 2 7
ascii_distro="kde"
;;
"Android"*)
setcolors 2 7
set_colors 2 7
ascii_length_force="19"
;;
"NetBSD"* | "Parabola"* | "Tails"* | "BLAG"*)
setcolors 5 7
;;
"OpenBSD"* | "GuixSD"*)
setcolors 3 7 6 1 8
;;
*"SUSE"* | "Manjaro"* | "Deepin"*)
setcolors 2 7
;;
"PCLinuxOS"* | "Slackware"* | "KaOS"* | "Kubuntu"* | "Lubuntu"* | "Xubuntu"* | "OpenIndiana"*)
setcolors 4 7 1
*"Mint"*)
set_colors 2 7
ascii_distro="mint"
;;
"Puppy"* | "Quirky Werewolf"* | "Precise Puppy"*)
setcolors 4 7
set_colors 4 7
ascii_distro="puppy"
;;
"Sparky"*)
setcolors 1 7
set_colors 1 7
ascii_distro="sparky"
;;
"Scientific"*)
setcolors 4 1 7
;;
"Solus"*)
setcolors 4 7
;;
"Trisquel"* | "NixOS"* | "Zorin"*)
setcolors 4 6
"Trisquel"* | "NixOS"* | "Zorin"* | "Antergos"*)
set_colors 4 6
;;
"Travis")
setcolors 1 2 3 4 5 6
set_colors 1 2 3 4 5 6
;;
"void"*)
setcolors 2 8
"Void"* | "Haiku"*)
set_colors 2 8
;;
"Mageia"* | "Porteus"*)
set_colors 6 7
;;
"Windows 8"* | "Windows 10"*)
setcolors 6 7
set_colors 6 7
ascii_distro="windows10"
;;
"Windows"*)
setcolors 1 2 4 3
;;
"Haiku"*)
setcolors 2 0
;;
"Raspbian"*)
setcolors 2 1
set_colors 1 2 4 3
;;
"Linux")
setcolors fg 8 3
set_colors fg 8 3
;;
*)
case "$os" in
"Linux")
if [[ "$os" == "Linux" ]]; then
ascii_distro="linux"
setcolors fg 8 3
;;
esac
set_colors fg 8 3
fi
;;
esac
# Overwrite distro colors if '$ascii_colors' doesn't
# equal 'distro'.
[[ "${ascii_colors[0]}" != "distro" ]] && \
setcolors ${ascii_colors[@]}
set_colors ${ascii_colors[@]}
}
setcolors() {
set_colors() {
# Ascii colors
c1="$(color "$1")${ascii_bold}"
c2="$(color "$2")${ascii_bold}"
c3="$(color "$3")${ascii_bold}"
@ -2564,6 +2559,7 @@ setcolors() {
c5="$(color "$5")${ascii_bold}"
c6="$(color "$6")${ascii_bold}"
# Text colors
if [[ "${colors[0]}" == "distro" ]]; then
title_color="$(color "$1")"
at_color="$reset"
@ -2584,16 +2580,17 @@ setcolors() {
info_color="$(color "${colors[5]}")"
fi
if [[ "$progress_color_elapsed" == "distro" ]]; then
progress_color_elapsed="$(color fg)"
# Bar colors
if [[ "$bar_color_elapsed" == "distro" ]]; then
bar_color_elapsed="$(color fg)"
else
progress_color_elapsed="$(color "$progress_color_elapsed")"
bar_color_elapsed="$(color "$bar_color_elapsed")"
fi
case "$progress_color_total $1" in
distro\ [736]) progress_color_total="$c2" ;;
distro\ [0-9]) progress_color_total="$c1" ;;
*) progress_color_total="$(color "$progress_color_total")" ;;
case "$bar_color_total $1" in
"distro "[736]) bar_color_total="$c2" ;;
"distro "[0-9]) bar_color_total="$c1" ;;
*) bar_color_total="$(color "$bar_color_total")" ;;
esac
}
@ -2605,41 +2602,6 @@ color() {
esac
}
bold() {
case "$ascii_bold" in
"on") ascii_bold="\033[1m" ;;
"off") ascii_bold="" ;;
esac
case "$bold" in
"on") bold="\033[1m" ;;
"off") bold="" ;;
esac
}
get_line_break() {
line_break=" "
# Calculate info height
info_height="$((info_height+=1))"
}
trim() {
# When a string is passed to 'echo' all trailing and leading
# whitespace is removed and inside the string multiple spaces are
# condensed into single spaces.
#
# The 'set -f/+f' is here so that 'echo' doesn't cause any expansion
# of special characters.
#
# The whitespace trim doesn't work with multiline strings so we use
# '${1//[[:space:]]/ }' to remove newlines beofre we trim the whitespace.
set -f
builtin echo -E ${1//[[:space:]]/ }
set +f
}
# OTHER
err() {
@ -2728,21 +2690,19 @@ get_user_config() {
bar() {
# Get the values
elapsed="$(($1 * progress_length / $2))"
elapsed="$(($1 * bar_length / $2))"
# Create the bar with spaces
prog="$(printf %"$elapsed"s)"
total="$(printf %"$((progress_length - elapsed))"s)"
total="$(printf %"$((bar_length - elapsed))"s)"
# Set the colors and swap the spaces for $progress_char
bar+="${progress_color_elapsed}${prog// /$progress_char_elapsed}"
bar+="${progress_color_total}${total// /$progress_char_total}"
# Set the colors and swap the spaces for $bar_char_
bar+="${bar_color_elapsed}${prog// /$bar_char_elapsed}"
bar+="${bar_color_total}${total// /$bar_char_total}"
# Borders
if [[ "$progress_border" == "on" ]]; then
bar+="$(color fg)]"
bar="$(color fg)[$bar"
fi
[[ "$bar_border" == "on" ]] && \
bar="$(color fg)[${bar}$(color fg)]"
printf "%b\n" "${bar}${info_color}"
}
@ -2753,6 +2713,8 @@ cache() {
}
kde_config_dir() {
# If the user is using KDE get the KDE
# configuration directory.
if [[ "$kde_config_dir" ]]; then
return
@ -2792,9 +2754,10 @@ get_term_padding() {
}
dynamic_prompt() {
# Calculate image height in terminal cells.
if [[ "$image_backend" != "ascii" ]]; then
if [[ "$image_backend" == "image" ]]; then
get_term_padding 2>/dev/null
# Calculate image height in terminal cells.
lines="$(((height + (${border:-0} * 2) + ${yoffset:-0}) / font_height))"
fi
@ -2836,9 +2799,15 @@ old_functions() {
old_flags() {
[[ -n "$osx_buildversion" ]] && err "Config: \$osx_buildversion is deprecated, use \$distro_shorthand instead."
[[ -n "$osx_codename" ]] && err "Config: \$osx_codename is deprecated, use \$distro_shorthand instead."
[[ -n "$progress_char" ]] && err "Config: \$progress_char is deprecated, use \$progress_char_elapsed and \$progress_char_total instead."
[[ "$cpu_cores" == "on" ]] && err "Config: \$cpu_cores='on' is deprecated, use \$cpu_cores='logical|physical|off' instead."
[[ -n "$image" ]] && { err "Config: \$image is deprecated, use \$image_source instead."; image_source="$image"; }
# All progress_ variables were changed to bar_
[[ -n "$progress_char" ]] && err "Config: \$progress_char is deprecated, use \$bar_char_elapsed and \$bar_char_total instead."
[[ -n "$progress_border" ]] && err "Config: \$progress_border is deprecated, use \$bar_border instead."
[[ -n "$progress_length" ]] && err "Config: \$progress_length is deprecated, use \$bar_length instead."
[[ -n "$progress_color_elapsed" ]] && err "Config: \$progress_color_elapsed is deprecated, use \$bar_color_elapsed instead."
[[ -n "$progress_color_total" ]] && err "Config: \$progress_color_total is deprecated, use \$bar_color_total instead."
}
cache_uname() {
@ -2910,20 +2879,20 @@ usage() { printf "%s" "
--block_height num Height of color blocks in lines
--block_range start end Range of colors to print as blocks
Progress Bars:
--progress_char 'elapsed char' 'total char'
Characters to use when drawing progress bars.
--progress_border on/off Whether or not to surround the bar with '[]'
--progress_length num Length in spaces to make the progress bars.
--progress_colors num num Colors to make the progress bar.
Bars:
--bar_char 'elapsed char' 'total char'
Characters to use when drawing bars.
--bar_border on/off Whether or not to surround the bar with '[]'
--bar_length num Length in spaces to make the bars.
--bar_colors num num Colors to make the bar.
Set in this order: elapsed, total
--cpu_display mode Progress bar mode.
--cpu_display mode Bar mode.
Takes: bar, infobar, barinfo, off
--memory_display mode Progress bar mode.
--memory_display mode Bar mode.
Takes: bar, infobar, barinfo, off
--battery_display mode Progress bar mode.
--battery_display mode Bar mode.
Takes: bar, infobar, barinfo, off
--disk_display mode Progress bar mode.
--disk_display mode Bar mode.
Takes: bar, infobar, barinfo, off
Image:
@ -3048,16 +3017,16 @@ get_args() {
--block_width) block_width="$2" ;;
--block_height) block_height="$2" ;;
# Progress Bars
--progress_char)
progress_char_elapsed="$2"
progress_char_total="$3"
# Bars
--bar_char)
bar_char_elapsed="$2"
bar_char_total="$3"
;;
--progress_border) progress_border="$2" ;;
--progress_length) progress_length="$2" ;;
--progress_colors)
progress_color_elapsed="$2"
progress_color_total="$3"
--bar_border) bar_border="$2" ;;
--bar_length) bar_length="$2" ;;
--bar_colors)
bar_color_elapsed="$2"
bar_color_total="$3"
;;
--cpu_display) cpu_display="$2" ;;
--memory_display) memory_display="$2" ;;
@ -3149,11 +3118,11 @@ main() {
cache_uname
get_os
get_default_config 2>/dev/null
old_flags
get_args "$@"
old_flags
get_distro
bold
colors
get_bold
get_distro_colors
# Restore cursor and clear screen on ctrl+c
trap 'printf "\033[?25h"; clear; exit' 2

View file

@ -132,39 +132,39 @@ Height of color blocks in lines
.B \--block_range 'start' 'end'
Range of colors to print as blocks
.SH PROGRESS BARS
.SH BARS
.TP
.B \--progress_char 'elapsed char' 'total char'
Characters to use when drawing progress bars.
.B \--bar_char 'elapsed char' 'total char'
Characters to use when drawing bars.
.TP
.B \--progress_border on/off
.B \--bar_border on/off
Whether or not to surround the bar with '[]'
.TP
.B \--progress_length 'num'
Length in spaces to make the progress bars.
.B \--bar_length 'num'
Length in spaces to make the bars.
.TP
.B \--progress_colors 'num' 'num'
Colors to make the progress bar.
.B \--bar_colors 'num' 'num'
Colors to make the bar.
.br
Set in this order: elapsed, total
.TP
.B \--cpu_display 'mode'
Progress bar mode.
Bar mode.
.br
Takes: bar, infobar, barinfo, off
.TP
.B \--memory_display 'mode'
Progress bar mode.
Bar mode.
.br
Takes: bar, infobar, barinfo, off
.TP
.B \--battery_display 'mode'
Progress bar mode.
Bar mode.
.br
Takes: bar, infobar, barinfo, off
.TP
.B \--disk_display 'mode'
Progress bar mode.
Bar mode.
.br
Takes: bar, infobar, barinfo, off