Merge pull request 'gen-keybinds: a C locale lost every section header — match the dash as a literal' (#55) from fix/gen-keybinds-locale-safe-sections into main
This commit was merged in pull request #55.
This commit is contained in:
commit
1cc4b76479
2 files changed
+30
-10
No files matched your search
+20
-10
@@ -42,17 +42,27 @@ gen() {
|
|||||||
echo "> GENERATED by \`scripts/gen-keybinds.sh\` from \`$(basename "$KBD")\` — do not edit by hand."
|
echo "> GENERATED by \`scripts/gen-keybinds.sh\` from \`$(basename "$KBD")\` — do not edit by hand."
|
||||||
echo
|
echo
|
||||||
awk '
|
awk '
|
||||||
# section header: // ─── Name ───
|
# Section marker: a comment decorated with box-drawing dashes on both sides,
|
||||||
/^[[:space:]]*\/\/[[:space:]]*─+ (.+) ─+[[:space:]]*$/ {
|
# `// ─── Name ───`. The dash is matched as a LITERAL and removed with gsub — never
|
||||||
|
# with a quantifier on the multibyte character. Under LC_ALL=C (cron, systemd units,
|
||||||
|
# agent shells) gawk works byte-wise, `─+` then means "the last byte of ─, repeated",
|
||||||
|
# and every header vanishes while the script still exits 0. Plain comments stay
|
||||||
|
# comments: only a dash-decorated one opens a section.
|
||||||
|
/^[[:space:]]*\/\/[[:space:]]*─/ {
|
||||||
s = $0
|
s = $0
|
||||||
sub(/^[[:space:]]*\/\/[[:space:]]*─+ /, "", s)
|
sub(/^[[:space:]]*\/\/[[:space:]]*/, "", s)
|
||||||
sub(/ ─+[[:space:]]*$/, "", s)
|
sub(/[[:space:]]+$/, "", s)
|
||||||
if (in_table) print ""
|
if (s ~ /─ .*─/) {
|
||||||
print "## " s
|
gsub(/─/, "", s)
|
||||||
print ""
|
gsub(/[[:space:]]+/, " ", s)
|
||||||
print "| Key | Action |"
|
sub(/^ /, "", s); sub(/ $/, "", s)
|
||||||
print "|-----|--------|"
|
if (in_table) print ""
|
||||||
in_table = 1
|
print "## " s
|
||||||
|
print ""
|
||||||
|
print "| Key | Action |"
|
||||||
|
print "|-----|--------|"
|
||||||
|
in_table = 1
|
||||||
|
}
|
||||||
next
|
next
|
||||||
}
|
}
|
||||||
# bind line: KEY [flags] [hotkey-overlay-title="..."] { action; }
|
# bind line: KEY [flags] [hotkey-overlay-title="..."] { action; }
|
||||||
|
|||||||
@@ -48,6 +48,16 @@ teardown() {
|
|||||||
[[ "$output" != *"a plain comment"* ]]
|
[[ "$output" != *"a plain comment"* ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "section headers survive a C locale, where awk reads bytes instead of characters" {
|
||||||
|
# Cron, systemd units and agent shells get LC_ALL=C while Frank's terminal does not.
|
||||||
|
# A matcher that puts a quantifier on a multibyte character then loses EVERY section
|
||||||
|
# header and prints a sheet with no sections at all — silently, exit status 0.
|
||||||
|
run env LC_ALL=C "$GEN" "$TMP/keybinds.kdl"
|
||||||
|
[[ "$output" == *"## Applications"* ]]
|
||||||
|
[[ "$output" == *"## Screenshots"* ]]
|
||||||
|
[[ "$output" != *"a plain comment"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
@test "row count matches bind count" {
|
@test "row count matches bind count" {
|
||||||
run "$GEN" "$TMP/keybinds.kdl"
|
run "$GEN" "$TMP/keybinds.kdl"
|
||||||
local rows
|
local rows
|
||||||
|
|||||||
Reference in new issue
Block a user