Compare commits

...

6 commits

Author SHA1 Message Date
908ab5189a
better quitting 2024-09-09 10:57:44 -05:00
8347ad4a55
capture stderr with nixos-rebuild 2024-09-09 09:30:53 -05:00
ee0b137279
add zippy to implemente "update" command 2024-09-09 08:52:36 -05:00
9736bb3bcd
flake.lock: Update
Flake lock file updates:

• Updated input 'hyprland':
    'git+https://github.com/hyprwm/Hyprland/?ref=refs/heads/main&rev=727f1b54cd1ba48774092a5d54acc0e55f3ffe0f' (2024-09-05)
  → 'git+https://github.com/hyprwm/Hyprland/?ref=refs/heads/main&rev=04421063af2941c6e27e6dca2bdc2c387778a3a5' (2024-09-09)
• Updated input 'lix':
    '72589e7032.tar.gz?narHash=sha256-UtHpRNYPabG0zW3XB8Dldb68O7n1JLSUczTwg37dcsA%3D&rev=72589e703258e5cb4de091390291ff84c3a22bf2' (2024-09-03)
  → 'c14486ae8d.tar.gz?narHash=sha256-8tzJO3PllVPc0RYE0OfXVWlgTiJxKH1nzXsQLGyFRJ4%3D&rev=c14486ae8d3bbc862c625d948a6b2f4dc0927d5b' (2024-09-09)
• Updated input 'lix-module':
    'cecf70b775.tar.gz?narHash=sha256-rT/OkVXKkns2YvyF1nFvl%2B8Gc3sld1c1sXPtGkbqaDY%3D&rev=cecf70b77539c1a593f60ec9d0305b5e537ab6a9' (2024-08-13)
  → '353b25f0b6.tar.gz?narHash=sha256-dCbHCwqrzcHlEsRilMX%2BKM3IfRV46ieGqDyAD3GgCSs%3D&rev=353b25f0b6da5ede15206d416345a2ec4195b5c8' (2024-09-08)
• Updated input 'nix-index-database':
    'github:nix-community/nix-index-database/32058e9138248874773630c846563b1a78ee7a5b' (2024-09-01)
  → 'github:nix-community/nix-index-database/642275444c5a9defce57219c944b3179bf2adaa9' (2024-09-08)
• Updated input 'nixos-wsl':
    'github:nix-community/NixOS-WSL/8a89995f745b1a9029d654c391a0f62ca03f7fe7' (2024-09-03)
  → 'github:nix-community/NixOS-WSL/34b95b3962f5b3436d4bae5091d1b2ff7c1eb180' (2024-09-09)
• Updated input 'nixos-wsl/nixpkgs':
    'github:NixOS/nixpkgs/6e99f2a27d600612004fbd2c3282d614bfee6421' (2024-08-30)
  → 'github:NixOS/nixpkgs/68e7dce0a6532e876980764167ad158174402c6f' (2024-09-07)
• Updated input 'nixpkgs':
    'github:nixos/nixpkgs/ad416d066ca1222956472ab7d0555a6946746a80' (2024-09-04)
  → 'github:nixos/nixpkgs/574d1eac1c200690e27b8eb4e24887f8df7ac27c' (2024-09-06)
• Updated input 'nixpkgs-wayland':
    'github:nix-community/nixpkgs-wayland/5502df5dcd4157b8195fdf61da29bb560f4bceab' (2024-09-05)
  → 'github:nix-community/nixpkgs-wayland/dc951da2b8fdaabc09a1bc72dd5744438976be47' (2024-09-09)
• Updated input 'nixpkgs-wayland/lib-aggregate':
    'github:nix-community/lib-aggregate/3f10d853f98081feec35b736e38da91202a87c3a' (2024-09-01)
  → 'github:nix-community/lib-aggregate/3c180ce6583583285ef1b105cbc1667ba00c3e8d' (2024-09-08)
• Updated input 'nixpkgs-wayland/lib-aggregate/nixpkgs-lib':
    'github:nix-community/nixpkgs.lib/7f0b9e4fbd91826cb9ce6babbc11c87903191051' (2024-09-01)
  → 'github:nix-community/nixpkgs.lib/68584f89dd0eb16fea5d80ae127f3f681f6a5df7' (2024-09-08)
