abstractions!

This commit is contained in:
Daylin Morgan 2024-09-25 14:37:59 -05:00
parent 5ee8117e96
commit 0bce099520
Signed by: daylin
GPG key ID: 950D13E9719334AD
3 changed files with 36 additions and 8 deletions

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,6 @@
template tryImport*(x, msg) =
const importable = compiles: import x
when not importable:
{.fatal: msg}
else:
import x