diff --git a/terminal_layout.sh b/terminal_layout.sh index 3e07f976a06f82c30b40aa331b505bacaf046cd4..a986c160b7bc26dc4118528deec827f11b98a837 100644 --- a/terminal_layout.sh +++ b/terminal_layout.sh @@ -13,6 +13,29 @@ TERMINAL_DIR="/Users/ml/Documents/src/bash/squeekboard-terminal-layout-generator NORMAL_DIR="/Users/ml/Documents/src/bash/squeekboard-terminal-layout-generator/normal_layout" # Add a special first row, with quick access to usefull keys in a terminal FIRST_ROW="first_row.template" +<<<<<<< HEAD +FIRST_ROW_WIDE="first_row_wide.template" +# For these sections use an alternate first row +FIRST_ROW_ALT_SECTIONS=("upper" "action") +FIRST_ROW_ALT="first_row_alt.template" +FIRST_ROW_ALT_WIDE="first_row_alt_wide.template" +# Additional outlines +OUTLINES="outlines.template" +OUTLINES_WIDE="outlines_wide.template" +# Additionnal views +VIEWS="views.template" +VIEWS_WIDE="views_wide.template" +# Additionnal buttons entries +BUTTONS="buttons.template" +BUTTONS_WIDE="buttons_wide.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=46 +HEIGHT_RESIZE_WIDE=37 +# A list of special keys that should not be resized +FIXED_HEIGHT_KEYS=("small" "unassigned") +======= # Additional outlines OUTLINES="outlines.template" # Additionnal buttons entries @@ -24,6 +47,7 @@ HEIGHT_RESIZE="42" HEIGHT_RESIZE_WIDE="37" # A list of special keys that should not be resized FIXED_HEIGHT_KEYS="term_small unassigned" +>>>>>>> 4c0b48b9fc39716806b1a960c6a8c1410bdf9cbe ########################################################################################## @@ -35,13 +59,44 @@ function add_outline { file=$1 echo " add_outline()..." cat /dev/null > $TERMINAL_DIR/$file.tmp +<<<<<<< HEAD + echo "$file" | grep -q "wide" + if [ $? -eq 0 ]; then + TEMPLATE=$OUTLINES_WIDE + else + TEMPLATE=$OUTLINES + fi + + IFS='' + while read line; do + echo "$line" | grep -q -E "^outlines:$" +======= IFS='' while read line; do echo $line | grep -q -E "^outlines:$" +>>>>>>> 4c0b48b9fc39716806b1a960c6a8c1410bdf9cbe if [ $? -eq 0 ]; then # begin outline section echo " Found outline header, adding datas..." echo "$line" >> $TERMINAL_DIR/$file.tmp +<<<<<<< HEAD + cat $TEMPLATE >> $TERMINAL_DIR/$file.tmp + else + echo "$line" | grep -q -e "[ ][ ][ ][ ]spaceline:.*" + if [ $? -eq 0 ]; then + 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 + fi + fi + done < $TERMINAL_DIR/$file.wrk + + rm -f height_resize.sed $TERMINAL_DIR/$file.wrk + mv $TERMINAL_DIR/$file.tmp $TERMINAL_DIR/$file.wrk +======= cat $OUTLINES >> $TERMINAL_DIR/$file.tmp else echo $line | grep -q -e "[ ][ ][ ][ ]spaceline:.*" @@ -57,6 +112,7 @@ function add_outline { file=$1 done < $NORMAL_DIR/$file rm -f height_resize.sed +>>>>>>> 4c0b48b9fc39716806b1a960c6a8c1410bdf9cbe } # @@ -64,16 +120,94 @@ function add_outline { file=$1 # function add_first_row { file=$1 echo " add_first_row()..." +<<<<<<< HEAD + cat /dev/null > $TERMINAL_DIR/$file.tmp + in_section_views=0 + in_alt_section=0 + is_wide=0 + + echo "$file" | grep -q "wide" + if [ $? -eq 0 ]; then + is_wide=1 + TEMPLATE=$FIRST_ROW_WIDE + TEMPLATE_ALT=$FIRST_ROW_ALT_WIDE + VIEWS_BLOCK=$VIEWS_WIDE + else + is_wide=0 + TEMPLATE=$FIRST_ROW + TEMPLATE_ALT=$FIRST_ROW_ALT + VIEWS_BLOCK=$VIEWS + fi + + IFS='' + while read line; do + echo "$line" | grep -q -E "^views:$" +======= cat /dev/null > $TERMINAL_DIR/$file.tmp1 in_section_views=0 IFS='' while read line; do echo $line | grep -q -E "^views:$" +>>>>>>> 4c0b48b9fc39716806b1a960c6a8c1410bdf9cbe if [ $? -eq 0 ]; then # begin views section echo " Found views header, looking for individual layouts..." in_section_views=1 +<<<<<<< HEAD + echo "$line" >> $TERMINAL_DIR/$file.tmp + else + echo "$line" | grep -q -E "^[ ][ ][ ][ ][a-z]*:$" + if [ $? -eq 0 ] && [ $in_section_views -eq 1 ]; then + echo -n " Found layout subsection ($line), adding" + for section_name in "$FIRST_ROW_ALT_SECTIONS"; do + echo "$line" | grep -q $section_name + if [ $? -eq 0 ]; then + # add alternale first row + echo -n " alternate" + echo "$line" >> $TERMINAL_DIR/$file.tmp + if [ $is_wide -eq 1 ]; then + echo " wide..." + cat $TEMPLATE_ALT >> $TERMINAL_DIR/$file.tmp + else + echo " short..." + cat $TEMPLATE_ALT >> $TERMINAL_DIR/$file.tmp + fi + else + echo -n " normal" + echo "$line" >> $TERMINAL_DIR/$file.tmp + if [ $is_wide -eq 1 ]; then + echo " wide..." + cat $TEMPLATE >> $TERMINAL_DIR/$file.tmp + else + echo " short.." + cat $TEMPLATE >> $TERMINAL_DIR/$file.tmp + fi + fi + done + else + echo "$line" | grep -q -E "^buttons:$" + if [ $? -eq 0 ]; then + # end of vews section, add terminal specific views bloc + length=`wc -l $TERMINAL_DIR/$file.tmp | awk '{print $1}'` + length=`expr $length - 1` + head -n $length $TERMINAL_DIR/$file.tmp > $TERMINAL_DIR/$file.tmp.short + rm -f $TERMINAL_DIR/$file.tmp + mv $TERMINAL_DIR/$file.tmp.short $TERMINAL_DIR/$file.tmp + in_section_views=0 + echo " Adding views block..." + cat $VIEWS_BLOCK >> $TERMINAL_DIR/$file.tmp + echo " " >> $TERMINAL_DIR/$file.tmp + fi + # just a normal line + echo "$line" >> $TERMINAL_DIR/$file.tmp + fi + fi + done < $TERMINAL_DIR/$file.wrk + + rm -f $TERMINAL_DIR/$file.wrk + mv $TERMINAL_DIR/$file.tmp $TERMINAL_DIR/$file.wrk +======= echo "$line" >> $TERMINAL_DIR/$file.tmp1 else echo $line | grep -q -E "^[ ][ ][ ][ ][a-z]*:$" @@ -93,10 +227,46 @@ function add_first_row { file=$1 done < $TERMINAL_DIR/$file mv $TERMINAL_DIR/$file.tmp1 $TERMINAL_DIR/$file +>>>>>>> 4c0b48b9fc39716806b1a960c6a8c1410bdf9cbe } function add_buttons { file=$1 echo " add_buttons()..." +<<<<<<< HEAD + cat /dev/null > $TERMINAL_DIR/$file.tmp + in_buttons_views=0 + + echo "$file" | grep -q "wide" + if [ $? -eq 0 ]; then + TEMPLATE=$BUTTONS_WIDE + else + TEMPLATE=$BUTTONS + fi + + IFS='' + while read line; do + echo "$line" | grep -q -E "^buttons:$" + if [ $? -eq 0 ]; then + # begin views section + echo " Found buttons header, adding datas..." + echo "$line" >> $TERMINAL_DIR/$file.tmp + cat $TEMPLATE >> $TERMINAL_DIR/$file.tmp + else + # a normal line, just append it to the destination file + echo "$line" >> $TERMINAL_DIR/$file.tmp + fi + done < $TERMINAL_DIR/$file.wrk + + rm -f $TERMINAL_DIR/$file.wrk + mv $TERMINAL_DIR/$file.tmp $TERMINAL_DIR/$file.wrk +} + +function resize_keys { file=$1 + echo " resize_keys().." + cat /dev/null > $TERMINAL_DIR/$file.tmp + + echo "$file" | grep -q "wide" +======= cat /dev/null > $TERMINAL_DIR/$file.tmp1 in_buttons_views=0 @@ -122,16 +292,36 @@ function resize_keys { file=$1 cat /dev/null > $TERMINAL_DIR/$file.tmp1 echo "$file" | grep -q wide +>>>>>>> 4c0b48b9fc39716806b1a960c6a8c1410bdf9cbe 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 +<<<<<<< HEAD + echo "s/height: [0-9]*/height: $HEIGHT_RESIZE/" > height_resize.sed +======= echo "s/height: [0-9]*/height: $HEIGHT_RESIZE/" > height_resize.sed +>>>>>>> 4c0b48b9fc39716806b1a960c6a8c1410bdf9cbe fi IFS='' while read line; do +<<<<<<< HEAD + echo "$line" | grep -q "height: " + if [ $? -eq 0 ]; then + # this is a key definition + for k in "$FIXED_HEIGHT_KEYS"; do + echo "$line" | grep -q "$k" + if [ $? -eq 0 ]; then + # don't resize + echo " Found a fixed key ($k)..." + echo "$line" >> $TERMINAL_DIR/$file.tmp + continue + else + echo " Found a normal key, resizing..." + echo "$line" | sed -f height_resize.sed >> $TERMINAL_DIR/$file.tmp +======= echo "$line" | grep -q "height" if [ $? -eq 0 ]; then @@ -144,16 +334,67 @@ function resize_keys { file=$1 continue else echo "$line" >> $TERMINAL_DIR/$file.tmp1 +>>>>>>> 4c0b48b9fc39716806b1a960c6a8c1410bdf9cbe fi done else # a normal line, just append it to the destination file +<<<<<<< HEAD + echo "$line" >> $TERMINAL_DIR/$file.tmp + fi + done < $TERMINAL_DIR/$file.wrk + + rm -f height_resize.sed $TERMINAL_DIR/$file.wrk + mv $TERMINAL_DIR/$file.tmp $TERMINAL_DIR/$file.wrk +} + +# +# function add_keys +# +function add_keys { file=$1 +#show_actions + echo " add_keys().." + cat /dev/null > $TERMINAL_DIR/$file.tmp + + IFS='' + while read line; do + echo "$line" | grep -q -E "^[ ].*-.*Return\"$" + if [ $? -eq 0 ]; then + # this is the last line of a layout, add the action key + echo " Found the last layout line, adding keys..." + echo "$line" | sed 's/Return/show_actions Return/' >> $TERMINAL_DIR/$file.tmp + else + # a normal line, just append it to the destination file + echo "$line" | grep -q -E "[.]" + if [ $? -eq 0 ]; then + # replace . by the period keywoard + echo " Found a dot..." + echo "$line" | sed 's/ [.] / period /' >> $TERMINAL_DIR/$file.tmp + else + echo "$line" >> $TERMINAL_DIR/$file.tmp + fi + fi + done < $TERMINAL_DIR/$file.wrk + + rm -f $TERMINAL_DIR/$file.wrk + mv $TERMINAL_DIR/$file.tmp $TERMINAL_DIR/$file.wrk +} + +# +# escape special caracters in yaml file +# +function escape { file=$1 + cat $TERMINAL_DIR/$file.wrk | sed -f escape.sed > $TERMINAL_DIR/$file.tmp + rm -f $TERMINAL_DIR/$file.wrk + mv $TERMINAL_DIR/$file.tmp $TERMINAL_DIR/$file.wrk +======= echo "$line" >> $TERMINAL_DIR/$file.tmp1 fi done < $TERMINAL_DIR/$file #rm -f height_resize.sed mv $TERMINAL_DIR/$file.tmp1 $TERMINAL_DIR/$file +>>>>>>> 4c0b48b9fc39716806b1a960c6a8c1410bdf9cbe } # @@ -162,6 +403,20 @@ function resize_keys { file=$1 function transform { file=$1 echo "transform($file)..." +<<<<<<< HEAD +# cp $NORMAL_DIR/$file $TERMINAL_DIR/$file.wrk + cat $NORMAL_DIR/$file | sed -f pre_escape.sed > $TERMINAL_DIR/$file.wrk + add_outline "$file" + add_first_row "$file" + add_buttons "$file" + resize_keys "$file" + add_keys "$file" + escape "$file" + echo " " + + rm -f $TERMINAL_DIR/$file + mv -f $TERMINAL_DIR/$file.wrk $TERMINAL_DIR/$file +======= add_outline "$file" add_first_row "$file.tmp" add_buttons "$file" @@ -169,6 +424,7 @@ function transform { file=$1 echo " " mv -f $TERMINAL_DIR/$file $TERMINAL_DIR/$1 +>>>>>>> 4c0b48b9fc39716806b1a960c6a8c1410bdf9cbe } #