From 2e3da189ca767c1a909a83a6a8ce5dbcf6b9494a Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Tue, 1 Oct 2019 01:52:32 +0300 Subject: [PATCH] pfetch: smarter terminal sequence handling --- pfetch | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/pfetch b/pfetch index f2694f4..5ca435e 100755 --- a/pfetch +++ b/pfetch @@ -1269,12 +1269,6 @@ get_ascii() { # Add a gap between the ascii art and the information. 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 # started prior to printing it. # '[1m': Print the ascii in bold. @@ -1284,11 +1278,6 @@ get_ascii() { } 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 # polluting the script with '2>/dev/null'. [ "$1" = -v ] || exec 2>/dev/null @@ -1307,6 +1296,26 @@ main() { 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 # throughout the script. 'read <