2021-06-14 22:03:55 -04:00
|
|
|
|
|
|
|
|
import blessed from 'neo-blessed';
|
|
|
|
|
import ansi from 'sisteransi';
|
2021-06-18 02:02:50 -04:00
|
|
|
import { getTheme } from './Theme.js';
|
2021-06-14 22:03:55 -04:00
|
|
|
|
|
|
|
|
export const screen = blessed.screen({
|
2021-06-18 02:02:50 -04:00
|
|
|
smartCSR: true,
|
|
|
|
|
terminal: 'xterm-256color'
|
2021-06-14 22:03:55 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export interface Renderable {
|
2021-06-18 21:29:45 -04:00
|
|
|
render(): void
|
2021-06-14 22:03:55 -04:00
|
|
|
}
|
|
|
|
|
|
2021-06-18 21:29:45 -04:00
|
|
|
// TODO move this to theme
|
2021-06-15 19:15:49 -04:00
|
|
|
export const boxStyle = () => {
|
|
|
|
|
return {
|
|
|
|
|
style: {
|
|
|
|
|
border: {
|
2021-06-18 02:02:50 -04:00
|
|
|
fg: getTheme().border.normal
|
2021-06-15 19:15:49 -04:00
|
|
|
},
|
|
|
|
|
focus: {
|
|
|
|
|
border: {
|
2021-06-18 02:02:50 -04:00
|
|
|
fg: getTheme().border.focused
|
2021-06-15 19:15:49 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
border: {
|
|
|
|
|
type: 'line'
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
2021-06-14 22:03:55 -04:00
|
|
|
|
|
|
|
|
let currentRenderable = null;
|
|
|
|
|
export function render(thing?: Renderable) {
|
|
|
|
|
if(!!thing) currentRenderable = thing;
|
|
|
|
|
currentRenderable.render();
|
|
|
|
|
screen.render();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const tasksPanel = blessed.box({
|
|
|
|
|
top: 1,
|
|
|
|
|
left: 0,
|
|
|
|
|
width: '50%+1',
|
|
|
|
|
height: '100%-1',
|
2021-06-15 19:15:49 -04:00
|
|
|
...boxStyle(),
|
2021-06-14 22:03:55 -04:00
|
|
|
tags: true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const menuPanel = blessed.box({
|
|
|
|
|
top: 1,
|
|
|
|
|
left: '50%+1',
|
|
|
|
|
width: '50%',
|
|
|
|
|
height: '100%-1',
|
2021-06-15 19:15:49 -04:00
|
|
|
...boxStyle(),
|
2021-06-14 22:03:55 -04:00
|
|
|
tags: true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const titleBar = blessed.box({
|
|
|
|
|
top: 0,
|
|
|
|
|
left: 0,
|
|
|
|
|
width: '100%',
|
|
|
|
|
height: 1,
|
|
|
|
|
tags: true,
|
2021-06-15 19:15:49 -04:00
|
|
|
});
|
|
|
|
|
|
2021-06-15 21:53:00 -04:00
|
|
|
export function setTitle(title) {
|
2021-06-18 02:02:50 -04:00
|
|
|
titleBar.setContent(` ${getTheme().header(title)}{|}${getTheme().subheader('v0.1.0')} {/}`);
|
2021-06-15 21:53:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setTitle('');
|
|
|
|
|
|
2021-06-15 19:15:49 -04:00
|
|
|
menuPanel.focus();
|
2021-06-14 22:03:55 -04:00
|
|
|
|
|
|
|
|
screen.append(tasksPanel);
|
|
|
|
|
screen.append(menuPanel);
|
|
|
|
|
screen.append(titleBar);
|
|
|
|
|
|
|
|
|
|
process.stdout.write(ansi.cursor.hide);
|
|
|
|
|
|
|
|
|
|
screen.key(['C-c'], function(ch, key) {
|
|
|
|
|
process.stdout.write(ansi.cursor.show);
|
2021-06-18 02:02:50 -04:00
|
|
|
setTimeout(_ => {
|
|
|
|
|
process.exit(0);
|
|
|
|
|
})
|
2021-06-16 15:26:42 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
tasksPanel.key('f2', () => {
|
|
|
|
|
menuPanel.focus();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
menuPanel.key('f1', () => {
|
|
|
|
|
tasksPanel.focus();
|
2021-06-14 22:03:55 -04:00
|
|
|
});
|