pfetch: smarter terminal sequence handling

This commit is contained in:
Dylan Araps 2019-10-01 01:52:32 +03:00
parent 344086b464
commit 2e3da189ca

31
pfetch
View File

@ -1269,12 +1269,6 @@ get_ascii() {
# Add a gap between the ascii art and the information. # Add a gap between the ascii art and the information.
ascii_width=$((ascii_width + 4)) ascii_width=$((ascii_width + 4))
# Minix and DragonFly don't support these!
# '[?7l': Disable line-wrapping.
# '[?25l': Hide the cursor.
[ "$os" != Minix ] && [ "$os" != DragonFly ] &&
printf '[?7l[?25l' >&6
# Print the ascii art and position the cursor back where we # Print the ascii art and position the cursor back where we
# started prior to printing it. # started prior to printing it.
# '[1m': Print the ascii in bold. # '[1m': Print the ascii in bold.
@ -1284,11 +1278,6 @@ 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 >&6' EXIT
# 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
@ -1307,6 +1296,26 @@ main() {
c7=''; c8='' c7=''; c8=''
} }
# Avoid text-wrapping from wrecking the program output
# and hide the cursor to hide its moving around during
# the printing process.
#
# Some terminals don't support these sequences, nor do they
# silently conceal them if they're printed resulting in
# partial sequences being printed to the terminal!
[ "$TERM" = dumb ] ||
[ "$TERM" = minix ] ||
[ "$TERM" = cons25 ] || {
# '[?7l': Disable line-wrapping.
# '[?25l': Hide the cursor.
printf '[?7l[?25l' >&6
# Leave the terminal how we found it on exit or Ctrl+C.
# '[?7h': Enable line-wrapping.
# '[?25h': Show the cursor.
trap 'printf [?7h[?25h >&6' EXIT
}
# Store the output of 'uname' to avoid calling it multiple times # Store the output of 'uname' to avoid calling it multiple times
# throughout the script. 'read <<EOF' is the simplest way of reading # throughout the script. 'read <<EOF' is the simplest way of reading
# a command into a list of variables. # a command into a list of variables.