diff options
| author | Mattias Andrée <maandree@operamail.com> | 2014-11-01 16:32:26 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@operamail.com> | 2014-11-01 16:32:26 +0100 |
| commit | 5b5ca2bcff6819585f23969b4ce477b4a74c76ef (patch) | |
| tree | 9e6a6924d9a911e70d8192315fef74e495d8e705 /src | |
| parent | m bug (diff) | |
| download | splashtool-5b5ca2bcff6819585f23969b4ce477b4a74c76ef.tar.gz splashtool-5b5ca2bcff6819585f23969b4ce477b4a74c76ef.tar.bz2 splashtool-5b5ca2bcff6819585f23969b4ce477b4a74c76ef.tar.xz | |
doc
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src')
| -rwxr-xr-x | src/splashtool | 56 |
1 files changed, 40 insertions, 16 deletions
diff --git a/src/splashtool b/src/splashtool index 2fc1c10..e7f317c 100755 --- a/src/splashtool +++ b/src/splashtool @@ -25,6 +25,7 @@ d="$(dirname "$(realpath "$0")")" cd "$(dirname "$1")" +# Create an images from the generated data. make_image () { if [ -z "${debug}" ]; then @@ -93,7 +94,11 @@ csel () # Truncate the number of lines, and fill in missing lines ltrunc () { - (cat ; awk "BEGIN { for (i=0; i<${1}; i++) print \" \"; }") | sed ${1}q + if [ ${1} = 0 ]; then + cat >/dev/null + else + (cat ; awk "BEGIN { for (i=0; i<${1}; i++) print \" \"; }") | sed ${1}q + fi } # Truncate the number of columns, and fill in missing columns @@ -115,15 +120,21 @@ cset () sed -e 's/^/\x1b'"$(csel "${1}")"'\x1b/' -e 's/$/\x1b\x1b/' } +# Replace horizontal tab space with blank space and trim comments and whitespace. data="$(sed -e 's/\t/ /g' < "$in" | sed -e '/^ *\(#\|$\)/d' -e 's/ # .*$//' -e 's/^ *//' -e 's/ *$//')" +# Get help message for the first menu entry. helptext="$(echo "${data}" | get_text)" -data="$((default_data ; echo "${data}") | grep -Pi '^(timeout|menu|font) ' | tac)" -data="$(echo "${data}" | sed -e 's/^MENU //' -e 's/^COLOR /COLOR_/')" +# Get get information that we will use. +data="$((default_data ; echo "${data}") | grep -Pi '^(timeout|menu|font) ')" +# Format `data` so it can be easily parsed. +data="$(echo "${data}" | tac | sed -e 's/^MENU //' -e 's/^COLOR /COLOR_/')" +# Get menu entry labels. labels="$(echo "${data}" | tac | grep -i '^label ' | sed -e 's/^..... //')" +# Preload some data and make things available to subshells. export data - export font="$(sel font)" +export title="$(sel title)" export width="$(sel width)" export vshift="$(sel vshift)" export helpmsgendrow="$(( $(sel helpmsgendrow) - ${vshift} ))" @@ -131,20 +142,26 @@ export helpmsgrow="$(sel helpmsgrow)" export menumargin=$(( (${width} - 70) / 2 )) export border="$(csel color_border)" +# Make image. ( +# Print background image, screen width (columns), and screen heights (lines) echo "$(sel background)" echo "${width}" echo "29" +# Format menu labels. labels="$(echo "${labels}" | ltrunc "$(sel rows)" | sed -e 's/^/ /' | ctrunc 68)" labels="$(echo "${labels}" | sed -e 1q | cset color_sel ; echo "${labels}" | sed -e 1d | cset color_unsel)" +# Format title. title="$(echo "${title}" | padl $(( (68 - $(echo -n "${title}" | wc -c)) / 2 )) | ctrunc 68 | cset color_title)" +# Format help message. helptext="$(echo "${helptext}" | ltrunc $(( ${helpmsgendrow} - ${helpmsgrow} + 1 )) | padl $(sel margin))" helptext="$(echo "${helptext}" | ctrunc "${width}" | cset color_help)" -text_ () +# Generate the menu. +menu_ () { line="$(printf "%68s" "" | sed -e 's/ /─/g')" echo "┌${line}┐" @@ -154,16 +171,20 @@ text_ () echo "└${line}┘" } +# Add more things to print. add_more () { echo "${more}" ; echo "${1}" | sed -e "s/^/"$(( $(sel ${2}) * 10 + ${3} ))" /" } -text="$(echo "${labels}" | text_ | cset color_border | padl ${menumargin})" +# Add menu. +text="$(echo "${labels}" | menu_ | cset color_border | padl ${menumargin})" text="$(awk "BEGIN { for (i=0; i<${vshift}; i++) print \" \"; }" ; echo "${text}")" +# Addition stuff. export more="" +# Add timeout counter. if [ ! "$(sel timeout)" = 0 ]; then timeout=$(( $(sel timeout) / 10 )) timeoutmsg_="Automatic boot in ${timeout} seconds" @@ -174,31 +195,31 @@ if [ ! "$(sel timeout)" = 0 ]; then export more="$(add_more "${timeoutmsg}" timeoutrow 0)" fi +# Add "Press [Tab] to edit options", not visible if there is a timeout counter. tabmsg="Press [Tab] to edit options" tabmsg="$(echo "${tabmsg}" | padl $(( (${width} - $(echo -n "${tabmsg}" | wc -c)) / 2 )) | cset color_tabmsg)" export more="$(add_more "${tabmsg}" tabmsgrow 1)" +# Add the help message export more="$(add_more "${helptext}" helpmsgrow 2)" + +# Sort (using a stable algorithm) `more` by the items' line indices. more="$(echo "${more}" | sed -e 1d | sort -n -s -k 1,1)" +# Print addition stuff (`more`). export text segs () { line=$(( $(echo "${text}" | wc -l) - $(sel vshift) )) last=0 - mod=0 while read -r seg; do current=$(echo "${seg}" | cut -d ' ' -f 1) index=$(( ${current} / 10 - 1 )) seg="$(echo "${seg}" | sed -e 's/^[^ ]* //')" if [ ${last} = ${current} ]; then - text="$(echo "${text}" ; echo "${seg}")" - line=$(( ${index} + 1 )) - elif (( ${line} <= ${index} )); then - if (( ${line} < ${index} )); then - text="$(echo "${text}" ; echo -n | ltrunc $(( ${index} - ${line} )) ; echo "${seg}")" - else - text="$(echo "${text}" ; echo "${seg}")" - fi + line=index + fi + if (( ${line} <= ${index} )); then + text="$(echo "${text}" ; echo -n | ltrunc $(( ${index} - ${line} )) ; echo "${seg}")" line=$(( ${index} + 1 )) fi last=${current} @@ -207,8 +228,11 @@ segs () } text="$(echo "${more}" | segs | ltrunc 29)" +# Print the image data. if [ -z "${debug}" ]; then + # Print the overlay. echo "${text}" + # Print the font. ( if echo "${font}" | grep -i '.gz$' 2>/dev/null >/dev/null; then psf2txt <(gunzip < "${font}") /dev/stderr @@ -217,8 +241,8 @@ if [ -z "${debug}" ]; then fi ) 2>&1 >/dev/null | grep -v ++ else + # Print the overlay with ANSI colours. echo "${text}" | sed -e 's/\x1b\([^\x1b]*\)\x1b/\x1b[\1m/g' fi - ) | make_image |
