add basic cli

This commit is contained in:
Daylin Morgan 2023-09-11 00:38:01 -05:00
parent 887a724606
commit 0df16a2654
Signed by: daylin
GPG Key ID: C1E52E7DD81DF79F
3 changed files with 46 additions and 6 deletions

View File

@ -53,9 +53,47 @@ proc bb*(s: string): string =
result.add "\e[0m"
when isMainModule:
echo bb"[bold]bold"
echo bb"[red]red"
echo bb"[bold red]bold red"
echo bb"[bold red]bold red[reset] no more red"
echo bb"[unknown]this text is red no?"
echo bb"\[red] <- not a pattern "
import std/[strformat, parseopt]
const version = staticExec "git describe --tags --always --dirty=-dev"
let help = &"""
{bb"[bold]bbansi[/] [green]<args>[/] [black]<-h|-v>[/]"}
usage:
bbansi "[yellow] yellow text!"
|-> {bb"[yellow] yellow text!"}
bbansi "[bold red] bold red[/] plain text..."
|-> {bb"[bold red] bold red text[/] plain text..."}
"""
proc writeHelp() =
echo help
quit(QuitSuccess)
proc writeVersion() =
echo "bbansi version -> ", version
quit(QuitSuccess)
var strArgs: seq[string]
var p = initOptParser()
for kind, key, val in p.getopt():
case kind:
of cmdEnd: break
of cmdShortOption, cmdLongOption:
case key:
of "help", "h": writeHelp()
of "version","v": writeVersion()
else:
echo bb"[red]ERROR[/]: unexpected option/value -> ", key, ", ", val
echo "Option and value: ", key, ", ", val
of cmdArgument:
strArgs.add key
if strArgs.len != 0:
for arg in strArgs:
echo arg.bb
else:
echo "[bold]---------------------".bb
echo bb"[bold]bold"
echo bb"[red]red"
echo bb"[bold red]bold red"
echo bb"[bold red]bold red[reset] no more red"
echo bb"[unknown]this text is red no?"
echo bb"\[red] <- not a pattern "

View File

@ -5,6 +5,7 @@ export strtabs
let bbReset* ="\e[0m"
# should these be an enum?
let
codeMap* = {
"reset":"0",

View File

@ -1,5 +1,6 @@
# bbansi todo's
- [ ] make unknown style error with compile time flag
- [ ] use an actual type and `$` mechanism
- [ ] add better escaping mechanism for bracketed text
- [ ] add support for custom 1-256 numbers and 8-bit numbers and truecolor