refactor: & -> fmt

This commit is contained in:
Daylin Morgan 2023-09-14 11:04:47 -05:00
parent 13ca3538d9
commit 29a4de39d6
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F

View file

@ -128,43 +128,42 @@ proc bbEcho*(args: varargs[string, `$`]) {.sideEffect.} =
stdout.write('\n') stdout.write('\n')
stdout.flushFile stdout.flushFile
# ---- cli
when isMainModule: when isMainModule:
import std/[strformat, parseopt] import std/[strformat, parseopt]
const version = staticExec "git describe --tags --always --dirty=-dev" const version = staticExec "git describe --tags --always --dirty=-dev"
const longOptPad = 8 const longOptPad = 8
let help = &""" let help = fmt"""
{bb"[bold]bbansi[/] \[[green]args...[/]] [faint][[-h,-v][/]"} [bold]bbansi[/] \[[green]args...[/]] [faint][[-h,-v][/]
{bb"[italic]usage"}: [italic]usage[/]:
bbansi "[yellow] yellow text!" bbansi "[[yellow] yellow text!"
|-> {bb"[yellow] yellow text!"} |-> [yellow] yellow text![/]
bbansi "[bold red] bold red text[/] plain text..." bbansi "[[bold red] bold red text[[/] plain text..."
|-> {bb"[bold red] bold red text[/] plain text..."} |-> [bold red] bold red text[/] plain text...
bbansi "[red]some red[/red] but all bold" --style:bold bbansi "[[red]some red[[/red] but all italic" --style:italic
|-> {"[red]some red[/red] but all bold".bb("bold")} |-> [italic][red]some red[/red] but all italic[/italic]
flags: flags:
""" & $(bb(collect(for (s, l, d) in [ """.bb & $(bb(collect(for (s, l, d) in [
("h", "help", "show this help"), ("h", "help", "show this help"),
("v", "version", "show version"), ("v", "version", "show version"),
("s", "style", "set style for string") ("s", "style", "set style for string")
]: ]:
&"[yellow]-{s}[/] [green]--{l.alignLeft(longOptPad)}[/] {d}").join("\n ") fmt"[yellow]-{s}[/] [green]--{l.alignLeft(longOptPad)}[/] {d}").join("\n ")
)) ))
proc testCard = proc testCard =
for style in [ for style in [
"bold", "faint", "italic", "underline", "bold", "faint", "italic", "underline",
"blink", "reverse", "conceal", "strike"]: "blink", "reverse", "conceal", "strike"]:
echo style, " -> ", bb(&"[{style}]****") echo style, " -> ", fmt"[{style}]****".bb
const colors = [ const colors = [
"black", "red", "green", "yellow", "black", "red", "green", "yellow",
"blue", "magenta", "cyan", "white", ] "blue", "magenta", "cyan", "white", ]
for color in colors: for color in colors:
echo color, " -> ", bb(&"[{color}]****") echo color, " -> ", fmt"[{color}]****".bb
for color in colors: for color in colors:
echo "on ", color, " -> ", bb(&"[ on {color}]****") echo "on ", color, " -> ", fmt"[on {color}]****".bb
proc debug(bbs: BbString): string = proc debug(bbs: BbString): string =
echo "bbString(" echo "bbString("
@ -178,7 +177,7 @@ flags:
echo help echo help
quit(QuitSuccess) quit(QuitSuccess)
proc writeVersion() = proc writeVersion() =
echo bb(&"[yellow]bbansi version[/][red] ->[/] [bold]{version}[/]") echo fmt"[yellow]bbansi version[/][red] ->[/] [bold]{version}[/]".bb
quit(QuitSuccess) quit(QuitSuccess)
var var
strArgs: seq[string] strArgs: seq[string]