//'minimal' blessed example
//detects keypresses (arrow keys or vim-keys) or 'q' to quit
//does not move cursor but shows it on screen

const blessed = require('blessed')
  , program = blessed.program();

process.title = 'blessed';

program.on('keypress', function(ch, key) {

  program.clear();
  program.bg('red');

  switch(key.name) {
    case 'q':
      program.disableMouse();
      program.showCursor();
      program.normalBuffer();
      process.exit(0);
   //reminder: listing two cases without a break between makes them work like an OR operator
    case 'right': //vim key 'l' or right-arrow
    case 'l': 
      program.write('moved right');
      break;
    case 'left': //vim key 'h' OR left-arrow
    case 'h':  
      program.write('moved left');
      break;
    case 'up': //vim key 'k' or up-arrow
    case 'k': 
      program.write('moved up');
      break;
    case 'down': //vim key 'j' or down-arrow
    case 'j':
      program.write('moved down');
      break;
    default: //else
      program.write('hit another key');
  } 

  program.bg('!red');

});

program.alternateBuffer();
//program.enableMouse();
//program.hideCursor();
program.clear();

program.move(1, 1);
program.bg('green');
program.write('Hello world', 'red fg');
program.setx((program.cols / 4 | 0) );
program.down(5);
program.write('Test direction keys (vim or arrow keys) or q to quit!');
program.bg('!black');
program.feed();
