diff --git a/src/hwylterm/chooser.nim b/src/hwylterm/chooser.nim index f7e0623..ca8d4ca 100644 --- a/src/hwylterm/chooser.nim +++ b/src/hwylterm/chooser.nim @@ -11,11 +11,8 @@ import std/[enumerate, os, strutils, sequtils, sets, terminal] - -template canImport(x): bool = compiles: import x -when not canImport(illwill): {.fatal: "hwylterm/choose requires illwill >= 0.4.1".} -import illwill - +import ./private/tryImport +tryImport(illwill, "hwylterm/choose requires illwill >= 0.4.1") proc exitProc() {.noconv.} = illwillDeInit() @@ -131,6 +128,31 @@ proc choose*[T](things: openArray[T], height: Natural = 6): seq[T] = when isMainModule: + # import std/parseopt + # var + # posArgs: seq[string] + # style: string + # showDebug: bool + # 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 cmdArgument: + # strArgs.add key + # for arg in strArgs: + # let styled = + # if style != "": + # arg.bb(style) + # else: + # arg.bb + # echo styled + # if showDebug: + # echo debug(styled) let items = LowercaseLetters.toSeq() let item = choose(items) echo "selected: ", item diff --git a/src/hwylterm/cli.nim b/src/hwylterm/cli.nim index 4449922..16992c9 100644 --- a/src/hwylterm/cli.nim +++ b/src/hwylterm/cli.nim @@ -3,11 +3,11 @@ Adapter to add hwylterm colors to cligen output. ]## + import std/[tables] import ./bbansi -template canImport(x): bool = compiles: import x -when not canImport(cligen): {.fatal: "hwylterm/cli requires cligen>= 1.7.5".} -import cligen +import ./private/tryImport +tryImport(cligen, "hwylterm/cli requires cligen>= 1.7.5") type diff --git a/src/hwylterm/private/tryImport.nim b/src/hwylterm/private/tryImport.nim new file mode 100644 index 0000000..f8e73c7 --- /dev/null +++ b/src/hwylterm/private/tryImport.nim @@ -0,0 +1,6 @@ +template tryImport*(x, msg) = + const importable = compiles: import x + when not importable: + {.fatal: msg} + else: + import x