pfetch: expand

This commit is contained in:
Dylan Araps 2019-09-24 20:17:57 +03:00
parent e83c8da065
commit b7be211b13

59
pfetch
View File

@ -55,27 +55,25 @@ log() {
# $[1] # $[1]
# #
# $[6] /home/goldie $ # $[6] /home/goldie $
#
# '$PF_COL1': Control color of info name. # Move the cursor to the right, the width of the ascii art with an
# '$PF_SEP': Control the separator between info name and info data. # additional gap for text spacing.
# '$PF_COL2': Control color of info data. printf '[%sC' "${ascii_width--1}"
# '$PF_ALIGN': Control the alignment amount.
# # Print the info name and color the text.
# '[14C': Move cursor 14 characters to the right. printf '[3%s;1m%s' "${PF_COL1-4}" "$1"
# TODO: Base this on ASCII art width.
# # Print the info name and info data separator.
# '[3%s': Color formatting. printf '%s' "$PF_SEP"
# '[m': Reset formatting.
# # Move the cursor backward the length of the *current* info name and
# '[%sD': Move cursor '${#1}' characters to the left. # then move it forwards the length of the *longest* info name. This
# This allows for aligned info names and data. # aligns each info data line.
# printf '[%sD[%sC' "${#1}" "${PF_ALIGN-$info_length}"
# '[6C': Move cursor 6 characters to the right.
# This aligns the info. # Print the info data, color it and strip all leading whitespace
printf '[%sC[3%s;1m%s%s[3%sm[%sD[%sC%s\n' \ # from the string.
"${ascii_width--1}" "${PF_COL1-4}" "$1" \ printf '[3%sm%s\n' "${PF_COL2-7}" "${2#${2%%[![:space:]]*}}"
"$PF_SEP" "${PF_COL2-7}" "${#1}" \
"${PF_ALIGN-$info_length}" "$2"
# Keep track of the number of times 'log()' has been run. # Keep track of the number of times 'log()' has been run.
: $((info_height+=1)) : $((info_height+=1))
@ -443,6 +441,11 @@ get_ascii() {
} }
main() { main() {
# Leave the terminal how we found it on exit or Ctrl+C.
# '[?7h': Enable line-wrapping.
# '[?25h': Un-hide the cursor.
trap 'printf [?7h[?25h' EXIT INT
# Hide 'stderr' unless the first argument is '-v'. This saves # Hide 'stderr' unless the first argument is '-v'. This saves
# polluting the script with '2>/dev/null'. # polluting the script with '2>/dev/null'.
[ "$1" = -v ] || exec 2>/dev/null [ "$1" = -v ] || exec 2>/dev/null
@ -497,14 +500,12 @@ main() {
# Position the cursor below both the ascii art and information lines # Position the cursor below both the ascii art and information lines
# according to the height of both. If the information exceeds the ascii # according to the height of both. If the information exceeds the ascii
# art in height, don't touch the cursor, else move it down N lines. # art in height, don't touch the cursor, else move it down N lines.
# cursor_pos=$((info_height > ascii_height ? 0 : ascii_height - info_height))
# 'log' contains the amount of 'get_' info lines that were printed.
# # Print '$cursor_pos' amount of newlines. Using cursor down doesn't scroll
# '[?7h': Enable line-wrapping. # the screen correctly if this causes the cursor to hit the bottom of the
# '[%sB': Move the cursor down N lines. # window. Using '0' gives us an extra iteration, adding a bottom line gap.
# '[?25h': Un-hide the cursor. printf '%0.s\n' $(seq 0 "$cursor_pos")
printf '[?7h[%sB\n[?25h' \
"$((info_height > ascii_height ? 0 : ascii_height - info_height))"
} }
main "$@" main "$@"