Browse Source

Re-write with better style

No unnecessary globals, just one temp, main(), mkhtml() and mkcss()...
Alois Mahdal 6 years ago
parent
commit
10f52005e7
1 changed files with 26 additions and 22 deletions
  1. 26
    22
      dotfiles/config/Xlib/colorscheme/mkdemo

+ 26
- 22
dotfiles/config/Xlib/colorscheme/mkdemo View File

@@ -4,22 +4,18 @@
4 4
 
5 5
 shellfu import pretty
6 6
 
7
-CSDEMO_FNAME=$1
8
-CSDEMO_BG="$(mktemp)"
9
-CSDEMO_FG="$(mktemp)"
10
-
11 7
 
12 8
 xd2html() {
13 9
     local name color
14
-    while read line;
10
+    while read -r line;
15 11
     do
16 12
         name="${line%%:*}"
17 13
         color="${line##*:}"
18 14
         test -n "$name"  || continue
19 15
         test -n "$color" || continue
20 16
         debug -v name color
21
-        test "$name" == "URxvt.background" && echo "$color" > "$CSDEMO_BG"
22
-        test "$name" == "URxvt.foreground" && echo "$color" > "$CSDEMO_FG"
17
+        test "$name" == "URxvt.background" && echo "$color" > "$Tmp/bg"
18
+        test "$name" == "URxvt.foreground" && echo "$color" > "$Tmp/fg"
23 19
         echos "        <p style='color: $color'>$name</p>"
24 20
     done
25 21
 }
@@ -28,8 +24,8 @@ htmlhead() {
28 24
     echos "<!doctype html>"
29 25
     echos "<html>"
30 26
     echos "    <head>"
31
-    echos "        <title>$CSDEMO_FNAME</title>"
32
-    echos "        <link rel='stylesheet' href='$CSDEMO_FNAME.css'>"
27
+    echos "        <title>$File</title>"
28
+    echos "        <link rel='stylesheet' href='$File.css'>"
33 29
     echos "    </head>"
34 30
     echos "    <body>"
35 31
 }
@@ -39,24 +35,32 @@ htmltail() {
39 35
     echos "</html>"
40 36
 }
41 37
 
42
-css() {
38
+mkcss() {
43 39
     echos "body {"
44 40
     echos "    font-size: xx-large;"
45 41
     echos "    font-family: monospace;"
46
-    echos "    color: $(cat "$CSDEMO_FG");"
47
-    echos "    background-color: $(cat "$CSDEMO_BG");"
42
+    echos "    color: $(cat "$Tmp/fg");"
43
+    echos "    background-color: $(cat "$Tmp/bg");"
48 44
     echos "}"
49 45
 }
50 46
 
51
-test -n "$CSDEMO_FNAME" || mkusage "scheme.Xresources"
47
+mkhtml() {
48
+    htmlhead
49
+    <"$File" xd2html
50
+    htmltail
51
+}
52 52
 
53
-htmlhead                 >  "$CSDEMO_FNAME.html"
54
-<"$CSDEMO_FNAME" xd2html >> "$CSDEMO_FNAME.html"
55
-htmltail                 >> "$CSDEMO_FNAME.html"
56
-debug -f "$CSDEMO_FG" "$CSDEMO_BG"
57
-test -s "$CSDEMO_FG" || die "failed to parse URxvt.foreground"
58
-test -s "$CSDEMO_BG" || die "failed to parse URxvt.background"
59
-css                         >  "$CSDEMO_FNAME.css"
53
+main() {
54
+    local File=$1
55
+    local Tmp
56
+    Tmp=$(mktemp -dt mkdemo.XXXXXXXX)
57
+    test -n "$File" || mkusage "scheme.Xresources"
58
+    mkhtml > "$File.html"
59
+    debug -f "$Tmp/fg" "$Tmp/bg"
60
+    test -s "$Tmp/fg" || die "failed to parse URxvt.foreground"
61
+    test -s "$Tmp/bg" || die "failed to parse URxvt.background"
62
+    mkcss >  "$File.css"
63
+    rm -r "$Tmp"
64
+}
60 65
 
61
-rm "$CSDEMO_BG"
62
-rm "$CSDEMO_FG"
66
+main "$@"