mirror of
https://github.com/daylinmorgan/hwylterm.git
synced 2024-12-21 18:50:44 -06:00
abstractions!
This commit is contained in:
parent
5ee8117e96
commit
0bce099520
3 changed files with 36 additions and 8 deletions
|
@ -11,11 +11,8 @@
|
||||||
|
|
||||||
|
|
||||||
import std/[enumerate, os, strutils, sequtils, sets, terminal]
|
import std/[enumerate, os, strutils, sequtils, sets, terminal]
|
||||||
|
import ./private/tryImport
|
||||||
template canImport(x): bool = compiles: import x
|
tryImport(illwill, "hwylterm/choose requires illwill >= 0.4.1")
|
||||||
when not canImport(illwill): {.fatal: "hwylterm/choose requires illwill >= 0.4.1".}
|
|
||||||
import illwill
|
|
||||||
|
|
||||||
|
|
||||||
proc exitProc() {.noconv.} =
|
proc exitProc() {.noconv.} =
|
||||||
illwillDeInit()
|
illwillDeInit()
|
||||||
|
@ -131,6 +128,31 @@ proc choose*[T](things: openArray[T], height: Natural = 6): seq[T] =
|
||||||
|
|
||||||
|
|
||||||
when isMainModule:
|
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 items = LowercaseLetters.toSeq()
|
||||||
let item = choose(items)
|
let item = choose(items)
|
||||||
echo "selected: ", item
|
echo "selected: ", item
|
||||||
|
|
|
@ -3,11 +3,11 @@
|
||||||
|
|
||||||
Adapter to add hwylterm colors to cligen output.
|
Adapter to add hwylterm colors to cligen output.
|
||||||
]##
|
]##
|
||||||
|
|
||||||
import std/[tables]
|
import std/[tables]
|
||||||
import ./bbansi
|
import ./bbansi
|
||||||
template canImport(x): bool = compiles: import x
|
import ./private/tryImport
|
||||||
when not canImport(cligen): {.fatal: "hwylterm/cli requires cligen>= 1.7.5".}
|
tryImport(cligen, "hwylterm/cli requires cligen>= 1.7.5")
|
||||||
import cligen
|
|
||||||
|
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
6
src/hwylterm/private/tryImport.nim
Normal file
6
src/hwylterm/private/tryImport.nim
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
template tryImport*(x, msg) =
|
||||||
|
const importable = compiles: import x
|
||||||
|
when not importable:
|
||||||
|
{.fatal: msg}
|
||||||
|
else:
|
||||||
|
import x
|
Loading…
Reference in a new issue