diff --git a/src/bbansi.nim b/src/bbansi.nim index e1f715c..0b181a3 100644 --- a/src/bbansi.nim +++ b/src/bbansi.nim @@ -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 "---------->" diff --git a/tests/tbasic.nim b/tests/tbasic.nim index dae8a8f..9b55ee4 100644 --- a/tests/tbasic.nim +++ b/tests/tbasic.nim @@ -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") +