mirror of
https://github.com/daylinmorgan/oizys.git
synced 2024-11-09 20:33:15 -06:00
Compare commits
4 commits
7c755099ef
...
1626f58535
Author | SHA1 | Date | |
---|---|---|---|
1626f58535 | |||
ffb91a61b3 | |||
a23f845086 | |||
530997fc08 |
16 changed files with 151 additions and 195 deletions
103
flake.lock
103
flake.lock
|
@ -117,6 +117,24 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"flake-parts": {
|
"flake-parts": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs-lib": "nixpkgs-lib"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1714606777,
|
||||||
|
"narHash": "sha256-bMkNmAXLj8iyTvxaaD/StcLSadbj1chPcJOjtuVnLmA=",
|
||||||
|
"owner": "hercules-ci",
|
||||||
|
"repo": "flake-parts",
|
||||||
|
"rev": "4d34ce6412bc450b1d4208c953dc97c7fc764f1a",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "hercules-ci",
|
||||||
|
"repo": "flake-parts",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"flake-parts_2": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs-lib": [
|
"nixpkgs-lib": [
|
||||||
"nixpkgs-wayland",
|
"nixpkgs-wayland",
|
||||||
|
@ -138,6 +156,21 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"flake-root": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1713493429,
|
||||||
|
"narHash": "sha256-ztz8JQkI08tjKnsTpfLqzWoKFQF4JGu2LRz8bkdnYUk=",
|
||||||
|
"owner": "srid",
|
||||||
|
"repo": "flake-root",
|
||||||
|
"rev": "bc748b93b86ee76e2032eecda33440ceb2532fcd",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "srid",
|
||||||
|
"repo": "flake-root",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"flake-utils": {
|
"flake-utils": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"systems": "systems_2"
|
"systems": "systems_2"
|
||||||
|
@ -485,7 +518,7 @@
|
||||||
"lib-aggregate": {
|
"lib-aggregate": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"flake-utils": "flake-utils_3",
|
"flake-utils": "flake-utils_3",
|
||||||
"nixpkgs-lib": "nixpkgs-lib"
|
"nixpkgs-lib": "nixpkgs-lib_2"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1726600542,
|
"lastModified": 1726600542,
|
||||||
|
@ -599,10 +632,10 @@
|
||||||
},
|
},
|
||||||
"nix-eval-jobs": {
|
"nix-eval-jobs": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"flake-parts": "flake-parts",
|
"flake-parts": "flake-parts_2",
|
||||||
"nix-github-actions": "nix-github-actions",
|
"nix-github-actions": "nix-github-actions",
|
||||||
"nixpkgs": "nixpkgs_5",
|
"nixpkgs": "nixpkgs_5",
|
||||||
"treefmt-nix": "treefmt-nix"
|
"treefmt-nix": "treefmt-nix_2"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1726529941,
|
"lastModified": 1726529941,
|
||||||
|
@ -660,6 +693,30 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"nixd": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-parts": "flake-parts",
|
||||||
|
"flake-root": "flake-root",
|
||||||
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
],
|
||||||
|
"treefmt-nix": "treefmt-nix"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1726640797,
|
||||||
|
"narHash": "sha256-tuqkFa7ZxcGwU8gTbKO61oGMdTmG9CiaI+NiaOV7SCI=",
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "nixd",
|
||||||
|
"rev": "e2f0d908d6f2ee7bf72c620ed3c78817143b50ae",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "nixd",
|
||||||
|
"rev": "e2f0d908d6f2ee7bf72c620ed3c78817143b50ae",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"nixgl": {
|
"nixgl": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"flake-utils": [
|
"flake-utils": [
|
||||||
|
@ -722,6 +779,24 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixpkgs-lib": {
|
"nixpkgs-lib": {
|
||||||
|
"locked": {
|
||||||
|
"dir": "lib",
|
||||||
|
"lastModified": 1714253743,
|
||||||
|
"narHash": "sha256-mdTQw2XlariysyScCv2tTE45QSU9v/ezLcHJ22f0Nxc=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "58a1abdbae3217ca6b702f03d3b35125d88a2994",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"dir": "lib",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs-lib_2": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1726362065,
|
"lastModified": 1726362065,
|
||||||
"narHash": "sha256-4h15WKdrs9zf6DGaeeV7ntU/pHHGkH6geYt1QBW0CP4=",
|
"narHash": "sha256-4h15WKdrs9zf6DGaeeV7ntU/pHHGkH6geYt1QBW0CP4=",
|
||||||
|
@ -923,6 +998,7 @@
|
||||||
"lix-module": "lix-module",
|
"lix-module": "lix-module",
|
||||||
"nim2nix": "nim2nix",
|
"nim2nix": "nim2nix",
|
||||||
"nix-index-database": "nix-index-database",
|
"nix-index-database": "nix-index-database",
|
||||||
|
"nixd": "nixd",
|
||||||
"nixos-wsl": "nixos-wsl",
|
"nixos-wsl": "nixos-wsl",
|
||||||
"nixpkgs": "nixpkgs_4",
|
"nixpkgs": "nixpkgs_4",
|
||||||
"nixpkgs-wayland": "nixpkgs-wayland",
|
"nixpkgs-wayland": "nixpkgs-wayland",
|
||||||
|
@ -1082,6 +1158,27 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"treefmt-nix": {
|
"treefmt-nix": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": [
|
||||||
|
"nixd",
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1722330636,
|
||||||
|
"narHash": "sha256-uru7JzOa33YlSRwf9sfXpJG+UAV+bnBEYMjrzKrQZFw=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "treefmt-nix",
|
||||||
|
"rev": "768acdb06968e53aa1ee8de207fd955335c754b7",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "treefmt-nix",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"treefmt-nix_2": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": [
|
"nixpkgs": [
|
||||||
"nixpkgs-wayland",
|
"nixpkgs-wayland",
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
nixpkgs-wayland.url = "github:nix-community/nixpkgs-wayland";
|
nixpkgs-wayland.url = "github:nix-community/nixpkgs-wayland";
|
||||||
nixos-wsl.url = "github:nix-community/NixOS-WSL";
|
nixos-wsl.url = "github:nix-community/NixOS-WSL";
|
||||||
nix-index-database.url = "github:nix-community/nix-index-database";
|
nix-index-database.url = "github:nix-community/nix-index-database";
|
||||||
|
# pipe support added
|
||||||
|
nixd.url = "github:nix-community/nixd/e2f0d908d6f2ee7bf72c620ed3c78817143b50ae";
|
||||||
|
|
||||||
lix = {
|
lix = {
|
||||||
url = "https://git.lix.systems/lix-project/lix/archive/main.tar.gz";
|
url = "https://git.lix.systems/lix-project/lix/archive/main.tar.gz";
|
||||||
|
@ -33,6 +35,7 @@
|
||||||
hyprman.url = "git+https://git.dayl.in/daylin/hyprman.git";
|
hyprman.url = "git+https://git.dayl.in/daylin/hyprman.git";
|
||||||
utils.url = "git+https://git.dayl.in/daylin/utils.git";
|
utils.url = "git+https://git.dayl.in/daylin/utils.git";
|
||||||
|
|
||||||
|
nixd.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
nim2nix.inputs.nixpkgs.follows = "nixpkgs";
|
nim2nix.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
hyprman.inputs.nixpkgs.follows = "nixpkgs";
|
hyprman.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
f1multiviewer.inputs.nixpkgs.follows = "nixpkgs";
|
f1multiviewer.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
{
|
{
|
||||||
lib,
|
|
||||||
config,
|
|
||||||
enabled,
|
enabled,
|
||||||
enableAttrs,
|
enableAttrs,
|
||||||
listify,
|
listify,
|
||||||
|
@ -12,8 +10,10 @@
|
||||||
nix-ld = enabled // {
|
nix-ld = enabled // {
|
||||||
overkill = enabled;
|
overkill = enabled;
|
||||||
};
|
};
|
||||||
# languages = "misc|nim|node|nushell|python|roc|tex|zig" |> listify;
|
languages =
|
||||||
languages = "misc|nim|node|nushell|python|roc|tex" |> listify;
|
"misc|nim|node|nushell|python|tex"
|
||||||
|
# + "roc|zig"
|
||||||
|
|> listify;
|
||||||
}
|
}
|
||||||
// (
|
// (
|
||||||
''
|
''
|
||||||
|
|
|
@ -5,7 +5,13 @@
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
networking.networkmanager = enabled;
|
networking = {
|
||||||
|
networkmanager = enabled;
|
||||||
|
networking.extraHosts = ''
|
||||||
|
192.168.50.56 mannaz.local
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
services.fwupd = enabled;
|
services.fwupd = enabled;
|
||||||
hardware.bluetooth = enabled // {
|
hardware.bluetooth = enabled // {
|
||||||
powerOnBoot = true;
|
powerOnBoot = true;
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
lib,
|
lib,
|
||||||
enabled,
|
enabled,
|
||||||
self,
|
self,
|
||||||
|
flake,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
|
@ -42,11 +43,12 @@ in
|
||||||
# environment.etc."channels/nixpkgs".source = inputs.nixpkgs.outPath;
|
# environment.etc."channels/nixpkgs".source = inputs.nixpkgs.outPath;
|
||||||
|
|
||||||
environment.systemPackages = [
|
environment.systemPackages = [
|
||||||
pkgs.nixd
|
# pkgs.nixd
|
||||||
pkgs.nixfmt-rfc-style
|
pkgs.nixfmt-rfc-style
|
||||||
pkgs.nix-output-monitor
|
pkgs.nix-output-monitor
|
||||||
|
|
||||||
self.packages.${pkgs.system}.default
|
self.packages.${pkgs.system}.default
|
||||||
|
(flake.pkg "nixd")
|
||||||
];
|
];
|
||||||
|
|
||||||
programs.nix-index-database.comma = enabled;
|
programs.nix-index-database.comma = enabled;
|
||||||
|
|
|
@ -6,3 +6,5 @@ task build, "build oizys":
|
||||||
when withDir(thisDir(), system.fileExists("nimble.paths")):
|
when withDir(thisDir(), system.fileExists("nimble.paths")):
|
||||||
include "nimble.paths"
|
include "nimble.paths"
|
||||||
# end Nimble config
|
# end Nimble config
|
||||||
|
#
|
||||||
|
--path:"../../../dev/github/daylinmorgan/hwylterm/src"
|
||||||
|
|
|
@ -8,5 +8,5 @@ buildNimblePackage {
|
||||||
verions = "unstable";
|
verions = "unstable";
|
||||||
src = lib.cleanSource ./.;
|
src = lib.cleanSource ./.;
|
||||||
nativeBuildInputs = [ openssl ];
|
nativeBuildInputs = [ openssl ];
|
||||||
nimbleDepsHash = "sha256-WeTbNoF+TuzWriqoHWk5DBVgBXtNBIBHMkwy8/+a2JA=";
|
nimbleDepsHash = "sha256-o+CN0LlVOcgjLpDfjItW/5GCXTWcPSx9GfwQn+u2ST4=";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,6 @@
|
||||||
{
|
{
|
||||||
"version": 2,
|
"version": 2,
|
||||||
"packages": {
|
"packages": {
|
||||||
"bbansi": {
|
|
||||||
"version": "0.1.1",
|
|
||||||
"vcsRevision": "9a85d9ed028f06f1ed1ee6851480a51408a6004e",
|
|
||||||
"url": "https://github.com/daylinmorgan/bbansi",
|
|
||||||
"downloadMethod": "git",
|
|
||||||
"dependencies": [],
|
|
||||||
"checksums": {
|
|
||||||
"sha1": "b338433f9a7a1b788b7583674c2b14096ced29ee"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"cligen": {
|
"cligen": {
|
||||||
"version": "1.7.0",
|
"version": "1.7.0",
|
||||||
"vcsRevision": "4193f802796f15559c81c6dd56724d6f20345917",
|
"vcsRevision": "4193f802796f15559c81c6dd56724d6f20345917",
|
||||||
|
@ -21,6 +11,16 @@
|
||||||
"sha1": "300bd7fdb6e48d2d98e34ed0661206b50331e99c"
|
"sha1": "300bd7fdb6e48d2d98e34ed0661206b50331e99c"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"hwylterm": {
|
||||||
|
"version": "0.1.0",
|
||||||
|
"vcsRevision": "9afc339a9791f25010ea89a4f52204ad8eeda858",
|
||||||
|
"url": "https://github.com/daylinmorgan/hwylterm",
|
||||||
|
"downloadMethod": "git",
|
||||||
|
"dependencies": [],
|
||||||
|
"checksums": {
|
||||||
|
"sha1": "853c67ee7f789d825ec6f46c9fbae68e03e43cdb"
|
||||||
|
}
|
||||||
|
},
|
||||||
"jsony": {
|
"jsony": {
|
||||||
"version": "1.1.5",
|
"version": "1.1.5",
|
||||||
"vcsRevision": "ea811bec7fa50f5abd3088ba94cda74285e93f18",
|
"vcsRevision": "ea811bec7fa50f5abd3088ba94cda74285e93f18",
|
||||||
|
|
|
@ -14,4 +14,5 @@ requires "nim >= 2.0.8"
|
||||||
requires "cligen"
|
requires "cligen"
|
||||||
requires "jsony"
|
requires "jsony"
|
||||||
requires "zippy"
|
requires "zippy"
|
||||||
requires "https://github.com/daylinmorgan/bbansi#9a85d9e"
|
requires "https://github.com/daylinmorgan/hwylterm#9afc339"
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
## nix begat oizys
|
## nix begat oizys
|
||||||
import std/[os, tables, sequtils, strformat,strutils]
|
import std/[os, tables, sequtils, strformat,strutils]
|
||||||
|
|
||||||
import cligen, bbansi
|
import hwylterm
|
||||||
|
import hwylterm/cli
|
||||||
import oizys/[context, github, nix, overlay, logging]
|
import oizys/[context, github, nix, overlay, logging]
|
||||||
|
|
||||||
|
|
||||||
addHandler(
|
addHandler(
|
||||||
newFancyConsoleLogger(
|
newFancyConsoleLogger(
|
||||||
levelThreshold=lvlAll,
|
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 t1.pairs(): result[k] = v
|
||||||
for k, v in t2.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:
|
when isMainModule:
|
||||||
|
import cligen
|
||||||
checkExes()
|
checkExes()
|
||||||
setupCligen()
|
hwylCli(clCfg)
|
||||||
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"
|
|
||||||
|
|
||||||
const
|
const
|
||||||
sharedHelp = {
|
sharedHelp = {
|
||||||
|
@ -133,15 +113,17 @@ when isMainModule:
|
||||||
cacheHelp = {
|
cacheHelp = {
|
||||||
"name" : "name of cachix binary cache"
|
"name" : "name of cachix binary cache"
|
||||||
}.toTable() // sharedHelp
|
}.toTable() // sharedHelp
|
||||||
|
let
|
||||||
# setting clCfg.use wasn't working?
|
# 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(
|
dispatchMulti(
|
||||||
[build, help = sharedHelp, usage = usage],
|
[build, help = sharedHelp],
|
||||||
[cache, help = cacheHelp, usage = usage],
|
[cache, help = cacheHelp ],
|
||||||
[ci, help = ciHelp, usage = usage],
|
[ci, help = ciHelp ],
|
||||||
[dry, help = sharedHelp, usage = usage],
|
[dry, help = sharedHelp],
|
||||||
[osCmd, help = sharedHelp, usage = osUsage, cmdName = "os"],
|
[osCmd, help = sharedHelp, usage = osUsage, cmdName = "os"],
|
||||||
[output, help = sharedHelp, usage = usage],
|
[output, help = sharedHelp],
|
||||||
[update, help = updateHelp, usage = usage],
|
[update, help = updateHelp],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import std/[logging, os, strformat, strutils]
|
import std/[logging, os, strformat, strutils]
|
||||||
from std/nativesockets import getHostname
|
from std/nativesockets import getHostname
|
||||||
import bbansi
|
import hwylterm
|
||||||
import ./logging
|
import ./logging
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
|
@ -3,7 +3,7 @@ import std/[
|
||||||
strutils, streams, logging
|
strutils, streams, logging
|
||||||
]
|
]
|
||||||
|
|
||||||
import ./spin
|
import hwylterm
|
||||||
|
|
||||||
|
|
||||||
func addArgs*(cmd: var string, args: openArray[string]) =
|
func addArgs*(cmd: var string, args: openArray[string]) =
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import std/[httpclient,logging, os, strformat, strutils, json, tables, tempfiles]
|
import std/[httpclient,logging, os, strformat, strutils, json, tables, tempfiles]
|
||||||
import jsony, bbansi, zippy/ziparchives
|
import jsony, hwylterm, zippy/ziparchives
|
||||||
import ./[logging, exec, context]
|
import ./[logging, exec, context]
|
||||||
|
|
||||||
# localPassC is used by zippy but the additional
|
# localPassC is used by zippy but the additional
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import std/[logging,strutils]
|
import std/[logging,strutils]
|
||||||
export logging
|
export logging
|
||||||
|
|
||||||
import bbansi
|
import hwylterm
|
||||||
|
|
||||||
var
|
var
|
||||||
handlers {.threadvar.}: seq[Logger]
|
handlers {.threadvar.}: seq[Logger]
|
||||||
|
|
|
@ -3,7 +3,7 @@ import std/[
|
||||||
enumerate, os, sequtils, strformat,
|
enumerate, os, sequtils, strformat,
|
||||||
strutils, sugar, logging, tables
|
strutils, sugar, logging, tables
|
||||||
]
|
]
|
||||||
import bbansi, jsony
|
import hwylterm, jsony
|
||||||
import ./[context, exec, logging]
|
import ./[context, exec, logging]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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)
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue