Node.prototype._createNode = function(opt_params) { this._node = blessed.list({ mouse: true, keys: true, scrollable: true, hidden: opt_params.hidden, left: opt_params.left, right: opt_params.right, top: opt_params.top, bottom: opt_params.bottom, width: opt_params.width, border: { type: 'line' }, style: { selected: { fg: 'black' } } }); app.ui.console.append(this._node); };
.then(items => { this.list = blessed.list({ items, parent: this.screen, border: 'line', label: ` ${this.url} `, keys: true, style: { selected: { bg: 'white', fg: 'black' } }, }) this.list.on('select', (item) => { const text = item.getText() if (text === '../') { const lastSlashIndex = this.url.lastIndexOf('/') if (lastSlashIndex > -1) { this.url = this.url.substring(0, lastSlashIndex) this.load() } } else if (text[text.length - 1] === '/') { this.navigate(text.substr(0, text.length - 1)) } else { this.output(text) } }) this.list.focus() this.screen.render() })
function magicSelect(rows) { screen = blessed.screen({autoPadding: true}); var list = blessed.list({}); list.setItems(rows); screen.append(list); screen.render(); }
var init = function() { rawList = blessed.list({ width: '30%', height: '100%', left: 0, style: { item: { bg: 'black', fg: 'blue' }, selected: { bg: 'yellow', fg: 'black' } }, align: 'left', keys: true, vi: true }); screen.append(rawList); };
module.exports = props => { const { items, search, onSelect, onToggle } = props let _items = items const list = blessed.list( Object.assign( { search, items: items.map(renderItem), }, listOpts, ), ) list._rawSetItems = list.setItems list.setItems = items => { _items = items list._rawSetItems(items.map(renderItem)) } list.key(['a'], () => { onToggle(_items[list.selected]) }) list.key(['c'], () => { onSelect(_items[list.selected], 'cast') }) list.on('select', (item, i) => { onSelect(_items[i]) }) return list }
export default (parent) => { let box = blessed.list({ ...listStyle, top: 1, left: '0', width: '30%', bottom: 2, items: ['Loading'] }); // let qsearch = blessed.textbox({ // //parent: parent, // top: 1, // left: 0, // height: 2, // width: '30%', // align: 'right', // label: 'qsearch:', // content: 'qsearch:', // inputOnFocus: true // }); let h = blessed.text({ ...headerStyle, //parent: parent, top: 0, left: 0, height: 1, width: '30%', align: 'center', content: 'Media Browser' }); let hHover = blessed.text({ top: 0, left: 0, height: 1, width: '30%', align: 'center', content: 'Media Browser', style: { fg: '#fffffe', bg: '#d65d0e', } }); parent.append(box); parent.append(h); parent.append(hHover); return { box, h, hHover, }; };
let createList = (emitter, s) => { if (!list) { list = blessed.list(options); list.focus(); screen = s; } applyListeners(emitter); handleUserInput(); return list; };
module.exports = function(searchBox, screen, log){ var blessed = require('blessed'); var tablesList = blessed.list({ width: '30%', height: '95%', label: "{center}tables{/center}", tags: true, scrollable: true, mouse: true, border: { type: 'line' }, padding: { left: 1, bottom: 2 }, keys: true, vi: true, style: { bg: 'black', fg: '#cccccc', border: { fg: '#ffffff' }, hover: { bg: 'green' }, selected: { fg: "gray", bg: "black", inverse: true } }, search: function(cb){ log.debug('search'); searchBox.focus(); searchBox.show(); screen.render(); searchBox.once('submit', function(searchString){ log.debug(searchString); searchBox.hide(); tablesList.focus(); screen.render(); return cb(searchString) }) } }); return tablesList; }
function Tree(options) { if (!(this instanceof Node)) return new Tree(options); var self = this; options = options || {}; options.bold = true; this.options = options; this.data = {}; this.nodeLines = []; this.lineNbr = 0; Box.call(this, options); options.extended = options.extended || false; options.keys = options.keys || ['+', 'space', 'enter']; options.template = options.template || {}; options.template.extend = options.template.extend || ' [+]'; options.template.retract = options.template.retract || ' [-]'; options.template.lines = options.template.lines || false; // Do not set height, since this create a bug where the first line is not always displayed this.rows = blessed.list({ top: options.top, width: options.width, //height: options.height, left: options.left, style: options.style, padding: options.padding, keys: true, mouse: options.mouse, tags: options.tags, input: options.input, vi: options.vi, ignoreKeys: options.ignoreKeys, scrollbar: options.scrollbar, scrollable: options.scrollable, }); this.append(this.rows); this.rows.key(options.keys, function() { var selectedNode = self.nodeLines[this.getItemIndex(this.selected)]; if (selectedNode.children) { selectedNode.extended = !selectedNode.extended; self.setData(self.data); self.screen.render(); } self.emit('select', selectedNode, this.getItemIndex(this.selected)); }); }
function showAnswers(answers, callback) { var listBox = blessed.box({ top: 'center', left: 'center', width: '90%', height: '90%', border: { type: 'line' }, tags: true }); var listOptions = { parent: listBox, border: { type: 'bg' } }; _.extend(listOptions, listStyle()); answersList = blessed.list(listOptions); answersList.setItems(answers.map(makeTitleForAnswer)); answersList.on('select', function () { callback(this.selected); }); answersList.key([ 'space', 'o' ], function () { answersList.enterSelected(); screen.render(); }); answersList.key(['b'], function() { var answer = answers[this.selected]; require('openurl').open(answer.link); }); answersList.key([ 'escape', 'q' ], () => { screen.remove(listBox); googleList.focus(); screen.render(); }); listBox.append(answersList); answersList.focus(); screen.append(listBox); screen.render(); }
export default (screen, items) => { let list = blessed.list({ ...style, top: 'center', left: 'center', width: '50%', height: '50%', border: { type: 'line' } }); screen.append(list); screen.saveFocus(); list.setItems(items); list.focus(); screen.render(); let keepFocus = () => list.focus(); list.on('blur', keepFocus); let done = () => { list.removeListener('blur', keepFocus); list.removeScreenEvent('keypress', press); screen.remove(list); screen.restoreFocus(); screen.render(); setTimeout(() => screen.blockEsc = false, 1000); }; let press = (ch, key) => { if (key.name === 'escape') { done(); return; } }; list.onScreenEvent('keypress', press); screen.blockEsc = true; return new Promise((resolve, reject) => { list.on('select', (item, index) => { done(); resolve(index); }); }); };
var createBottom = function() { if (graph2appended) { screen.remove(graph2); screen.remove(processList); } graph2appended = true; graph2 = blessed.box({ top: graph.height + 1, left: 'left', width: '50%', height: graph.height - 2, content: '', fg: loadedTheme.chart.fg, tags: true, border: loadedTheme.chart.border }); screen.append(graph2); processList = blessed.box({ top: graph.height + 1, left: '50%', width: screen.width - graph2.width, height: graph.height - 2, keys: true, mouse: true, fg: loadedTheme.table.fg, tags: true, border: loadedTheme.table.border }); screen.append(processList); processListSelection = blessed.list({ height: processList.height - 3, top: 2, width: processList.width - 2, left: 1, keys: true, vi: true, search: function(jump) { // @TODO //jump('string of thing to jump to'); }, style: loadedTheme.table.items, mouse: true }); processList.append(processListSelection); processListSelection.focus(); screen.render(); };
function showGoogleList(links, titles, callback) { var options = { parent: screen, // cols: 20, // rows: 20, width: '100%', height: '100%-1', top: 'center', left: 'center', padding: 1, title: 'Select Answer:', mouse: true } _.extend(options, listStyle()); googleList = blessed.list(options); googleList.setItems(titles); googleList.prepend(new blessed.Text({ // left: 2, content: 'Select one code tip:' })); googleList.on('select', function(event) { callback(this.selected); }); googleList.key(['space', 'o'], function() { googleList.enterSelected(); screen.render(); }); googleList.key(['escape', 'q'], function() { exit(); }); googleList.key(['b'], function() { var link = links[this.selected] try { require('openurl').open(link.link); } catch(e) {} }); googleList.select(0); googleList.focus(); screen.render(); }
var drawBoxes = function() { drawHeader(); drawFooter(); graph = blessed.box({ top: 2, left: 'left', width: '70%', height: '90%', content: '', fg: loadedTheme.chart.fg, tags: true, border: loadedTheme.chart.border }); screen.append(graph); folderList = blessed.list({ top: 2, left: '70%', width: screen.width - graph.width, height: graph.height, scrollable: true, keys: true, mouse: true, vi: true, fg: loadedTheme.table.fg, tags: true, border: loadedTheme.table.border, selectedBg: '#EB8118', selectedBold: true }); folderList.setLabel(' Folders list '); folderList.on('select', function(data){ var itemContent = data.content.split(' '); activeFolder = currentPath + itemContent[0]; setfetchFoldersDatas(); }); screen.append(folderList); screen.render(); };
module.exports = function(screen, parent, items, opts) { var style = opts.style , layout = opts.layout; return blessed.list({ parent: parent, top: 0, left: 0, keys: true, vi: true, width: layout.navWidth, height: screen.height, selectedFg: style.bg, selectedBg: style.fg, itemFg: style.fg, itemBg: style.bg, items: items, style: style, border: opts.border }); };
Users.initPane = function() { $.pane = blessed.list({ parent : screen.self(), width : '10%', height : '92%', right : true, fg : $.tpl.fg, bg : $.tpl.bg, border : $.tpl.border, selectedBg : $.tpl.selectedBg, mouse : true, keys : true, vi : true }) $.pane.prepend(new blessed.Text({ left : 2, content : $.tpl.title, })) $.pane.select(0) }
function install_attributeList() { attributeList = blessed.list({ parent: area1, label: " {bold}{cyan-fg}Attribute List{/cyan-fg}{/bold} ", top: 0, tags: true, left: w2 + "+1", width: "60%-1", height: "50%", border: "line", noCellBorders: true, scrollbar: scrollbar, style: _.clone(style), align: "left", keys: true }); area1.append(attributeList); attributeList.setItems(makeItems([])); }
nmterm.start = function(callback) { var screen = blessed.screen({ autoPadding: true, fastCSR: true, log: process.env.HOME + '/.nmterm/debug.ui.log' }); nmterm.networks = []; nmterm.screen = screen; screen._.target = null; screen._.wrapper = blessed.box({ parent: screen, left: 0, right: 0, top: 0, bottom: 0 }); screen._.bar = blessed.listbar({ parent: screen._.wrapper, top: 0, left: 0, right: 0, height: 1, keys: true, mouse: true, autoCommandKeys: true, style: { item: { fg: 'blue', hover: { fg: 'white', bg: 'black' } }, selected: { fg: 'white', bg: 'black' }, prefix: { fg: 'white' } } }); screen._.sep = blessed.line({ parent: screen._.wrapper, top: 1, left: 0, right: 0, orientation: 'horizontal' }); var tabs = screen._.tabs = {}; ['wifi', 'networks', 'rfkill', 'logs', 'debug'].forEach(function(name) { if (name === 'debug' && !nmterm.config.debug) { return; } var tab = tabs[name] = blessed.box({ top: 2, left: 0, right: 0, bottom: 0, scrollable: true, keys: true, vi: true, alwaysScroll: true, scrollbar: { ch: ' ' }, style: { scrollbar: { inverse: true } } }); screen._.bar.addItem({ text: name, callback: function() { // if (screen._.msg) screen._.msg.hide(); if (screen._.target) screen._.target.detach(); screen._.wrapper.append(tab); tab.focus(); screen._.target = tab; screen.render(); } }); }); function exit() { //screen._.msg.hide = function() {}; //screen._.msg.display('Shutting down...', -1); return callback(); } function refresh(callback) { nmterm._getNetworks(function(err, networks) { if (err) return screen._.msg.error(err.message); nmterm._getConfiguredNetworks(function(err, cnetworks) { if (err) return screen._.msg.error(err.message); var connection = cnetworks.filter(function(net) { return net.connected && net; })[0]; nmterm.networks = networks; var index = tabs.wifi._.list.selected; tabs.wifi._.list.clearItems(); networks.forEach(function(network) { var text = network.ssid; if (network.ssid === connection.name) { text += ' : Connection via ' + connection.device; } tabs.wifi._.list.addItem(text); }); tabs.wifi._.list.select(index); screen.render(); if (typeof callback === 'function') callback(); }); }); } setTimeout(function() { (function self() { return refresh(function() { return setTimeout(self, 10000); }); })(); }, 1); screen.key('f5', function() { return refresh(); }); screen.ignoreLocked.push('C-c'); screen.key('C-c', function(ch, key) { return exit(); }); /** * Wifi */ tabs.wifi.on('focus', function() { tabs.wifi._.list.focus(); }); tabs.wifi._.list = blessed.list({ parent: tabs.wifi, top: 0, left: 0, right: 0, bottom: 0, keys: true, vi: true, mouse: true, tags: true, style: { scrollbar: { inverse: true }, selected: { bg: 'blue' }, item: { hover: { bg: 'blue' } } }, scrollbar: { ch: ' ' } }); tabs.wifi._.list.on('select', function(el, index) { var text = utils.inspect(nmterm.networks[index]); return screen._.details.display(text, -1); }); tabs.wifi._.list.key('C', function(key) { nmterm._connectNetwork(nmterm.networks[index].ssid, refresh); }); tabs.wifi._.list.key('D', function(key) { nmterm._diconnectNetwork(nmterm.networks[index].ssid, refresh); }); tabs.wifi._.list.key('R', function(key) { refresh(); }); tabs.wifi._.list.key('K', function(key) { nmterm._checkRfkill(function(err, enabled) { if (enabled) { nmterm._rfkill(refresh); } else { nmterm._unrfkill(refresh); } }); }); tabs.wifi._.list.key('right', function(key) { var index = tabs.wifi._.list.selected; var network = nmterm.networks[index]; tabs.configure._.list.clearItems(); // check to see if there's a configured network nmterm._getConfiguredNetwork(network.ssid, function(err, cnet) { // configure Object.keys(network).forEach(function(key) { var value = network[key]; tabs.configure._.list.addItem(key + ': ' + value); }); // if (screen._.msg) screen._.msg.hide(); if (screen._.target) screen._.target.detach(); screen._.wrapper.append(tabs.configure); tabs.configure.focus(); screen._.target = tabs.configure; screen.render(); }); }); /** * Configure */ tabs.configure = blessed.box({ top: 2, left: 0, right: 0, bottom: 0, scrollable: true, keys: true, vi: true, alwaysScroll: true, scrollbar: { ch: ' ' }, style: { scrollbar: { inverse: true } } }); tabs.configure.on('focus', function() { tabs.configure._.list.focus(); }); tabs.configure._.list = blessed.list({ parent: tabs.configure, top: 0, left: 0, right: 0, bottom: 0, keys: true, vi: true, mouse: true, tags: true, style: { scrollbar: { inverse: true }, selected: { bg: 'blue' }, item: { hover: { bg: 'blue' } } }, scrollbar: { ch: ' ' } }); tabs.configure._.list.key('q', function() { if (screen._.target) screen._.target.detach(); screen._.wrapper.append(tabs.wifi); tabs.wifi.focus(); screen._.target = tabs.wifi; screen.render(); }); /** * Global Widgets */ screen._.prompt = blessed.prompt({ parent: screen, top: 'center', left: 'center', height: 'shrink', width: 'shrink', keys: true, vi: true, mouse: true, tags: true, content: 'Label:', border: 'line', hidden: true }); screen._.question = blessed.question({ parent: screen, top: 'center', left: 'center', width: 'shrink', height: 'shrink', keys: true, vi: true, mouse: true, tags: true, content: 'Label:', border: 'line', hidden: true }); screen._.fm = blessed.filemanager({ parent: screen, top: 'center', left: 'center', width: '70%', height: '50%', keys: true, vi: true, mouse: true, tags: true, label: ' Choose a file... ', border: 'line', hidden: true }); screen._.picker = blessed.list({ parent: screen, top: 'center', left: 'center', width: '70%', height: '50%', border: 'line', keys: true, vi: true, mouse: true, tags: true, hidden: true, style: { scrollbar: { inverse: true }, selected: { bg: 'blue' }, item: { hover: { bg: 'blue' } } }, scrollbar: { ch: ' ' } }); /** * Loader */ screen._.loader = blessed.loading({ parent: screen, top: 'center', left: 'center', height: 5, align: 'center', width: '50%', tags: true, hidden: true, border: 'line' }); /** * Message */ screen._.msg = blessed.message({ parent: screen, top: 'center', left: 'center', height: 'shrink', width: '50%', align: 'center', tags: true, hidden: true, border: 'line', ignoreKeys: ['q'] }); /** * Details */ screen._.details = blessed.message({ parent: screen, top: 'center', left: 'center', width: '70%', height: '50%', scrollable: true, alwaysScroll: true, keys: true, vi: true, mouse: true, tags: true, hidden: true, border: 'line', scrollbar: { ch: ' ' }, style: { scrollbar: { bg: 'blue' } } }); screen._.bar.commands[0].callback(); };
var screen = blessed.screen({ autoPadding: true }); screen.key('q', function() { process.exit(0); }); var home = blessed.list({ parent: screen, padding: { top: 2 }, mouse: true, keys: true, fg: 'white', bg: 'blue', selectedFg: 'blue', selectedBg: 'white', items: [ '» REMOVE AUTHENTICATION PROVIDER', '» CHANGE EMAIL SERVICE', '» ADD NODE.JS CLUSTER SUPPORT', '» EXIT' ] }); var footer = blessed.text({ parent: screen, bottom: 0, fg: 'white', bg: 'blue', tags: true,
}); app.use(bodyParser.urlencoded()); // Create a screen object. var screen = blessed.screen(); var list = blessed.list({ parent : screen, width : '60%', height : '60%', top : 0, left : 0, align : 'left', fg : 'blue', border : { type : 'line' }, // selectedBg: 'white', selectedBold : true, mouse : true, keys : true, vi : true }); var list2 = blessed.list({ parent : screen, width : '40%', height : '100%', top : 0, right : 0,
Dashboard.init = function() { // Init Screen this.screen = blessed.screen({ smartCSR: true, fullUnicode: true }); this.screen.title = 'PM2 Dashboard'; this.list = blessed.list({ top: '0', left: '0', width: WIDTH_LEFT_PANEL + '%', height: '70%', padding: 0, scrollbar: { ch: ' ', inverse: false }, border: { type: 'line' }, keys: true, autoCommandKeys: true, tags: true, style: { selected: { bg: 'blue', fg: 'white' }, scrollbar: { bg: 'blue', fg: 'black' }, fg: 'white', border: { fg: 'blue' }, header: { fg: 'blue' } } }); this.logBox = blessed.box({ label: ' Global Logs ', top: '0', left: WIDTH_LEFT_PANEL + '%', width: 100 - WIDTH_LEFT_PANEL + '%', height: '70%', padding: DEFAULT_PADDING, scrollable: true, scrollbar: { ch: ' ', inverse: false }, keys: true, autoCommandKeys: true, tags: true, border: { type: 'line' }, style: { fg: 'white', border: { fg: 'white' }, scrollbar: { bg: 'blue', fg: 'black' } } }); this.metadataBox = blessed.box({ label: ' Metadata ', top: '70%', left: WIDTH_LEFT_PANEL + '%', width: 100 - WIDTH_LEFT_PANEL + '%', height: '26%', padding: DEFAULT_PADDING, scrollable: true, scrollbar: { ch: ' ', inverse: false }, keys: true, autoCommandKeys: true, tags: true, border: { type: 'line' }, style: { fg: 'white', border: { fg: 'white' }, scrollbar: { bg: 'blue', fg: 'black' } } }); this.metricsBox = blessed.list({ label: ' Custom metrics {#444-fg}(http://bit.ly/code-metrics){/} ', top: '70%', left: '0%', width: WIDTH_LEFT_PANEL + '%', height: '26%', padding: DEFAULT_PADDING, scrollbar: { ch: ' ', inverse: false }, keys: true, autoCommandKeys: true, tags: true, border: { type: 'line' }, style: { fg: 'white', border: { fg: 'white' }, scrollbar: { bg: 'blue', fg: 'black' } } }); this.box4 = blessed.text({ content: ' left/right: switch boards | up/down/mouse: scroll | Ctrl-C: exit{|} {cyan-fg}{bold}To go further check out https://keymetrics.io/{/} ', left: '0%', top: '95%', width: '100%', height: '6%', valign: 'middle', tags: true, style: { fg: 'white' } }); this.list.focus(); this.screen.append(this.list); this.screen.append(this.logBox); this.screen.append(this.metadataBox); this.screen.append(this.metricsBox); this.screen.append(this.box4); this.list.setLabel(' Process list '); this.screen.render(); var that = this; var i = 0; var boards = ['list', 'logBox', 'metricsBox', 'metadataBox']; this.screen.key(['left', 'right'], function(ch, key) { (key.name === 'left') ? i-- : i++; if (i == 4) i = 0; if (i == -1) i = 3; that[boards[i]].focus(); that[boards[i]].style.border.fg = 'blue'; if (key.name === 'left') { if (i == 3) that[boards[0]].style.border.fg = 'white'; else that[boards[i + 1]].style.border.fg = 'white'; } else { if (i == 0) that[boards[3]].style.border.fg = 'white'; else that[boards[i - 1]].style.border.fg = 'white'; } }); this.screen.key(['escape', 'q', 'C-c'], function(ch, key) { this.screen.destroy(); process.exit(0); }); // async refresh of the ui setInterval(function () { that.screen.render(); }, 300); return this; }
bg: 'default' }); var list = blessed.list({ parent: screen, label: '', align: 'left', mouse: true, top: 1, bottom: 3, width: '100%', style: { fg: 'blue', bg: 'default', selected: { bg: 'magenta' }, item: { hover: { fg: 'white', bg: 'black', bold: true } } }, tags: true, items: [], }); var timebox = blessed.box({ parent: screen,
left: 'center', scrollable: true, scrollbar: { bg: 'blue' }, mouse: true, alwaysScroll: true, border: {type:'line'} }) var methodBox = blessed.list({ parent: form, width: '15%', left: '10%', height: '10%', mouse:true, top: '7%', border: { type: 'line' }, selectedBg: 'green' }); methodBox.setItems(["GET","POST", "PATCH", "DELETE", "PUT"]); var url = blessed.textbox({ parent: form, width: '60%', height: 3, border: {type: 'line'}, keys: true,
Class.prototype._menu = function(){ process.title = this.name; // get some colors var bg = blessed.colors.match(this.background); var fg = blessed.colors.match(this.foreground); // create screen this.menu = blessed.screen({ term: (isWin ? 'windows-ansi' : null) }); // title bar var titleBar = blessed.text({ top: 0, left: 0, width: '100%', bold: true, bg: bg, fg: fg, content: this.name, align: 'center', tags: true }); this.menu.append(titleBar); // list of lessons var lessonNames = this.lessons.map(function(i){ return i.displayName(); }); var lessonList = blessed.list({ align: 'center', mouse: true, keys: true, bg: bg, fg: fg, selectedBg: fg, selectedFg: bg, border: { type: 'line', fg: 'default', bg: 'default' }, width: '90%', height: '80%', top: 'center', left: 'center', items: lessonNames, scrollbar: { ch: ' ', track: { bg: 'red' }, style: { inverse: true } } }); lessonList.on('select', function(e, idx){ this.emit('select', this.lessons[idx]); this._onselect(this.lessons[idx]); }.bind(this)); this.menu.append(lessonList); lessonList.select(0); // list label lessonList.prepend(blessed.text({ left: 2, content: ' Lessons ' })); // catch keys this.menu.key(['escape', 'q', 'C-c'], function() { process.exit(0); }); // and render lessonList.focus(); this.menu.render(); };
function showList(error, body) { if(error) { return process.exit(0); } var episodes = body.home_highlights.elements.filter(function(element) { return element.type == 'episode'; }); var details = blessed.box({ parent: screen, top: '0', left: 'center', width: '50%', height: 7, content: ' _ _ _ _ \n' + ' (_)_ __| |__ _ _ _ ___ _ _ ___ __| (_)\n' + ' | | \'_ \\ / _` | || / -_) \'_|___/ _| | |\n' + ' |_| .__/_\\__,_|\\_, \\___|_| \\__|_|_|\n' + ' |_| |__/ \n', align: 'center', style: { bg: 'magenta', fg: 'white', bold: true }, border: { type: 'line' } }); var list = blessed.list({ parent: screen, top: 7, left: 'center', width: '50%', bottom: 0, padding: { left: 1, right: 1 }, keys: true, mouse: false, label: 'Highlights', border: { type: 'line' }, style: { fg: 'magenta', bg: 'default', invert: true, selected: { fg: 'default', bg: 'magenta' } }, items: episodes.map(function(episode) { return episode.title + (episode.subtitle ? ' - ' + episode.subtitle : ''); }) }); list.on('hover', function(item, index) { console.log(item, index); }); list.focus(); list.on('select', function(item, index) { showLoadingDialog(); var episode = episodes[index]; setTimeout(function() { screen.exec('./play.sh', [episode.id], null, function() { hideLoadingDialog(); }); }, 0); }); screen.render(); }
function Connections(screen, config, client) { var connections = Connections.connections var sidePanelWidth = 25 if (connections) { connections.detach() screen.append(connections) return connections } connections = Connections.connections = blessed.box({ parent: screen, mouse: true, keys: true, tags: true, label: '{247-bg} {black-fg}CONNECTIONS{/black-fg} {/247-bg}', vi: true, align: 'left', border: { type: 'ascii', bg: 'white', fg: 247 }, style: { bg: 'white', fg: 'black', scrollbar: { inverse: true }, selected: { bg: 'blue' }, item: { hover: { bg: 'black' } } }, left: 'center', top: '15%', width: '70%', height: 21 }) // screen.on('keypress', function(ch, key) { // if (connections.visible && key.name == 'escape') { // connections.hide() // screen.render() // } // }) var form = blessed.form({ parent: connections, mouse: true, keys: true, vi: true, bg: 'white', fg: 'black', left: 1, right: 1, top: 1, bottom: 3 }) var list = connections._.list = blessed.list({ parent: form, mouse: true, keys: true, vi: true, left: 0, top: 1, bottom: 1, width: sidePanelWidth, align: 'left', items: Object.keys(config.connections), scrollbar: { ch: ' ' }, style: { bg: 'white', fg: 'black', scrollbar: { inverse: true }, selected: { bg: 243, fg: 'white' }, item: { hover: { bg: 'black', fg: 'white' } } } }) list.on('select', function() { var keys = Object.keys(config.connections) var key = keys[list.selected] var conn = config.connections[key] toggleType(conn.local) textName.setValue(key) textPath.setValue(conn.path) textPort.setValue(conn.port) textHost.setValue(conn.host) textManifest.setValue(conn.manifest) screen.render() }) // // TODO: add 'postrender' event // process.nextTick(function() { list.focus() list.emit('select') screen.render() }) // list.on('focus', function() { // list.select(1) // }) var labelWidth = 15 var formLabelRemote = blessed.element({ parent: form, content: ['Name\n\nType\n\nKey Encoding Value Encoding', '\n\n\n\nPort\n\nHost\n\nManifest File'].join(''), left: 1, style: { bg: 'white', fg: 'black', }, top: 1, left: sidePanelWidth + 1, right: 1, height: 14 }) var formLabelLocal = blessed.element({ parent: form, content: ['Name\n\nType\n\nKey Encoding Value Encoding', '\n\n\n\nPath\n\nCache Size\n\nCompression'].join(''), left: 1, style: { bg: 'white', fg: 'black', }, top: 1, left: sidePanelWidth + 1, right: 1, hidden: true, height: 14 }) var textName = blessed.textbox({ parent: form, mouse: true, keys: true, bg: 243, fg: 'white', hoverBg: 'black', height: 1, left: sidePanelWidth + labelWidth + 1, right: 1, top: 1 }) var checkType = blessed.checkbox({ parent: form, mouse: true, keys: true, shrink: true, style: { bg: 'white', fg: 'black' }, height: 1, left: sidePanelWidth + labelWidth + 1, top: 3, name: 'check', content: 'Local Database' }) var textKeyEncoding = blessed.textbox({ parent: form, mouse: true, keys: true, bg: 243, fg: 'white', hoverBg: 'black', height: 1, left: sidePanelWidth + labelWidth + 1, width: 10, top: 5, value: 'utf8' }) var textValueEncoding = blessed.textbox({ parent: form, mouse: true, keys: true, bg: 243, fg: 'white', hoverBg: 'black', height: 1, left: sidePanelWidth + labelWidth + 30, width: 10, top: 5, value: 'json' }) function toggleType(local) { if (local) { textPath.show() buttonClearLocal.show() textCacheSize.show() formLabelLocal.show() formLabelRemote.hide() textPort.hide() textHost.hide() buttonClearManifest.hide() textManifest.hide() checkType.check() } else { textPath.hide() buttonClearLocal.hide() textCacheSize.hide() formLabelLocal.hide() formLabelRemote.show() textPort.show() textHost.show() buttonClearManifest.show() textManifest.show() checkType.uncheck() } screen.render() } checkType.on('click', function() { toggleType(checkType.checked) }) var textPath = blessed.textbox({ parent: form, mouse: true, keys: true, bg: 243, fg: 'white', hoverBg: 'black', height: 1, left: sidePanelWidth + labelWidth + 1, right: 11, top: 9, hidden: true, name: 'text' }) var buttonClearLocal = blessed.button({ parent: form, top: 9, height: 1, right: 1, width: 9, content: ' Clear ', align: 'center', style: { bg: 243, fg: 'white', focus: { bg: 'black' } }, hoverBg: 'black', hoverFg: 'black', hidden: true, mouse: true, }) buttonClearLocal.on('click', function() { textPath.clearValue() screen.render() }) var textCacheSize = blessed.textbox({ parent: form, mouse: true, keys: true, bg: 243, fg: 'white', hoverBg: 'black', height: 1, left: sidePanelWidth + labelWidth + 1, width: 25, top: 11, hidden: true, value: '8388608' }) var checkCompression = blessed.checkbox({ parent: form, mouse: true, keys: true, shrink: true, style: { bg: 'white', fg: 'black' }, height: 1, left: sidePanelWidth + labelWidth + 1, top: 13, checked: true, content: 'Use Snappy' }) var sep = blessed.line({ parent: connections, orientation: 'horizontal', left: sidePanelWidth + 2, right: 2, top: 8, style: { bg: 'white', fg: 247, } }) var textPort = blessed.textbox({ parent: form, mouse: true, keys: true, bg: 243, fg: 'white', hoverBg: 'black', height: 1, left: sidePanelWidth + labelWidth + 1, right: 1, top: 9, name: 'text' }) var textHost = blessed.textbox({ parent: form, mouse: true, keys: true, bg: 243, fg: 'white', hoverBg: 'black', height: 1, left: sidePanelWidth + labelWidth + 1, right: 1, top: 11, name: 'text' }) var textManifest = blessed.textbox({ parent: form, mouse: true, keys: false, bg: 243, fg: 'white', hoverBg: 'black', height: 1, right: 11, left: sidePanelWidth + labelWidth + 1, top: 13, name: 'text' }) var buttonClearManifest = blessed.button({ parent: form, top: 13, height: 1, right: 1, width: 9, content: ' Clear ', align: 'center', style: { bg: 243, fg: 'white', focus: { bg: 'black' } }, hoverBg: 'black', hoverFg: 'black', mouse: true, }) buttonClearManifest.on('click', function() { textManifest.clearValue() screen.render() }) function locate() { connections.hide() fm.pick(process.cwd(), function(err, fname) { if (!fname) { connections.show() screen.render() return fm.hide() } if (checkType.checked) { textPath.setValue((path.dirname(fname))) connections.show() fm.hide() textPath.emit('blur') screen.render() return } fs.readFile(fname, function(err, data) { if (err) return output.error('NOT OK!', err) textManifest.setValue(fname) connections.show() screen.render() }) }) } textManifest.on('click', locate) textPath.on('click', locate) var buttonDelete = blessed.button({ parent: form, bottom: 0, height: 1, right: 10, width: 10, content: ' Delete ', align: 'center', style: { bg: 243, fg: 'white', focus: { bg: 'black' } }, hoverBg: 'black', autoFocus: false, mouse: true }) var buttonSave = blessed.button({ parent: form, bottom: 0, height: 1, right: 1, width: 8, content: ' Save ', align: 'center', style: { bg: 243, fg: 'white', focus: { bg: 'black' } }, hoverBg: 'black', autoFocus: false, mouse: true, }) var buttonCreate = blessed.button({ parent: connections, bottom: 1, height: 1, right: 14, width: 10, content: ' Create ', align: 'center', style: { bg: 243, fg: 'white', focus: { bg: 'black' } }, hoverBg: 'black', autoFocus: false, mouse: true, }) var buttonConnect = blessed.button({ parent: connections, bottom: 1, height: 1, right: 2, width: 11, content: ' Connect ', align: 'center', style: { bg: 243, fg: 'white', focus: { bg: 'black' } }, hoverBg: 'black', autoFocus: false, mouse: true, }) textPort.on('focus', function() { this.readInput() }) textHost.on('focus', function() { this.readInput() }) textName.on('focus', function() { this.readInput() }) textKeyEncoding.on('focus', function() { this.readInput() }) textValueEncoding.on('focus', function() { this.readInput() }) buttonSave.on('click', function() { var name = textName.getValue() var port = textPort.getValue() var host = textHost.getValue() var fpath = textPath.getValue() var keyEncoding = textKeyEncoding.getValue() var valueEncoding = textValueEncoding.getValue() var manifest = textManifest.getValue() var cacheSize = parseInt(textCacheSize.getValue()) if (!config.connections[name]) { list.add(name) } if (!config.connections[name]) { config.connections[name] = {} } var o = {} o.path = fpath o.keyEncoding = keyEncoding o.valueEncoding = valueEncoding o.local = checkType.checked o.compression = checkCompression.checked o.cacheSize = cacheSize o.port = port o.host = host o.manifest = manifest config.connections[name] = o Output.log(config) utils.writeConfig(config) }) buttonCreate.on('click', function() { var name = 'New Connection ' + list.items.length var port = '1337' var host = '127.0.0.1' var o = {} o.port = port o.host = host o.manifest = '' o.keyEncoding = 'utf8' o.valueEncoding = 'json' config.connections[name] = o textName.setValue(name) textPort.setValue(port) textHost.setValue(host) textManifest.setValue('') textKeyEncoding.setValue('utf8') textValueEncoding.setValue('utf8') list.add(name) list.scrollTo(list.items.length) list.select(list.items.length) screen.render() }) buttonDelete.on('click', function() { // // this whole stinky code is because lists don't // update properly. make a pull request to fix. // var list = list var index = list.selected var item = list.items[index] if (!item || item.content == 'Default') return if (!config.connections[item.content]) return delete config.connections[item.content] var l = list.items.length if (l > 0) { while(l--) { list.removeItem(l) } } list.setItems(Object.keys(config.connections)) screen.render() utils.writeConfig(config) }) buttonConnect.on('click', function() { var name = textName.getValue() client.connect(config.connections[name], function(err) { if (err) return Output.log(err.message) config.connection = name Connections.toggle() client.query(function(err, keys) { if (err) Output.log('NOT OK!', err) keylist.update(keys) commands.update('{yellow-fg}⚡{/yellow-fg} ' + name + ' ') screen.render() }) }) }) var sep_h = blessed.line({ parent: connections, orientation: 'horizontal', left: 0, style: { bg: 'white', fg: 247, }, bottom: 2, right: 0 }) var sep_v = blessed.line({ parent: connections, orientation: 'vertical', style: { bg: 'white', fg: 247, }, left: sidePanelWidth, top: 1, bottom: 3 }) var cap_left = blessed.element({ parent: connections, content: '├', left: 0, style: { bg: 'white', fg: 247, }, bottom: 2, width: 1, height: 1 }) var cap_right = blessed.element({ parent: connections, content: '┤', right: 0, bottom: 2, style: { bg: 'white', fg: 247, }, width: 1, height: 1 }) var fm = blessed.filemanager({ parent: screen, label: ' Select a file ', border: { type: 'ascii' }, scrollbar: { ch: ' ' }, style: { scrollbar: { inverse: true }, selected: { bg: 'blue' }, item: { hover: { bg: 'blue' } } }, mouse: true, keys: true, vi: true, left: 'center', top: 'center', width: 'half', height: 'half', hidden: true }) var cap_upper = blessed.element({ parent: connections, content: '┬', style: { bg: 'white', fg: 247, }, left: sidePanelWidth, top: 0, width: 1, height: 1 }) var cap_lower = blessed.element({ parent: connections, content: '┴', style: { bg: 'white', fg: 247, }, left: sidePanelWidth, bottom: 2, height: 1, width: 1 }) return connections }
scope.content = blessed.list({ align: 'left', keys: true, tags: true, label: 'Search Results', style: { bg: 'black', fg: 'lightgreen', item: { height: 2 }, selected: { bg: 'lightgreen', fg: 'black' } }, border: { type: 'ascii', bg: 'black', fg: 'lightgreen' }, width: '100%', bottom: 1, top: 1, left: 0, scrollbar: { ch: ' ', track: { bg: 'lightgreen' }, style: { inverse: true } } });
function Tree(screen, model, client) { var tree = Tree.tree if (tree) { tree.detach() screen.append(tree) return tree } tree = Tree.tree = blessed.list({ parent: screen, hidden: true, keys: true, vi: true, align: 'center', content: '\n No sublevels from this level.', mouse: true, tags: true, label: '{247-bg} {black-fg}TREE{/black-fg} {/247-bg}', width: 'half', height: 'half', left: 'center', top: 'center', hidden: true, padding: { top: 1, bottom: 1 }, style: { bg: 'white', fg: 'black', item: { hover: { bg: 239, fg: 'white' } } }, border: { bg: 'white', fg: 247, type: 'ascii' } }) var bounce tree.on('select', function() { clearTimeout(bounce) bounce = setTimeout(function() { var item = tree.items[tree.selected].content.replace(/[^\w]/g, '') //output.log(item) }, 100) }) tree._.client = client tree.setFront() return tree }
export function createUI() { var screen = blessed.screen({ smartCSR: true, debug: true }); screen.key(['escape', 'q', 'C-c'], function(ch, key){ return process.exit(0); }); screen.title = 'Mail'; let onSelect = _ => _; let onArchive = _ => _; let messageList = []; const confirmBox = blessed.question({ parent: screen, top: 'center', left: 'center', shrink: true, padding: 5, style: { bg: "red" } }); const promptBox = blessed.prompt({ parent: screen, top: 'center', left: 'center', width: "50%", height: "50%", padding: 5, style: { bg: "green" } }); const messageBox = blessed.box({ parent: screen, top: '10', left: '10', bottom: '10', width: '50%', border: { fg: 'blue' }, style: { fg: 'green' } }); const list = blessed.list({ parent: screen, label: " Senders ", border: 'line', top: '10', right: '1', width: '30%', bottom: '10', keys: true, scrollbar: { ch: ' ', track: { bg: 'cyan' }, style: { inverse: true } }, style: { selected: { fg: 'black', bg: 'green' }, item: { fg: 'white' }, bg: 'black' } }); const groupText = (group) => { const prefix = group.collapsed ? '+' : '-'; const num = group.listItems.length; return `${prefix} (${num}) ${group.text}`; }; const listItemText = (item) => { const check = item.checked ? '✓' : ' '; return ` [${check}] ${item.text}`; }; const renderList = () => { let lastSelected = list.selected; list.clearItems(); _.each(messageList, (group) => { list.add(groupText(group)); if (!group.collapsed) { _.each(group.listItems, item => list.add(listItemText(item))); } }); list.select(lastSelected); let selectionText = ""; const numSelected = selected(messageList).length; if (numSelected) { selectionText = `(${numSelected} selected) `; } list.setLabel(` Senders ${selectionText}`); screen.render(); }; renderList(); screen.key('j', () => { list.down(1); screen.render(); }); screen.key('k', () => { list.up(1); screen.render(); }); screen.key('x', () => { let item = lookupInList(messageList, list.selected); item.toggle(); renderList(); }); screen.key('space', () => { let item = lookupInList(messageList, list.selected); item.expandOrContract(); renderList(); }); list.on('select', () => { let item = lookupInList(messageList, list.selected); onSelect(item); screen.render(); }); list.key('y', () => { onArchive(); }); const confirm = (message, cb) => { confirmBox.focus(); confirmBox.ask(message, (err, confirmed) => { if (err) { throw err; } cb(confirmed); screen.render(); list.focus(); }); }; const prompt = (message, cb) => { promptBox.focus(); promptBox.input(message + " ", "", (err, text) => { screen.debug('text is ' + err + ":" + text); if (err) { throw err; } cb(text); screen.render(); list.focus(); }); }; screen.append(messageBox); screen.append(list); screen.append(confirmBox); screen.append(promptBox); list.focus(); screen.render(); return { updateMessageList: newList => { messageList = newList; renderList(); }, updateMessagePane: text => { messageBox.setContent(text); screen.render(); }, selectedMessages: () => { const selectedItems = selected(messageList); return _.map(selectedItems, 'data'); }, deselectAll: () => { deselectAll(messageList); renderList(); }, onListSelect: cb => { onSelect = cb; }, onArchive: cb => { onArchive = cb; }, confirm, prompt }; }
export default (screen, artist) => { let layout; let list; let layoutOpts = { parent: screen, label: 'Choose Artist', top: 'center', left: 'center', width: '50%', height: '50%', content: 'Loading...', tags: true, border: { type: 'line' } }; let listOpts = { top: 0, tags: true, padding: { left: 1, right: 1 }, input: true, scrollable: true, keys: true, vi: true, mouse: true, scrollbar: { ch: ' ', inverse: true, fg: 'gray' }, style: { selected: { bg: 'yellow' } } }; let clear = () => { layout.destroy(); screen.blockEsc = false; screen.restoreFocus(); }; screen.blockEsc = true; list = blessed.list(listOpts); list.key(['escape', 'left', 'right', 'tab'], () => clear()); list.key(['pageup'], () => { list.up(list.height); screen.render(); }); list.key(['pagedown'], () => { list.down(list.height); screen.render(); }); return new Promise((resolve, reject) => { list.on('select', (selected, index) => { clear(); resolve(selected.content); }); }); };