diff --git a/src/interface/screen.ts b/src/interface/screen.ts index c9f93b5..041f725 100644 --- a/src/interface/screen.ts +++ b/src/interface/screen.ts @@ -1,4 +1,4 @@ -import { Screen } from '../types/types'; +import { Screen, BoxElement, BlessedElement } from '../types/types'; import { getCommands, registerCommand } from '../util/command-util'; import { doCopyCommitMessage, @@ -8,7 +8,7 @@ import { } from '../util/interface-actions'; import { generateLog } from '../util/log-util'; import { getHelpDialog, toggleHelp } from './help-dialog'; -import { getScreenElement } from './interface-elements'; +import { getScreenElement, getBoxElement } from './interface-elements'; import { getMainContentContainer } from './main-content-container'; import { getNotificationContainer } from './notification'; import { getStatusBar } from './status-bar'; @@ -21,12 +21,24 @@ export const getScreen = (): Screen => { smartCSR: true, }); + screen.key(['C-c', 'q', 'escape'], () => process.exit(0)); + screen._listenedMouse = true; - screen.append(getMainContentContainer()); - screen.append(getStatusBar()); - screen.append(getNotificationContainer()); - screen.append(getHelpDialog()); + let wrapper: BoxElement = getBoxElement({ + bottom: 0, + left: 0, + name: 'wrapper', + right: 0, + top: 0, + }); + + screen.append(wrapper); + + wrapper.append(getMainContentContainer()); + wrapper.append(getStatusBar()); + wrapper.append(getNotificationContainer()); + wrapper.append(getHelpDialog()); screen.key('?', toggleHelp); screen.key('m', doCopyCommitMessage); @@ -34,11 +46,38 @@ export const getScreen = (): Screen => { screen.key('r', () => generateLog(screen)); screen.key('x', doMarkCommit); screen.key('y', doCopyCommitSHA); - screen.key(['C-c', 'q', 'escape'], () => process.exit(0)); + + const wrapperHider = getHider(wrapper); for (const command of getCommands()) { - screen.key(command.key, async () => registerCommand(screen, command)); + screen.key(command.key, async () => { + if (command.foreground) { + wrapperHider.hide(); + } + + await registerCommand(screen, command); + + if (command.foreground) { + wrapperHider.show(); + } + }); } return screen; }; + +interface Hider { + hide(): void; + show(): void; +} + +const getHider = (element: BlessedElement): Hider => ({ + hide() { + element.hide(); + element.screen.render(); + }, + show() { + element.show(); + element.screen.render(); + }, +});