From 530997fc088c334a9951325e765a234bdffac069 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Tue, 17 Sep 2024 17:39:06 -0500 Subject: [PATCH] bbansi was consumed by hwylterm --- pkgs/oizys-nim/config.nims | 2 + pkgs/oizys-nim/default.nix | 2 +- pkgs/oizys-nim/nimble.lock | 20 ++-- pkgs/oizys-nim/oizys.nimble | 3 +- pkgs/oizys-nim/src/oizys.nim | 46 +++------ pkgs/oizys-nim/src/oizys/context.nim | 2 +- pkgs/oizys-nim/src/oizys/exec.nim | 2 +- pkgs/oizys-nim/src/oizys/github.nim | 2 +- pkgs/oizys-nim/src/oizys/logging.nim | 2 +- pkgs/oizys-nim/src/oizys/nix.nim | 2 +- pkgs/oizys-nim/src/oizys/spin.nim | 137 --------------------------- 11 files changed, 34 insertions(+), 186 deletions(-) delete mode 100644 pkgs/oizys-nim/src/oizys/spin.nim diff --git a/pkgs/oizys-nim/config.nims b/pkgs/oizys-nim/config.nims index bbf9469..e55e4a1 100644 --- a/pkgs/oizys-nim/config.nims +++ b/pkgs/oizys-nim/config.nims @@ -6,3 +6,5 @@ task build, "build oizys": when withDir(thisDir(), system.fileExists("nimble.paths")): include "nimble.paths" # end Nimble config +# +--path:"../../../dev/github/daylinmorgan/hwylterm/src" diff --git a/pkgs/oizys-nim/default.nix b/pkgs/oizys-nim/default.nix index 1504c35..cdf5551 100644 --- a/pkgs/oizys-nim/default.nix +++ b/pkgs/oizys-nim/default.nix @@ -8,5 +8,5 @@ buildNimblePackage { verions = "unstable"; src = lib.cleanSource ./.; nativeBuildInputs = [ openssl ]; - nimbleDepsHash = "sha256-WeTbNoF+TuzWriqoHWk5DBVgBXtNBIBHMkwy8/+a2JA="; + nimbleDepsHash = "sha256-o+CN0LlVOcgjLpDfjItW/5GCXTWcPSx9GfwQn+u2ST4="; } diff --git a/pkgs/oizys-nim/nimble.lock b/pkgs/oizys-nim/nimble.lock index 5fc6710..ff51e83 100644 --- a/pkgs/oizys-nim/nimble.lock +++ b/pkgs/oizys-nim/nimble.lock @@ -1,16 +1,6 @@ { "version": 2, "packages": { - "bbansi": { - "version": "0.1.1", - "vcsRevision": "9a85d9ed028f06f1ed1ee6851480a51408a6004e", - "url": "https://github.com/daylinmorgan/bbansi", - "downloadMethod": "git", - "dependencies": [], - "checksums": { - "sha1": "b338433f9a7a1b788b7583674c2b14096ced29ee" - } - }, "cligen": { "version": "1.7.0", "vcsRevision": "4193f802796f15559c81c6dd56724d6f20345917", @@ -21,6 +11,16 @@ "sha1": "300bd7fdb6e48d2d98e34ed0661206b50331e99c" } }, + "hwylterm": { + "version": "0.1.0", + "vcsRevision": "9afc339a9791f25010ea89a4f52204ad8eeda858", + "url": "https://github.com/daylinmorgan/hwylterm", + "downloadMethod": "git", + "dependencies": [], + "checksums": { + "sha1": "853c67ee7f789d825ec6f46c9fbae68e03e43cdb" + } + }, "jsony": { "version": "1.1.5", "vcsRevision": "ea811bec7fa50f5abd3088ba94cda74285e93f18", diff --git a/pkgs/oizys-nim/oizys.nimble b/pkgs/oizys-nim/oizys.nimble index e5f2ac4..93d0d82 100644 --- a/pkgs/oizys-nim/oizys.nimble +++ b/pkgs/oizys-nim/oizys.nimble @@ -14,4 +14,5 @@ requires "nim >= 2.0.8" requires "cligen" requires "jsony" requires "zippy" -requires "https://github.com/daylinmorgan/bbansi#9a85d9e" +requires "https://github.com/daylinmorgan/hwylterm#9afc339" + diff --git a/pkgs/oizys-nim/src/oizys.nim b/pkgs/oizys-nim/src/oizys.nim index ac2ad92..ee2ffdc 100644 --- a/pkgs/oizys-nim/src/oizys.nim +++ b/pkgs/oizys-nim/src/oizys.nim @@ -1,10 +1,10 @@ ## nix begat oizys import std/[os, tables, sequtils, strformat,strutils] -import cligen, bbansi +import hwylterm +import hwylterm/cli import oizys/[context, github, nix, overlay, logging] - addHandler( newFancyConsoleLogger( levelThreshold=lvlAll, @@ -91,31 +91,11 @@ proc `//`(t1: Table[string, string], t2: Table[string, string]): Table[string, s for k, v in t1.pairs(): result[k] = v for k, v in t2.pairs(): result[k] = v -proc setupCligen() = - let isColor = getEnv("NO_COLOR") == "" - if clCfg.useMulti == "": - clCfg.useMulti = - if isColor: "${doc}\e[1mUsage\e[m:\n $command {SUBCMD} [sub-command options & parameters]\n\n\e[1msubcommands\e[m:\n$subcmds" - else: "${doc}Usage:\n $command {SUBCMD} [sub-command options & parameters]\n\nsubcommands:\n$subcmds" - - if not isColor: return - if clCfg.helpAttr.len == 0: - clCfg.helpAttr = {"cmd": "\e[1;36m", "clDescrip": "", "clDflVal": "\e[33m", - "clOptKeys": "\e[32m", "clValType": "\e[31m", "args": "\e[3m"}.toTable() - clCfg.helpAttrOff = {"cmd": "\e[m", "clDescrip": "\e[m", "clDflVal": "\e[m", - "clOptKeys": "\e[m", "clValType": "\e[m", "args": "\e[m"}.toTable() - # clCfg.use does nothing? - clCfg.useHdr = "\e[1musage\e[m:\n " when isMainModule: + import cligen checkExes() - setupCligen() - let (optOpen, optClose) = - if getEnv("NO_COLOR") == "": ("\e[1m","\e[m") - else: ("","") - let - usage = &"$command [flags]\n$doc{optOpen}Options{optClose}:\n$options" - osUsage = &"$command [subcmd] [flags]\n$doc{optOpen}Options{optClose}:\n$options" + hwylCli(clCfg) const sharedHelp = { @@ -133,15 +113,17 @@ when isMainModule: cacheHelp = { "name" : "name of cachix binary cache" }.toTable() // sharedHelp - - # setting clCfg.use wasn't working? + let + # clUse must be set here using clCfg doesn't seem to work with dispatchMutli ... + clUse* = $bb("$command $args\n${doc}[bold]Options[/]:\n$options") + osUsage = $bb("$command [[subcmd] $args\n$doc[bold]Options[/]:\n$options") dispatchMulti( - [build, help = sharedHelp, usage = usage], - [cache, help = cacheHelp, usage = usage], - [ci, help = ciHelp, usage = usage], - [dry, help = sharedHelp, usage = usage], + [build, help = sharedHelp], + [cache, help = cacheHelp ], + [ci, help = ciHelp ], + [dry, help = sharedHelp], [osCmd, help = sharedHelp, usage = osUsage, cmdName = "os"], - [output, help = sharedHelp, usage = usage], - [update, help = updateHelp, usage = usage], + [output, help = sharedHelp], + [update, help = updateHelp], ) diff --git a/pkgs/oizys-nim/src/oizys/context.nim b/pkgs/oizys-nim/src/oizys/context.nim index ee6c81d..379fbce 100644 --- a/pkgs/oizys-nim/src/oizys/context.nim +++ b/pkgs/oizys-nim/src/oizys/context.nim @@ -1,6 +1,6 @@ import std/[logging, os, strformat, strutils] from std/nativesockets import getHostname -import bbansi +import hwylterm import ./logging type diff --git a/pkgs/oizys-nim/src/oizys/exec.nim b/pkgs/oizys-nim/src/oizys/exec.nim index 6555dff..ad1da3c 100644 --- a/pkgs/oizys-nim/src/oizys/exec.nim +++ b/pkgs/oizys-nim/src/oizys/exec.nim @@ -3,7 +3,7 @@ import std/[ strutils, streams, logging ] -import ./spin +import hwylterm func addArgs*(cmd: var string, args: openArray[string]) = diff --git a/pkgs/oizys-nim/src/oizys/github.nim b/pkgs/oizys-nim/src/oizys/github.nim index 1cb2dfb..f5b63d0 100644 --- a/pkgs/oizys-nim/src/oizys/github.nim +++ b/pkgs/oizys-nim/src/oizys/github.nim @@ -1,5 +1,5 @@ import std/[httpclient,logging, os, strformat, strutils, json, tables, tempfiles] -import jsony, bbansi, zippy/ziparchives +import jsony, hwylterm, zippy/ziparchives import ./[logging, exec, context] # localPassC is used by zippy but the additional diff --git a/pkgs/oizys-nim/src/oizys/logging.nim b/pkgs/oizys-nim/src/oizys/logging.nim index 708a43a..f1f7993 100644 --- a/pkgs/oizys-nim/src/oizys/logging.nim +++ b/pkgs/oizys-nim/src/oizys/logging.nim @@ -1,7 +1,7 @@ import std/[logging,strutils] export logging -import bbansi +import hwylterm var handlers {.threadvar.}: seq[Logger] diff --git a/pkgs/oizys-nim/src/oizys/nix.nim b/pkgs/oizys-nim/src/oizys/nix.nim index 2c6a247..8c70007 100644 --- a/pkgs/oizys-nim/src/oizys/nix.nim +++ b/pkgs/oizys-nim/src/oizys/nix.nim @@ -3,7 +3,7 @@ import std/[ enumerate, os, sequtils, strformat, strutils, sugar, logging, tables ] -import bbansi, jsony +import hwylterm, jsony import ./[context, exec, logging] diff --git a/pkgs/oizys-nim/src/oizys/spin.nim b/pkgs/oizys-nim/src/oizys/spin.nim deleted file mode 100644 index ab5f4b0..0000000 --- a/pkgs/oizys-nim/src/oizys/spin.nim +++ /dev/null @@ -1,137 +0,0 @@ -import std/[os, locks, sequtils, terminal] - -import bbansi - -type - SpinnerKind* = enum - Dots - Spinner* = object - interval*: int - frames*: seq[string] - -proc makeSpinner*(interval: int, frames: seq[string]): Spinner = - Spinner(interval: interval, frames: frames) - -const Spinners*: array[SpinnerKind, Spinner] = [ - # Dots - Spinner(interval: 80, frames: @["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"]), -] - - -type - Spinny = ref object - t: Thread[Spinny] - lock: Lock - text: string - running: bool - frames: seq[string] - frame: string - interval: int - customSymbol: bool - style: string - - EventKind = enum - Stop, SymbolChange, TextChange, - - SpinnyEvent = object - kind: EventKind - payload: string - -var spinnyChannel: Channel[SpinnyEvent] - -proc newSpinny*(text: string, s: Spinner): Spinny = - let style = "bold blue" - Spinny( - text: text, - running: true, - frames: mapIt(s.frames, $bb(it, style)), - customSymbol: false, - interval: s.interval, - style: "bold blue" - ) - -proc newSpinny*(text: string, spinType: SpinnerKind): Spinny = - newSpinny(text, Spinners[spinType]) - -proc setSymbolColor*(spinny: Spinny, style: string) = - spinny.frames = mapIt(spinny.frames, $bb(it, style)) - -proc setSymbol*(spinny: Spinny, symbol: string) = - spinnyChannel.send(SpinnyEvent(kind: SymbolChange, payload: symbol)) - -proc setText*(spinny: Spinny, text: string) = - spinnyChannel.send(SpinnyEvent(kind: TextChange, payload: text)) - -proc handleEvent(spinny: Spinny, eventData: SpinnyEvent): bool = - result = true - case eventData.kind - of Stop: - result = false - of SymbolChange: - spinny.customSymbol = true - spinny.frame = eventData.payload - of TextChange: - spinny.text = eventData.payload - -proc spinnyLoop(spinny: Spinny) {.thread.} = - var frameCounter = 0 - - while spinny.running: - let data = spinnyChannel.tryRecv() - if data.dataAvailable: - # If we received a Stop event - if not spinny.handleEvent(data.msg): - spinnyChannel.close() - # This is required so we can reopen the same channel more than once - # See https://github.com/nim-lang/Nim/issues/6369 - spinnyChannel = default(typeof(spinnyChannel)) - # TODO: Do we need spinny.running at all? - spinny.running = false - break - - stdout.flushFile() - if not spinny.customSymbol: - spinny.frame = spinny.frames[frameCounter] - - withLock spinny.lock: - eraseLine() - stdout.write(spinny.frame & " " & spinny.text) - stdout.flushFile() - - sleep spinny.interval - - if frameCounter >= spinny.frames.len - 1: - frameCounter = 0 - else: - frameCounter += 1 - -proc start*(spinny: Spinny) = - initLock spinny.lock - spinnyChannel.open() - createThread(spinny.t, spinnyLoop, spinny) - -proc stop(spinny: Spinny, kind: EventKind, payload = "") = - spinnyChannel.send(SpinnyEvent(kind: kind, payload: payload)) - spinnyChannel.send(SpinnyEvent(kind: Stop)) - joinThread spinny.t - eraseLine stdout - flushFile stdout - - -proc stop*(spinny: Spinny) = - spinny.stop(Stop) - -template withSpinner*(msg: string = "", body: untyped): untyped = - var spinner {.inject.} = newSpinny(msg, Dots) - if isatty(stdout): # don't spin if it's not a tty - start spinner - - body - - if isatty(stdout): - stop spinner - -template withSpinner*(body: untyped): untyped = - withSpinner("", body) - -