mirror of
https://github.com/daylinmorgan/hwylterm.git
synced 2025-02-23 09:45:50 -06:00
fix bbstring handling
This commit is contained in:
parent
38cbe9f020
commit
dc78efe1d8
1 changed files with 43 additions and 17 deletions
|
@ -25,10 +25,10 @@ type
|
||||||
|
|
||||||
var spinnyChannel: Channel[SpinnyEvent]
|
var spinnyChannel: Channel[SpinnyEvent]
|
||||||
|
|
||||||
proc newSpinny*(text: string | Bbstring, s: Spinner): Spinny =
|
proc newSpinny*(text: Bbstring, s: Spinner): Spinny =
|
||||||
let style = "bold blue"
|
let style = "bold blue"
|
||||||
Spinny(
|
Spinny(
|
||||||
text: bb(text),
|
text: text,
|
||||||
running: true,
|
running: true,
|
||||||
frames: s.frames,
|
frames: s.frames,
|
||||||
bbFrames: mapIt(s.frames, bb(bbEscape(it), style)),
|
bbFrames: mapIt(s.frames, bb(bbEscape(it), style)),
|
||||||
|
@ -38,6 +38,9 @@ proc newSpinny*(text: string | Bbstring, s: Spinner): Spinny =
|
||||||
file: stderr,
|
file: stderr,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
proc newSpinny*(text: string, s: Spinner): Spinny =
|
||||||
|
newSpinny(bb(text), s)
|
||||||
|
|
||||||
proc newSpinny*(text: string | Bbstring, spinType: SpinnerKind): Spinny =
|
proc newSpinny*(text: string | Bbstring, spinType: SpinnerKind): Spinny =
|
||||||
newSpinny(text, Spinners[spinType])
|
newSpinny(text, Spinners[spinType])
|
||||||
|
|
||||||
|
@ -110,6 +113,7 @@ proc stop*(spinny: Spinny) =
|
||||||
spinny.stop(Stop)
|
spinny.stop(Stop)
|
||||||
|
|
||||||
template withSpinner*(msg: string = "", body: untyped): untyped =
|
template withSpinner*(msg: string = "", body: untyped): untyped =
|
||||||
|
block:
|
||||||
var spinner {.inject.} = newSpinny(msg, Dots)
|
var spinner {.inject.} = newSpinny(msg, Dots)
|
||||||
if isatty(spinner.file): # don't spin if it's not a tty
|
if isatty(spinner.file): # don't spin if it's not a tty
|
||||||
start spinner
|
start spinner
|
||||||
|
@ -118,10 +122,22 @@ template withSpinner*(msg: string = "", body: untyped): untyped =
|
||||||
else:
|
else:
|
||||||
body
|
body
|
||||||
|
|
||||||
|
template withSpinner*(msg: BbString = bb"", body: untyped): untyped =
|
||||||
|
block:
|
||||||
|
var spinner {.inject.} = newSpinny(msg, Dots)
|
||||||
|
if isatty(spinner.file): # don't spin if it's not a tty
|
||||||
|
start spinner
|
||||||
|
body
|
||||||
|
stop spinner
|
||||||
|
else:
|
||||||
|
body
|
||||||
|
|
||||||
|
|
||||||
template withSpinner*(body: untyped): untyped =
|
template withSpinner*(body: untyped): untyped =
|
||||||
withSpinner("", body)
|
withSpinner("", body)
|
||||||
|
|
||||||
template with*(kind: SpinnerKind, msg: string, body: untyped): untyped =
|
template with*(kind: SpinnerKind, msg: string, body: untyped): untyped =
|
||||||
|
block:
|
||||||
var spinner {.inject.} = newSpinny(msg, kind)
|
var spinner {.inject.} = newSpinny(msg, kind)
|
||||||
if isatty(spinner.file): # don't spin if it's not a tty
|
if isatty(spinner.file): # don't spin if it's not a tty
|
||||||
start spinner
|
start spinner
|
||||||
|
@ -130,8 +146,18 @@ template with*(kind: SpinnerKind, msg: string, body: untyped): untyped =
|
||||||
else:
|
else:
|
||||||
body
|
body
|
||||||
|
|
||||||
|
template with*(kind: SpinnerKind, msg: BbString, body: untyped): untyped =
|
||||||
|
block:
|
||||||
|
var spinner {.inject.} = newSpinny(msg, kind)
|
||||||
|
if isatty(spinner.file): # don't spin if it's not a tty
|
||||||
|
start spinner
|
||||||
|
body
|
||||||
|
stop spinner
|
||||||
|
else:
|
||||||
|
body
|
||||||
|
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
for kind, _ in Spinners:
|
for kind, _ in Spinners:
|
||||||
with(kind, $kind):
|
with(kind, $kind):
|
||||||
sleep 1 * 1000
|
sleep 1 * 1000
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue