refactor: drop string table for normal table

This commit is contained in:
Daylin Morgan 2023-09-15 17:10:25 -05:00
parent ad53d89eb9
commit 3db462973b
Signed by: daylin
GPG Key ID: C1E52E7DD81DF79F
4 changed files with 26 additions and 9 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ bin/
tests/*
!tests/*.nim
!tests/*.nims
public/

16
config.nims Normal file
View File

@ -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}")

View File

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

View File

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