mirror of
https://github.com/daylinmorgan/hwylterm.git
synced 2024-12-22 03:00:43 -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]
|
import ./bbansi/[styles, utils, colors]
|
||||||
export utils
|
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
|
type
|
||||||
BbSpan* = object
|
BbSpan* = object
|
||||||
styles*: seq[string]
|
styles*: seq[string]
|
||||||
|
@ -206,6 +217,7 @@ proc bbEcho*(args: varargs[string, `$`]) {.sideEffect.} =
|
||||||
stdout.write('\n')
|
stdout.write('\n')
|
||||||
stdout.flushFile
|
stdout.flushFile
|
||||||
|
|
||||||
|
# NOTE: could move to standlone modules in the tools/ directory
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
import std/[parseopt, sugar]
|
import std/[parseopt, sugar]
|
||||||
const version = staticExec "git describe --tags --always --dirty=-dev"
|
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"
|
bbCheck "[#FF0000]red", "\e[38;2;255;0;0mred\e[0m"
|
||||||
|
|
||||||
suite "strutils":
|
suite "strutils":
|
||||||
|
test "stripAnsi":
|
||||||
|
check stripAnsi("\e[1mBold String!") == "Bold String!"
|
||||||
|
|
||||||
test "&":
|
test "&":
|
||||||
check "plain string" & bb"[red]red string" == bb"plain string[red]red string"
|
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":
|
test "truncate":
|
||||||
let tester = bb"[red]a red[/] [blue on red]blue on red part"
|
let tester = bb"[red]a red[/] [blue on red]blue on red part"
|
||||||
|
|
Loading…
Reference in a new issue