• Updated input 'nixpkgs-wayland/nixpkgs':
    'github:nixos/nixpkgs/ad416d066ca1222956472ab7d0555a6946746a80' (2024-09-04)
  → 'github:nixos/nixpkgs/574d1eac1c200690e27b8eb4e24887f8df7ac27c' (2024-09-06)
• Updated input 'roc':
    'github:roc-lang/roc/640bd15ca1dcf82bebe6a357e1a384b3ffdd4658' (2024-09-05)
  → 'github:roc-lang/roc/9a4d55672551fb4ffb54983272bb02d119c19f85' (2024-09-07)
• Updated input 'zig-overlay':
    'github:mitchellh/zig-overlay/5848c57bc396697ae4ed69f5e1295fe655c3ffae' (2024-09-05)
  → 'github:mitchellh/zig-overlay/4dedc1009bf778d0fbd9fbbddce39a696eb5fb9b' (2024-09-09)
• Updated input 'zls':
    'github:zigtools/zls/ace6f6da90a4420cd6632363b30762e577e2b922' (2024-09-01)
  → 'github:zigtools/zls/dd78968d4c8deefd33addc2b1cc14f60d89ec1a9' (2024-09-08)
2024-09-09 08:52:36 -05:00
6e31339e3c
remove spinner colorize procs 2024-09-09 08:44:28 -05:00
24829d6de2
indentation 2024-09-09 08:18:12 -05:00
13 changed files with 123 additions and 156 deletions

View file

@ -97,15 +97,15 @@ jobs:
- name: Build
run: >
nix run .
--
build
$(nix run . -- output --host "${{ matrix.host }}" --flake .)
--flake .
--debug
--
--keep-going
--print-build-logs
--out-link current
--
build
"$(nix run . -- output --host "${{ matrix.host }}" --flake .)"
--flake .
--debug
--
--keep-going
--print-build-logs
--out-link current
- run: git checkout flake-lock
@ -116,15 +116,15 @@ jobs:
- name: Build Updated
run: >
nix run .
--
build
$(nix run . -- output --host "${{ matrix.host }}" --flake .)
--flake .
--debug
--
--keep-going
--print-build-logs
--out-link updated
--
build
"$(nix run . -- output --host "${{ matrix.host }}" --flake .)"
--flake .
--debug
--
--keep-going
--print-build-logs
--out-link updated
- run: |
echo "# System Diff" >> $GITHUB_STEP_SUMMARY

View file

