JSPM

terminal-joystick

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q17598F
  • License MIT

A joystick for your terminal.

Package Exports

  • terminal-joystick

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (terminal-joystick) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.