UNPKG

console-gui-tools

Version:

A simple library to draw option menu, text popup or other widgets and layout on a Node.js console.

183 lines 6.36 kB
/// <reference types="node" /> /// <reference types="node" /> /// <reference types="node" /> import { EventEmitter } from "events"; /** * @typedef {Object} MouseEventArgs * @description This type is used to define the parameters of the Mouse Listener event (mouseevent) data. * * @prop {string} code - The code of the pressed key. * @prop {boolean} alt - If the alt key is pressed. * @prop {boolean} ctrl - If the ctrl key is pressed. * @prop {boolean} shift - If the shift key is pressed. * @prop {boolean} left - If the left mouse key is pressed. * @prop {boolean} right - If the right mouse key is pressed. * @prop {number} x - The x position of the mouse (terminal column). * @prop {number} y - The y position of the mouse (terminal row). * @prop {number | null} xFrom - The original x position of the mouse (terminal column) when the drag started. * @prop {number | null} yFrom - The original y position of the mouse (terminal row) when the drag started. * * @example const mouseEventArgs = { code: "MOUSE", alt: false, ctrl: false, shift: false, left: true, right: false, x: 10, y: 10, xFrom: null, yFrom: null } * * @export * @interface MouseEventArgs */ export interface MouseEventArgs { code: number; alt: boolean; ctrl: boolean; shift: boolean; left: boolean; right: boolean; x: number; y: number; xFrom: number | null; yFrom: number | null; } /** * @typedef {Object} MouseEvent * @description This type is used to define the parameters of the Mouse Listener event (mouseevent). * available event names: * - MOUSE_MOTION: mouse moved (no button pressed / hover) * - MOUSE_DRAG: Valorized xFrom and yFrom. Use left or right to know which button is pressed. * - MOUSE_LEFT_BUTTON_PRESS * - MOUSE_LEFT_BUTTON_RELEASE * - MOUSE_RIGHT_BUTTON_PRESS * - MOUSE_RIGHT_BUTTON_RELEASE * - MOUSE_MIDDLE_BUTTON_PRESS * - MOUSE_MIDDLE_BUTTON_RELEASE * - MOUSE_WHEEL_UP * - MOUSE_WHEEL_DOWN * * @prop {string} name - The name of the event. * @prop {number} eaten - The number of eaten events. * @prop {MouseEventArgs} args - The arguments of the event. * * @example const mouseEvent = { name: "MOUSE_MOTION", eaten: 0, args: { code: "MOUSE", alt: false, ctrl: false, shift: false, left: true, right: false, x: 10, y: 10, xFrom: null, yFrom: null } } * * @export * @interface MouseEvent */ export interface MouseEvent { name: string; eaten: number; data: MouseEventArgs; } /** * @typedef {Object} RelativeMouseEvent * @description This type is used to define the parameters of the Mouse Listener event (mouseevent) data, relative to a widget. * * @prop {string} name - The name of the event. * @prop {object} data - The data of the event. * @prop {number} data.x - The x position of the mouse (terminal column). * @prop {number} data.y - The y position of the mouse (terminal row). * * @export * @interface RelativeMouseEvent */ export interface RelativeMouseEvent { name: string; data: { x: number; y: number; }; } /** * @class MouseManager * @description This class is used to manage the mouse tracking events. * * ![MouseManager](https://user-images.githubusercontent.com/14907987/201913001-713ca6e7-c277-42f7-ac1a-5f90ee1b144f.gif) * * Emits the following events: * - "mouseevent" when the user confirm * - "error" when an error occurs * @param {object} Terminal - The terminal object (process.stdout). * @emits mouseevent - The mouse event. * * @extends EventEmitter * @example const mouse = new MouseManager(process.stdout) */ export declare class MouseManager extends EventEmitter { Terminal: NodeJS.WriteStream; Input: NodeJS.ReadStream; prependStdinChunk: null | Buffer; /** @const {Object} keymap - Object containing "MOUSE" array of key codes. */ keymap: { MOUSE: { code: string; event: string; handler: string; }[]; }; /** @const {Object} state - Object containing the state of the mouse buttons. */ state: { button: { left: { x: number; y: number; } | null; middle: { x: number; y: number; } | null; right: { x: number; y: number; } | null; other: { x: number; y: number; } | null; }; }; constructor(_Terminal: NodeJS.WriteStream, _Input: NodeJS.ReadStream); /** * @description Manage the mouse events for the x11 protocol. * @param {string} basename - The name of the event. * @param {Buffer} buffer - The data of the event. **/ mouseX11Protocol: (basename: string, buffer: Buffer) => MouseEvent; /** * @description Manage the mouse events for the SGR protocol. * @param {string} basename - The name of the event. * @param {Buffer} buffer - The data of the event. **/ mouseSGRProtocol: (basename: string, buffer: Buffer) => MouseEvent | { name: string; eaten: number; data: { matches: RegExpMatchArray | null; }; }; /** * @description Enables "mouseevent" event on the *input* stream. Note that `stream` must be * an *output* stream (i.e. a Writable Stream instance), usually `process.stdout`. * * @api public */ enableMouse(): void; /** * @description Disables "mouseevent" event from being sent to the *input* stream. * Note that `stream` must be an *output* stream (i.e. a Writable Stream instance), * usually `process.stdout`. * * @api public */ disableMouse(): void; /** * @description Manage the stdin data to detect mouse events. * @param {Buffer} chunk - The data of the event. **/ onStdin: (chunk: Buffer) => void; /** * @description Test if the key is a part of the mouse event. * @param {{ code: string, sequence: string }} key - The key object to test. * @return {number} - 1 if the key is the header of a mouse event, -1 if is a body part, 0 otherwise. **/ isMouseFrame(key: { code: string; sequence: string; }, lock: boolean): number; } export default MouseManager; //# sourceMappingURL=MouseManager.d.ts.map