diff --git a/src/bbansi.nim b/src/bbansi.nim index 7f4a570..1e1bd0a 100644 --- a/src/bbansi.nim +++ b/src/bbansi.nim @@ -153,6 +153,19 @@ flags: &"[yellow]-{s}[/] [green]--{l.alignLeft(longOptPad)}[/] {d}").join("\n ") )) + proc testCard = + for style in [ + "bold", "faint", "italic", "underline", + "blink", "reverse", "conceal", "strike"]: + echo style, " -> ", bb(&"[{style}]****") + const colors = [ + "black", "red", "green", "yellow", + "blue", "magenta", "cyan", "white", ] + for color in colors: + echo color, " -> ", bb(&"[{color}]****") + for color in colors: + echo "on ", color, " -> ", bb(&"[ on {color}]****") + proc debug(bbs: BbString): string = echo "bbString(" echo " raw: ", bbs.raw @@ -179,6 +192,7 @@ flags: case key: of "help", "h": writeHelp() of "version", "v": writeVersion() + of "testCard": testCard(); quit(QuitSuccess) of "style", "s": if val == "": echo "[red]ERROR[/]: expected value for -s/--style".bb diff --git a/src/bbansi/styles.nim b/src/bbansi/styles.nim index 4158b5b..273c262 100644 --- a/src/bbansi/styles.nim +++ b/src/bbansi/styles.nim @@ -3,7 +3,7 @@ import std/[strtabs, strutils] let bbReset* = "\e[0m" let - bbStyles = { + bbStyles* = { "bold": "1", "b": "1", "faint": "2", @@ -15,9 +15,10 @@ let "reverse": "7", "conceal": "8", "strike": "9", + }.newStringTable(modeCaseInsensitive) - bbColors = { + bbColors* = { "black": "0", "red": "1", "green": "2", @@ -32,8 +33,8 @@ proc toAnsiCode*(s: string): string = var styles: seq[string] bgStyle: string - if " on " in s: - let fgBgSplit = s.rsplit(" on ", maxsplit = 1) + if " on " in s or s.startswith("on"): + let fgBgSplit = s.rsplit("on", maxsplit = 1) styles = fgBgSplit[0].splitWhitespace() bgStyle = fgBgSplit[1].strip() else: