Add ANSI output format

This commit is contained in:
2026-07-06 08:54:57 -05:00
parent b5e8175618
commit 14f5be9ad1
6 changed files with 378 additions and 39 deletions
+87
View File
@@ -187,6 +187,71 @@ HEB 4 7 2 line 1 do not harden your hearts."
"\n" &
" John 8:1-2 (TEST)"
test "plain output can suppress annotation footnotes":
const rows =
"JHN\t8\t1\t0\tparagraph\t0\tJesus spoke.\t" &
"""{"annotations":[{"kind":"crossReference","offset":12,"targetText":"Mt 21:1"}]}""" & "\n"
let passages = embedded_bible.fetchPlainPassages(
rows,
"John 8:1",
"TEST",
annotations = "none")
check passages[0] == "1 Jesus spoke.\n" &
" John 8:1 (TEST)"
test "plain output filters annotation footnotes by kind":
const rows =
"JHN\t8\t1\t0\tparagraph\t0\tJesus spoke plainly.\t" &
"""{"annotations":[{"kind":"note","offset":20,"targetText":"A note."}]}""" & "\n" &
"JHN\t8\t2\t0\tsame\t0\tHe taught.\t" &
"""{"annotations":[{"kind":"crossReference","offset":10,"targetText":"Mt 26:55"}]}""" & "\n"
let notesOnly = embedded_bible.fetchPlainPassages(
rows,
"John 8:1-2",
"TEST",
annotations = "note")
let crossReferencesOnly = embedded_bible.fetchPlainPassages(
rows,
"John 8:1-2",
"TEST",
annotations = "crossReference")
let both = embedded_bible.fetchPlainPassages(
rows,
"John 8:1-2",
"TEST",
annotations = "note,crossReference")
check notesOnly[0] == "1 Jesus spoke plainly.[a] 2 He taught.\n" &
"\n" &
"a. A note.\n" &
"\n" &
" John 8:1-2 (TEST)"
check crossReferencesOnly[0] == "1 Jesus spoke plainly. 2 He taught.[a]\n" &
"\n" &
"a. Mt 26:55\n" &
"\n" &
" John 8:1-2 (TEST)"
check both[0] == "1 Jesus spoke plainly.[a] 2 He taught.[b]\n" &
"\n" &
"a. A note.\n" &
"b. Mt 26:55\n" &
"\n" &
" John 8:1-2 (TEST)"
test "rejects unknown annotation filter kinds":
const rows =
"JHN\t8\t1\t0\tparagraph\t0\tJesus spoke.\t" &
"""{"annotations":[{"kind":"note","offset":12,"targetText":"A note."}]}""" & "\n"
expect ValueError:
discard embedded_bible.fetchPlainPassages(
rows,
"John 8:1",
"TEST",
annotations = "gloss")
test "plain output resets footnote labels per chapter":
const rows =
"JHN\t8\t59\t0\tparagraph\t0\tThey took up stones.\t" &
@@ -238,3 +303,25 @@ HEB 4 7 2 line 1 do not harden your hearts."
"[^a]: Jn 8:12\n" &
"\n" &
"> -- *John 8:59-9:1 (TEST)*"
test "ansi output renders verse numbers in gray and words of Christ in dark red":
const rows =
"JHN\t8\t1\t0\tparagraph\t0\tJesus said.\t" &
"""{"wordsOfChrist":true}""" & "\n"
let passages = embedded_bible.fetchAnsiPassages(rows, "John 8:1", "TEST")
check passages[0] == "\x1b[90m1\x1b[0m \x1b[31mJesus said.\x1b[0m\n" &
" John 8:1 (TEST)"
test "ansi output renders footnotes in cyan":
const rows =
"JHN\t8\t1\t0\tparagraph\t0\tJesus said.\t" &
"""{"wordsOfChrist":true,"annotations":[{"kind":"crossReference","offset":11,"targetText":"Mt 21:1"}]}""" &
"\n"
let passages = embedded_bible.fetchAnsiPassages(rows, "John 8:1", "TEST")
check passages[0] == "\x1b[90m1\x1b[0m \x1b[31mJesus said.\x1b[36m[a]\x1b[0m\x1b[31m\x1b[0m\n" &
"\n" &
"\x1b[36ma. Mt 21:1\x1b[0m\n" &
"\n" &
" John 8:1 (TEST)"