diff --git a/.gitignore b/.gitignore index a1db20d..ffec908 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ bin/ tests/* !tests/*.nim !tests/*.nims +public/ diff --git a/config.nims b/config.nims new file mode 100644 index 0000000..cb194e8 --- /dev/null +++ b/config.nims @@ -0,0 +1,16 @@ +import std/[os, strformat] + +task docs, "Deploy doc html + search index to public/ directory": + let + name = "bbansi" + version = gorgeEx("git describe --tags --match 'v*'").output + srcFile = "src" / (name & ".nim") + gitUrl = fmt"https://github.com/daylinmorgan/{name}" + selfExec fmt"doc --project --index:on --git.url:{gitUrl} --git.commit:{version} --outdir:public {srcFile}" + withDir "public": + mvFile(name & ".html", "index.html") + for file in walkDirRec(".", {pcFile}): + # As we renamed the file, we need to rename that in hyperlinks + exec(fmt"sed -i -r 's|{name}\.html|index.html|g' {file}") + # drop 'src/' from titles + exec(fmt"sed -i -r 's/<(.*)>src\//<\1>/' {file}") diff --git a/src/bbansi/styles.nim b/src/bbansi/styles.nim index c1c6dc3..3561daf 100644 --- a/src/bbansi/styles.nim +++ b/src/bbansi/styles.nim @@ -1,8 +1,8 @@ -import std/[strtabs, strutils] +import std/[strutils, tables] let bbReset* = "\e[0m" -let +const bbStyles = { "bold": "1", "b": "1", @@ -15,7 +15,7 @@ let "reverse": "7", "conceal": "8", "strike": "9", - }.newStringTable(modeCaseInsensitive) + }.toTable bbColors = { "black": "0", @@ -26,7 +26,7 @@ let "magenta": "5", "cyan": "6", "white": "7", - }.newStringTable(modeCaseInsensitive) + }.toTable proc toAnsiCode*(s: string): string = var @@ -35,8 +35,8 @@ proc toAnsiCode*(s: string): string = bgStyle: string if " on " in s or s.startswith("on"): let fgBgSplit = s.rsplit("on", maxsplit = 1) - styles = fgBgSplit[0].splitWhitespace() - bgStyle = fgBgSplit[1].strip() + styles = fgBgSplit[0].toLowerAscii().splitWhitespace() + bgStyle = fgBgSplit[1].strip().toLowerAscii() else: styles = s.splitWhitespace() for style in styles: diff --git a/tests/tbasic.nim b/tests/tbasic.nim index 5859a31..23ef67c 100644 --- a/tests/tbasic.nim +++ b/tests/tbasic.nim @@ -34,9 +34,6 @@ suite "basic": bbCheck "[[red] ignored pattern", "[red] ignored pattern" test "newlines": - # Proc Strings: raw strings, - # but the method name that prefixes the string is called - # so that foo"12\" -> foo(r"12\") bbCheck "[red]Red Text[/]\nNext Line", "\e[31mRed Text\e[0m\nNext Line" test "on color": @@ -50,6 +47,9 @@ suite "basic": check "a plain string" & "[blue] a blue string".bb == "a plain string[blue] a blue string".bb + test "case": + bbCheck "[red]no case sensitivity[/RED]", "\e[31mno case sensitivity\e[0m" + test "style full": check "[red]Red[/red]".bb == bb("Red", "red") check "[b][yellow]not yellow[/][/b]".bb == bb("[yellow]not yellow[/]", "b")