Skip to content

Instantly share code, notes, and snippets.

@johnspackman
Created August 8, 2013 18:05
Show Gist options
  • Save johnspackman/6187052 to your computer and use it in GitHub Desktop.
Save johnspackman/6187052 to your computer and use it in GitHub Desktop.
var blessed = require('blessed');
var program = blessed.program();
// Create a screen object.
var screen = blessed.screen();
function drawTui() {
// Create a box perfectly centered horizontally and vertically.
var box = blessed.box({
top: 'center',
left: 'center',
width: '50%',
height: '50%',
content: 'Hello {bold}world{/bold}!',
tags: true,
border: {
type: 'line'
},
style: {
fg: 'white',
bg: 'magenta',
border: {
fg: '#ffffff'
},
hover: {
bg: 'green'
}
}
});
// Append our box to the screen.
screen.append(box);
// If our box is clicked, change the content.
box.on('click', function(data) {
box.setContent('{center}Some different {red-fg}content{/red-fg}.{/center}');
screen.render();
});
// If box is focused, handle `enter`/`return` and give us some more content.
box.key(['enter', 'return'], function(ch, key) {
box.setContent('{right}Even different {black-fg}content{/black-fg}.{/right}\n');
box.setLine(1, 'bar');
box.insertLine(1, 'foo');
screen.render();
});
//Focus our element.
box.focus();
//Render the screen.
screen.render();
}
//Quit on Escape, q, or Control-C.
screen.key(['escape', 'q', 'C-c'], function(ch, key) {
process.exit(0);
});
var tuiMode = true;
var pass = 0;
var timerId = null;
screen.key(['t'], function(ch, key) {
tuiMode = !tuiMode;
if (tuiMode) {
if (timerId) {
clearInterval(timerId);
timerId = null;
}
drawTui();
} else {
var nodes = screen.children.slice();
for (var i = 0; i < nodes.length; i++)
screen.remove(nodes[i]);
screen.render();
timerId = setInterval(function() {
console.log("hello " + (++pass));
}, 100);
}
});
drawTui();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment