terminal-joystick

1.0.1 • Public • Published

terminal-joystick

🎮 A joystick for your terminal.

Joystick

⚠️ Highly experimental

Install

npm i -S terminal-joystick

Usage

const { TerminalJoystick, ON_DRAG } = require('terminal-joystick');
 
const joystick = new TerminalJoystick({
  title : 'Joystick - Example',
});
 
joystick.on(ON_DRAG, ({ angle, intensity }) => {
  // Do stuff...
});
 
joystick.on(ON_DRAG_END, ({ angle, intensity }) => {
  // Do stuff...
});

Using with blessed

To add terminal-joystick to an existing blessed application, you just need to provide a reference to the blessed.screen object and a parent container :

const { TerminalJoystick, ON_DRAG } = require('terminal-joystick');
 
const screen = blessed.screen();
const container = new blessed.Box({
  left : 'center',
  top  : 'center',
  width : '100%',
  height : '100%',
});
 
const joystick = new TerminalJoystick({
  parent : container,
  title : 'Joystick - Example',
  screen,
});
 
joystick.on(ON_DRAG, ({ angle, intensity }) => {
  // Do stuff...
});

API

  • new TerminalJoystick(opts)
    • screen : reference to an existing blessed screen (optional)
    • container :
      • size : pad's size (default : 100)
      • All blessed.Element properties
    • joystick :
      • size : joystick's size (default : 15)
      • All blessed.Element properties
    • title : terminal tab title (optional) / Only used if screen is not provided
    • noReturnToOrigin : A flag to disable the joystick return to its initial position when mouse click is released.
  • on(event, handler) : TerminalJoystick extends EventEmitter.
    • ON_DRAG : emitted when the joystick is dragged.
      • angle : angle in degress (0-360) between the joystick and the x-axis.
      • intensity : distance from the center (0-1)
      • x : coordinate along the x-axis between -1 and 1
      • y : coordinate along the y-axis between -1 and 1
    • ON_DRAG_END : emitted when the mouse click is released.

Package Sidebar

Install

npm i terminal-joystick

Weekly Downloads

0

Version

1.0.1

License

MIT

Last publish

Collaborators

  • matthieulemoine