@ -323,11 +323,11 @@
"xdph": "xdph"
},
"locked": {
"lastModified": 1725563063,
"narHash": "sha256-tnBDplJLVDCfQyU8QV/WMlKXWqdburHmC3tp2XZmhtA=",
"lastModified": 1725873008,
"narHash": "sha256-hVPjlB0EPbf98tm4LcwOmS80tO/qfAoXqXKWZjDUG50=",
"ref": "refs/heads/main",
"rev": "727f1b54cd1ba48774092a5d54acc0e55f3ffe0f",
"revCount": 5188,
"rev": "04421063af2941c6e27e6dca2bdc2c387778a3a5",
"revCount": 5203,
"submodules": true,
"type": "git",
"url": "https://github.com/hyprwm/Hyprland/"
@ -488,11 +488,11 @@
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1725192674,
"narHash": "sha256-xEAVzgkjtdi9b4nl1yHWtiaPqYuvB7pwU9OurXv9Lls=",
"lastModified": 1725797487,
"narHash": "sha256-1NqTS6PePeoLVH8UY6poIoxlNq1Hhgn7RZs+OT8b2wQ=",
"owner": "nix-community",
"repo": "lib-aggregate",
"rev": "3f10d853f98081feec35b736e38da91202a87c3a",
"rev": "3c180ce6583583285ef1b105cbc1667ba00c3e8d",
"type": "github"
},
"original": {
@ -504,11 +504,11 @@
"lix": {
"flake": false,
"locked": {
"lastModified": 1725389327,
"narHash": "sha256-UtHpRNYPabG0zW3XB8Dldb68O7n1JLSUczTwg37dcsA=",
"rev": "72589e703258e5cb4de091390291ff84c3a22bf2",
"lastModified": 1725846500,
"narHash": "sha256-8tzJO3PllVPc0RYE0OfXVWlgTiJxKH1nzXsQLGyFRJ4=",
"rev": "c14486ae8d3bbc862c625d948a6b2f4dc0927d5b",
"type": "tarball",
"url": "https://git.lix.systems/api/v1/repos/lix-project/lix/archive/72589e703258e5cb4de091390291ff84c3a22bf2.tar.gz?rev=72589e703258e5cb4de091390291ff84c3a22bf2"
"url": "https://git.lix.systems/api/v1/repos/lix-project/lix/archive/c14486ae8d3bbc862c625d948a6b2f4dc0927d5b.tar.gz?rev=c14486ae8d3bbc862c625d948a6b2f4dc0927d5b"
},
"original": {
"type": "tarball",
@ -527,11 +527,11 @@
]
},
"locked": {
"lastModified": 1723511483,
"narHash": "sha256-rT/OkVXKkns2YvyF1nFvl+8Gc3sld1c1sXPtGkbqaDY=",
"rev": "cecf70b77539c1a593f60ec9d0305b5e537ab6a9",
"lastModified": 1725836728,
"narHash": "sha256-dCbHCwqrzcHlEsRilMX+KM3IfRV46ieGqDyAD3GgCSs=",
"rev": "353b25f0b6da5ede15206d416345a2ec4195b5c8",
"type": "tarball",
"url": "https://git.lix.systems/api/v1/repos/lix-project/nixos-module/archive/cecf70b77539c1a593f60ec9d0305b5e537ab6a9.tar.gz?rev=cecf70b77539c1a593f60ec9d0305b5e537ab6a9"
"url": "https://git.lix.systems/api/v1/repos/lix-project/nixos-module/archive/353b25f0b6da5ede15206d416345a2ec4195b5c8.tar.gz?rev=353b25f0b6da5ede15206d416345a2ec4195b5c8"
},
"original": {
"type": "tarball",
@ -647,11 +647,11 @@
]
},
"locked": {
"lastModified": 1725161148,
"narHash": "sha256-WfAHq3Ag3vLNFfWxKHjFBFdPI6JIideWFJod9mx1eoo=",
"lastModified": 1725765290,
"narHash": "sha256-hwX53i24KyWzp2nWpQsn8lfGQNCP0JoW/bvQmcR1DPY=",
"owner": "nix-community",
"repo": "nix-index-database",
"rev": "32058e9138248874773630c846563b1a78ee7a5b",
"rev": "642275444c5a9defce57219c944b3179bf2adaa9",
"type": "github"
},
"original": {
@ -692,11 +692,11 @@
"nixpkgs": "nixpkgs_3"
},
"locked": {
"lastModified": 1725358307,
"narHash": "sha256-su/Nzp2X8JlaD9wPYQGXeTilaVa5H06X7A3kqCLJNuo=",
"lastModified": 1725882169,
"narHash": "sha256-v5L+Dh6KdyycIgcdIc6SQ1fRNNvFJmYz02+fyeptA2o=",
"owner": "nix-community",
"repo": "NixOS-WSL",
"rev": "8a89995f745b1a9029d654c391a0f62ca03f7fe7",
"rev": "34b95b3962f5b3436d4bae5091d1b2ff7c1eb180",
"type": "github"
},
"original": {
@ -723,11 +723,11 @@
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1725152544,
"narHash": "sha256-Tm344cnFM9f2YZsgWtJduvhIrvLr3Bi8J4Xc+UZDKYE=",
"lastModified": 1725757153,
"narHash": "sha256-c1a6iLmCVPFI9EUVMrBN8xdmFxFXEjcVwiTSVmqajOs=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "7f0b9e4fbd91826cb9ce6babbc11c87903191051",
"rev": "68584f89dd0eb16fea5d80ae127f3f681f6a5df7",
"type": "github"
},
"original": {
@ -744,11 +744,11 @@
"nixpkgs": "nixpkgs_6"
},
"locked": {
"lastModified": 1725541051,
"narHash": "sha256-ke/qx3H6K789rijVpnDPD6M/BWqqueWMtXD+nGvqZ1k=",
"lastModified": 1725885379,
"narHash": "sha256-gw+CYMQRqzErAIp4WOTTeX6YXOhgk9YWyTM1Sa2cACA=",
"owner": "nix-community",
"repo": "nixpkgs-wayland",
"rev": "5502df5dcd4157b8195fdf61da29bb560f4bceab",
"rev": "dc951da2b8fdaabc09a1bc72dd5744438976be47",
"type": "github"
},
"original": {
@ -775,11 +775,11 @@
},
"nixpkgs_3": {
"locked": {
"lastModified": 1725001927,
"narHash": "sha256-eV+63gK0Mp7ygCR0Oy4yIYSNcum2VQwnZamHxYTNi+M=",
"lastModified": 1725693463,
"narHash": "sha256-ZPzhebbWBOr0zRWW10FfqfbJlan3G96/h3uqhiFqmwg=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "6e99f2a27d600612004fbd2c3282d614bfee6421",
"rev": "68e7dce0a6532e876980764167ad158174402c6f",
"type": "github"
},
"original": {
@ -791,11 +791,11 @@
},
"nixpkgs_4": {
"locked": {
"lastModified": 1725432240,
"narHash": "sha256-+yj+xgsfZaErbfYM3T+QvEE2hU7UuE+Jf0fJCJ8uPS0=",
"lastModified": 1725634671,
"narHash": "sha256-v3rIhsJBOMLR8e/RNWxr828tB+WywYIoajrZKFM+0Gg=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "ad416d066ca1222956472ab7d0555a6946746a80",
"rev": "574d1eac1c200690e27b8eb4e24887f8df7ac27c",
"type": "github"
},
"original": {
@ -823,11 +823,11 @@
},
"nixpkgs_6": {
"locked": {
"lastModified": 1725432240,
"narHash": "sha256-+yj+xgsfZaErbfYM3T+QvEE2hU7UuE+Jf0fJCJ8uPS0=",
"lastModified": 1725634671,
"narHash": "sha256-v3rIhsJBOMLR8e/RNWxr828tB+WywYIoajrZKFM+0Gg=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "ad416d066ca1222956472ab7d0555a6946746a80",
"rev": "574d1eac1c200690e27b8eb4e24887f8df7ac27c",
"type": "github"
},
"original": {
@ -900,11 +900,11 @@
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1725557788,
"narHash": "sha256-mPw63Fk1veQx18OVQijlvKbxxXF1uzI8N+0pF/tDnqE=",
"lastModified": 1725679186,
"narHash": "sha256-Eq+AI70CYMpIAhCjJ0VOoafd3tVhRYgXi8CzEqDn0KI=",
"owner": "roc-lang",
"repo": "roc",
"rev": "640bd15ca1dcf82bebe6a357e1a384b3ffdd4658",
"rev": "9a4d55672551fb4ffb54983272bb02d119c19f85",
"type": "github"
},
"original": {
@ -1184,11 +1184,11 @@
]
},
"locked": {
"lastModified": 1725538257,
"narHash": "sha256-J8UYDbHm8zSU+MruQ0VGEFL7eOJUkYsi7O4rCc0EcCk=",
"lastModified": 1725883895,
"narHash": "sha256-Nt0LE6HnWoJNSE7eo9XewYwwVm0aZQd4Rta7l+Kav1E=",
"owner": "mitchellh",
"repo": "zig-overlay",
"rev": "5848c57bc396697ae4ed69f5e1295fe655c3ffae",
"rev": "4dedc1009bf778d0fbd9fbbddce39a696eb5fb9b",
"type": "github"
},
"original": {
@ -1209,11 +1209,11 @@
]
},
"locked": {
"lastModified": 1725202623,
"narHash": "sha256-+UdfnVQIMYEBNN5lVK/Pn6fs2YMohP+f/4XAU7qTTHo=",
"lastModified": 1725812318,
"narHash": "sha256-kqPJwnlhGByYBE1gqr7WI7O/Em8LmLPTBhPEST8OA8s=",
"owner": "zigtools",
"repo": "zls",
"rev": "ace6f6da90a4420cd6632363b30762e577e2b922",
"rev": "dd78968d4c8deefd33addc2b1cc14f60d89ec1a9",
"type": "github"
},
"original": {

View file

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

View file

@ -30,6 +30,16 @@
"checksums": {
"sha1": "6aeb83e7481ca8686396a568096054bc668294df"
}
},
"zippy": {
"version": "0.10.16",
"vcsRevision": "a99f6a7d8a8e3e0213b3cad0daf0ea974bf58e3f",
"url": "https://github.com/guzba/zippy",
"downloadMethod": "git",
"dependencies": [],
"checksums": {
"sha1": "da3bb5ea388f980babcc29760348e2899d29a639"
}
}
},
"tasks": {}

