diff options
| author | Dylan Araps <dylan.araps@gmail.com> | 2019-10-01 01:52:32 +0300 |
|---|---|---|
| committer | Dylan Araps <dylan.araps@gmail.com> | 2019-10-01 01:52:32 +0300 |
| commit | 2e3da189ca767c1a909a83a6a8ce5dbcf6b9494a (patch) | |
| tree | ae52b8ad84ec7c293914814af448498de3ba85e9 | |
| parent | 344086b46485ba89f39fb6e51da9fd5e638e7368 (diff) | |
| download | pfetch-2e3da189ca767c1a909a83a6a8ce5dbcf6b9494a.tar.gz | |
pfetch: smarter terminal sequence handling
| -rwxr-xr-x | pfetch | 31 |
1 files changed, 20 insertions, 11 deletions
@@ -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='[37m'; c8='[38m' } + # 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 <<EOF' is the simplest way of reading # a command into a list of variables. |
