PDA

View Full Version : [SOLVED] Retrieve line length from console?


sea
15th September 2011, 12:28 PM
Heyas

Wondering if there is a way to retrieve the line length in lxterminal.
Havent found it in --help or man.
Afaik the --geometry is used to SET it, but i'd like to GET.

Thank you.

---------- Post added at 11:28 AM ---------- Previous post was at 10:33 AM ----------

To be a little more specific, i'd like to set my scripts to use the max width of the console.
Mainwhile to have them a minimal width.

At this time, i set both 'hardcoded' into variables.

Code Snippet:

# | Variables
seaTotalWidth="50"
seaMinimumWidth="75"
if [[ "$seaTotalWidth" < "$seaMinimumWidth" ]] ; then seaTotalWidth=$seaMinimumWidth ;fi
seaBorderLeft="# |" ; seaBorderRight="| #"
seaBorderLine="-"
seaBorderLeftLen="${#seaBorderLeft}" ; seaBorderRightLen="${#seaBorderRight}"
seaSpanWidth=$[ $seaTotalWidth - $seaBorderLeftLen - $seaBorderRightLen ]

for (( j = 0 ; j <= $seaSpanWidth; j++ )) ; do
tmpspan="$tmpspan$seaBorderLine"
done
span=$tmpspan

liner() { echo -e "$seaBorderLeft${seaf}$span${reset}$seaBorderRight" ; }
# |
# | sea Header- & Footerline
# |
seaecho() { # $leftvalue $rightvalue
leftvalue=$1 ; rightvalue=$2
lenL=${#leftvalue} ; lenR=${#rightvalue}
empty=$[ seaSpanWidth - lenL - lenR - 2 ]
for (( i = 2 ; i <= $empty; i++ )) ; do
spacer="$spacer "
done
echo leftval: $lenL, spacer: ${#spacer}, rightval: $lenR
toPrint="$seaBorderLeft $leftvalue $spacer $rightvalue $seaBorderRight"
#echo ${#toPrint}
echo -e "$toPrint"
}
seaHeadline() { # | Say Hello
clear
#seaLogo
release=$(release)
curDate=$(date '+%a %Y.%B.%d - %H:%M:%S')
seaecho "sea Scripts : $seaVer" "$curDate"
seaecho "${release}" "${seaDE} Desktop"
#echo -e "# | ${seacolor} sea Scripts : $seaVer \t\t$curDate${reset} | #"
#echo -e "# | ${seacolor}${whitef} $release${seacolor} \t\t $seaDE Desktop \t\t${reset} | #"
liner
}

ah7013
15th September 2011, 12:32 PM
You could use

WIDTH=`tput cols`

the WIDTH variable will then contain the width of the console.

sea
15th September 2011, 12:58 PM

Awesome, thank you.

stevea
23rd September 2011, 05:29 AM
In a bash script just use
$COLUMNS
$LINES