View file

@ -13,4 +13,5 @@ bin = @["oizys"]
requires "nim >= 2.0.8"
requires "cligen"
requires "jsony"
requires "zippy"
requires "https://github.com/daylinmorgan/bbansi#9a85d9e"

View file

@ -46,24 +46,23 @@ overlay:
proc osCmd() =
## nixos-rebuild
if len(rest) == 0: quit "please provide subcmd"
if len(rest) == 0: fatalQuit "please provide subcmd"
let subcmd = rest[0]
if subcmd notin nixosSubcmds:
error (
fatalQuit(
&"unknown nixos-rebuild subcmd: {subcmd}\nexpected one of: \n" &
nixosSubcmds.mapIt(" " & it).join("\n")
); quit QuitFailure
)
nixosRebuild(subcmd, rest[1..^1])
proc ci(`ref`: string = "main") =
## trigger GHA update flow
if rest.len == 0:
fatal "expected workflow file name"; quit QuitFailure
if rest.len == 0: fatalQuit "expected workflow file name"
createDispatch(rest[0], `ref`)
proc checkExes() =
if findExe("nix") == "":
quit("oizys requires nix", QuitFailure)
fatalQuit "oizys requires nix"
proc `//`(t1: Table[string, string], t2: Table[string, string]): Table[string, string] =
# nix style shallow table merge

