| 1 |
/** |
| 2 |
* Copyright (c) 2017 The xterm.js authors. All rights reserved. |
| 3 |
* @license MIT |
| 4 |
*/ |
| 5 |
|
| 6 |
import { CharData, IColor, ICoreTerminal, ITerminalOptions } from 'common/Types'; |
| 7 |
import { IBuffer } from 'common/buffer/Types'; |
| 8 |
import { IDisposable, Terminal as ITerminalApi } from '@xterm/xterm'; |
| 9 |
import { channels, css } from 'common/Color'; |
| 10 |
import type { Event } from 'vs/base/common/event'; |
| 11 |
|
| 12 |
/** |
| 13 |
* A portion of the public API that are implemented identially internally and simply passed through. |
| 14 |
*/ |
| 15 |
type InternalPassthroughApis = Omit<ITerminalApi, 'buffer' | 'parser' | 'unicode' | 'modes' | 'writeln' | 'loadAddon'>; |
| 16 |
|
| 17 |
export interface ITerminal extends InternalPassthroughApis, ICoreTerminal { |
| 18 |
screenElement: HTMLElement | undefined; |
| 19 |
browser: IBrowser; |
| 20 |
buffer: IBuffer; |
| 21 |
linkifier: ILinkifier2 | undefined; |
| 22 |
options: Required<ITerminalOptions>; |
| 23 |
|
| 24 |
onBlur: Event<void>; |
| 25 |
onFocus: Event<void>; |
| 26 |
onA11yChar: Event<string>; |
| 27 |
onA11yTab: Event<number>; |
| 28 |
onWillOpen: Event<HTMLElement>; |
| 29 |
|
| 30 |
cancel(ev: MouseEvent | WheelEvent | KeyboardEvent | InputEvent, force?: boolean): boolean | void; |
| 31 |
} |
| 32 |
|
| 33 |
export type CustomKeyEventHandler = (event: KeyboardEvent) => boolean; |
| 34 |
export type CustomWheelEventHandler = (event: WheelEvent) => boolean; |
| 35 |
|
| 36 |
export type LineData = CharData[]; |
| 37 |
|
| 38 |
export interface ICompositionHelper { |
| 39 |
readonly isComposing: boolean; |
| 40 |
compositionstart(): void; |
| 41 |
compositionupdate(ev: CompositionEvent): void; |
| 42 |
compositionend(): void; |
| 43 |
updateCompositionElements(dontRecurse?: boolean): void; |
| 44 |
keydown(ev: KeyboardEvent): boolean; |
| 45 |
} |
| 46 |
|
| 47 |
export interface IBrowser { |
| 48 |
isNode: boolean; |
| 49 |
userAgent: string; |
| 50 |
platform: string; |
| 51 |
isFirefox: boolean; |
| 52 |
isMac: boolean; |
| 53 |
isIpad: boolean; |
| 54 |
isIphone: boolean; |
| 55 |
isWindows: boolean; |
| 56 |
} |
| 57 |
|
| 58 |
export interface IColorSet { |
| 59 |
foreground: IColor; |
| 60 |
background: IColor; |
| 61 |
cursor: IColor; |
| 62 |
cursorAccent: IColor; |
| 63 |
selectionForeground: IColor | undefined; |
| 64 |
selectionBackgroundTransparent: IColor; |
| 65 |
/** The selection blended on top of background. */ |
| 66 |
selectionBackgroundOpaque: IColor; |
| 67 |
selectionInactiveBackgroundTransparent: IColor; |
| 68 |
selectionInactiveBackgroundOpaque: IColor; |
| 69 |
scrollbarSliderBackground: IColor; |
| 70 |
scrollbarSliderHoverBackground: IColor; |
| 71 |
scrollbarSliderActiveBackground: IColor; |
| 72 |
overviewRulerBorder: IColor; |
| 73 |
ansi: IColor[]; |
| 74 |
/** Maps original colors to colors that respect minimum contrast ratio. */ |
| 75 |
contrastCache: IColorContrastCache; |
| 76 |
/** Maps original colors to colors that respect _half_ of the minimum contrast ratio. */ |
| 77 |
halfContrastCache: IColorContrastCache; |
| 78 |
} |
| 79 |
|
| 80 |
export type ReadonlyColorSet = Readonly<Omit<IColorSet, 'ansi'>> & { ansi: Readonly<Pick<IColorSet, 'ansi'>['ansi']> }; |
| 81 |
|
| 82 |
export interface IColorContrastCache { |
| 83 |
clear(): void; |
| 84 |
setCss(bg: number, fg: number, value: string | null): void; |
| 85 |
getCss(bg: number, fg: number): string | null | undefined; |
| 86 |
setColor(bg: number, fg: number, value: IColor | null): void; |
| 87 |
getColor(bg: number, fg: number): IColor | null | undefined; |
| 88 |
} |
| 89 |
|
| 90 |
export interface IPartialColorSet { |
| 91 |
foreground: IColor; |
| 92 |
background: IColor; |
| 93 |
cursor?: IColor; |
| 94 |
cursorAccent?: IColor; |
| 95 |
selectionBackground?: IColor; |
| 96 |
ansi: IColor[]; |
| 97 |
} |
| 98 |
|
| 99 |
export interface IViewport extends IDisposable { |
| 100 |
scrollBarWidth: number; |
| 101 |
readonly onRequestScrollLines: Event<{ amount: number, suppressScrollEvent: boolean }>; |
| 102 |
syncScrollArea(immediate?: boolean, force?: boolean): void; |
| 103 |
getLinesScrolled(ev: WheelEvent): number; |
| 104 |
getBufferElements(startLine: number, endLine?: number): { bufferElements: HTMLElement[], cursorElement?: HTMLElement }; |
| 105 |
handleWheel(ev: WheelEvent): boolean; |
| 106 |
handleTouchStart(ev: TouchEvent): void; |
| 107 |
handleTouchMove(ev: TouchEvent): boolean; |
| 108 |
scrollLines(disp: number): void; // todo api name? |
| 109 |
reset(): void; |
| 110 |
} |
| 111 |
|
| 112 |
export interface ILinkifierEvent { |
| 113 |
x1: number; |
| 114 |
y1: number; |
| 115 |
x2: number; |
| 116 |
y2: number; |
| 117 |
cols: number; |
| 118 |
fg: number | undefined; |
| 119 |
} |
| 120 |
|
| 121 |
interface ILinkState { |
| 122 |
decorations: ILinkDecorations; |
| 123 |
isHovered: boolean; |
| 124 |
} |
| 125 |
export interface ILinkWithState { |
| 126 |
link: ILink; |
| 127 |
state?: ILinkState; |
| 128 |
} |
| 129 |
|
| 130 |
export interface ILinkifier2 extends IDisposable { |
| 131 |
onShowLinkUnderline: Event<ILinkifierEvent>; |
| 132 |
onHideLinkUnderline: Event<ILinkifierEvent>; |
| 133 |
readonly currentLink: ILinkWithState | undefined; |
| 134 |
} |
| 135 |
|
| 136 |
export interface ILink { |
| 137 |
range: IBufferRange; |
| 138 |
text: string; |
| 139 |
decorations?: ILinkDecorations; |
| 140 |
activate(event: MouseEvent, text: string): void; |
| 141 |
hover?(event: MouseEvent, text: string): void; |
| 142 |
leave?(event: MouseEvent, text: string): void; |
| 143 |
dispose?(): void; |
| 144 |
} |
| 145 |
|
| 146 |
export interface ILinkDecorations { |
| 147 |
pointerCursor: boolean; |
| 148 |
underline: boolean; |
| 149 |
} |
| 150 |
|
| 151 |
export interface IBufferRange { |
| 152 |
start: IBufferCellPosition; |
| 153 |
end: IBufferCellPosition; |
| 154 |
} |
| 155 |
|
| 156 |
export interface IBufferCellPosition { |
| 157 |
x: number; |
| 158 |
y: number; |
| 159 |
} |
| 160 |
|
| 161 |
export type CharacterJoinerHandler = (text: string) => [number, number][]; |
| 162 |
|
| 163 |
export interface ICharacterJoiner { |
| 164 |
id: number; |
| 165 |
handler: CharacterJoinerHandler; |
| 166 |
} |
| 167 |
|
| 168 |
export interface IRenderDebouncer extends IDisposable { |
| 169 |
refresh(rowStart: number | undefined, rowEnd: number | undefined, rowCount: number): void; |
| 170 |
} |
| 171 |
|
| 172 |
export interface IRenderDebouncerWithCallback extends IRenderDebouncer { |
| 173 |
addRefreshCallback(callback: FrameRequestCallback): number; |
| 174 |
} |
| 175 |
|
| 176 |
export interface IBufferElementProvider { |
| 177 |
provideBufferElements(): DocumentFragment | HTMLElement; |
| 178 |
} |
| 179 |
|
| 180 |
// An IIFE to generate DEFAULT_ANSI_COLORS. |
| 181 |
export const DEFAULT_ANSI_COLORS = Object.freeze((() => { |
| 182 |
const colors = [ |
| 183 |
// dark: |
| 184 |
css.toColor('#2e3436'), |
| 185 |
css.toColor('#cc0000'), |
| 186 |
css.toColor('#4e9a06'), |
| 187 |
css.toColor('#c4a000'), |
| 188 |
css.toColor('#3465a4'), |
| 189 |
css.toColor('#75507b'), |
| 190 |
css.toColor('#06989a'), |
| 191 |
css.toColor('#d3d7cf'), |
| 192 |
// bright: |
| 193 |
css.toColor('#555753'), |
| 194 |
css.toColor('#ef2929'), |
| 195 |
css.toColor('#8ae234'), |
| 196 |
css.toColor('#fce94f'), |
| 197 |
css.toColor('#729fcf'), |
| 198 |
css.toColor('#ad7fa8'), |
| 199 |
css.toColor('#34e2e2'), |
| 200 |
css.toColor('#eeeeec') |
| 201 |
]; |
| 202 |
|
| 203 |
// Fill in the remaining 240 ANSI colors. |
| 204 |
// Generate colors (16-231) |
| 205 |
const v = [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff]; |
| 206 |
for (let i = 0; i < 216; i++) { |
| 207 |
const r = v[(i / 36) % 6 | 0]; |
| 208 |
const g = v[(i / 6) % 6 | 0]; |
| 209 |
const b = v[i % 6]; |
| 210 |
colors.push({ |
| 211 |
css: channels.toCss(r, g, b), |
| 212 |
rgba: channels.toRgba(r, g, b) |
| 213 |
}); |
| 214 |
} |
| 215 |
|
| 216 |
// Generate greys (232-255) |
| 217 |
for (let i = 0; i < 24; i++) { |
| 218 |
const c = 8 + i * 10; |
| 219 |
colors.push({ |
| 220 |
css: channels.toCss(c, c, c), |
| 221 |
rgba: channels.toRgba(c, c, c) |
| 222 |
}); |
| 223 |
} |
| 224 |
|
| 225 |
return colors; |
| 226 |
})()); |