Commit 72c8cf0
Changed files (3)
experimental.d.ts
@@ -18,10 +18,12 @@ interface Echo {
(pieces: TemplateStringsArray, ...args: any[]): void
(...args: any[]): void
}
+export const echo: Echo
interface Retry {
(pieces: TemplateStringsArray, ...args: any[]): Promise<ProcessOutput>
}
-
-export const echo: Echo
export const retry: (count: number) => Retry
+
+type StopSpinner = () => void
+export function startSpinner(title: string): StopSpinner
experimental.mjs
@@ -51,3 +51,9 @@ function stringify(arg) {
}
return `${arg}`
}
+
+// Starts a simple CLI spinner, and returns stop() func.
+export function startSpinner(title = '') {
+ let i = 0, spin = () => process.stdout.write(` ${'⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'[i++ % 10]} ${title}\r`)
+ return (id => () => clearInterval(id))(setInterval(spin, 100))
+}
README.md
@@ -383,6 +383,18 @@ echo`Current branch is ${branch}.`
echo('Current branch is', branch)
```
+### `startSpinner()`
+
+Starts a simple CLI spinner, and returns `stop()` function.
+
+```js
+import {startSpinner} from 'zx/experimental'
+
+let stop = startSpinner()
+await $`long-running command`
+stop()
+```
+
### FAQ
#### Passing env variables