Compare commits

...

4 commits

Author SHA1 Message Date
5c5bdd9e16 flake.lock: Update
Flake lock file updates:

• Updated input 'f1multiviewer':
    'github:daylinmorgan/f1multiviewer-flake/663a121c6b36ab86ea039dc15e7aff7710703e78' (2024-09-13)
  → 'github:daylinmorgan/f1multiviewer-flake/fb4a3f5dd59c80aa3a210d8ea1ae77f2da0d39ca' (2024-09-19)
• Updated input 'hyprland':
    'git+https://github.com/hyprwm/Hyprland/?ref=refs/heads/main&rev=3c9716acfd00c6ea1b7bcd1dc63f97b51cc09998' (2024-09-17)
  → 'git+https://github.com/hyprwm/Hyprland/?ref=refs/heads/main&rev=9856378384539e35cd943604e6a4d696a9d25447' (2024-09-19)
• Updated input 'hyprland/aquamarine':
    'github:hyprwm/aquamarine/e4a13203112a036fc7f437d391c7810f3dd5ab52' (2024-09-07)
  → 'github:hyprwm/aquamarine/752d0fbd141fabb5a1e7f865199b80e6e76f8d8e' (2024-09-18)
• Updated input 'lix':
    '8ab5743904.tar.gz?narHash=sha256-CrvIEzBzvvfE7jGIXBv6hSYDxv4eYeHWAwVho5WrF48%3D&rev=8ab5743904a06c78153281bf61b3aa8aa451a489' (2024-09-17)
  → '79246a3733.tar.gz?narHash=sha256-oBo2DRCazfJV/qUTgUGcS9s694sHNsIs5U09cOszeAc%3D&rev=79246a37337c5df2224dbc2461c722e1e678f6de' (2024-09-18)
• Updated input 'lix-module':
    '353b25f0b6.tar.gz?narHash=sha256-dCbHCwqrzcHlEsRilMX%2BKM3IfRV46ieGqDyAD3GgCSs%3D&rev=353b25f0b6da5ede15206d416345a2ec4195b5c8' (2024-09-08)
  → 'b0e6f35950.tar.gz?narHash=sha256-b2rMO8%2BjKjY55d8uynX7FjV4NIPu/WzPux0kWOAzwoo%3D&rev=b0e6f359500d66670cc16f521e4f62d6a0a4864e' (2024-09-18)
• Updated input 'lix-module/flake-utils':
    'github:numtide/flake-utils/b1d9ab70662946ef0850d488da1c9019f3a9752a' (2024-03-11)
  → 'github:numtide/flake-utils/c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a' (2024-09-17)
• Updated input 'nixpkgs-wayland':
    'github:nix-community/nixpkgs-wayland/e2d0b0171ddf364b687d091ee603d0c3a7079166' (2024-09-17)
  → 'github:nix-community/nixpkgs-wayland/72f9ecac5ada9ff6bb7c5811a43cb2f80fc8b6ca' (2024-09-19)
• Updated input 'roc':
    'github:roc-lang/roc/3215a8f3d73daf881185e4f7474972f2059754b6' (2024-09-17)
  → 'github:roc-lang/roc/9678046d916bdf19bc817cc8eb0d1d712dfb84d4' (2024-09-19)
• Updated input 'zig-overlay':
    'github:mitchellh/zig-overlay/a2f15c93b689b31044d5604fb0cd5bac818daf01' (2024-09-17)
  → 'github:mitchellh/zig-overlay/7e7ad073ba0a34ff75e7cf60f9f7153cf965f27f' (2024-09-20)
• Updated input 'zls':
    'github:zigtools/zls/cf9b49a67b15693d62926ea11d17f53efc60be50' (2024-09-16)
  → 'github:zigtools/zls/2b613d32696676bcbc257e31542a1dcbfa7f22a8' (2024-09-20)
2024-09-20 00:48:31 +00:00
ffb91a61b3
cleanup 2024-09-18 16:13:30 -05:00
a23f845086
use development version of nixd for pipe support 2024-09-18 15:00:54 -05:00
530997fc08
bbansi was consumed by hwylterm 2024-09-18 15:00:54 -05:00
15 changed files with 177 additions and 227 deletions

