Move primitive types from common/Types.ts to common/primitives/Types.ts
Extract low-level types (IParams, ParamsArray, IDisposable, color, keyboard, mouse, charset, etc.) into primitives/Types.ts. Keep runtime/integration types (ITerminalOptions, IInputHandler, terminal modes) in common/Types.ts. Lifecycle re-exports IDisposable from primitives/Types.ts. Co-authored-by: Daniel Imms <Tyriar@users.noreply.github.com>
This commit is contained in:
co-authored by
Daniel Imms
parent
f6c1b21258
commit
bd8510e3ab
@@ -3,7 +3,7 @@
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { IColor, IColorRGB } from '../Types';
|
||||
import { IColor, IColorRGB } from './Types';
|
||||
|
||||
let $r = 0;
|
||||
let $g = 0;
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
* Simplified from VS Code's lifecycle.ts - no tracking/leak detection.
|
||||
*/
|
||||
|
||||
export interface IDisposable {
|
||||
dispose(): void;
|
||||
}
|
||||
import type { IDisposable } from './Types';
|
||||
|
||||
export type { IDisposable };
|
||||
|
||||
export function toDisposable(fn: () => void): IDisposable {
|
||||
return { dispose: fn };
|
||||
|
||||
@@ -0,0 +1,228 @@
|
||||
/**
|
||||
* Copyright (c) 2018 The xterm.js authors. All rights reserved.
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
/** sequence params serialized to js arrays */
|
||||
export type ParamsArray = (number | number[])[];
|
||||
|
||||
/** Interface of Params storage class. */
|
||||
export interface IParams {
|
||||
/** from ctor */
|
||||
maxLength: number;
|
||||
maxSubParamsLength: number;
|
||||
|
||||
/** param values and its length */
|
||||
params: Int32Array;
|
||||
length: number;
|
||||
|
||||
/** methods */
|
||||
clone(): IParams;
|
||||
toArray(): ParamsArray;
|
||||
reset(): void;
|
||||
resetZdm(): void;
|
||||
addParam(value: number): void;
|
||||
addSubParam(value: number): void;
|
||||
hasSubParams(idx: number): boolean;
|
||||
getSubParams(idx: number): Int32Array | null;
|
||||
getSubParamsAll(): {[idx: number]: Int32Array};
|
||||
}
|
||||
|
||||
export interface IDisposable {
|
||||
dispose(): void;
|
||||
}
|
||||
|
||||
export type CursorStyle = 'block' | 'underline' | 'bar';
|
||||
|
||||
export type CursorInactiveStyle = 'outline' | 'block' | 'bar' | 'underline' | 'none';
|
||||
|
||||
export type XtermListener = (...args: any[]) => void;
|
||||
|
||||
/**
|
||||
* A keyboard event interface which does not depend on the DOM, KeyboardEvent implicitly extends
|
||||
* this event.
|
||||
*/
|
||||
export interface IKeyboardEvent {
|
||||
altKey: boolean;
|
||||
ctrlKey: boolean;
|
||||
shiftKey: boolean;
|
||||
metaKey: boolean;
|
||||
/** @deprecated See KeyboardEvent.keyCode */
|
||||
keyCode: number;
|
||||
key: string;
|
||||
type: string;
|
||||
code: string;
|
||||
}
|
||||
|
||||
export const enum KeyboardResultType {
|
||||
SEND_KEY,
|
||||
SELECT_ALL,
|
||||
PAGE_UP,
|
||||
PAGE_DOWN
|
||||
}
|
||||
|
||||
export interface IKeyboardResult {
|
||||
type: KeyboardResultType;
|
||||
cancel: boolean;
|
||||
key: string | undefined;
|
||||
}
|
||||
|
||||
export interface ICharset {
|
||||
[key: string]: string | undefined;
|
||||
}
|
||||
|
||||
export interface IColor {
|
||||
readonly css: string;
|
||||
readonly rgba: number; // 32-bit int with rgba in each byte
|
||||
}
|
||||
export type IColorRGB = [red: number, green: number, blue: number];
|
||||
|
||||
/**
|
||||
* Tracks the current hyperlink. Since these are treated as extended attirbutes, these get passed on
|
||||
* to the linkifier when anything is printed. Doing it this way ensures that even when the cursor
|
||||
* moves around unexpectedly the link is tracked, as opposed to using a start position and
|
||||
* finalizing it at the end.
|
||||
*/
|
||||
export interface IOscLinkData {
|
||||
id?: string;
|
||||
uri: string;
|
||||
}
|
||||
|
||||
export interface IRowRange {
|
||||
start: number;
|
||||
end: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for mouse events in the core.
|
||||
*/
|
||||
export const enum CoreMouseButton {
|
||||
LEFT = 0,
|
||||
MIDDLE = 1,
|
||||
RIGHT = 2,
|
||||
NONE = 3,
|
||||
WHEEL = 4,
|
||||
// additional buttons 1..8
|
||||
// untested!
|
||||
AUX1 = 8,
|
||||
AUX2 = 9,
|
||||
AUX3 = 10,
|
||||
AUX4 = 11,
|
||||
AUX5 = 12,
|
||||
AUX6 = 13,
|
||||
AUX7 = 14,
|
||||
AUX8 = 15
|
||||
}
|
||||
|
||||
export const enum CoreMouseAction {
|
||||
UP = 0, // buttons, wheel
|
||||
DOWN = 1, // buttons, wheel
|
||||
LEFT = 2, // wheel only
|
||||
RIGHT = 3, // wheel only
|
||||
MOVE = 32 // buttons only
|
||||
}
|
||||
|
||||
export interface ICoreMouseEvent {
|
||||
/** column (zero based). */
|
||||
col: number;
|
||||
/** row (zero based). */
|
||||
row: number;
|
||||
/** xy pixel positions. */
|
||||
x: number;
|
||||
y: number;
|
||||
/**
|
||||
* Button the action occurred. Due to restrictions of the tracking protocols
|
||||
* it is not possible to report multiple buttons at once.
|
||||
* Wheel is treated as a button.
|
||||
* There are invalid combinations of buttons and actions possible
|
||||
* (like move + wheel), those are silently ignored by the MouseStateService.
|
||||
*/
|
||||
button: CoreMouseButton;
|
||||
action: CoreMouseAction;
|
||||
/**
|
||||
* Modifier states.
|
||||
* Protocols will add/ignore those based on specific restrictions.
|
||||
*/
|
||||
ctrl?: boolean;
|
||||
alt?: boolean;
|
||||
shift?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* CoreMouseEventType
|
||||
* To be reported to the browser component which events a mouse
|
||||
* protocol wants to be catched and forwarded as an ICoreMouseEvent
|
||||
* to MouseStateService.
|
||||
*/
|
||||
export const enum CoreMouseEventType {
|
||||
NONE = 0,
|
||||
/** any mousedown event */
|
||||
DOWN = 1,
|
||||
/** any mouseup event */
|
||||
UP = 2,
|
||||
/** any mousemove event while a button is held */
|
||||
DRAG = 4,
|
||||
/** any mousemove event without a button */
|
||||
MOVE = 8,
|
||||
/** any wheel event */
|
||||
WHEEL = 16
|
||||
}
|
||||
|
||||
/**
|
||||
* Mouse protocol interface.
|
||||
* A mouse protocol can be registered and activated at the MouseStateService.
|
||||
* `events` should contain a list of needed events as a hint for the browser component
|
||||
* to install/remove the appropriate event handlers.
|
||||
* `restrict` applies further protocol specific restrictions like not allowed
|
||||
* modifiers or filtering invalid event types.
|
||||
*/
|
||||
export interface ICoreMouseProtocol {
|
||||
events: CoreMouseEventType;
|
||||
restrict: (e: ICoreMouseEvent) => boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* CoreMouseEncoding
|
||||
* The tracking encoding can be registered and activated at the MouseStateService.
|
||||
* If a ICoreMouseEvent passes all procotol restrictions it will be encoded
|
||||
* with the active encoding and sent out.
|
||||
* Note: Returning an empty string will supress sending a mouse report,
|
||||
* which can be used to skip creating falsey reports in limited encodings
|
||||
* (DEFAULT only supports up to 223 1-based as coord value).
|
||||
*/
|
||||
export type CoreMouseEncoding = (event: ICoreMouseEvent) => string;
|
||||
|
||||
// color events from common, used for OSC 4/10/11/12 and 104/110/111/112
|
||||
export const enum ColorRequestType {
|
||||
REPORT = 0,
|
||||
SET = 1,
|
||||
RESTORE = 2
|
||||
}
|
||||
|
||||
// IntRange from https://stackoverflow.com/a/39495173
|
||||
type Enumerate<N extends number, Acc extends number[] = []> = Acc['length'] extends N
|
||||
? Acc[number]
|
||||
: Enumerate<N, [...Acc, Acc['length']]>;
|
||||
type IntRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
|
||||
|
||||
export type ColorIndex = IntRange<0, 256>; // number from 0 to 255
|
||||
export type AllColorIndex = ColorIndex | SpecialColorIndex;
|
||||
export const enum SpecialColorIndex {
|
||||
FOREGROUND = 256,
|
||||
BACKGROUND = 257,
|
||||
CURSOR = 258
|
||||
}
|
||||
export interface IColorReportRequest {
|
||||
type: ColorRequestType.REPORT;
|
||||
index: AllColorIndex;
|
||||
}
|
||||
export interface IColorSetRequest {
|
||||
type: ColorRequestType.SET;
|
||||
index: AllColorIndex;
|
||||
color: IColorRGB;
|
||||
}
|
||||
export interface IColorRestoreRequest {
|
||||
type: ColorRequestType.RESTORE;
|
||||
index?: AllColorIndex;
|
||||
}
|
||||
export type IColorEvent = (IColorReportRequest | IColorSetRequest | IColorRestoreRequest)[];
|
||||
@@ -3,7 +3,7 @@
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { IColorRGB } from '../../Types';
|
||||
import { IColorRGB } from '../Types';
|
||||
import { IAttributeData, IExtendedAttrs } from './Types';
|
||||
import { Attributes, FgFlags, BgFlags, UnderlineStyle, ExtFlags } from './Constants';
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import { CircularList, IInsertEvent } from '../CircularList';
|
||||
import { Disposable, toDisposable } from '../Lifecycle';
|
||||
import { IdleTaskQueue } from '../TaskQueue';
|
||||
import { ICharset } from '../../Types';
|
||||
import { ICharset } from '../Types';
|
||||
import { IAttributeData, IBuffer, IBufferLine, ICellData } from './Types';
|
||||
import { ExtendedAttrs } from './AttributeData';
|
||||
import { BufferLine, DEFAULT_ATTR_DATA } from './BufferLine';
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import type { IEvent } from '../Event';
|
||||
import type { ICircularList } from '../CircularList';
|
||||
import type { ICharset } from '../../Types';
|
||||
import type { ICharset } from '../Types';
|
||||
import type { IDisposable } from '../Lifecycle';
|
||||
import type { UnderlineStyle } from './Constants';
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { ICharset } from '../../Types';
|
||||
import { ICharset } from '../Types';
|
||||
|
||||
/**
|
||||
* The character sets supported by the terminal. These enable several languages
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
import { assert } from 'chai';
|
||||
import { evaluateKeyboardEvent } from './Keyboard';
|
||||
import { IKeyboardResult, IKeyboardEvent } from '../../Types';
|
||||
import { IKeyboardResult, IKeyboardEvent } from '../Types';
|
||||
|
||||
/**
|
||||
* A helper function for testing which allows passing in a partial event and defaults will be filled
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { IKeyboardEvent, IKeyboardResult, KeyboardResultType } from '../../Types';
|
||||
import { IKeyboardEvent, IKeyboardResult, KeyboardResultType } from '../Types';
|
||||
import { C0 } from '../data/EscapeSequences';
|
||||
|
||||
// reg + shift key mappings for digits and special chars
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
import { assert } from 'chai';
|
||||
import { KittyKeyboard, KittyKeyboardEventType, KittyKeyboardFlags } from './KittyKeyboard';
|
||||
import { IKeyboardEvent } from '../../Types';
|
||||
import { IKeyboardEvent } from '../Types';
|
||||
|
||||
function createEvent(partialEvent: Partial<IKeyboardEvent> = {}): IKeyboardEvent {
|
||||
return {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* @see https://sw.kovidgoyal.net/kitty/keyboard-protocol/
|
||||
*/
|
||||
|
||||
import { IKeyboardEvent, IKeyboardResult, KeyboardResultType } from '../../Types';
|
||||
import { IKeyboardEvent, IKeyboardResult, KeyboardResultType } from '../Types';
|
||||
import { C0 } from '../data/EscapeSequences';
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import { assert } from 'chai';
|
||||
import { Win32InputMode, Win32ControlKeyState } from './Win32InputMode';
|
||||
import { IKeyboardEvent, KeyboardResultType } from '../../Types';
|
||||
import { IKeyboardEvent, KeyboardResultType } from '../Types';
|
||||
|
||||
type EventOpts = Partial<IKeyboardEvent>;
|
||||
const ev = (opts: EventOpts): IKeyboardEvent => ({
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* Rc: Repeat count (usually 1)
|
||||
*/
|
||||
|
||||
import { IKeyboardEvent, IKeyboardResult, KeyboardResultType } from '../../Types';
|
||||
import { IKeyboardEvent, IKeyboardResult, KeyboardResultType } from '../Types';
|
||||
import { C0 } from '../data/EscapeSequences';
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import { IApcHandler, IHandlerCollection, ApcFallbackHandlerType, IApcParser, ISubParserStackState } from './Types';
|
||||
import { ParserConstants } from './Constants';
|
||||
import { utf32ToString } from '../input/TextDecoder';
|
||||
import { IDisposable } from '../../Types';
|
||||
import { IDisposable } from '../Types';
|
||||
import { LimitedStringBuilder } from '../StringBuilder';
|
||||
|
||||
const EMPTY_HANDLERS: IApcHandler[] = [];
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { IDisposable } from '../../Types';
|
||||
import { IDisposable } from '../Types';
|
||||
import { IDcsHandler, IParams, IHandlerCollection, IDcsParser, DcsFallbackHandlerType, ISubParserStackState } from './Types';
|
||||
import { utf32ToString } from '../input/TextDecoder';
|
||||
import { Params } from './Params';
|
||||
|
||||
@@ -10,7 +10,7 @@ import { StringToUtf32, stringFromCodePoint, utf32ToString } from '../input/Text
|
||||
import { ParserState } from './Constants';
|
||||
import { Params } from './Params';
|
||||
import { OscHandler } from './OscParser';
|
||||
import { IDisposable } from '../../Types';
|
||||
import { IDisposable } from '../Types';
|
||||
import { DcsHandler } from './DcsParser';
|
||||
import { ApcHandler } from './ApcParser';
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import { IParsingState, IDcsHandler, IEscapeSequenceParser, IParams, IOscHandler, IHandlerCollection, CsiHandlerType, OscFallbackHandlerType, IOscParser, EscHandlerType, IDcsParser, DcsFallbackHandlerType, IFunctionIdentifier, ExecuteFallbackHandlerType, CsiFallbackHandlerType, EscFallbackHandlerType, PrintHandlerType, PrintFallbackHandlerType, ExecuteHandlerType, IParserStackState, ParserStackType, ResumableHandlersType, IApcHandler, IApcParser, ApcFallbackHandlerType } from './Types';
|
||||
import { ParserState, ParserAction } from './Constants';
|
||||
import { Disposable, toDisposable } from '../Lifecycle';
|
||||
import { IDisposable } from '../../Types';
|
||||
import { IDisposable } from '../Types';
|
||||
import { Params } from './Params';
|
||||
import { OscParser } from './OscParser';
|
||||
import { DcsParser } from './DcsParser';
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import { IOscHandler, IHandlerCollection, OscFallbackHandlerType, IOscParser, ISubParserStackState } from './Types';
|
||||
import { OscState, ParserConstants } from './Constants';
|
||||
import { utf32ToString } from '../input/TextDecoder';
|
||||
import { IDisposable } from '../../Types';
|
||||
import { IDisposable } from '../Types';
|
||||
import { LimitedStringBuilder } from '../StringBuilder';
|
||||
|
||||
const EMPTY_HANDLERS: IOscHandler[] = [];
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { IDisposable, IParams, ParamsArray } from '../../Types';
|
||||
import { IDisposable, IParams, ParamsArray } from '../Types';
|
||||
import { ParserState } from './Constants';
|
||||
|
||||
export type { IParams, ParamsArray };
|
||||
|
||||
Reference in New Issue
Block a user