-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Api fetching status indicator on tty (#768)
- Loading branch information
1 parent
935bd77
commit ebd1dad
Showing
4 changed files
with
59 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,26 @@ | ||
import _ from 'lodash' | ||
|
||
export { defaultLogger, truncate } from '@acala-network/chopsticks-core' | ||
|
||
const showProgress = process.stdout.isTTY && !process.env['CI'] && !process.env['TEST'] | ||
|
||
export const spinnerFrames = | ||
process.platform === 'win32' ? ['-', '\\', '|', '/'] : ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'] | ||
let index = 0 | ||
|
||
// clear to the right from cursor | ||
const clearStatus = _.debounce(() => process.stdout.clearLine(1), 500, { trailing: true }) | ||
|
||
export const apiFetching = _.throttle( | ||
() => { | ||
if (!showProgress) return | ||
|
||
// print ` ⠋ Fetching|` and move cursor at position 0 of the line `| ⠋ Fetching` | ||
process.stdout.write(` ${spinnerFrames[index++]} Fetching`) | ||
process.stdout.cursorTo(0) | ||
index = ++index % spinnerFrames.length | ||
clearStatus() | ||
}, | ||
50, | ||
{ leading: true }, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters