2021-06-14 22:03:55 -04:00
|
|
|
|
|
|
|
|
import blessed from 'neo-blessed';
|
|
|
|
|
import ansi from 'sisteransi';
|
|
|
|
|
|
|
|
|
|
export const screen = blessed.screen({
|
|
|
|
|
smartCSR: true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export interface Renderable {
|
|
|
|
|
render: () => void
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const fg = (color) => '{' + color + '-fg}';
|
|
|
|
|
const bg = (color) => '{' + color + '-bg}';
|
|
|
|
|
const color = (color) => { return { fg: fg(color), bg: bg(color) } }
|
|
|
|
|
|
|
|
|
|
export const tags = {
|
|
|
|
|
black: color('black'),
|
|
|
|
|
red: color('red'),
|
|
|
|
|
green: color('green'),
|
|
|
|
|
yellow: color('yellow'),
|
|
|
|
|
blue: color('blue'),
|
|
|
|
|
magenta: color('magenta'),
|
|
|
|
|
cyan: color('cyan'),
|
|
|
|
|
white: color('white'),
|
|
|
|
|
reset: '{/}',
|
|
|
|
|
bright: '{bold}'
|
2021-06-15 19:15:49 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const boxStyle = () => {
|
|
|
|
|
return {
|
|
|
|
|
style: {
|
|
|
|
|
border: {
|
|
|
|
|
fg: 'white'
|
|
|
|
|
},
|
|
|
|
|
focus: {
|
|
|
|
|
border: {
|
|
|
|
|
fg: 'cyan'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
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) {
|
|
|
|
|
titleBar.setContent(` ${title}{|}{bold}{black-fg}v0.1.0 {/}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
return process.exit(0);
|
|
|
|
|
});
|