-
-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: add build loading awareness in the terminal - Import loading awareness animation for build process - Start loading animation when build and rebuild starts - Stop loading animation when build succeeds or fails * refactor: improve loading animation code structure - Move state management to a single state object - Extract LOADING_TEXT to constants - Add consistent bracket style --------- Co-authored-by: L <[email protected]>
- Loading branch information
Showing
3 changed files
with
51 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const LOADING_TEXT = "🔄 Building" | ||
const state = { | ||
loadingInterval: null as NodeJS.Timeout | null, | ||
isLoading: false, | ||
dotCount: 0 | ||
} | ||
|
||
export const startLoading = () => { | ||
if (state.isLoading) { | ||
return | ||
} | ||
state.isLoading = true | ||
process.stdout.write(LOADING_TEXT) | ||
state.loadingInterval = setInterval(() => { | ||
state.dotCount = (state.dotCount + 1) % 4 | ||
let dotString = state.dotCount === 0 ? " " : ".".repeat(state.dotCount) | ||
process.stdout.write(`\r${LOADING_TEXT}${dotString}`) | ||
}, 400) | ||
} | ||
|
||
export const stopLoading = () => { | ||
if (!state.isLoading) { | ||
return | ||
} | ||
state.isLoading = false | ||
if (state.loadingInterval) { | ||
clearInterval(state.loadingInterval) | ||
state.loadingInterval = null | ||
} | ||
// Clear the loading text | ||
process.stdout.write("\r" + " ".repeat(20) + "\r") | ||
} |
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