mirror of
https://github.com/daylinmorgan/hwylterm.git
synced 2025-02-23 09:45:50 -06:00
add add
This commit is contained in:
parent
50d0ee5a3b
commit
4c63636c24
2 changed files with 15 additions and 1 deletions
|
@ -347,6 +347,12 @@ func add*(x: var Bbstring, y :Bbstring) =
|
||||||
for span in y.spans:
|
for span in y.spans:
|
||||||
x.spans.add shift(span, i)
|
x.spans.add shift(span, i)
|
||||||
|
|
||||||
|
# TODO: squash "like" spans for efficiency?
|
||||||
|
func add*(x: var Bbstring, y: string) =
|
||||||
|
let i = x.plain.len
|
||||||
|
x.plain.add y
|
||||||
|
x.spans.add BbSpan(styles: @[], slice:[i, i + y.len - 1 ])
|
||||||
|
|
||||||
func bbEscape*(s: string): string {.inline.} =
|
func bbEscape*(s: string): string {.inline.} =
|
||||||
s.replace("[", "[[").replace("\\", "\\\\")
|
s.replace("[", "[[").replace("\\", "\\\\")
|
||||||
|
|
||||||
|
|
|
@ -92,5 +92,13 @@ suite "strutils":
|
||||||
check (bb"[red]red").align(10) == bb" [red]red"
|
check (bb"[red]red").align(10) == bb" [red]red"
|
||||||
check (bb"[red]red").alignLeft(10) == bb"[red]red[/] "
|
check (bb"[red]red").alignLeft(10) == bb"[red]red[/] "
|
||||||
|
|
||||||
|
test "add":
|
||||||
|
var x = bb("[red]red")
|
||||||
|
x.add bb("[yellow]yellow")
|
||||||
|
check bb"[red]red[/][yellow]yellow[/]" == x
|
||||||
|
|
||||||
|
var y = bb("[red]red")
|
||||||
|
y.add "yellow"
|
||||||
|
check bb"[red]red[/]yellow" == y
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue