Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

issue# 3: added initial support for screen width detection

git-svn-id: http://shflags.googlecode.com/svn/trunk/source/1.0@81 9d7cb843-df4f-0410-8a79-4785ae5a3405
  • Loading branch information...
commit 759a7a47138d29804b7c77f656b3993ed7ba64f7 1 parent 706fdcd
kate.ward@forestent.com authored
Showing with 31 additions and 11 deletions.
  1. +2 −0  doc/CHANGES-1.0.txt
  2. +16 −8 src/shflags
  3. +13 −3 src/shflags_test_private.sh
2  doc/CHANGES-1.0.txt
View
@@ -30,6 +30,8 @@ when FLAGS() is called stating that the help flag already defined.
Issue# 2: Passing the --nohelp option no longer gives help output.
+Issue# 3: Added initial support for screen width detection.
+
Changes with 1.0.1
------------------
24 src/shflags
View
@@ -442,15 +442,22 @@ _flags_itemInList()
return ${flags_return}
}
-# Returns the length of a string.
+# Returns the width of the current screen.
#
-# Args:
-# str: string: string to determine length of
# Output:
-# integer: length of string
-_flags_strlen()
+# integer: width in columns of the current screen.
+_flags_screenColumns()
{
- echo "$1" |awk '{print length($0)}'
+ _flags_size_=`stty size 2>/dev/null`
+ if [ $? -eq ${FLAGS_TRUE} ]; then
+ _flags_cols_=`expr "${_flags_size_}" : '[0-9]* \([0-9]*\)'`
+ else
+ # TODO(kward): support 'tput cols' as well, if possible. be warned that it
+ # doesn't work when put inside backticks (i.e. a sub-shell).
+ _flags_cols_=80
+ fi
+ echo ${_flags_cols_}
+ unset _flags_cols_ _flags_size_
}
# Validate a boolean.
@@ -920,8 +927,9 @@ flags_help()
_flags_defaultStr="(default: ${_flags_defaultStr})"
_flags_helpStr=" ${_flags_flagStr} ${_flags_help} ${_flags_defaultStr}"
- _flags_helpStrLen=`_flags_strlen "${_flags_helpStr}"`
- if [ ${_flags_helpStrLen} -lt 80 ]; then
+ _flags_helpStrLen=`expr "${_flags_helpStr}" : '.*'`
+ flags_screenCols_=`_flags_screenColumns`
+ if [ ${_flags_helpStrLen} -lt ${flags_screenCols_} ]; then
echo "${_flags_helpStr}" >&2
else
_flags_emptyStr="`echo ${_flags_flagStr} |sed 's/./ /g'`"
16 src/shflags_test_private.sh
View
@@ -52,7 +52,15 @@ testItemInList()
assertFalse 'empty lists should not match' $?
}
-testValidateBoolean() {
+testScreenColumns()
+{
+ cols=`_flags_screenColumns`
+ value=`expr "${cols}" : '\([0-9]*\)'`
+ assertNotNull "unexpected screen width (${cols})" "${value}"
+}
+
+testValidateBoolean()
+{
# valid values
for value in ${TH_BOOL_VALID}; do
_flags_validateBoolean "${value}"
@@ -66,7 +74,8 @@ testValidateBoolean() {
done
}
-testValidateFloat() {
+testValidateFloat()
+{
# valid values
for value in ${TH_INT_VALID} ${TH_FLOAT_VALID}; do
_flags_validateFloat "${value}"
@@ -80,7 +89,8 @@ testValidateFloat() {
done
}
-testValidateInteger() {
+testValidateInteger()
+{
# valid values
for value in ${TH_INT_VALID}; do
_flags_validateInteger "${value}"
Please sign in to comment.
Something went wrong with that request. Please try again.