View file

@ -20,11 +20,11 @@
]
},
"locked": {
"lastModified": 1725753098,
"narHash": "sha256-/NO/h/qD/eJXAQr/fHA4mdDgYsNT9thHQ+oT6KPi2ac=",
"lastModified": 1726665257,
"narHash": "sha256-rEzEZtd3iyVo5RJ1OGujOlnywNf3gsrOnjAn1NLciD4=",
"owner": "hyprwm",
"repo": "aquamarine",
"rev": "e4a13203112a036fc7f437d391c7810f3dd5ab52",
"rev": "752d0fbd141fabb5a1e7f865199b80e6e76f8d8e",
"type": "github"
},
"original": {
@ -40,11 +40,11 @@
]
},
"locked": {
"lastModified": 1726248534,
"narHash": "sha256-NYDOvN3Y9r8F0tHE2Yh7lzoGN3OhfieYjFV9QzlEdhc=",
"lastModified": 1726706336,
"narHash": "sha256-QZvf+SPKR2WGr9+gyUG5E+AXE0728Qbez0bx4rLPZNw=",
"owner": "daylinmorgan",
"repo": "f1multiviewer-flake",
"rev": "663a121c6b36ab86ea039dc15e7aff7710703e78",
"rev": "fb4a3f5dd59c80aa3a210d8ea1ae77f2da0d39ca",
"type": "github"
},
"original": {
@ -117,6 +117,24 @@
}
},
"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": {
"nixpkgs-lib": [
"nixpkgs-wayland",
@ -138,16 +156,31 @@
"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": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"lastModified": 1726560853,
"narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a",
"type": "github"
},
"original": {
@ -323,11 +356,11 @@
"xdph": "xdph"
},
"locked": {
"lastModified": 1726580240,
"narHash": "sha256-VBXNeRJMaiqbIietRihPYnWA7bFJO2wqqlPg0f9Xfjc=",
"lastModified": 1726761214,
"narHash": "sha256-xaecVNHaxiAXDCUFZzDLMP3jbxpBjQTqT4Bku2z5vGA=",
"ref": "refs/heads/main",
"rev": "3c9716acfd00c6ea1b7bcd1dc63f97b51cc09998",
"revCount": 5227,
"rev": "9856378384539e35cd943604e6a4d696a9d25447",
"revCount": 5240,
"submodules": true,
"type": "git",
"url": "https://github.com/hyprwm/Hyprland/"
@ -485,7 +518,7 @@
"lib-aggregate": {
"inputs": {
"flake-utils": "flake-utils_3",
"nixpkgs-lib": "nixpkgs-lib"
"nixpkgs-lib": "nixpkgs-lib_2"
},
"locked": {
"lastModified": 1726600542,
@ -504,11 +537,11 @@
"lix": {
"flake": false,
"locked": {
"lastModified": 1726590994,
"narHash": "sha256-CrvIEzBzvvfE7jGIXBv6hSYDxv4eYeHWAwVho5WrF48=",
"rev": "8ab5743904a06c78153281bf61b3aa8aa451a489",
"lastModified": 1726702585,
"narHash": "sha256-oBo2DRCazfJV/qUTgUGcS9s694sHNsIs5U09cOszeAc=",
"rev": "79246a37337c5df2224dbc2461c722e1e678f6de",
"type": "tarball",
"url": "https://git.lix.systems/api/v1/repos/lix-project/lix/archive/8ab5743904a06c78153281bf61b3aa8aa451a489.tar.gz?rev=8ab5743904a06c78153281bf61b3aa8aa451a489"
"url": "https://git.lix.systems/api/v1/repos/lix-project/lix/archive/79246a37337c5df2224dbc2461c722e1e678f6de.tar.gz?rev=79246a37337c5df2224dbc2461c722e1e678f6de"
},
"original": {
"type": "tarball",
@ -527,11 +560,11 @@
]
},
"locked": {
"lastModified": 1725836728,
"narHash": "sha256-dCbHCwqrzcHlEsRilMX+KM3IfRV46ieGqDyAD3GgCSs=",
"rev": "353b25f0b6da5ede15206d416345a2ec4195b5c8",
"lastModified": 1726631249,
"narHash": "sha256-b2rMO8+jKjY55d8uynX7FjV4NIPu/WzPux0kWOAzwoo=",
"rev": "b0e6f359500d66670cc16f521e4f62d6a0a4864e",
"type": "tarball",
"url": "https://git.lix.systems/api/v1/repos/lix-project/nixos-module/archive/353b25f0b6da5ede15206d416345a2ec4195b5c8.tar.gz?rev=353b25f0b6da5ede15206d416345a2ec4195b5c8"
"url": "https://git.lix.systems/api/v1/repos/lix-project/nixos-module/archive/b0e6f359500d66670cc16f521e4f62d6a0a4864e.tar.gz?rev=b0e6f359500d66670cc16f521e4f62d6a0a4864e"
},
"original": {
"type": "tarball",
@ -599,10 +632,10 @@
},
"nix-eval-jobs": {
"inputs": {
"flake-parts": "flake-parts",
"flake-parts": "flake-parts_2",
"nix-github-actions": "nix-github-actions",
"nixpkgs": "nixpkgs_5",
"treefmt-nix": "treefmt-nix"
"treefmt-nix": "treefmt-nix_2"
},
"locked": {
"lastModified": 1726529941,
@ -660,6 +693,30 @@
"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": {
"inputs": {
"flake-utils": [
@ -722,6 +779,24 @@
}
},
"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": {
"lastModified": 1726362065,
"narHash": "sha256-4h15WKdrs9zf6DGaeeV7ntU/pHHGkH6geYt1QBW0CP4=",
@ -744,11 +819,11 @@
"nixpkgs": "nixpkgs_6"
},
"locked": {
"lastModified": 1726604396,
"narHash": "sha256-N96NVHAYUxK4L7uaeKi45a+v61VIpimzHyQsKctBpb4=",
"lastModified": 1726763265,
"narHash": "sha256-OTKyjTGJin00CtTdIDbRB0mSHhBp49cVGGNepSDByWY=",
"owner": "nix-community",
"repo": "nixpkgs-wayland",
"rev": "e2d0b0171ddf364b687d091ee603d0c3a7079166",
"rev": "72f9ecac5ada9ff6bb7c5811a43cb2f80fc8b6ca",
"type": "github"
},
"original": {
@ -900,11 +975,11 @@
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1726567229,
"narHash": "sha256-5BfrNDZBwiG0dN09V7Skd5Bpr2HwVMCdDWOvneQ2iZ4=",
"lastModified": 1726732492,
"narHash": "sha256-3raayMMIG/FRtPmSBVaVluHZkD7NYeUQldjmt3iR8d4=",
"owner": "roc-lang",
"repo": "roc",
"rev": "3215a8f3d73daf881185e4f7474972f2059754b6",
"rev": "9678046d916bdf19bc817cc8eb0d1d712dfb84d4",
"type": "github"
},
"original": {
@ -923,6 +998,7 @@
"lix-module": "lix-module",
"nim2nix": "nim2nix",
"nix-index-database": "nix-index-database",
"nixd": "nixd",
"nixos-wsl": "nixos-wsl",
"nixpkgs": "nixpkgs_4",
"nixpkgs-wayland": "nixpkgs-wayland",
@ -1082,6 +1158,27 @@
}
},
"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": {
"nixpkgs": [
"nixpkgs-wayland",
@ -1184,11 +1281,11 @@
]
},
"locked": {
"lastModified": 1726575046,
"narHash": "sha256-XD2qJ30wTLUz7BOXVz1wY/q+RJBvI7f6ksGJrYMbFAg=",
"lastModified": 1726792091,
"narHash": "sha256-dYu645m+1xsSpyx0IIZ4bc/G6Mw1mQMz221QOxRYzI0=",
"owner": "mitchellh",
"repo": "zig-overlay",
"rev": "a2f15c93b689b31044d5604fb0cd5bac818daf01",
"rev": "7e7ad073ba0a34ff75e7cf60f9f7153cf965f27f",
"type": "github"
},
"original": {
@ -1209,11 +1306,11 @@
]
},
"locked": {
"lastModified": 1726516447,
"narHash": "sha256-CV6Mr2zm5ZmtW4RnC3taJqA0tZ0U0ERzLBoO6GfzGWA=",
"lastModified": 1726791560,
"narHash": "sha256-0SDGQeb/onI7zVdNOdUhTJ2r4EmSJQJV2bjyXENBgws=",
"owner": "zigtools",
"repo": "zls",
"rev": "cf9b49a67b15693d62926ea11d17f53efc60be50",
"rev": "2b613d32696676bcbc257e31542a1dcbfa7f22a8",
"type": "github"
},
"original": {

View file

@ -9,6 +9,8 @@
nixpkgs-wayland.url = "github:nix-community/nixpkgs-wayland";
nixos-wsl.url = "github:nix-community/NixOS-WSL";
nix-index-database.url = "github:nix-community/nix-index-database";
# pipe support added
nixd.url = "github:nix-community/nixd/e2f0d908d6f2ee7bf72c620ed3c78817143b50ae";
lix = {
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";
utils.url = "git+https://git.dayl.in/daylin/utils.git";
nixd.inputs.nixpkgs.follows = "nixpkgs";
nim2nix.inputs.nixpkgs.follows = "nixpkgs";
hyprman.inputs.nixpkgs.follows = "nixpkgs";
f1multiviewer.inputs.nixpkgs.follows = "nixpkgs";

View file

@ -1,6 +1,4 @@
{
lib,
config,
enabled,
enableAttrs,
listify,
@ -12,8 +10,10 @@
nix-ld = enabled // {
overkill = enabled;
};
# languages = "misc|nim|node|nushell|python|roc|tex|zig" |> listify;
languages = "misc|nim|node|nushell|python|roc|tex" |> listify;
languages =
"misc|nim|node|nushell|python|tex"
# + "roc|zig"
|> listify;
}
// (
''

View file

@ -4,6 +4,7 @@
lib,
enabled,
self,
flake,
...
}:
let
@ -42,11 +43,12 @@ in
# environment.etc."channels/nixpkgs".source = inputs.nixpkgs.outPath;
environment.systemPackages = [
pkgs.nixd
# pkgs.nixd
pkgs.nixfmt-rfc-style
pkgs.nix-output-monitor
self.packages.${pkgs.system}.default
(flake.pkg "nixd")
];
programs.nix-index-database.comma = enabled;

View file

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

View file

@ -8,5 +8,5 @@ buildNimblePackage {
verions = "unstable";
src = lib.cleanSource ./.;
nativeBuildInputs = [ openssl ];
nimbleDepsHash = "sha256-WeTbNoF+TuzWriqoHWk5DBVgBXtNBIBHMkwy8/+a2JA=";
nimbleDepsHash = "sha256-o+CN0LlVOcgjLpDfjItW/5GCXTWcPSx9GfwQn+u2ST4=";
}

View file

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

View file

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

View file

@ -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],
)

View file

@ -1,6 +1,6 @@
import std/[logging, os, strformat, strutils]
from std/nativesockets import getHostname
import bbansi
import hwylterm
import ./logging
type

View file

@ -3,7 +3,7 @@ import std/[
strutils, streams, logging
]
import ./spin
import hwylterm
func addArgs*(cmd: var string, args: openArray[string]) =

View file

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

View file

@ -1,7 +1,7 @@
import std/[logging,strutils]
export logging
import bbansi
import hwylterm
var
handlers {.threadvar.}: seq[Logger]

View file

@ -3,7 +3,7 @@ import std/[
enumerate, os, sequtils, strformat,
strutils, sugar, logging, tables
]
import bbansi, jsony
import hwylterm, jsony
import ./[context, exec, logging]

View file

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