Skip to content

Commit

Permalink
screen.ts - manually hides the existing content when calling 'spawn'.…
Browse files Browse the repository at this point in the history
… This fixes a visual issue on some terminals where the content would not fully leave when spawning a foreground process
  • Loading branch information
drewbrokke committed Aug 23, 2019
1 parent eeaf2a4 commit 378e0e8
Showing 1 changed file with 47 additions and 8 deletions.
55 changes: 47 additions & 8 deletions src/interface/screen.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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';
Expand All @@ -21,24 +21,63 @@ 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);
screen.key('o', doOpenFilesInEditor);
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();
},
});

0 comments on commit 378e0e8

Please sign in to comment.