UNPKG

burst-whale-watch

Version:

An account watcher for Burstcoin

128 lines 4.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const blessed = require("neo-blessed"); const selectors_1 = require("../state/selectors"); const constants_1 = require("../constants"); class Scene { constructor(store, config) { this.store = store; this.config = config; this.autoCloseInterval = null; this.views = {}; this.onExitFn = () => { }; this.screen = blessed.screen({ smartCSR: true, autoPadding: true, fullUnicode: true, title: `BURST Whale Watcher by ohager`, cursor: { artificial: true, shape: 'line', blink: false, }, }); this.screen.enableInput(); this.screen.key(['escape', 'q', 'C-c'], () => { this.showQuitDialog(); }); this.screen.key('s', this.printState.bind(this)); this.screen.key('left', this.scrollLeft.bind(this)); this.screen.key('right', this.scrollRight.bind(this)); process.once('unhandledRejection', (e) => { this.__handleException(e); }); } printState() { console.debug(this.store.get()); } scrollRight() { const index = selectors_1.selectCurrentAccountIndex(this.store.get()); this.store.update((prevState) => ({ app: Object.assign(Object.assign({}, prevState.app), { currentAccountIndex: Math.min(this.config.accounts.length - constants_1.MAX_VISIBLE_ACCOUNTS, index + 1) }) })); } scrollLeft() { const index = selectors_1.selectCurrentAccountIndex(this.store.get()); this.store.update((prevState) => ({ app: Object.assign(Object.assign({}, prevState.app), { currentAccountIndex: Math.max(0, index - 1) }) })); } showQuitDialog() { if (!this.quitDialog) { this.quitDialog = blessed.box({ parent: this.screen, hidden: false, top: 'center', left: 'center', width: 'shrink', height: 5, tags: true, keys: true, mouse: true, shadow: true, transparent: true, label: { text: `Quit?`, side: 'left' }, border: { type: 'line', fg: 'red' }, style: { fg: 'white', bg: 'red', } }); this.quitDialog.key(['escape', 'n', 'enter', 'y', 'q'], ch => { switch (ch) { case 'q': case 'y': { this.onExitFn({ reason: 'quit', detail: null }); break; } default: { this.quitDialog.hide(); this.screen.render(); } } }); } this.quitDialog.focus(); this.quitDialog.setLine(1, " Do you really want to quit? {grey-fg}(press y/n){/} "); this.quitDialog.show(); this.screen.render(); } addView(name, view) { this.screen.append(view.element); this.views[name] = view; } view(name) { return this.views[name]; } render(state) { try { Object.getOwnPropertyNames(this.views).forEach(p => { this.views[p].update(state); }); if (this.quitDialog) { this.quitDialog.setFront(); } this.screen.render(); } catch (e) { this.__handleException(e); } } destroy() { this.screen.destroy(); this.views = {}; } onExit(callback) { this.onExitFn = callback; } __handleException(e) { this.destroy(); this.onExitFn({ reason: 'error', detail: e }); } } exports.Scene = Scene; //# sourceMappingURL=scene.js.map