From 0825e282cdfeefa42a2e6292580c38f8c0834253 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 10 Jun 2016 17:58:24 +1000 Subject: [PATCH 1/4] Add terminology support --- neofetch | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/neofetch b/neofetch index a0ac4f44..34582c17 100755 --- a/neofetch +++ b/neofetch @@ -2277,23 +2277,41 @@ getimage () { stty -echo if [ -n "$TMUX" ]; then printf "%b%s" "\033Ptmux;\033\033[14t\033\033[c\033\\" + + elif [ "$image_backend" == "tycat" ]; then + printf "%b%s" "\033}qs\000" + else printf "%b%s" "\033[14t\033[c" fi # The escape code above prints the output AFTER the prompt so this - # loop below reads it as input. wtf xterm - read -t 1 -d c -s -r term_size + # loop below reads it as input. wtf xterm / terminology + if [ "$image_backend" == "tycat" ]; then + read -t 1 -s -r term_size + else + read -t 1 -d c -s -r term_size + fi stty echo # Split the string - term_size=${term_size//'['} - term_size=${term_size/';'} - term_size=${term_size/$'\E4'} - term_size=${term_size/t*} - term_height=${term_size/';'*} - term_width=${term_size/*';'} - + if [ "$image_backend" == "tycat" ]; then + lines=${term_size%%';'*} + columns=${term_size%';'*';'*} + columns=${columns#*';'} + font_height=${term_size##*';'} + font_weight=${term_size#*';'*';'} + font_weight=${font_weight%';'*} + term_height=$((font_height * columns)) + term_width=$((font_weight * lines)) + else + term_size=${term_size//'['} + term_size=${term_size/';'} + term_size=${term_size/$'\E4'} + term_size=${term_size/t*} + term_height=${term_size/';'*} + term_width=${term_size/*';'} + fi # If $img isn't a file or the terminal doesn't support xterm escape sequences, # fallback to ascii mode. @@ -3287,6 +3305,10 @@ if [ "$image" != "off" ]; then # If iterm2 is detected use iterm2 backend. if [ -n "$ITERM_PROFILE" ]; then image_backend="iterm2" + + elif [ ! -z "$(tycat 2>/dev/null)" ]; then + image_backend="tycat" + else image_backend="w3m" fi @@ -3311,6 +3333,10 @@ if [ "$image" != "off" ] && [ "$image" != "ascii" ]; then "iterm2") printf "%b%s\a\n" "\033]1337;File=width=${width}px;height=${height}px;inline=1:$(base64 < "$img")" ;; + + "tycat") + tycat "$img" + ;; esac fi From f09890ff3345a75ca1fea6258d85f11138a2c6d1 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 10 Jun 2016 18:11:47 +1000 Subject: [PATCH 2/4] Reduce read count to 1 --- neofetch | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/neofetch b/neofetch index 34582c17..b78f19f0 100755 --- a/neofetch +++ b/neofetch @@ -2283,15 +2283,11 @@ getimage () { else printf "%b%s" "\033[14t\033[c" + read_flags="-d c" fi # The escape code above prints the output AFTER the prompt so this - # loop below reads it as input. wtf xterm / terminology - if [ "$image_backend" == "tycat" ]; then - read -t 1 -s -r term_size - else - read -t 1 -d c -s -r term_size - fi + read -t 1 ${read_flags} -s -r term_size stty echo # Split the string From 442c5d936bbe528f24a33c8c3d60816fa8a5866d Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 10 Jun 2016 18:31:19 +1000 Subject: [PATCH 3/4] Reduce size of term_size format block --- neofetch | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/neofetch b/neofetch index b78f19f0..dc2ba915 100755 --- a/neofetch +++ b/neofetch @@ -2290,16 +2290,15 @@ getimage () { read -t 1 ${read_flags} -s -r term_size stty echo + + # 83;28;8;15 + # Split the string if [ "$image_backend" == "tycat" ]; then - lines=${term_size%%';'*} - columns=${term_size%';'*';'*} - columns=${columns#*';'} - font_height=${term_size##*';'} - font_weight=${term_size#*';'*';'} - font_weight=${font_weight%';'*} - term_height=$((font_height * columns)) - term_width=$((font_weight * lines)) + term_size=(${term_size//;/ }) + term_width=$((term_size[2] * term_size[0])) + term_height=$((term_size[3] * term_size[1])) + else term_size=${term_size//'['} term_size=${term_size/';'} @@ -2311,7 +2310,7 @@ getimage () { # If $img isn't a file or the terminal doesn't support xterm escape sequences, # fallback to ascii mode. - if [ ! -f "$img" ] || [ ${#term_size} -le 5 ]; then + if [ ! -f "$img" ] || [ ${#term_size} -le 5 ] && [ "$image_backend" != "tycat" ]; then image="ascii" getascii From e747943c08b9a1c30985a7fadfd16ab06a2cdfaa Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 10 Jun 2016 18:34:47 +1000 Subject: [PATCH 4/4] Remove stray newlines --- neofetch | 3 --- 1 file changed, 3 deletions(-) diff --git a/neofetch b/neofetch index dc2ba915..1b40d079 100755 --- a/neofetch +++ b/neofetch @@ -2290,9 +2290,6 @@ getimage () { read -t 1 ${read_flags} -s -r term_size stty echo - - # 83;28;8;15 - # Split the string if [ "$image_backend" == "tycat" ]; then term_size=(${term_size//;/ })