add support for / escape pattern

This commit is contained in:
Daylin Morgan 2023-09-10 19:11:50 -05:00
parent e6639f1669
commit 2abf49541d
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F
2 changed files with 6 additions and 3 deletions

View file

@ -27,7 +27,7 @@ proc bb*(s: string): string =
if noColor: if noColor:
inc i inc i
continue continue
if pattern == "reset": if pattern in ["reset","/"]:
result.add bbReset result.add bbReset
addReset = false addReset = false
else: else:
@ -51,4 +51,4 @@ when isMainModule:
echo bb"[bold red]bold red" echo bb"[bold red]bold red"
echo bb"[bold red]bold red[reset] no more red" echo bb"[bold red]bold red[reset] no more red"
echo bb"[unknown]this text is red no?" echo bb"[unknown]this text is red no?"
echo bb"\[red] <- not a pattern [[red] <- also not a pattern" echo bb"\[red] <- not a pattern "

View file

@ -14,5 +14,8 @@ test "basic":
check "Unknown Style" == bb"[unknown]Unknown Style" check "Unknown Style" == bb"[unknown]Unknown Style"
check "\e[1m\e[31mBold Red Text\e[0m" == bb"[bold red]Bold Red Text" check "\e[1m\e[31mBold Red Text\e[0m" == bb"[bold red]Bold Red Text"
check "\e[1m\e[31mBold Red Text\e[0mPlain Text" == bb"[bold red]Bold Red Text[reset]Plain Text" check "\e[1m\e[31mBold Red Text\e[0mPlain Text" == bb"[bold red]Bold Red Text[reset]Plain Text"
check "\e[1mBold\e[0m Not Bold" == bb"[bold]Bold[/] Not Bold"
# not sure how rich handles this # not sure how rich handles this
check "[red] ignored pattern" == bb"[[red] ignored pattern"
test "escaped":
check "[red] ignored pattern" == bb"\[red] ignored pattern"