[rsbac] Re: [diff] rsbac_menu terminal size detection fix
Guillaume Destuynder
kang at rsbac.org
Wed Feb 23 19:44:42 CET 2005
>
>
>Hello,
>
>Attached is my quick fix for the terminal size detection issue, please
>test if it works fine for you. Thanks and take care!
>
>===
>
>--- old/rsbac_menu 2005-02-22 15:58:54.000000000 +0200
>+++ new/rsbac_menu 2005-02-22 15:58:54.000000000 +0200
>@@ -67,14 +67,18 @@
> exit
> fi
>
>-# test for LINES and COLUMNS (should be exported e.g. in /etc/profile)
>-if test -z "$LINES" ; then LINES=25 ; fi
>-if test -z "$COLUMNS" ; then COLUMNS=80 ; fi
>-export LINES
>-export COLUMNS
>-declare -i BL=$LINES-4
>-declare -i BC=$COLUMNS-4
>-declare -i MAXLINES=$LINES-10
>+set_geometry () {
>+LINES=
>+COLUMNS=
>+BL=${1:-24}
>+BC=${2:-80}
>+[ $BL = 0 ] && BL=24
>+[ $BC = 0 ] && BC=80
>+BL=$((BL-4))
>+BC=$((BC-5))
>+MAXLINES=$BL-10
>+}
>+set_geometry `stty size 2>/dev/null`
> gl () {
> if test $1 -gt $MAXLINES
> then echo $MAXLINES
>
>===
>
>--
>Best regards,
> torc mailto:torc at iptel.by <http://rsbac.dyndns.org/mailman/listinfo/rsbac>
>
Sorry, the patch didn't work for me :(
LINES and COLUMNS are unset after I run rsbac_menu or simply if i copy
and execute set_geometry() which breaks my terminal size detection. I do
not know how/why it works for you.
Also, I wonder what is: BL=${1:-24} and the next one for, I never saw
the syntax, can you explain me ? :)
Anyway, I modified the patch this way:
--- old/rsbac_menu 2005-02-22 15:58:54.000000000 +0200
+++ new/rsbac_menu 2005-02-22 15:58:54.000000000 +0200
@@ -67,14 +67,18 @@
exit
fi
-# test for LINES and COLUMNS (should be exported e.g. in /etc/profile)
-if test -z "$LINES" ; then LINES=25 ; fi
-if test -z "$COLUMNS" ; then COLUMNS=80 ; fi
-export LINES
-export COLUMNS
-declare -i BL=$LINES-4
-declare -i BC=$COLUMNS-4
-declare -i MAXLINES=$LINES-10
+# Get real terminal size
+if [ -f $(which stty) ]; then
+ LINES=$(stty size|awk '{print $1}')
+ COLUMNS=$(stty size|awk '{print $2}')
+
+# Else set sane default values
+else
+ if [ -z "$LINES" ]; then LINES=25; fi
+ if [ -z "$COLUMNS" ]; then COLUMNS=80; fi
+fi
+export $LINES $COLUMNS
+
+BL=$(($LINES-4))
+BC=$(($COLUMNS-4))
+MAXLINES=$(($LINES-10))
+
gl () {
if test $1 -gt $MAXLINES
then echo $MAXLINES
It works perfectly for me :)
stty gets the terminal size for you and its exported. if you don't have stty sizes are default 25:80
declare -i is not needed with expression parsing as integer checking is already done
else that's it. some awk overhead ^^
Of course, every rsbac_*menu needs this
I think a small script with all the shared code for every script would be nice.
I will try to find time to look into it if my bash doesn't looks too bad :)
kang
More information about the rsbac
mailing list