mirror of
https://github.com/daylinmorgan/bbansi.git
synced 2024-12-21 18:40:44 -06:00
refactor: drop string table for normal table
This commit is contained in:
parent
ad53d89eb9
commit
3db462973b
4 changed files with 26 additions and 9 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@ bin/
|
||||||
tests/*
|
tests/*
|
||||||
!tests/*.nim
|
!tests/*.nim
|
||||||
!tests/*.nims
|
!tests/*.nims
|
||||||
|
public/
|
||||||
|
|
16
config.nims
Normal file
16
config.nims
Normal 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}")
|
|
@ -1,8 +1,8 @@
|
||||||
import std/[strtabs, strutils]
|
import std/[strutils, tables]
|
||||||
|
|
||||||
let bbReset* = "\e[0m"
|
let bbReset* = "\e[0m"
|
||||||
|
|
||||||
let
|
const
|
||||||
bbStyles = {
|
bbStyles = {
|
||||||
"bold": "1",
|
"bold": "1",
|
||||||
"b": "1",
|
"b": "1",
|
||||||
|
@ -15,7 +15,7 @@ let
|
||||||
"reverse": "7",
|
"reverse": "7",
|
||||||
"conceal": "8",
|
"conceal": "8",
|
||||||
"strike": "9",
|
"strike": "9",
|
||||||
}.newStringTable(modeCaseInsensitive)
|
}.toTable
|
||||||
|
|
||||||
bbColors = {
|
bbColors = {
|
||||||
"black": "0",
|
"black": "0",
|
||||||
|
@ -26,7 +26,7 @@ let
|
||||||
"magenta": "5",
|
"magenta": "5",
|
||||||
"cyan": "6",
|
"cyan": "6",
|
||||||
"white": "7",
|
"white": "7",
|
||||||
}.newStringTable(modeCaseInsensitive)
|
}.toTable
|
||||||
|
|
||||||
proc toAnsiCode*(s: string): string =
|
proc toAnsiCode*(s: string): string =
|
||||||
var
|
var
|
||||||
|
@ -35,8 +35,8 @@ proc toAnsiCode*(s: string): string =
|
||||||
bgStyle: string
|
bgStyle: string
|
||||||
if " on " in s or s.startswith("on"):
|
if " on " in s or s.startswith("on"):
|
||||||
let fgBgSplit = s.rsplit("on", maxsplit = 1)
|
let fgBgSplit = s.rsplit("on", maxsplit = 1)
|
||||||
styles = fgBgSplit[0].splitWhitespace()
|
styles = fgBgSplit[0].toLowerAscii().splitWhitespace()
|
||||||
bgStyle = fgBgSplit[1].strip()
|
bgStyle = fgBgSplit[1].strip().toLowerAscii()
|
||||||
else:
|
else:
|
||||||
styles = s.splitWhitespace()
|
styles = s.splitWhitespace()
|
||||||
for style in styles:
|
for style in styles:
|
||||||
|
|
|
@ -34,9 +34,6 @@ suite "basic":
|
||||||
bbCheck "[[red] ignored pattern", "[red] ignored pattern"
|
bbCheck "[[red] ignored pattern", "[red] ignored pattern"
|
||||||
|
|
||||||
test "newlines":
|
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"
|
bbCheck "[red]Red Text[/]\nNext Line", "\e[31mRed Text\e[0m\nNext Line"
|
||||||
|
|
||||||
test "on color":
|
test "on color":
|
||||||
|
@ -50,6 +47,9 @@ suite "basic":
|
||||||
check "a plain string" & "[blue] a blue string".bb ==
|
check "a plain string" & "[blue] a blue string".bb ==
|
||||||
"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":
|
test "style full":
|
||||||
check "[red]Red[/red]".bb == bb("Red", "red")
|
check "[red]Red[/red]".bb == bb("Red", "red")
|
||||||
check "[b][yellow]not yellow[/][/b]".bb == bb("[yellow]not yellow[/]", "b")
|
check "[b][yellow]not yellow[/][/b]".bb == bb("[yellow]not yellow[/]", "b")
|
||||||
|
|
Loading…
Reference in a new issue