aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--DEPENDENCIES11
-rwxr-xr-xsrc/parse.py179
-rwxr-xr-xsrc/splashtool199
4 files changed, 194 insertions, 198 deletions
diff --git a/.gitignore b/.gitignore
index 46e6d89..ec8994b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,10 +1,11 @@
_/
bin/
+obj/
__pycache__/
\#*\#
.*
!.git*
-*
+*~
*.bak
*.swp
*.swo
diff --git a/DEPENDENCIES b/DEPENDENCIES
index 1630c35..31a66bd 100644
--- a/DEPENDENCIES
+++ b/DEPENDENCIES
@@ -2,13 +2,12 @@ RUNTIME:
gzip: decompress fonts
nafe: read font files
kbd: default font
- sh: 1 source file is written in shell script
- python3: 1 source files are written in Python 3
- java-runtime: 1 source file is written in Java
+ bash
+ python3
+ java-runtime
awk
grep
- bash
-BUILDTIME:
- java-environment: 1 source file is written in Java
+BUILD:
+ java-environment
diff --git a/src/parse.py b/src/parse.py
deleted file mode 100755
index e64f52b..0000000
--- a/src/parse.py
+++ /dev/null
@@ -1,179 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-# splashtool – A simple tool for creating SYSLINUX splashes without fuss
-#
-# Copyright © 2013, 2014 Mattias Andrée (maandree@member.fsf.org)
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-import os
-import sys
-
-
-DEBUG = False
-
-
-timeout = 0
-title = ''
-background = 'splash.png'
-font = '/usr/share/kbd/consolefonts/default8x16.psfu.gz'
-helptext = ''
-labels = ''
-width = 78
-margin = 3
-rows = 12
-vshift = 0
-timeoutrow = 18
-tabmsgrow = 18
-helpmsgrow = 22
-helpmsgendrow = 29
-colour_border = '#ff808080#00000000'
-colour_title = '#ffffffff#00000000'
-colour_sel = '#ff808080#ffd0a290'
-colour_unsel = '#ffffffff#00000000'
-colour_help = '#ffffffff#00000000'
-colour_timeout_msg = '#ffffff00#00000000'
-colour_timeout = '#ffffff00#00000000'
-colour_tabmsg = '#ffffff00#00000000'
-
-
-texthelp = False
-while True:
- try:
- line = input()
- orig = line
- while ' ' in line:
- line = line.replace(' ', ' ')
- line = line.split(' ')
- line[0] = line[0].lower()
- if (line[0] == 'endtext') and (len(line) == 1):
- texthelp = False
- elif texthelp:
- helptext += orig + '\n'
- elif line[0] == 'text':
- texthelp = True
- elif line[0] == 'timeout':
- timeout = int(line[1])
- elif line[0] == 'menu':
- line[1] = line[1].lower()
- if line[1] == 'title': title = line[2]
- elif line[1] == 'background': background = line[2]
- elif line[1] == 'font': font = line[2]
- elif line[1] == 'width': width = int(line[2])
- elif line[1] == 'height': height = int(line[2])
- elif line[1] == 'margin': margin = int(line[2])
- elif line[1] == 'rows': rows = int(line[2])
- elif line[1] == 'vshift': vshift = int(line[2])
- elif line[1] == 'timeoutrow': timeoutrow = int(line[2])
- elif line[1] == 'tabmsgrow': tabmsgrow = int(line[2])
- elif line[1] == 'helpmsgrow': helpmsgrow = int(line[2])
- elif line[1] == 'helpmsgendrow': helpmsgendrow = int(line[2])
- elif line[1] == 'color':
- colour = line[4] + line[5]
- if line[2] == 'border':
- colour_border = colour
- elif line[2] == 'title':
- colour_title = colour
- elif line[2] == 'sel':
- colour_sel = colour
- elif line[2] == 'unsel':
- colour_unsel = colour
- elif line[2] == 'help':
- colour_help = colour
- elif line[2] == 'timeout_msg':
- colour_timeout_msg = colour
- elif line[2] == 'timeout':
- colour_timeout = colour
- elif line[2] == 'tabmag':
- colour_tabmsg = colour
- elif line[1] == 'label':
- line = orig[orig.lower().find('label') + 6:]
- while line.startswith(' '):
- line = line[1:]
- labels += line + '\n'
- except:
- break
-
-
-if DEBUG:
- colour_border = ''
- colour_title = ''
- colour_sel = ''
- colour_unsel = ''
- colour_help = ''
- colour_timeout_msg = ''
- colour_timeout = ''
- colour_tabmsg = ''
-
-
-border = colour_border
-
-labels = (labels + '\n' * rows).split('\n')[:rows]
-labels = [(' ' + x + ' ' * 68)[:68] + '\033\033' for x in labels]
-labels = ['\033' + (colour_sel if x is labels[0] else colour_unsel) + '\033' + x for x in labels]
-
-title = (' ' * ((68 - len(title)) // 2) + title + ' ' * 68)[:68]
-title = '\033' + colour_title + '\033' + title + '\033\033'
-
-helpmsgendrow -= vshift
-helptext = (helptext + '\n' * (helpmsgendrow - helpmsgrow + 1)).split('\n')[: helpmsgendrow - helpmsgrow + 1]
-helptext = ['\033' + colour_help + '\033' + (' ' * margin + x + ' ' * width)[:width] + '\033\033' for x in helptext]
-helptext = '\n'.join(helptext)
-
-menumargin = (width - 70) // 2
-text = '\n' * vshift + ' ' * menumargin + '\033' + border + '\033┌' + '─' * 68 + '┐\033\033\n'
-text += ' ' * menumargin + '\033' + border + '\033│\033\033' + title + '\033' + border + '\033│\033\033\n'
-text += ' ' * menumargin + '\033' + border + '\033├' + '─' * 68 + '┤\033\033\n'
-for label in labels:
- text += ' ' * menumargin + '\033' + border + '\033│\033\033' + label + '\033' + border + '\033│\033\033\n'
-text += ' ' * menumargin + '\033' + border + '\033└' + '─' * 68 + '┘\033\033\n'
-
-more = []
-
-if timeout > 0:
- timeoutmsg = 'Automatic boot in %i seconds' % (timeout // 10)
- timeoutmsg = (width - len(timeoutmsg)) // 2
- timeoutmsg = ' ' * timeoutmsg + '\033%s\033Automatic boot in \033%s\033%i\033%s\033 seconds...\033\033'
- timeoutmsg %= (colour_timeout_msg, colour_timeout, timeout // 10, colour_timeout_msg)
- more.append((timeoutrow * 10 + 0, timeoutmsg))
-tabmsg = 'Press [Tab] to edit options'
-tabmsg = ' ' * ((width - len(tabmsg)) // 2) + tabmsg
-more.append((tabmsgrow * 10 + 1, '\033%s\033%s\033\033' % (colour_tabmsg, tabmsg)))
-more.append((helpmsgrow * 10 + 2, helptext))
-
-more = [(x[0] // 10, x[1]) for x in sorted(more, key = lambda x : x[0])]
-line = len(text.split('\n')) - vshift
-
-for seg in more:
- if line <= seg[0]:
- text += '\n' * (seg[0] - line) + seg[1] + '\n'
- line = seg[0] + len(seg[1].split('\n'))
-
-text = '\n'.join((text + '\n' * 30).split('\n')[:30])
-
-print(background)
-print(width)
-print(29)
-if DEBUG:
- text = text.replace('\033', '')
-print(text, end = '')
-sys.stdout.flush()
-
-if not DEBUG:
- if font.lower().endswith('.gz'):
- os.system('bash -c "psf2txt <(gunzip < \'%s\') /dev/stderr 2>&1 >/dev/null | grep -v ++"' % font.replace('\'', '\'\\\'\''))
- else:
- os.system('bash -c "psf2txt \'%s\' /dev/stderr 2>&1 >/dev/null | grep -v ++"' % font.replace('\'', '\'\\\'\''))
-
diff --git a/src/splashtool b/src/splashtool
index 8443f46..7376e50 100755
--- a/src/splashtool
+++ b/src/splashtool
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
#
# splashtool – A simple tool for creating SYSLINUX splashes without fuss
#
@@ -22,18 +22,193 @@ in="$(realpath "$1")"
out="$(realpath "$2")"
d="$(dirname "$(realpath "$0")")"
-# Remove all information we do not need.
-trim ()
+cd "$(dirname "$1")"
+
+
+# Get the description text do display.
+get_text ()
{
- sed -e 's/\t/ /g' | sed -e '/^[ \t]*\(#\|$\)/d' -e 's/ #.*$//' -e 's/^ *//' -e 's/ *$//' |
- awk 'BEGIN { text = 0; }
- { t=tolower($1);
- if (t=="text") text+=1;
- if (t=="timeout" || t=="menu" || t=="font" || text==1) print $LINE;
- if (t=="endtext") text+=1;
- }'
+ awk 'BEGIN { text = 0; }
+ { t=tolower($1);
+ if (t=="endtext") text+=1;
+ if (text==1) print $LINE;
+ if (t=="text") text+=1;
+ }'
}
-cd "$(dirname "$1")"
-trim < "$in" | "$d"/parse.py | java -cp "$d" Assemble "$out" "$3"
+# Default values.
+default_data ()
+{
+ cat <<EOF
+TIMEOUT 0
+MENU TITLE
+MENU BACKGROUND splash.png
+MENU FONT /usr/share/kbd/consolefonts/default8x16.psfu.gz
+MENU WIDTH 78
+MENU MARGIN 3
+MENU ROWS 12
+MENU VSHIFT 0
+MENU TIMEOUTROW 18
+MENU TABMSGROW 18
+MENU HELPMSGROW 22
+MENU HELPMSGENDROW 29
+MENU COLOR border _ #ff808080 #00000000 _
+MENU COLOR title _ #ffffffff #00000000 _
+MENU COLOR sel _ #ff808080 #ffd0a290 _
+MENU COLOR unsel _ #ffffffff #00000000 _
+MENU COLOR help _ #ffffffff #00000000 _
+MENU COLOR timeout_msg _ #ffffff00 #00000000 _
+MENU COLOR timeout _ #ffffff00 #00000000 _
+MENU COLOR tabmsg _ #ffffff00 #00000000 _
+EOF
+}
+
+# Select variable
+sel ()
+{
+ prefix="$(echo "${data}" | grep -io "^${1} " | sed 1q)"
+ echo "${data}" | grep -i "^${1} " | sed -e "s/^${prefix}//;q" | sed -e 's/^ *//'
+}
+
+# Select colour variable
+csel ()
+{
+ if [ -z "${debug}" ]; then
+ sel "${1}" | sed -e 's/^\([^ ][^ ]*\) *\([^ ][^ ]*\) *\([^ ][^ ]*\).*/\2\3/g'
+ else
+ sel "${1}" | sed -e 's/^\([^ ][^ ]*\).*/\1/g'
+ fi
+}
+
+# Truncate the number of lines, and fill in missing lines
+ltrunc ()
+{
+ (cat ; awk "BEGIN { for (i=0; i<${1}; i++) print \" \"; }") | sed ${1}q
+}
+
+# Truncate the number of columns, and fill in missing columns
+ctrunc ()
+{
+ spaces="$(printf "%${1}s" "")"
+ sed -e 's/$/'"${spaces}"'/' | grep -Po "^$(echo "${spaces}" | sed -e 'y/ /./')"
+}
+
+# Add columns the left side
+padl ()
+{
+ while read -r l; do printf "%${1}s%s\n" "" "${l}"; done
+}
+
+# Colourise text
+cset ()
+{
+ sed -e 's/^/\x1b'"$(csel "${1}")"'\x1b/' -e 's/$/\x1b\x1b/'
+}
+
+data="$(sed -e 's/\t/ /g' < "$in" | sed -e '/^ *\(#\|$\)/d' -e 's/ # .*$//' -e 's/^ *//' -e 's/ *$//')"
+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_/')"
+labels="$(echo "${data}" | tac | grep -i '^label ' | sed -e 's/^..... //')"
+
+export data
+
+export font="$(sel font)"
+export width="$(sel width)"
+export vshift="$(sel vshift)"
+export helpmsgendrow="$(( $(sel helpmsgendrow) - ${vshift} ))"
+export helpmsgrow="$(sel helpmsgrow)"
+export menumargin=$(( (${width} - 70) / 2 ))
+export border="$(csel color_border)"
+
+(
+echo "$(sel background)"
+echo "${width}"
+echo "29"
+
+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)"
+
+title="$(echo "${title}" | padl $(( (68 - $(echo -n "${title}" | wc -c)) / 2 )) | ctrunc 68 | cset color_title)"
+
+helptext="$(echo "${helptext}" | ltrunc $(( ${helpmsgendrow} - ${helpmsgrow} + 1 )) | padl $(sel margin))"
+helptext="$(echo "${helptext}" | ctrunc "${width}" | cset color_help)"
+
+text_ ()
+{
+ line="$(printf "%68s" "" | sed -e 's/ /─/g')"
+ echo "┌${line}┐"
+ echo $'│\e\e'"${title}"$'\e'"${border}"$'\e│'
+ echo "├${line}┤"
+ sed -e 's/^/│\x1b\x1b/' -e 's/$/\x1b'"${border}"'\x1b│/'
+ echo "└${line}┘"
+}
+
+add_more ()
+{
+ echo "${more}" ; echo "${1}" | sed -e "s/^/"$(( $(sel ${2}) * 10 + ${3} ))" /"
+}
+
+text="$(echo "${labels}" | text_ | cset color_border | padl ${menumargin})"
+text="$(awk "BEGIN { for (i=0; i<${vshift}; i++) print \" \"; }" ; echo "${text}")"
+
+export more=""
+
+if [ ! "$(sel timeout)" = 0 ]; then
+ timeout=$(( $(sel timeout) / 10 ))
+ timeoutmsg_="Automatic boot in ${timeout} seconds"
+ timeoutmsg_=$(( (${width} - $(echo -n "${timeoutmsg_}" | wc -c)) / 2 ))
+ timout=$'\e'"$(csel color_timeout)"$'\e'"${timeout}"$'\e'"$(csel color_timeout_msg)"$'\e'
+ timeoutmsg="Automatic boot in ${timeout} seconds"
+ timeoutmsg="$(echo "${timeoutmsg}" | cset color_timeout_msg | padl ${timeoutmsg_})"
+ export more="$(add_more "${timeoutmsg}" timeoutrow 0)"
+fi
+
+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)"
+export more="$(add_more "${helptext}" helpmsgrow 2)"
+more="$(echo "${more}" | sed -e 1d | sort -n -s -k 1,1)"
+
+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 ))
+ 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} + 1 ))
+ fi
+ last=${current}
+ done
+ echo "${text}"
+}
+text="$(echo "${more}" | segs | ltrunc 30)"
+
+if [ -z "${debug}" ]; then
+ echo "${text}"
+ (
+ if echo "${font}" | grep -i '.gz$' 2>/dev/null >/dev/null; then
+ psf2txt <(gunzip < "${font}") /dev/stderr
+ else
+ psf2txt "${font}" /dev/stderr
+ fi
+ ) 2>&1 >/dev/null | grep -v ++
+else
+ echo "${text}" | sed -e 's/\x1b\([^\x1b]*\)\x1b/\x1b[\1m/g'
+fi
+
+) # | java -cp "$d" Assemble "$out" "$3"