View file

@ -1,6 +1,8 @@
import std/[logging, os, strformat, strutils]
from std/nativesockets import getHostname
import ./logging
type
OizysContext* = object
flake, host: string
@ -24,8 +26,7 @@ var oc = initContext()
proc checkPath(s: string): string =
## fail if path doesn't exist
if not s.dirExists:
error fmt"flake path: {s} does not exist"
quit()
errorQuit fmt"flake path: {s} does not exist"
s
# public api -------------------------------------
@ -44,6 +45,7 @@ proc updateContext*(
oc.flake =
if flake.startsWith("github") or flake.startsWith("git+"): flake
else: checkPath(flake.normalizedPath().absolutePath())
debug oc
proc getHosts*(): seq[string] = return oc.hosts
proc getFlake*(): string = return oc.flake

View file

@ -1,7 +1,11 @@
import std/[httpclient,logging, os, strformat, strutils, json]
import ./logging
var ghToken = getEnv("GITHUB_TOKEN")
proc checkToken() {.inline.} =
if ghToken == "": fatalQuit "GITHUB_TOKEN not set"
#[curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
@ -11,16 +15,17 @@ var ghToken = getEnv("GITHUB_TOKEN")
-d '{"ref":"topic-branch","inputs":{"name":"Mona the Octocat","home":"San Francisco, CA"}}'
]#
proc postGhApi(url: string, body: JsonNode) =
if ghToken == "": fatal "GITHUB_TOKEN not set"; quit QuitFailure
checkToken()
let client = newHttpClient()
client.headers = newHttpHeaders({
"Accept" : "application/vnd.github+json",
"Authorization" : fmt"Bearer {ghToken}",
"X-GitHub-Api-Version": "2022-11-28",
})
let response = client.post(url, body = $body)
try:
let response = client.post(url, body = $body)
info fmt"Status: {response.code}"
except:
error "failed to get response code"

View file

@ -19,3 +19,4 @@ restic-gdrive
gitea
lock
code
comma-with-db

View file

