Skip to content

Commit 0d308c4

Browse files
committed
feat: show tui loading overlay for repo switch
1 parent 296c536 commit 0d308c4

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

apps/cli/src/tui/app.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,33 @@ export async function startTui(params: StartTuiParams): Promise<void> {
653653
});
654654
};
655655

656+
const withLoadingOverlay = async <T>(message: string, task: () => T | Promise<T>): Promise<T> => {
657+
const box = blessed.box({
658+
parent: widgets.screen,
659+
border: 'line',
660+
label: ' Loading ',
661+
width: '56%',
662+
height: 7,
663+
top: 'center',
664+
left: 'center',
665+
tags: true,
666+
content: `${message}\n\nThis can take a few seconds on large repos.`,
667+
style: {
668+
border: { fg: '#5bc0eb' },
669+
fg: 'white',
670+
bg: '#101522',
671+
},
672+
});
673+
widgets.screen.render();
674+
await new Promise<void>((resolve) => setTimeout(resolve, 0));
675+
try {
676+
return await task();
677+
} finally {
678+
box.destroy();
679+
widgets.screen.render();
680+
}
681+
};
682+
656683
const switchRepository = (
657684
target: RepositoryTarget,
658685
overrides?: Partial<{
@@ -734,7 +761,9 @@ export async function startTui(params: StartTuiParams): Promise<void> {
734761
}
735762

736763
if (choice.kind === 'existing') {
737-
switchRepository(choice.target);
764+
await withLoadingOverlay(`Opening ${choice.target.owner}/${choice.target.repo}...`, async () => {
765+
switchRepository(choice.target);
766+
});
738767
pushActivity(`[repo] switched to ${choice.target.owner}/${choice.target.repo}`);
739768
updateFocus('clusters');
740769
return;
@@ -766,7 +795,9 @@ export async function startTui(params: StartTuiParams): Promise<void> {
766795
}
767796

768797
if (choice.kind === 'existing') {
769-
switchRepository(choice.target);
798+
await withLoadingOverlay(`Opening ${choice.target.owner}/${choice.target.repo}...`, async () => {
799+
switchRepository(choice.target);
800+
});
770801
pushActivity(`[repo] opened ${choice.target.owner}/${choice.target.repo}`);
771802
updateFocus('clusters');
772803
return true;

0 commit comments

Comments
 (0)