Commit 2e11b4e
Changed files (7)
examples
examples/parallel.mjs
@@ -14,11 +14,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-import { startSpinner } from 'zx/experimental'
-
let tests = await glob('test/*.test.js')
let stop = startSpinner('running tests')
-$.verbose = false
try {
let res = await Promise.all(tests.map((file) => $`npx uvu . ${file}`))
res.forEach((r) => console.log(r.toString()))
src/experimental.ts
@@ -66,13 +66,3 @@ function stringify(arg: ProcessOutput | any) {
}
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))
-}
src/globals.ts
@@ -16,6 +16,7 @@ declare global {
var question: typeof _.question
var quiet: typeof _.quiet
var sleep: typeof _.sleep
+ var startSpinner: typeof _.startSpinner
var which: typeof _.which
var within: typeof _.within
var YAML: typeof _.YAML
src/goods.ts
@@ -52,3 +52,21 @@ export function cd(dir: string) {
if ($.verbose) console.log('$', colorize(`cd ${dir}`))
$.cwd = path.resolve($.cwd, dir)
}
+
+/**
+ * Starts a simple CLI spinner.
+ * @param title Spinner's title.
+ * @return A stop() func.
+ */
+export function startSpinner(title = '') {
+ let i = 0,
+ v = $.verbose
+ $.verbose = false
+ let spin = () =>
+ process.stdout.write(` ${'⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'[i++ % 10]} ${title}\r`)
+ let id = setInterval(spin, 100)
+ return () => {
+ clearInterval(id)
+ $.verbose = v
+ }
+}
src/index.ts
@@ -22,6 +22,7 @@ import {
globby,
path,
sleep,
+ startSpinner,
which,
YAML,
os,
@@ -53,6 +54,7 @@ export {
question,
quiet,
sleep,
+ startSpinner,
which,
within,
YAML,
test/experimental.test.js
@@ -15,12 +15,7 @@
import { test } from 'uvu'
import * as assert from 'uvu/assert'
import '../build/globals.js'
-import {
- echo,
- retry,
- startSpinner,
- withTimeout,
-} from '../build/experimental.js'
+import { echo, retry, withTimeout } from '../build/experimental.js'
import chalk from 'chalk'
@@ -64,10 +59,4 @@ test('echo works', async () => {
)
})
-test('spinner works', async () => {
- let s = startSpinner('waiting')
- await sleep(1000)
- s()
-})
-
test.run()
test/index.test.js
@@ -17,8 +17,8 @@ import * as assert from 'uvu/assert'
import { inspect } from 'node:util'
import { Writable } from 'node:stream'
import { Socket } from 'node:net'
-import '../build/globals.js'
import { ProcessPromise } from '../build/index.js'
+import '../build/globals.js'
$.verbose = false
@@ -381,6 +381,12 @@ test('within() restores previous cwd', async () => {
await promise
})
+test('spinner works', async () => {
+ let s = startSpinner('waiting')
+ await sleep(1000)
+ s()
+})
+
test('inherit() works', async () => {
let p = $`printf foo`.inherit()
assert.throws(() => p.stdin)