mirror of
https://github.com/daylinmorgan/hwylterm.git
synced 2024-11-16 06:28:32 -06:00
tests + stripAnsi
This commit is contained in:
parent
99fd2c1546
commit
a6641c5e37
2 changed files with 16 additions and 0 deletions
|
@ -11,6 +11,17 @@ import std/[os, sequtils, strformat, strutils]
|
|||
import ./bbansi/[styles, utils, colors]
|
||||
export utils
|
||||
|
||||
func stripAnsi*(s: string): string =
|
||||
## remove all ansi escape codes from a string
|
||||
var i: int
|
||||
while i < s.len:
|
||||
if s[i] == '\e':
|
||||
while s[i] != 'm':
|
||||
inc i
|
||||
inc i
|
||||
result.add s[i]
|
||||
inc i
|
||||
|
||||
type
|
||||
BbSpan* = object
|
||||
styles*: seq[string]
|
||||
|
@ -206,6 +217,7 @@ proc bbEcho*(args: varargs[string, `$`]) {.sideEffect.} =
|
|||
stdout.write('\n')
|
||||
stdout.flushFile
|
||||
|
||||
# NOTE: could move to standlone modules in the tools/ directory
|
||||
when isMainModule:
|
||||
import std/[parseopt, sugar]
|
||||
const version = staticExec "git describe --tags --always --dirty=-dev"
|
||||
|
|
|
@ -65,8 +65,12 @@ suite "basic":
|
|||
bbCheck "[#FF0000]red", "\e[38;2;255;0;0mred\e[0m"
|
||||
|
||||
suite "strutils":
|
||||
test "stripAnsi":
|
||||
check stripAnsi("\e[1mBold String!") == "Bold String!"
|
||||
|
||||
test "&":
|
||||
check "plain string" & bb"[red]red string" == bb"plain string[red]red string"
|
||||
check (bb"a [b]bold string") & " and plain string" == bb"a [b]bold string[/] and plain string"
|
||||
|
||||
test "truncate":
|
||||
let tester = bb"[red]a red[/] [blue on red]blue on red part"
|
||||
|
|
Loading…
Reference in a new issue