diff --git a/config.nims b/config.nims index 050dd4e..0d9d4d2 100644 --- a/config.nims +++ b/config.nims @@ -2,6 +2,7 @@ import std/[os, strformat, strutils] task test, "run tests": selfExec "r tests/tbbansi.nim" + selfExec "r tests/tcli.nim" task develop, "install cligen for development": exec "nimble install -l 'cligen@1.7.5'" diff --git a/src/hwylterm/cli.nim b/src/hwylterm/cli.nim index b217510..58e3457 100644 --- a/src/hwylterm/cli.nim +++ b/src/hwylterm/cli.nim @@ -72,6 +72,7 @@ proc bbImpl(cli: HwylCli): string = result.add indent(cli.usage, 2 ) result.add "\n" if cli.flags.len > 0: + result.add "\n" result.add "[" & cli.styles.hdr & "]" result.add "flags[/]:\n" for f in cli.flags: diff --git a/tests/tcli.nim b/tests/tcli.nim index 091766d..c90201e 100644 --- a/tests/tcli.nim +++ b/tests/tcli.nim @@ -1,28 +1,17 @@ import std/[ - compilesettings, - os, - osproc, - strutils, - times, unittest ] -const pathToSrc = querySetting(SingleValueSetting.projectPath) -proc cliRun(cmd: string): string = - let (output, _) = execCmdEx(pathToSrc / "bbansi.out " & cmd) - return output.strip() +import hwylterm, hwylterm/cli suite "cli": - setup: - let - cli = pathToSrc / "bbansi.out" - srcDir = pathToSrc / ".." / "src" - cmd = "nim c -o:" & cli & " " & (srcDir / "bbansi.nim") - if not cli.fileExists or getFileInfo(cli).lastWriteTime < getFileInfo(srcDir).lastWriteTime: - echo " -> compiling test binary" - require execCmdEx(cmd).exitCode == 0 - test "simple": - check "\e[31mRed\e[0m" == cliRun "[red]Red[/]" - check "\e[1;31mRed\e[0m\e[1m Not Red but Bold\e[0m" == - cliRun "'[red]Red[/] Not Red but Bold' " & "--style:bold" + test "cli": + let expected = """[b]test-program[/] [[args...] + +[b cyan]flags[/]: + [yellow]-h[/] [magenta]--help [/] []show this help[/] + [yellow]-V[/] [magenta]--version[/] []print version[/] +""" + let cli = newHwylCli("[b]test-program[/] [[args...]",flags = [("h","help","show this help",),("V","version","print version")]) + check $cli == $bb(expected) diff --git a/todo.md b/todo.md index 71de928..38022e0 100644 --- a/todo.md +++ b/todo.md @@ -2,7 +2,8 @@ - [x] add cligen adapters to add colors with bbansi - [ ] add integration test check cligen -- [ ] add generic help generator to accompany parseopt +- [x] add generic help generator to accompany parseopt + ## improvements - [ ] consider reducing illwill surface to only relevant IO (input) features @@ -14,7 +15,7 @@ - [x] make a basic choose one from list widget - [ ] tables/boxes? - [ ] confirmation proc -- [ ]basic progress bar +- [ ] basic progress bar - [ ] support for 256 and truecolors - [ ] support for rgb colors - [ ] modify 256 colors w/parser changes to be `"[color(9)]red"` instead of `[9]red`