Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Being Blessed

Being Blessed

A talk about how to create TUI's with JavaScript using Blessed, the package made by Christopher Jeffrey (JJ).

More information about the topic in here: http://recodes.co/being-blessed/

This talk was given at Sophilabs in May, 2015.

More Decks by Rodrigo Espinosa Curbelo

Other Decks in Programming

Transcript

  1. “Blessed is a high-level terminal interface library built in node.js

    that allows us to create impressive terminal applications easily.”
  2. Adding events var blessed = require('blessed'); var screen = blessed.screen();

    screen.key('q', function () { process.exit(0); }); screen.render();
  3. q

  4. Adding elements 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: '#f0f0f0' }, hover: { bg: 'green' } } }); screen.append(box); screen.render();
  5. Setting async data var box = blessed.box({ top: 'center', left:

    'center', width: '60%', height: '80%', tags: true, style: {fg: 'white', bg: 'blue'} }); screen.append(box); fs.readFile(‘./t.txt', {encoding: 'utf8'}, function (err, data) { box.setText(data); screen.render(); }); screen.render();
  6. With padding var box = blessed.box({ top: 'center', left: 'center',

    width: '60%', height: '80%', tags: true, padding: 3, style: {fg: 'white', bg: 'blue'} }); screen.append(box); fs.readFile(‘./t.txt', {encoding: 'utf8'}, function (err, data) { box.setText(data); screen.render(); }); screen.render();
  7. Using tags var box = blessed.box({… tags: true, … });

    screen.append(box); fs.readFile('./dummy-text.txt', {encoding: 'utf8'}, function (err, data) { data = data.replace(/illuminati/gi, '{green-fg}{bold}illuminati{/bold}{/green-fg}'); data = data.replace(/illuminatus/gi, '{red-bg}{bold}illuminatus{/bold}{/red-bg}'); box.setContent(data); screen.render(); }); screen.render();
  8. “Blessed comes with a number of high- level widgets so

    you can avoid all the nasty low-level terminal stuff.”
  9. Box

  10. List example var list = blessed.list({ top: 'center', left: 'center',

    width: '60%', height: '80%', padding: 3, input: true, style: {fg: 'white', bg: 'blue'} }); screen.append(list); list.setItems([ 'The Illuminati', 'plural of Latin illuminatus', 'enlightened' ]); screen.render();
  11. Input Textarea Textbox Button ProgressBar FileManager Checkbox RadioSet RadioButton Prompt

    Question Message Loading Listbar Log Table Node Screen Element Box Text Line List Form ListTable Terminal Image Layout