@ -106,3 +106,12 @@ method log*(logger: FancyConsoleLogger, level: Level, args: varargs[string, `$`]
proc addHandlers*(handler: Logger) =
handlers.add(handler)
template errorQuit*(args: varargs[string, `$`]) =
error args
quit QuitFailure
template fatalQuit*(args: varargs[string, `$`]) =
error args
quit QuitFailure

View file

@ -4,7 +4,7 @@ import std/[
strutils, sugar, logging, tables
]
import bbansi, jsony
import ./[context, exec]
import ./[context, exec, logging]
proc nixCommand(cmd: string): string =
@ -23,10 +23,9 @@ const nixosSubcmds* =
repl build-vm build-vm-with-bootloader list-generations""".splitWhitespace()
proc nixosRebuild*(subcmd: string, rest: seq[string] = @[]) =
var cmd = fmt"sudo nixos-rebuild {subcmd} --flake {getFlake()} --log-format multiline"
if getHosts().len > 1:
error "nixos-rebuild only supports one host"
quit QuitFailure
fatalQuit "nixos-rebuild only supports one host"
var cmd = fmt"sudo nixos-rebuild {subcmd} --flake {getFlake()} --log-format multiline"
cmd.addArgs rest
quitWithCmd cmd
@ -77,8 +76,8 @@ proc parseDryRunOutput(err: string): DryRunOutput =
stderr.writeLine err
quit()
of 0:
info "nothing to do";
quit(QuitSuccess)
info "nothing to do"
quit QuitSuccess
else:
fatal "unexpected output from nix"
stderr.writeLine err
@ -88,7 +87,7 @@ proc parseDryRunOutput(err: string): DryRunOutput =
result.toFetch.sort(cmpDrv)
proc trunc(s: string, limit: int): string =
if s.len <= limit:
if s.len <= limit:
s
else:
s[0..(limit-4)] & "..."
@ -175,9 +174,7 @@ proc writeDervationsToStepSummary(drvs: seq[string]) =
fmt"| {name} | {hash} |"
)
let summaryFilePath = getEnv("GITHUB_STEP_SUMMARY")
if summaryFilePath == "":
fatal "no github step summary found"
quit QuitFailure
if summaryFilePath == "": fatalQuit "no github step summary found"
let output = open(summaryFilePath,fmAppend)
output.writeLine("| derivation | hash |\n|---|---|")
output.writeLine(rows.join("\n"))
@ -217,7 +214,7 @@ proc nixBuildHostDry*(minimal: bool, rest: seq[string]) =
cmd.addArg "--dry-run"
cmd.addArgs rest
let (_, err) =
runCmdCaptWithSpinner(cmd, "evaluating derivation for: " & getHosts().join(" "))
runCmdCaptWithSpinner(cmd, "evaluating derivation for: " & getHosts().join(" "), {CaptStderr})
let output = parseDryRunOutput err
display output
@ -226,8 +223,7 @@ template `bbfmt`(pattern: static string): untyped =
bb(fmt(pattern))
proc nixBuildWithCache*(minimal: bool, name: string, rest:seq[string]) =
if findExe("cachix") == "":
fatal "is cachix installed?"; quit QuitFailure
if findExe("cachix") == "": fatalQuit "is cachix installed?"
info bbfmt"building and pushing to cache: [b]{name}"
var cmd = "cachix"
cmd.addArgs ["watch-exec","--"]

View file

@ -1,49 +1,6 @@
import std/[os, locks, sequtils, terminal]
# https://github.com/molnarmark/colorize
proc reset(): string = "\e[0m"
# foreground colors
proc fgRed*(s: string): string = "\e[31m" & s & reset()
proc fgBlack*(s: string): string = "\e[30m" & s & reset()
proc fgGreen*(s: string): string = "\e[32m" & s & reset()
proc fgYellow*(s: string): string = "\e[33m" & s & reset()
proc fgBlue*(s: string): string = "\e[34m" & s & reset()
proc fgMagenta*(s: string): string = "\e[35m" & s & reset()
proc fgCyan*(s: string): string = "\e[36m" & s & reset()
proc fgLightGray*(s: string): string = "\e[37m" & s & reset()
proc fgDarkGray*(s: string): string = "\e[90m" & s & reset()
proc fgLightRed*(s: string): string = "\e[91m" & s & reset()
proc fgLightGreen*(s: string): string = "\e[92m" & s & reset()
proc fgLightYellow*(s: string): string = "\e[93m" & s & reset()
proc fgLightBlue*(s: string): string = "\e[94m" & s & reset()
proc fgLightMagenta*(s: string): string = "\e[95m" & s & reset()
proc fgLightCyan*(s: string): string = "\e[96m" & s & reset()
proc fgWhite*(s: string): string = "\e[97m" & s & reset()
# background colors
proc bgBlack*(s: string): string = "\e[40m" & s & reset()
proc bgRed*(s: string): string = "\e[41m" & s & reset()
proc bgGreen*(s: string): string = "\e[42m" & s & reset()
proc bgYellow*(s: string): string = "\e[43m" & s & reset()
proc bgBlue*(s: string): string = "\e[44m" & s & reset()
proc bgMagenta*(s: string): string = "\e[45m" & s & reset()
proc bgCyan*(s: string): string = "\e[46m" & s & reset()
proc bgLightGray*(s: string): string = "\e[47m" & s & reset()
proc bgDarkGray*(s: string): string = "\e[100m" & s & reset()
proc bgLightRed*(s: string): string = "\e[101m" & s & reset()
proc bgLightGreen*(s: string): string = "\e[102m" & s & reset()
proc bgLightYellow*(s: string): string = "\e[103m" & s & reset()
proc bgLightBlue*(s: string): string = "\e[104m" & s & reset()
proc bgLightMagenta*(s: string): string = "\e[105m" & s & reset()
proc bgLightCyan*(s: string): string = "\e[106m" & s & reset()
proc bgWhite*(s: string): string = "\e[107m" & s & reset()
# formatting functions
proc bold*(s: string): string = "\e[1m" & s & reset()
proc underline*(s: string): string = "\e[4m" & s & reset()
proc hidden*(s: string): string = "\e[8m" & s & reset()
proc invert*(s: string): string = "\e[7m" & s & reset()
import bbansi
type
SpinnerKind* = enum
@ -71,10 +28,10 @@ type
frame: string
interval: int
customSymbol: bool
style: string
EventKind = enum
Stop, StopSuccess, StopError,
SymbolChange, TextChange,
Stop, SymbolChange, TextChange,
SpinnyEvent = object
kind: EventKind
@ -83,19 +40,21 @@ type
var spinnyChannel: Channel[SpinnyEvent]
proc newSpinny*(text: string, s: Spinner): Spinny =
let style = "bold blue"
Spinny(
text: text,
running: true,
frames: s.frames,
frames: mapIt(s.frames, $bb(it, style)),
customSymbol: false,
interval: s.interval
interval: s.interval,
style: "bold blue"
)
proc newSpinny*(text: string, spinType: SpinnerKind): Spinny =
newSpinny(text, Spinners[spinType])
proc setSymbolColor*(spinny: Spinny, color: proc(x: string): string) =
spinny.frames = mapIt(spinny.frames, color(it))
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))
@ -113,14 +72,6 @@ proc handleEvent(spinny: Spinny, eventData: SpinnyEvent): bool =
spinny.frame = eventData.payload
of TextChange:
spinny.text = eventData.payload
of StopSuccess:
spinny.customSymbol = true
spinny.frame = "".bold.fgGreen
spinny.text = eventData.payload.bold.fgGreen
of StopError:
spinny.customSymbol = true
spinny.frame = "".bold.fgRed
spinny.text = eventData.payload.bold.fgRed
proc spinnyLoop(spinny: Spinny) {.thread.} =
var frameCounter = 0
@ -147,7 +98,7 @@ proc spinnyLoop(spinny: Spinny) {.thread.} =
stdout.write(spinny.frame & " " & spinny.text)
stdout.flushFile()
sleep(spinny.interval)
sleep spinny.interval
if frameCounter >= spinny.frames.len - 1:
frameCounter = 0
@ -155,14 +106,14 @@ proc spinnyLoop(spinny: Spinny) {.thread.} =
frameCounter += 1
proc start*(spinny: Spinny) =
initLock(spinny.lock)
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)
joinThread spinny.t
eraseLine stdout
flushFile stdout
@ -170,15 +121,8 @@ proc stop(spinny: Spinny, kind: EventKind, payload = "") =
proc stop*(spinny: Spinny) =
spinny.stop(Stop)
proc success*(spinny: Spinny, msg: string) =
spinny.stop(StopSuccess, msg)
proc error*(spinny: Spinny, msg: string) =
spinny.stop(StopError, msg)
template withSpinner*(msg: string = "", body: untyped): untyped =
var spinner {.inject.} = newSpinny(msg, Dots)
spinner.setSymbolColor(fgBlue)
if isatty(stdout): # don't spin if it's not a tty
start spinner

View file

@ -2,7 +2,7 @@
- [x] nix commands including dry runs
- [ ] gh api commands
- [ ] ci <- start with the easier one
- [x] ci <- start with the easier one
- [ ] update
<!-- generated with <3 by daylinmorgan/todo -->