feat add helper to style a full string

This commit is contained in:
Daylin Morgan 2023-09-12 10:14:03 -05:00
parent 6b79b0de07
commit bcc70173b5
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F
2 changed files with 9 additions and 6 deletions

View file

@ -122,6 +122,9 @@ proc bb*(s: string): BbString =
next
result.closeFinalSpan
proc bb*(s: string, style: string): BbString =
bb("[" & style & "]" & s & "[/" & style & "]")
proc `&`*(x: BbString, y: BbString): Bbstring =
# there is probably a more efficient way to do this
bb(x.raw & y.raw)
@ -172,8 +175,3 @@ flags:
quit(QuitSuccess)
for arg in strArgs:
echo arg.bb
echo "---------->"
echo "\e[31mRed Text\e[0m\nNext Line"
echo "[red]Red Text[/red]\nNext Line".bb
echo "---------->"

View file

@ -5,7 +5,7 @@
#
# To run these tests, simply execute `nimble test`.
import unittest
import std/[strutils,unittest]
import bbansi
@ -40,3 +40,8 @@ suite "basic":
check "[red]RED[/]".bb.len == 3
check bb("[blue]Blue[/]") & " " & bb("[red]Red[/]") == "[blue]Blue[/] [red]Red[/]".bb
check "a plain string" & "[blue] a blue string".bb == "a plain string[blue] a blue string".bb
test "style full":
check "[red]Red[/red]".bb == bb("Red","red")
check "[b][yellow]not yellow[/][/b]".bb == bb("[yellow]not yellow[/]","b")