mirror of
https://github.com/daylinmorgan/hwylterm.git
synced 2025-02-23 01:35:50 -06:00
add bbMarkup
This commit is contained in:
parent
097d963b2a
commit
5d7e404d0d
2 changed files with 6 additions and 0 deletions
|
@ -353,6 +353,10 @@ func add*(x: var Bbstring, y: string) =
|
|||
x.plain.add y
|
||||
x.spans.add BbSpan(styles: @[], slice:[i, i + y.len - 1 ])
|
||||
|
||||
func bbMarkup*(s: string, style: string): string =
|
||||
## enclose a string in bbansi markup for the given style
|
||||
fmt"[{style}]{s}[/{style}]"
|
||||
|
||||
func bbEscape*(s: string): string {.inline.} =
|
||||
s.replace("[", "[[").replace("\\", "\\\\")
|
||||
|
||||
|
|
|
@ -16,11 +16,13 @@ suite "basic":
|
|||
bbCheck "[bold red]Bold Red Text", "\e[1;38;5;1mBold Red Text\e[0m"
|
||||
bbCheck "[red]5[/]", "\e[38;5;1m5\e[0m"
|
||||
bbCheck "[bold][red]5","\e[1;38;5;1m5\e[0m"
|
||||
check "[bold]bold[/bold]" == "bold".bbMarkup("bold")
|
||||
|
||||
test "compile time":
|
||||
const s = bb"[red]red text"
|
||||
check s == bb"[red]red text"
|
||||
|
||||
|
||||
test "closing":
|
||||
bbCheck "[bold]Bold[red] Bold Red[/red] Bold Only",
|
||||
"\e[1mBold\e[0m\e[1;38;5;1m Bold Red\e[0m\e[1m Bold Only\e[0m"
|
||||
|
|
Loading…
Add table
Reference in a new issue