diff --git a/terminal_layout.sh b/terminal_layout.sh index 88ec5874cb38dabd22b95c2495cb52cd990ec3ce..3e07f976a06f82c30b40aa331b505bacaf046cd4 100644 --- a/terminal_layout.sh +++ b/terminal_layout.sh @@ -19,6 +19,11 @@ OUTLINES="outlines.template" BUTTONS="buttons.template" # Spacebar resize since we may add usefull caracters on the last row, prevent the whole layout shrinking SPACE_RESIZE="110" +# Button resize because a terminal layout has 1 more row than a normal layout +HEIGHT_RESIZE="42" +HEIGHT_RESIZE_WIDE="37" +# A list of special keys that should not be resized +FIXED_HEIGHT_KEYS="term_small unassigned" ########################################################################################## @@ -41,15 +46,17 @@ function add_outline { file=$1 else echo $line | grep -q -e "[ ][ ][ ][ ]spaceline:.*" if [ $? -eq 0 ]; then - echo " Found space, resizing..." - echo "s/width: [0-9]*/width: $SPACE_RESIZE/" > resize.sed - echo $line | sed -f resize.sed >> $TERMINAL_DIR/$file.tmp - rm -f resize.sed + echo " Found space, resizing width..." + echo "s/width: [0-9]*/width: $SPACE_RESIZE/" > space_resize.sed + echo $line | sed -f space_resize.sed >> $TERMINAL_DIR/$file.tmp + rm -f space_resize.sed else - echo "$line" >> $TERMINAL_DIR/$file.tmp + echo "$line" | sed -f height_resize.sed >> $TERMINAL_DIR/$file.tmp fi fi done < $NORMAL_DIR/$file + + rm -f height_resize.sed } # @@ -110,6 +117,45 @@ function add_buttons { file=$1 mv $TERMINAL_DIR/$file.tmp1 $TERMINAL_DIR/$file } +function resize_keys { file=$1 + echo " resize_keys().." + cat /dev/null > $TERMINAL_DIR/$file.tmp1 + + echo "$file" | grep -q wide + if [ $? -eq 0 ]; then + # set height for a wide layout + echo "s/height: [0-9]*/height: $HEIGHT_RESIZE_WIDE/" > height_resize.sed + else + # set height for a normal layout + echo "s/height: [0-9]*/height: $HEIGHT_RESIZE/" > height_resize.sed + fi + + IFS='' + while read line; do + + echo "$line" | grep -q "height" + if [ $? -eq 0 ]; then + # this is a key definition + for k in "$FIXED_HEIGHT_KEYS"; do + echo "$line" | grep -v -q "$k" + if [ $? -eq 0 ]; then + # don't resize + echo "$line" | sed -f height_resize.sed >> $TERMINAL_DIR/$file.tmp1 + continue + else + echo "$line" >> $TERMINAL_DIR/$file.tmp1 + fi + done + else + # a normal line, just append it to the destination file + echo "$line" >> $TERMINAL_DIR/$file.tmp1 + fi + done < $TERMINAL_DIR/$file + + #rm -f height_resize.sed + mv $TERMINAL_DIR/$file.tmp1 $TERMINAL_DIR/$file +} + # # transform $files normal layout in a terminal layout # @@ -119,6 +165,7 @@ function transform { file=$1 add_outline "$file" add_first_row "$file.tmp" add_buttons "$file" + resize_keys "$file" echo " " mv -f $TERMINAL_DIR/$file $TERMINAL_DIR/$1