Check-in by ben on 2025-04-11 21:05:49

 Simplify periodic table display when multiple elements are
 selected. Blur out the de-selected symbols by replacing letters
 with . characters. Bump version to 3

 INSERTED    DELETED
       23         59 periodic.awk
       23         59 TOTAL over 1 changed file

Index: periodic.awk
==================================================================
--- periodic.awk
+++ periodic.awk
@@ -1,6 +1,6 @@
-# periodic.awk version 2 by Ben Collver
+# periodic.awk version 3 by Ben Collver
#
# Generate static gopher content for the periodic table of elements.
#
# Edit gopher_dir, gopher_host, and gopher_port in function main()
#
@@ -757,12 +757,12 @@

    close(f)
    return
}

-function print_table(f,    col, cols, element, i, key, \
-    row, rows, sel, sel_l, sel_r, symbol)
+function print_table(f,    col, cols, element, key, row, rows, sel, \
+    symbol)
{
    cols = table["cols"]
    rows = table["rows"]

    for (row = 1; row <= rows; row++) {
@@ -769,66 +769,26 @@
        for (col = 1; col <= cols; col++) {
            key = row "_" col
            element = table[key]
            sel = selection[key]
            key = element "_Symbol"
-            symbol = sprintf("%-2s", elements[key])
-            if (sel) {
-                sub(/ /, "_", symbol)
-            }
-            if (col == 1) {
-                key = row "_" (col + 1)
-                sel_r = selection[key]
-                if (sel) {
-                    if (sel_r) {
-                        printf "[%s", symbol >>f
-                    } else {
-                        printf "[%s]", symbol >>f
-                    }
-                } else {
-                    printf " %s", symbol >>f
-                }
-            } else if (col == cols) {
-                key = row "_" (col - 1)
-                sel_l = selection[key]
-                if (sel) {
-                    if (sel_l) {
-                        printf "_%s]", symbol >>f
-                    } else {
-                        printf "[%s]", symbol >>f
-                    }
-                } else {
-                    if (sel_l) {
-                        printf "%s", symbol >>f
-                    } else {
-                        printf " %s", symbol >>f
-                    }
-                }
-            } else {
-                key = row "_" (col - 1)
-                sel_l = selection[key]
-                key = row "_" (col + 1)
-                sel_r = selection[key]
-                if (sel) {
-                    if (sel_l) {
-                        if (sel_r) {
-                            printf "_%s", symbol >>f
-                        } else {
-                            printf "_%s]", symbol >>f
-                        }
-                    } else {
-                        if (sel_r) {
-                            printf "[%s", symbol >>f
-                        } else {
-                            printf "[%s]", symbol >>f
-                        }
-                    }
-                } else {
-                    if (sel_l) {
-                        printf "%s", symbol >>f
-                    } else {
-                        printf " %s", symbol >>f
+            symbol = elements[key]
+            if (selected > 1) {
+                if (!sel) {
+                    gsub(/./, ".", symbol)
+                }
+                printf " %-2s", symbol >>f
+            } else {
+                if (sel) {
+                    printf "[%-2s]", symbol >>f
+                } else {
+                    key = row "_" (col - 1)
+                    sel = selection[key]
+                    if (sel) {
+                        printf "%-2s", symbol >>f
+                    } else {
+                        printf " %-2s", symbol >>f
                    }
                }
            }
        }
        printf "\n" >>f
@@ -873,16 +833,20 @@

function select_atom(element,     col, key, row) {
    col = table_col[element]
    row = table_row[element]
    key = row "_" col
+    if (selection[key] != 1) {
+        selected++
+    }
    selection[key] = 1
    return
}

function select_clear() {
    delete selection
+    selected = 0
    return
}

function select_family(family_id,    i, key, len) {
    len = elements["length"]