A simple import that allows listening to key and mouse events from the Node.js (X11 only) terminal, and has additional printing features
- Save
xwindow.jsto your project's working directory - Require it –
const xwin = require('./xwindow.js'); - Pass your input binding function into
xwin.getEvents()
An example:
function capture_event(data_object) {
console.log(data_object);
} capture.getEvents(capture_event);prints to the terminal after clicking, scrolling, and pressing A:
{ event: 'mouse', button: 'Left', x: 64, y: 18 }
{ event: 'mouse', button: 'Scroll-Up', x: 64, y: 18 }
{ event: 'mouse', button: 'Scroll-Up', x: 64, y: 18 }
{ event: 'keypress', ctrl: false, name: 'a', shift: false, key: 'a' }getEvents – listens for keypress and mouse events and transmits them to a given function
- Any mouse events will return an object with attributes
event,button,x, andy. - Any keyboard events will return an object with attributes
event,ctrl(boolean),name,shift(boolean), andkey
clear – clears the terminal and resets the cursor
getCursor – returns an object containing the x and y coordinates of the terminal's print cursor
setCursor – sets the terminal's cursor to the given position
- setCursor expects two integer arguments: the
xandycoordinates
color – takes in a color name and returns the printable escape sequence
- color takes one or two arguments; the string to be printed, and an optional
boolthat tells color to change the background color instead - this is used directly within the print call, for example:
console.log( xwin.color('red')+ "Hello, World!");
xwin.reset();`reset – resets the terminal color and display settings
- A replacement for Inquirer, Prompts, et cetera
- Simple Terminal-based Games like Rogue
- Terminal-based Text Editors
