feat: start testcard implementation

This commit is contained in:
Daylin Morgan 2023-09-13 02:58:48 -05:00
parent 48cd26b644
commit 32abc9910a
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F
2 changed files with 19 additions and 4 deletions

View file

@ -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

View file

@ -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: