From e4a8a76c157dd412d5749f4d8d6e8bea259acfad Mon Sep 17 00:00:00 2001 From: inxi-svn Date: Thu, 3 Apr 2014 04:19:16 +0000 Subject: [PATCH] branch one, test for esc handling gnu sed vs bsd sed --- inxi | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/inxi b/inxi index 3568035..8140b17 100755 --- a/inxi +++ b/inxi @@ -2,8 +2,8 @@ ######################################################################## #### Script Name: inxi #### Version: 2.1.15 -#### Date: 2014-04-01 -#### Patch Number: 02-b1 +#### Date: 2014-04-02 +#### Patch Number: 01-b1 ######################################################################## #### SPECIAL THANKS ######################################################################## @@ -521,6 +521,7 @@ C2='' CN='' ## Always leave these blank, these are only going to be set in inxi.conf files, that makes testing ## for user changes easier after sourcing the files +ESC='\x1b' GLOBAL_COLOR_SCHEME='' IRC_COLOR_SCHEME='' IRC_CONS_COLOR_SCHEME='' @@ -825,6 +826,7 @@ initialize_data() BSD_TYPE='bsd' # all other bsds SED_I="-i ''" SED_RX='-E' + ESC=$(echo | tr '\n' '\033') fi fi # now set the script BOOLEANS for files required to run features @@ -8908,11 +8910,12 @@ get_weather_data() # args: $1 - string to strip color code characters out of # returns count of string length minus colors +# note; this cleanup may not be working on bsd sed calculate_line_length() { local string=$1 # ansi:  irc: \x0312 - string=$( sed -e "s/\x1b\[[0-9]\{1,2\}\(;[0-9]\{1,2\}\)\{0,2\}m//g" -e "s/\\\x0[0-9]\{1,3\}//g" <<< $string ) + string=$( sed -e 's/'$ESC'\[[0-9]\{1,2\}\(;[0-9]\{1,2\}\)\{0,2\}m//g' -e 's/\\\x0[0-9]\{1,3\}//g' <<< $string ) count=${#string} echo $count } @@ -10526,12 +10529,14 @@ print_networking_ip_data() if_string='' fi else - if [[ $( calculate_line_length "$if_string_holding$if_string" ) -lt $COLS_INNER ]];then - if_string_holding="$if_string_holding$if_string" - else - full_string=$( create_print_line " " "$if_string_holding${CN}" ) - print_screen_output "$full_string" + if [[ $( calculate_line_length "$if_string_holding$if_string" ) -gt $COLS_INNER ]];then + if [[ -n $if_string_holding ]];then + full_string=$( create_print_line " " "$if_string_holding${CN}" ) + print_screen_output "$full_string" + fi if_string_holding="$if_string" + else + if_string_holding="$if_string_holding$if_string" fi fi ((i++)) @@ -10679,7 +10684,7 @@ print_optical_drive_data() else multisession='no' fi - multisession=" ${C1}multisession$SEP3${C2} $multisession" + multisession="${C1}multisession$SEP3${C2} $multisession " if [[ -z ${a_drives[11]} ]];then dvd='N/A' elif [[ ${a_drives[11]} == 1 ]];then @@ -10693,7 +10698,7 @@ print_optical_drive_data() else state="${a_drives[14]}" fi - state=" ${C1}state$SEP3${C2} $state" + state="${C1}state$SEP3${C2} $state " fi if [[ -n ${a_drives[9]} && ${a_drives[9]} == 1 ]];then rw_support='cd-r' @@ -10714,8 +10719,8 @@ print_optical_drive_data() if [[ -z $rw_support ]];then rw_support='none' fi - drive_data="${C1}Features: speed$SEP3${C2} $speed$multisession " - part_2_data="$audio ${C1}dvd$SEP3${C2} $dvd ${C1}rw$SEP3${C2} $rw_support$state" + drive_data="${C1}Features: speed$SEP3${C2} $speed $multisession" + part_2_data="$audio${C1}dvd$SEP3${C2} $dvd ${C1}rw$SEP3${C2} $rw_support $state" if [[ $( calculate_line_length "$drive_data$part_2_data" ) -lt $COLS_INNER ]];then drive_data=$( create_print_line "$Line_Starter" "$drive_data$part_2_data${CN}" ) print_screen_output "$drive_data" @@ -10841,8 +10846,10 @@ print_partition_data() else line_starter=' ' fi - partition_data=$( create_print_line "$line_starter" "${a_partition_data[$i]}${CN}" ) - print_screen_output "$partition_data" + if [[ -n ${a_partition_data[$i]} ]];then + partition_data=$( create_print_line "$line_starter" "${a_partition_data[$i]}${CN}" ) + print_screen_output "$partition_data" + fi done eval $LOGFE