xterm.d.ts 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908
  1. /**
  2. * @license MIT
  3. *
  4. * This contains the type declarations for the xterm.js library. Note that
  5. * some interfaces differ between this file and the actual implementation in
  6. * src/, that's because this file declares the *public* API which is intended
  7. * to be stable and consumed by external programs.
  8. */
  9. /// <reference lib="dom"/>
  10. declare module '@xterm/xterm' {
  11. /**
  12. * A string or number representing text font weight.
  13. */
  14. export type FontWeight = 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900' | number;
  15. /**
  16. * A string representing log level.
  17. */
  18. export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'off';
  19. /**
  20. * An object containing options for the terminal.
  21. */
  22. export interface ITerminalOptions {
  23. /**
  24. * Whether to allow the use of proposed API. When false, any usage of APIs
  25. * marked as experimental/proposed will throw an error. The default is
  26. * false.
  27. */
  28. allowProposedApi?: boolean;
  29. /**
  30. * Whether background should support non-opaque color. It must be set before
  31. * executing the `Terminal.open()` method and can't be changed later without
  32. * executing it again. Note that enabling this can negatively impact
  33. * performance.
  34. */
  35. allowTransparency?: boolean;
  36. /**
  37. * If enabled, alt + click will move the prompt cursor to position
  38. * underneath the mouse. The default is true.
  39. */
  40. altClickMovesCursor?: boolean;
  41. /**
  42. * When enabled the cursor will be set to the beginning of the next line
  43. * with every new line. This is equivalent to sending '\r\n' for each '\n'.
  44. * Normally the termios settings of the underlying PTY deals with the
  45. * translation of '\n' to '\r\n' and this setting should not be used. If you
  46. * deal with data from a non-PTY related source, this settings might be
  47. * useful.
  48. */
  49. convertEol?: boolean;
  50. /**
  51. * Whether the cursor blinks.
  52. */
  53. cursorBlink?: boolean;
  54. /**
  55. * The style of the cursor when the terminal is focused.
  56. */
  57. cursorStyle?: 'block' | 'underline' | 'bar';
  58. /**
  59. * The width of the cursor in CSS pixels when `cursorStyle` is set to 'bar'.
  60. */
  61. cursorWidth?: number;
  62. /**
  63. * The style of the cursor when the terminal is not focused.
  64. */
  65. cursorInactiveStyle?: 'outline' | 'block' | 'bar' | 'underline' | 'none';
  66. /**
  67. * Whether to draw custom glyphs for block element and box drawing
  68. * characters instead of using the font. This should typically result in
  69. * better rendering with continuous lines, even when line height and letter
  70. * spacing is used. Note that this doesn't work with the DOM renderer which
  71. * renders all characters using the font. The default is true.
  72. */
  73. customGlyphs?: boolean;
  74. /**
  75. * Whether input should be disabled.
  76. */
  77. disableStdin?: boolean;
  78. /**
  79. * A {@link Document} to use instead of the one that xterm.js was attached
  80. * to. The purpose of this is to improve support in multi-window
  81. * applications where HTML elements may be references across multiple
  82. * windows which can cause problems with `instanceof`.
  83. *
  84. * The type is `any` because using `Document` can cause TS to have
  85. * performance/compiler problems.
  86. */
  87. documentOverride?: any | null;
  88. /**
  89. * Whether to draw bold text in bright colors. The default is true.
  90. */
  91. drawBoldTextInBrightColors?: boolean;
  92. /**
  93. * The modifier key hold to multiply scroll speed.
  94. */
  95. fastScrollModifier?: 'none' | 'alt' | 'ctrl' | 'shift';
  96. /**
  97. * The scroll speed multiplier used for fast scrolling.
  98. */
  99. fastScrollSensitivity?: number;
  100. /**
  101. * The font size used to render text.
  102. */
  103. fontSize?: number;
  104. /**
  105. * The font family used to render text.
  106. */
  107. fontFamily?: string;
  108. /**
  109. * The font weight used to render non-bold text.
  110. */
  111. fontWeight?: FontWeight;
  112. /**
  113. * The font weight used to render bold text.
  114. */
  115. fontWeightBold?: FontWeight;
  116. /**
  117. * Whether to ignore the bracketed paste mode. When true, this will always
  118. * paste without the `\x1b[200~` and `\x1b[201~` sequences, even when the
  119. * shell enables bracketed mode.
  120. */
  121. ignoreBracketedPasteMode?: boolean;
  122. /**
  123. * The spacing in whole pixels between characters.
  124. */
  125. letterSpacing?: number;
  126. /**
  127. * The line height used to render text.
  128. */
  129. lineHeight?: number;
  130. /**
  131. * The handler for OSC 8 hyperlinks. Links will use the `confirm` browser
  132. * API with a strongly worded warning if no link handler is set.
  133. *
  134. * When setting this, consider the security of users opening these links,
  135. * at a minimum there should be a tooltip or a prompt when hovering or
  136. * activating the link respectively. An example of what might be possible is
  137. * a terminal app writing link in the form `javascript:...` that runs some
  138. * javascript, a safe approach to prevent that is to validate the link
  139. * starts with http(s)://.
  140. */
  141. linkHandler?: ILinkHandler | null;
  142. /**
  143. * What log level to use, this will log for all levels below and including
  144. * what is set:
  145. *
  146. * 1. trace
  147. * 2. debug
  148. * 3. info (default)
  149. * 4. warn
  150. * 5. error
  151. * 6. off
  152. */
  153. logLevel?: LogLevel;
  154. /**
  155. * A logger to use instead of `console`.
  156. */
  157. logger?: ILogger | null;
  158. /**
  159. * Whether to treat option as the meta key.
  160. */
  161. macOptionIsMeta?: boolean;
  162. /**
  163. * Whether holding a modifier key will force normal selection behavior,
  164. * regardless of whether the terminal is in mouse events mode. This will
  165. * also prevent mouse events from being emitted by the terminal. For
  166. * example, this allows you to use xterm.js' regular selection inside tmux
  167. * with mouse mode enabled.
  168. */
  169. macOptionClickForcesSelection?: boolean;
  170. /**
  171. * The minimum contrast ratio for text in the terminal, setting this will
  172. * change the foreground color dynamically depending on whether the contrast
  173. * ratio is met. Example values:
  174. *
  175. * - 1: The default, do nothing.
  176. * - 4.5: Minimum for WCAG AA compliance.
  177. * - 7: Minimum for WCAG AAA compliance.
  178. * - 21: White on black or black on white.
  179. */
  180. minimumContrastRatio?: number;
  181. /**
  182. * Whether to rescale glyphs horizontally that are a single cell wide but
  183. * have glyphs that would overlap following cell(s). This typically happens
  184. * for ambiguous width characters (eg. the roman numeral characters U+2160+)
  185. * which aren't featured in monospace fonts. This is an important feature
  186. * for achieving GB18030 compliance.
  187. *
  188. * The following glyphs will never be rescaled:
  189. *
  190. * - Emoji glyphs
  191. * - Powerline glyphs
  192. * - Nerd font glyphs
  193. *
  194. * Note that this doesn't work with the DOM renderer. The default is false.
  195. */
  196. rescaleOverlappingGlyphs?: boolean;
  197. /**
  198. * Whether to select the word under the cursor on right click, this is
  199. * standard behavior in a lot of macOS applications.
  200. */
  201. rightClickSelectsWord?: boolean;
  202. /**
  203. * Whether screen reader support is enabled. When on this will expose
  204. * supporting elements in the DOM to support NVDA on Windows and VoiceOver
  205. * on macOS.
  206. */
  207. screenReaderMode?: boolean;
  208. /**
  209. * The amount of scrollback in the terminal. Scrollback is the amount of
  210. * rows that are retained when lines are scrolled beyond the initial
  211. * viewport. Defaults to 1000.
  212. */
  213. scrollback?: number;
  214. /**
  215. * Whether to scroll to the bottom whenever there is some user input. The
  216. * default is true.
  217. */
  218. scrollOnUserInput?: boolean;
  219. /**
  220. * The scrolling speed multiplier used for adjusting normal scrolling speed.
  221. */
  222. scrollSensitivity?: number;
  223. /**
  224. * The duration to smoothly scroll between the origin and the target in
  225. * milliseconds. Set to 0 to disable smooth scrolling and scroll instantly.
  226. */
  227. smoothScrollDuration?: number;
  228. /**
  229. * The size of tab stops in the terminal.
  230. */
  231. tabStopWidth?: number;
  232. /**
  233. * The color theme of the terminal.
  234. */
  235. theme?: ITheme;
  236. /**
  237. * Whether "Windows mode" is enabled. Because Windows backends winpty and
  238. * conpty operate by doing line wrapping on their side, xterm.js does not
  239. * have access to wrapped lines. When Windows mode is enabled the following
  240. * changes will be in effect:
  241. *
  242. * - Reflow is disabled.
  243. * - Lines are assumed to be wrapped if the last character of the line is
  244. * not whitespace.
  245. *
  246. * When using conpty on Windows 11 version >= 21376, it is recommended to
  247. * disable this because native text wrapping sequences are output correctly
  248. * thanks to https://github.com/microsoft/terminal/issues/405
  249. *
  250. * @deprecated Use {@link windowsPty}. This value will be ignored if
  251. * windowsPty is set.
  252. */
  253. windowsMode?: boolean;
  254. /**
  255. * Compatibility information when the pty is known to be hosted on Windows.
  256. * Setting this will turn on certain heuristics/workarounds depending on the
  257. * values:
  258. *
  259. * - `if (backend !== undefined || buildNumber !== undefined)`
  260. * - When increasing the rows in the terminal, the amount increased into
  261. * the scrollback. This is done because ConPTY does not behave like
  262. * expect scrollback to come back into the viewport, instead it makes
  263. * empty rows at of the viewport. Not having this behavior can result in
  264. * missing data as the rows get replaced.
  265. * - `if !(backend === 'conpty' && buildNumber >= 21376)`
  266. * - Reflow is disabled
  267. * - Lines are assumed to be wrapped if the last character of the line is
  268. * not whitespace.
  269. */
  270. windowsPty?: IWindowsPty;
  271. /**
  272. * A string containing all characters that are considered word separated by
  273. * the double click to select work logic.
  274. */
  275. wordSeparator?: string;
  276. /**
  277. * Enable various window manipulation and report features.
  278. * All features are disabled by default for security reasons.
  279. */
  280. windowOptions?: IWindowOptions;
  281. /**
  282. * The width, in pixels, of the canvas for the overview ruler. The overview
  283. * ruler will be hidden when not set.
  284. */
  285. overviewRulerWidth?: number;
  286. }
  287. /**
  288. * An object containing additional options for the terminal that can only be
  289. * set on start up.
  290. */
  291. export interface ITerminalInitOnlyOptions {
  292. /**
  293. * The number of columns in the terminal.
  294. */
  295. cols?: number;
  296. /**
  297. * The number of rows in the terminal.
  298. */
  299. rows?: number;
  300. }
  301. /**
  302. * Contains colors to theme the terminal with.
  303. */
  304. export interface ITheme {
  305. /** The default foreground color */
  306. foreground?: string;
  307. /** The default background color */
  308. background?: string;
  309. /** The cursor color */
  310. cursor?: string;
  311. /** The accent color of the cursor (fg color for a block cursor) */
  312. cursorAccent?: string;
  313. /** The selection background color (can be transparent) */
  314. selectionBackground?: string;
  315. /** The selection foreground color */
  316. selectionForeground?: string;
  317. /**
  318. * The selection background color when the terminal does not have focus (can
  319. * be transparent)
  320. */
  321. selectionInactiveBackground?: string;
  322. /** ANSI black (eg. `\x1b[30m`) */
  323. black?: string;
  324. /** ANSI red (eg. `\x1b[31m`) */
  325. red?: string;
  326. /** ANSI green (eg. `\x1b[32m`) */
  327. green?: string;
  328. /** ANSI yellow (eg. `\x1b[33m`) */
  329. yellow?: string;
  330. /** ANSI blue (eg. `\x1b[34m`) */
  331. blue?: string;
  332. /** ANSI magenta (eg. `\x1b[35m`) */
  333. magenta?: string;
  334. /** ANSI cyan (eg. `\x1b[36m`) */
  335. cyan?: string;
  336. /** ANSI white (eg. `\x1b[37m`) */
  337. white?: string;
  338. /** ANSI bright black (eg. `\x1b[1;30m`) */
  339. brightBlack?: string;
  340. /** ANSI bright red (eg. `\x1b[1;31m`) */
  341. brightRed?: string;
  342. /** ANSI bright green (eg. `\x1b[1;32m`) */
  343. brightGreen?: string;
  344. /** ANSI bright yellow (eg. `\x1b[1;33m`) */
  345. brightYellow?: string;
  346. /** ANSI bright blue (eg. `\x1b[1;34m`) */
  347. brightBlue?: string;
  348. /** ANSI bright magenta (eg. `\x1b[1;35m`) */
  349. brightMagenta?: string;
  350. /** ANSI bright cyan (eg. `\x1b[1;36m`) */
  351. brightCyan?: string;
  352. /** ANSI bright white (eg. `\x1b[1;37m`) */
  353. brightWhite?: string;
  354. /** ANSI extended colors (16-255) */
  355. extendedAnsi?: string[];
  356. }
  357. /**
  358. * Pty information for Windows.
  359. */
  360. export interface IWindowsPty {
  361. /**
  362. * What pty emulation backend is being used.
  363. */
  364. backend?: 'conpty' | 'winpty';
  365. /**
  366. * The Windows build version (eg. 19045)
  367. */
  368. buildNumber?: number;
  369. }
  370. /**
  371. * A replacement logger for `console`.
  372. */
  373. export interface ILogger {
  374. /**
  375. * Log a trace message, this will only be called if
  376. * {@link ITerminalOptions.logLevel} is set to trace.
  377. */
  378. trace(message: string, ...args: any[]): void;
  379. /**
  380. * Log a debug message, this will only be called if
  381. * {@link ITerminalOptions.logLevel} is set to debug or below.
  382. */
  383. debug(message: string, ...args: any[]): void;
  384. /**
  385. * Log a debug message, this will only be called if
  386. * {@link ITerminalOptions.logLevel} is set to info or below.
  387. */
  388. info(message: string, ...args: any[]): void;
  389. /**
  390. * Log a debug message, this will only be called if
  391. * {@link ITerminalOptions.logLevel} is set to warn or below.
  392. */
  393. warn(message: string, ...args: any[]): void;
  394. /**
  395. * Log a debug message, this will only be called if
  396. * {@link ITerminalOptions.logLevel} is set to error or below.
  397. */
  398. error(message: string | Error, ...args: any[]): void;
  399. }
  400. /**
  401. * An object that can be disposed via a dispose function.
  402. */
  403. export interface IDisposable {
  404. dispose(): void;
  405. }
  406. /**
  407. * An event that can be listened to.
  408. * @returns an `IDisposable` to stop listening.
  409. */
  410. export interface IEvent<T, U = void> {
  411. (listener: (arg1: T, arg2: U) => any): IDisposable;
  412. }
  413. /**
  414. * Represents a specific line in the terminal that is tracked when scrollback
  415. * is trimmed and lines are added or removed. This is a single line that may
  416. * be part of a larger wrapped line.
  417. */
  418. export interface IMarker extends IDisposableWithEvent {
  419. /**
  420. * A unique identifier for this marker.
  421. */
  422. readonly id: number;
  423. /**
  424. * The actual line index in the buffer at this point in time. This is set to
  425. * -1 if the marker has been disposed.
  426. */
  427. readonly line: number;
  428. }
  429. /**
  430. * Represents a disposable that tracks is disposed state.
  431. */
  432. export interface IDisposableWithEvent extends IDisposable {
  433. /**
  434. * Event listener to get notified when this gets disposed.
  435. */
  436. onDispose: IEvent<void>;
  437. /**
  438. * Whether this is disposed.
  439. */
  440. readonly isDisposed: boolean;
  441. }
  442. /**
  443. * Represents a decoration in the terminal that is associated with a
  444. * particular marker and DOM element.
  445. */
  446. export interface IDecoration extends IDisposableWithEvent {
  447. /*
  448. * The marker for the decoration in the terminal.
  449. */
  450. readonly marker: IMarker;
  451. /**
  452. * An event fired when the decoration
  453. * is rendered, returns the dom element
  454. * associated with the decoration.
  455. */
  456. readonly onRender: IEvent<HTMLElement>;
  457. /**
  458. * The element that the decoration is rendered to. This will be undefined
  459. * until it is rendered for the first time by {@link IDecoration.onRender}.
  460. * that.
  461. */
  462. element: HTMLElement | undefined;
  463. /**
  464. * The options for the overview ruler that can be updated. This will only
  465. * take effect when {@link IDecorationOptions.overviewRulerOptions} were
  466. * provided initially.
  467. */
  468. options: Pick<IDecorationOptions, 'overviewRulerOptions'>;
  469. }
  470. /**
  471. * Overview ruler decoration options
  472. */
  473. interface IDecorationOverviewRulerOptions {
  474. color: string;
  475. position?: 'left' | 'center' | 'right' | 'full';
  476. }
  477. /*
  478. * Options that define the presentation of the decoration.
  479. */
  480. export interface IDecorationOptions {
  481. /**
  482. * The line in the terminal where
  483. * the decoration will be displayed
  484. */
  485. readonly marker: IMarker;
  486. /*
  487. * Where the decoration will be anchored -
  488. * defaults to the left edge
  489. */
  490. readonly anchor?: 'right' | 'left';
  491. /**
  492. * The x position offset relative to the anchor
  493. */
  494. readonly x?: number;
  495. /**
  496. * The width of the decoration in cells, defaults to 1.
  497. */
  498. readonly width?: number;
  499. /**
  500. * The height of the decoration in cells, defaults to 1.
  501. */
  502. readonly height?: number;
  503. /**
  504. * The background color of the cell(s). When 2 decorations both set the
  505. * foreground color the last registered decoration will be used. Only the
  506. * `#RRGGBB` format is supported.
  507. */
  508. readonly backgroundColor?: string;
  509. /**
  510. * The foreground color of the cell(s). When 2 decorations both set the
  511. * foreground color the last registered decoration will be used. Only the
  512. * `#RRGGBB` format is supported.
  513. */
  514. readonly foregroundColor?: string;
  515. /**
  516. * What layer to render the decoration at when {@link backgroundColor} or
  517. * {@link foregroundColor} are used. `'bottom'` will render under the
  518. * selection, `'top`' will render above the selection\*.
  519. *
  520. * *\* The selection will render on top regardless of layer on the canvas
  521. * renderer due to how it renders selection separately.*
  522. */
  523. readonly layer?: 'bottom' | 'top';
  524. /**
  525. * When defined, renders the decoration in the overview ruler to the right
  526. * of the terminal. {@link ITerminalOptions.overviewRulerWidth} must be set
  527. * in order to see the overview ruler.
  528. * @param color The color of the decoration.
  529. * @param position The position of the decoration.
  530. */
  531. overviewRulerOptions?: IDecorationOverviewRulerOptions;
  532. }
  533. /**
  534. * The set of localizable strings.
  535. */
  536. export interface ILocalizableStrings {
  537. /**
  538. * The aria label for the underlying input textarea for the terminal.
  539. */
  540. promptLabel: string;
  541. /**
  542. * Announcement for when line reading is suppressed due to too many lines
  543. * being printed to the terminal when `screenReaderMode` is enabled.
  544. */
  545. tooMuchOutput: string;
  546. }
  547. /**
  548. * Enable various window manipulation and report features
  549. * (`CSI Ps ; Ps ; Ps t`).
  550. *
  551. * Most settings have no default implementation, as they heavily rely on
  552. * the embedding environment.
  553. *
  554. * To implement a feature, create a custom CSI hook like this:
  555. * ```ts
  556. * term.parser.addCsiHandler({final: 't'}, params => {
  557. * const ps = params[0];
  558. * switch (ps) {
  559. * case XY:
  560. * ... // your implementation for option XY
  561. * return true; // signal Ps=XY was handled
  562. * }
  563. * return false; // any Ps that was not handled
  564. * });
  565. * ```
  566. *
  567. * Note on security:
  568. * Most features are meant to deal with some information of the host machine
  569. * where the terminal runs on. This is seen as a security risk possibly
  570. * leaking sensitive data of the host to the program in the terminal.
  571. * Therefore all options (even those without a default implementation) are
  572. * guarded by the boolean flag and disabled by default.
  573. */
  574. export interface IWindowOptions {
  575. /**
  576. * Ps=1 De-iconify window.
  577. * No default implementation.
  578. */
  579. restoreWin?: boolean;
  580. /**
  581. * Ps=2 Iconify window.
  582. * No default implementation.
  583. */
  584. minimizeWin?: boolean;
  585. /**
  586. * Ps=3 ; x ; y
  587. * Move window to [x, y].
  588. * No default implementation.
  589. */
  590. setWinPosition?: boolean;
  591. /**
  592. * Ps = 4 ; height ; width
  593. * Resize the window to given `height` and `width` in pixels.
  594. * Omitted parameters should reuse the current height or width.
  595. * Zero parameters should use the display's height or width.
  596. * No default implementation.
  597. */
  598. setWinSizePixels?: boolean;
  599. /**
  600. * Ps=5 Raise the window to the front of the stacking order.
  601. * No default implementation.
  602. */
  603. raiseWin?: boolean;
  604. /**
  605. * Ps=6 Lower the xterm window to the bottom of the stacking order.
  606. * No default implementation.
  607. */
  608. lowerWin?: boolean;
  609. /** Ps=7 Refresh the window. */
  610. refreshWin?: boolean;
  611. /**
  612. * Ps = 8 ; height ; width
  613. * Resize the text area to given height and width in characters.
  614. * Omitted parameters should reuse the current height or width.
  615. * Zero parameters use the display's height or width.
  616. * No default implementation.
  617. */
  618. setWinSizeChars?: boolean;
  619. /**
  620. * Ps=9 ; 0 Restore maximized window.
  621. * Ps=9 ; 1 Maximize window (i.e., resize to screen size).
  622. * Ps=9 ; 2 Maximize window vertically.
  623. * Ps=9 ; 3 Maximize window horizontally.
  624. * No default implementation.
  625. */
  626. maximizeWin?: boolean;
  627. /**
  628. * Ps=10 ; 0 Undo full-screen mode.
  629. * Ps=10 ; 1 Change to full-screen.
  630. * Ps=10 ; 2 Toggle full-screen.
  631. * No default implementation.
  632. */
  633. fullscreenWin?: boolean;
  634. /** Ps=11 Report xterm window state.
  635. * If the xterm window is non-iconified, it returns "CSI 1 t".
  636. * If the xterm window is iconified, it returns "CSI 2 t".
  637. * No default implementation.
  638. */
  639. getWinState?: boolean;
  640. /**
  641. * Ps=13 Report xterm window position. Result is "CSI 3 ; x ; y t".
  642. * Ps=13 ; 2 Report xterm text-area position. Result is "CSI 3 ; x ; y t".
  643. * No default implementation.
  644. */
  645. getWinPosition?: boolean;
  646. /**
  647. * Ps=14 Report xterm text area size in pixels. Result is "CSI 4 ; height ; width t".
  648. * Ps=14 ; 2 Report xterm window size in pixels. Result is "CSI 4 ; height ; width t".
  649. * Has a default implementation.
  650. */
  651. getWinSizePixels?: boolean;
  652. /**
  653. * Ps=15 Report size of the screen in pixels. Result is "CSI 5 ; height ; width t".
  654. * No default implementation.
  655. */
  656. getScreenSizePixels?: boolean;
  657. /**
  658. * Ps=16 Report xterm character cell size in pixels. Result is "CSI 6 ; height ; width t".
  659. * Has a default implementation.
  660. */
  661. getCellSizePixels?: boolean;
  662. /**
  663. * Ps=18 Report the size of the text area in characters. Result is "CSI 8 ; height ; width t".
  664. * Has a default implementation.
  665. */
  666. getWinSizeChars?: boolean;
  667. /**
  668. * Ps=19 Report the size of the screen in characters. Result is "CSI 9 ; height ; width t".
  669. * No default implementation.
  670. */
  671. getScreenSizeChars?: boolean;
  672. /**
  673. * Ps=20 Report xterm window's icon label. Result is "OSC L label ST".
  674. * No default implementation.
  675. */
  676. getIconTitle?: boolean;
  677. /**
  678. * Ps=21 Report xterm window's title. Result is "OSC l label ST".
  679. * No default implementation.
  680. */
  681. getWinTitle?: boolean;
  682. /**
  683. * Ps=22 ; 0 Save xterm icon and window title on stack.
  684. * Ps=22 ; 1 Save xterm icon title on stack.
  685. * Ps=22 ; 2 Save xterm window title on stack.
  686. * All variants have a default implementation.
  687. */
  688. pushTitle?: boolean;
  689. /**
  690. * Ps=23 ; 0 Restore xterm icon and window title from stack.
  691. * Ps=23 ; 1 Restore xterm icon title from stack.
  692. * Ps=23 ; 2 Restore xterm window title from stack.
  693. * All variants have a default implementation.
  694. */
  695. popTitle?: boolean;
  696. /**
  697. * Ps>=24 Resize to Ps lines (DECSLPP).
  698. * DECSLPP is not implemented. This settings is also used to
  699. * enable / disable DECCOLM (earlier variant of DECSLPP).
  700. */
  701. setWinLines?: boolean;
  702. }
  703. /**
  704. * The class that represents an xterm.js terminal.
  705. */
  706. export class Terminal implements IDisposable {
  707. /**
  708. * The element containing the terminal.
  709. */
  710. readonly element: HTMLElement | undefined;
  711. /**
  712. * The textarea that accepts input for the terminal.
  713. */
  714. readonly textarea: HTMLTextAreaElement | undefined;
  715. /**
  716. * The number of rows in the terminal's viewport. Use
  717. * `ITerminalOptions.rows` to set this in the constructor and
  718. * `Terminal.resize` for when the terminal exists.
  719. */
  720. readonly rows: number;
  721. /**
  722. * The number of columns in the terminal's viewport. Use
  723. * `ITerminalOptions.cols` to set this in the constructor and
  724. * `Terminal.resize` for when the terminal exists.
  725. */
  726. readonly cols: number;
  727. /**
  728. * Access to the terminal's normal and alt buffer.
  729. */
  730. readonly buffer: IBufferNamespace;
  731. /**
  732. * (EXPERIMENTAL) Get all markers registered against the buffer. If the alt
  733. * buffer is active this will always return [].
  734. */
  735. readonly markers: ReadonlyArray<IMarker>;
  736. /**
  737. * Get the parser interface to register custom escape sequence handlers.
  738. */
  739. readonly parser: IParser;
  740. /**
  741. * (EXPERIMENTAL) Get the Unicode handling interface
  742. * to register and switch Unicode version.
  743. */
  744. readonly unicode: IUnicodeHandling;
  745. /**
  746. * Gets the terminal modes as set by SM/DECSET.
  747. */
  748. readonly modes: IModes;
  749. /**
  750. * Gets or sets the terminal options. This supports setting multiple
  751. * options.
  752. *
  753. * @example Get a single option
  754. * ```ts
  755. * console.log(terminal.options.fontSize);
  756. * ```
  757. *
  758. * @example Set a single option:
  759. * ```ts
  760. * terminal.options.fontSize = 12;
  761. * ```
  762. * Note that for options that are object, a new object must be used in order
  763. * to take effect as a reference comparison will be done:
  764. * ```ts
  765. * const newValue = terminal.options.theme;
  766. * newValue.background = '#000000';
  767. *
  768. * // This won't work
  769. * terminal.options.theme = newValue;
  770. *
  771. * // This will work
  772. * terminal.options.theme = { ...newValue };
  773. * ```
  774. *
  775. * @example Set multiple options
  776. * ```ts
  777. * terminal.options = {
  778. * fontSize: 12,
  779. * fontFamily: 'Courier New'
  780. * };
  781. * ```
  782. */
  783. options: ITerminalOptions;
  784. /**
  785. * Natural language strings that can be localized.
  786. */
  787. static strings: ILocalizableStrings;
  788. /**
  789. * Creates a new `Terminal` object.
  790. *
  791. * @param options An object containing a set of options.
  792. */
  793. constructor(options?: ITerminalOptions & ITerminalInitOnlyOptions);
  794. /**
  795. * Adds an event listener for when the bell is triggered.
  796. * @returns an `IDisposable` to stop listening.
  797. */
  798. onBell: IEvent<void>;
  799. /**
  800. * Adds an event listener for when a binary event fires. This is used to
  801. * enable non UTF-8 conformant binary messages to be sent to the backend.
  802. * Currently this is only used for a certain type of mouse reports that
  803. * happen to be not UTF-8 compatible.
  804. * The event value is a JS string, pass it to the underlying pty as
  805. * binary data, e.g. `pty.write(Buffer.from(data, 'binary'))`.
  806. * @returns an `IDisposable` to stop listening.
  807. */
  808. onBinary: IEvent<string>;
  809. /**
  810. * Adds an event listener for the cursor moves.
  811. * @returns an `IDisposable` to stop listening.
  812. */
  813. onCursorMove: IEvent<void>;
  814. /**
  815. * Adds an event listener for when a data event fires. This happens for
  816. * example when the user types or pastes into the terminal. The event value
  817. * is whatever `string` results, in a typical setup, this should be passed
  818. * on to the backing pty.
  819. * @returns an `IDisposable` to stop listening.
  820. */
  821. onData: IEvent<string>;
  822. /**
  823. * Adds an event listener for when a key is pressed. The event value
  824. * contains the string that will be sent in the data event as well as the
  825. * DOM event that triggered it.
  826. * @returns an `IDisposable` to stop listening.
  827. */
  828. onKey: IEvent<{ key: string, domEvent: KeyboardEvent }>;
  829. /**
  830. * Adds an event listener for when a line feed is added.
  831. * @returns an `IDisposable` to stop listening.
  832. */
  833. onLineFeed: IEvent<void>;
  834. /**
  835. * Adds an event listener for when rows are rendered. The event value
  836. * contains the start row and end rows of the rendered area (ranges from `0`
  837. * to `Terminal.rows - 1`).
  838. * @returns an `IDisposable` to stop listening.
  839. */
  840. onRender: IEvent<{ start: number, end: number }>;
  841. /**
  842. * Adds an event listener for when data has been parsed by the terminal,
  843. * after {@link write} is called. This event is useful to listen for any
  844. * changes in the buffer.
  845. *
  846. * This fires at most once per frame, after data parsing completes. Note
  847. * that this can fire when there are still writes pending if there is a lot
  848. * of data.
  849. */
  850. onWriteParsed: IEvent<void>;
  851. /**
  852. * Adds an event listener for when the terminal is resized. The event value
  853. * contains the new size.
  854. * @returns an `IDisposable` to stop listening.
  855. */
  856. onResize: IEvent<{ cols: number, rows: number }>;
  857. /**
  858. * Adds an event listener for when a scroll occurs. The event value is the
  859. * new position of the viewport.
  860. * @returns an `IDisposable` to stop listening.
  861. */
  862. onScroll: IEvent<number>;
  863. /**
  864. * Adds an event listener for when a selection change occurs.
  865. * @returns an `IDisposable` to stop listening.
  866. */
  867. onSelectionChange: IEvent<void>;
  868. /**
  869. * Adds an event listener for when an OSC 0 or OSC 2 title change occurs.
  870. * The event value is the new title.
  871. * @returns an `IDisposable` to stop listening.
  872. */
  873. onTitleChange: IEvent<string>;
  874. /**
  875. * Unfocus the terminal.
  876. */
  877. blur(): void;
  878. /**
  879. * Focus the terminal.
  880. */
  881. focus(): void;
  882. /**
  883. * Input data to application side. The data is treated the same way input
  884. * typed into the terminal would (ie. the {@link onData} event will fire).
  885. * @param data The data to forward to the application.
  886. * @param wasUserInput Whether the input is genuine user input. This is true
  887. * by default and triggers additionalbehavior like focus or selection
  888. * clearing. Set this to false if the data sent should not be treated like
  889. * user input would, for example passing an escape sequence to the
  890. * application.
  891. */
  892. input(data: string, wasUserInput?: boolean): void;
  893. /**
  894. * Resizes the terminal. It's best practice to debounce calls to resize,
  895. * this will help ensure that the pty can respond to the resize event
  896. * before another one occurs.
  897. * @param x The number of columns to resize to.
  898. * @param y The number of rows to resize to.
  899. */
  900. resize(columns: number, rows: number): void;
  901. /**
  902. * Opens the terminal within an element. This should also be called if the
  903. * xterm.js element ever changes browser window.
  904. * @param parent The element to create the terminal within. This element
  905. * must be visible (have dimensions) when `open` is called as several DOM-
  906. * based measurements need to be performed when this function is called.
  907. */
  908. open(parent: HTMLElement): void;
  909. /**
  910. * Attaches a custom key event handler which is run before keys are
  911. * processed, giving consumers of xterm.js ultimate control as to what keys
  912. * should be processed by the terminal and what keys should not.
  913. * @param customKeyEventHandler The custom KeyboardEvent handler to attach.
  914. * This is a function that takes a KeyboardEvent, allowing consumers to stop
  915. * propagation and/or prevent the default action. The function returns
  916. * whether the event should be processed by xterm.js.
  917. *
  918. * @example A custom keymap that overrides the backspace key
  919. * ```ts
  920. * const keymap = [
  921. * { "key": "Backspace", "shiftKey": false, "mapCode": 8 },
  922. * { "key": "Backspace", "shiftKey": true, "mapCode": 127 }
  923. * ];
  924. * term.attachCustomKeyEventHandler(ev => {
  925. * if (ev.type === 'keydown') {
  926. * for (let i in keymap) {
  927. * if (keymap[i].key == ev.key && keymap[i].shiftKey == ev.shiftKey) {
  928. * socket.send(String.fromCharCode(keymap[i].mapCode));
  929. * return false;
  930. * }
  931. * }
  932. * }
  933. * });
  934. * ```
  935. */
  936. attachCustomKeyEventHandler(customKeyEventHandler: (event: KeyboardEvent) => boolean): void;
  937. /**
  938. * Attaches a custom wheel event handler which is run before keys are
  939. * processed, giving consumers of xterm.js control over whether to proceed
  940. * or cancel terminal wheel events.
  941. * @param customWheelEventHandler The custom WheelEvent handler to attach.
  942. * This is a function that takes a WheelEvent, allowing consumers to stop
  943. * propagation and/or prevent the default action. The function returns
  944. * whether the event should be processed by xterm.js.
  945. *
  946. * @example A handler that prevents all wheel events while ctrl is held from
  947. * being processed.
  948. * ```ts
  949. * term.attachCustomWheelEventHandler(ev => {
  950. * if (ev.ctrlKey) {
  951. * return false;
  952. * }
  953. * return true;
  954. * });
  955. * ```
  956. */
  957. attachCustomWheelEventHandler(customWheelEventHandler: (event: WheelEvent) => boolean): void;
  958. /**
  959. * Registers a link provider, allowing a custom parser to be used to match
  960. * and handle links. Multiple link providers can be used, they will be asked
  961. * in the order in which they are registered.
  962. * @param linkProvider The link provider to use to detect links.
  963. */
  964. registerLinkProvider(linkProvider: ILinkProvider): IDisposable;
  965. /**
  966. * (EXPERIMENTAL) Registers a character joiner, allowing custom sequences of
  967. * characters to be rendered as a single unit. This is useful in particular
  968. * for rendering ligatures and graphemes, among other things.
  969. *
  970. * Each registered character joiner is called with a string of text
  971. * representing a portion of a line in the terminal that can be rendered as
  972. * a single unit. The joiner must return a sorted array, where each entry is
  973. * itself an array of length two, containing the start (inclusive) and end
  974. * (exclusive) index of a substring of the input that should be rendered as
  975. * a single unit. When multiple joiners are provided, the results of each
  976. * are collected. If there are any overlapping substrings between them, they
  977. * are combined into one larger unit that is drawn together.
  978. *
  979. * All character joiners that are registered get called every time a line is
  980. * rendered in the terminal, so it is essential for the handler function to
  981. * run as quickly as possible to avoid slowdowns when rendering. Similarly,
  982. * joiners should strive to return the smallest possible substrings to
  983. * render together, since they aren't drawn as optimally as individual
  984. * characters.
  985. *
  986. * NOTE: character joiners are only used by the canvas renderer.
  987. *
  988. * @param handler The function that determines character joins. It is called
  989. * with a string of text that is eligible for joining and returns an array
  990. * where each entry is an array containing the start (inclusive) and end
  991. * (exclusive) indexes of ranges that should be rendered as a single unit.
  992. * @returns The ID of the new joiner, this can be used to deregister
  993. */
  994. registerCharacterJoiner(handler: (text: string) => [number, number][]): number;
  995. /**
  996. * (EXPERIMENTAL) Deregisters the character joiner if one was registered.
  997. * NOTE: character joiners are only used by the canvas renderer.
  998. * @param joinerId The character joiner's ID (returned after register)
  999. */
  1000. deregisterCharacterJoiner(joinerId: number): void;
  1001. /**
  1002. * Adds a marker to the normal buffer and returns it.
  1003. * @param cursorYOffset The y position offset of the marker from the cursor.
  1004. * @returns The new marker or undefined.
  1005. */
  1006. registerMarker(cursorYOffset?: number): IMarker;
  1007. /**
  1008. * (EXPERIMENTAL) Adds a decoration to the terminal using
  1009. * @param decorationOptions, which takes a marker and an optional anchor,
  1010. * width, height, and x offset from the anchor. Returns the decoration or
  1011. * undefined if the alt buffer is active or the marker has already been
  1012. * disposed of.
  1013. * @throws when options include a negative x offset.
  1014. */
  1015. registerDecoration(decorationOptions: IDecorationOptions): IDecoration | undefined;
  1016. /**
  1017. * Gets whether the terminal has an active selection.
  1018. */
  1019. hasSelection(): boolean;
  1020. /**
  1021. * Gets the terminal's current selection, this is useful for implementing
  1022. * copy behavior outside of xterm.js.
  1023. */
  1024. getSelection(): string;
  1025. /**
  1026. * Gets the selection position or undefined if there is no selection.
  1027. */
  1028. getSelectionPosition(): IBufferRange | undefined;
  1029. /**
  1030. * Clears the current terminal selection.
  1031. */
  1032. clearSelection(): void;
  1033. /**
  1034. * Selects text within the terminal.
  1035. * @param column The column the selection starts at.
  1036. * @param row The row the selection starts at.
  1037. * @param length The length of the selection.
  1038. */
  1039. select(column: number, row: number, length: number): void;
  1040. /**
  1041. * Selects all text within the terminal.
  1042. */
  1043. selectAll(): void;
  1044. /**
  1045. * Selects text in the buffer between 2 lines.
  1046. * @param start The 0-based line index to select from (inclusive).
  1047. * @param end The 0-based line index to select to (inclusive).
  1048. */
  1049. selectLines(start: number, end: number): void;
  1050. /*
  1051. * Disposes of the terminal, detaching it from the DOM and removing any
  1052. * active listeners. Once the terminal is disposed it should not be used
  1053. * again.
  1054. */
  1055. dispose(): void;
  1056. /**
  1057. * Scroll the display of the terminal
  1058. * @param amount The number of lines to scroll down (negative scroll up).
  1059. */
  1060. scrollLines(amount: number): void;
  1061. /**
  1062. * Scroll the display of the terminal by a number of pages.
  1063. * @param pageCount The number of pages to scroll (negative scrolls up).
  1064. */
  1065. scrollPages(pageCount: number): void;
  1066. /**
  1067. * Scrolls the display of the terminal to the top.
  1068. */
  1069. scrollToTop(): void;
  1070. /**
  1071. * Scrolls the display of the terminal to the bottom.
  1072. */
  1073. scrollToBottom(): void;
  1074. /**
  1075. * Scrolls to a line within the buffer.
  1076. * @param line The 0-based line index to scroll to.
  1077. */
  1078. scrollToLine(line: number): void;
  1079. /**
  1080. * Clear the entire buffer, making the prompt line the new first line.
  1081. */
  1082. clear(): void;
  1083. /**
  1084. * Write data to the terminal.
  1085. * @param data The data to write to the terminal. This can either be raw
  1086. * bytes given as Uint8Array from the pty or a string. Raw bytes will always
  1087. * be treated as UTF-8 encoded, string data as UTF-16.
  1088. * @param callback Optional callback that fires when the data was processed
  1089. * by the parser.
  1090. */
  1091. write(data: string | Uint8Array, callback?: () => void): void;
  1092. /**
  1093. * Writes data to the terminal, followed by a break line character (\n).
  1094. * @param data The data to write to the terminal. This can either be raw
  1095. * bytes given as Uint8Array from the pty or a string. Raw bytes will always
  1096. * be treated as UTF-8 encoded, string data as UTF-16.
  1097. * @param callback Optional callback that fires when the data was processed
  1098. * by the parser.
  1099. */
  1100. writeln(data: string | Uint8Array, callback?: () => void): void;
  1101. /**
  1102. * Writes text to the terminal, performing the necessary transformations for
  1103. * pasted text.
  1104. * @param data The text to write to the terminal.
  1105. */
  1106. paste(data: string): void;
  1107. /**
  1108. * Tells the renderer to refresh terminal content between two rows
  1109. * (inclusive) at the next opportunity.
  1110. * @param start The row to start from (between 0 and this.rows - 1).
  1111. * @param end The row to end at (between start and this.rows - 1).
  1112. */
  1113. refresh(start: number, end: number): void;
  1114. /**
  1115. * Clears the texture atlas of the canvas renderer if it's active. Doing
  1116. * this will force a redraw of all glyphs which can workaround issues
  1117. * causing the texture to become corrupt, for example Chromium/Nvidia has an
  1118. * issue where the texture gets messed up when resuming the OS from sleep.
  1119. */
  1120. clearTextureAtlas(): void;
  1121. /**
  1122. * Perform a full reset (RIS, aka '\x1bc').
  1123. */
  1124. reset(): void;
  1125. /**
  1126. * Loads an addon into this instance of xterm.js.
  1127. * @param addon The addon to load.
  1128. */
  1129. loadAddon(addon: ITerminalAddon): void;
  1130. }
  1131. /**
  1132. * An addon that can provide additional functionality to the terminal.
  1133. */
  1134. export interface ITerminalAddon extends IDisposable {
  1135. /**
  1136. * This is called when the addon is activated.
  1137. */
  1138. activate(terminal: Terminal): void;
  1139. }
  1140. /**
  1141. * An object representing a range within the viewport of the terminal.
  1142. */
  1143. export interface IViewportRange {
  1144. /**
  1145. * The start of the range.
  1146. */
  1147. start: IViewportRangePosition;
  1148. /**
  1149. * The end of the range.
  1150. */
  1151. end: IViewportRangePosition;
  1152. }
  1153. /**
  1154. * An object representing a cell position within the viewport of the terminal.
  1155. */
  1156. interface IViewportRangePosition {
  1157. /**
  1158. * The x position of the cell. This is a 0-based index that refers to the
  1159. * space in between columns, not the column itself. Index 0 refers to the
  1160. * left side of the viewport, index `Terminal.cols` refers to the right side
  1161. * of the viewport. This can be thought of as how a cursor is positioned in
  1162. * a text editor.
  1163. */
  1164. x: number;
  1165. /**
  1166. * The y position of the cell. This is a 0-based index that refers to a
  1167. * specific row.
  1168. */
  1169. y: number;
  1170. }
  1171. /**
  1172. * A link handler for OSC 8 hyperlinks.
  1173. */
  1174. interface ILinkHandler {
  1175. /**
  1176. * Calls when the link is activated.
  1177. * @param event The mouse event triggering the callback.
  1178. * @param text The text of the link.
  1179. * @param range The buffer range of the link.
  1180. */
  1181. activate(event: MouseEvent, text: string, range: IBufferRange): void;
  1182. /**
  1183. * Called when the mouse hovers the link. To use this to create a DOM-based
  1184. * hover tooltip, create the hover element within `Terminal.element` and
  1185. * add the `xterm-hover` class to it, that will cause mouse events to not
  1186. * fall through and activate other links.
  1187. * @param event The mouse event triggering the callback.
  1188. * @param text The text of the link.
  1189. * @param range The buffer range of the link.
  1190. */
  1191. hover?(event: MouseEvent, text: string, range: IBufferRange): void;
  1192. /**
  1193. * Called when the mouse leaves the link.
  1194. * @param event The mouse event triggering the callback.
  1195. * @param text The text of the link.
  1196. * @param range The buffer range of the link.
  1197. */
  1198. leave?(event: MouseEvent, text: string, range: IBufferRange): void;
  1199. /**
  1200. * Whether to receive non-HTTP URLs from LinkProvider. When false, any
  1201. * usage of non-HTTP URLs will be ignored. Enabling this option without
  1202. * proper protection in `activate` function may cause security issues such
  1203. * as XSS.
  1204. */
  1205. allowNonHttpProtocols?: boolean;
  1206. }
  1207. /**
  1208. * A custom link provider.
  1209. */
  1210. interface ILinkProvider {
  1211. /**
  1212. * Provides a link a buffer position
  1213. * @param bufferLineNumber The y position of the buffer to check for links
  1214. * within.
  1215. * @param callback The callback to be fired when ready with the resulting
  1216. * link(s) for the line or `undefined`.
  1217. */
  1218. provideLinks(bufferLineNumber: number, callback: (links: ILink[] | undefined) => void): void;
  1219. }
  1220. /**
  1221. * A link within the terminal.
  1222. */
  1223. interface ILink {
  1224. /**
  1225. * The buffer range of the link.
  1226. */
  1227. range: IBufferRange;
  1228. /**
  1229. * The text of the link.
  1230. */
  1231. text: string;
  1232. /**
  1233. * What link decorations to show when hovering the link, this property is
  1234. * tracked and changes made after the link is provided will trigger changes.
  1235. * If not set, all decroations will be enabled.
  1236. */
  1237. decorations?: ILinkDecorations;
  1238. /**
  1239. * Calls when the link is activated.
  1240. * @param event The mouse event triggering the callback.
  1241. * @param text The text of the link.
  1242. */
  1243. activate(event: MouseEvent, text: string): void;
  1244. /**
  1245. * Called when the mouse hovers the link. To use this to create a DOM-based
  1246. * hover tooltip, create the hover element within `Terminal.element` and add
  1247. * the `xterm-hover` class to it, that will cause mouse events to not fall
  1248. * through and activate other links.
  1249. * @param event The mouse event triggering the callback.
  1250. * @param text The text of the link.
  1251. */
  1252. hover?(event: MouseEvent, text: string): void;
  1253. /**
  1254. * Called when the mouse leaves the link.
  1255. * @param event The mouse event triggering the callback.
  1256. * @param text The text of the link.
  1257. */
  1258. leave?(event: MouseEvent, text: string): void;
  1259. /**
  1260. * Called when the link is released and no longer used by xterm.js.
  1261. */
  1262. dispose?(): void;
  1263. }
  1264. /**
  1265. * A set of decorations that can be applied to links.
  1266. */
  1267. interface ILinkDecorations {
  1268. /**
  1269. * Whether the cursor is set to pointer.
  1270. */
  1271. pointerCursor: boolean;
  1272. /**
  1273. * Whether the underline is visible
  1274. */
  1275. underline: boolean;
  1276. }
  1277. /**
  1278. * A range within a buffer.
  1279. */
  1280. interface IBufferRange {
  1281. /**
  1282. * The start position of the range.
  1283. */
  1284. start: IBufferCellPosition;
  1285. /**
  1286. * The end position of the range.
  1287. */
  1288. end: IBufferCellPosition;
  1289. }
  1290. /**
  1291. * A position within a buffer.
  1292. */
  1293. interface IBufferCellPosition {
  1294. /**
  1295. * The x position within the buffer (1-based).
  1296. */
  1297. x: number;
  1298. /**
  1299. * The y position within the buffer (1-based).
  1300. */
  1301. y: number;
  1302. }
  1303. /**
  1304. * Represents a terminal buffer.
  1305. */
  1306. interface IBuffer {
  1307. /**
  1308. * The type of the buffer.
  1309. */
  1310. readonly type: 'normal' | 'alternate';
  1311. /**
  1312. * The y position of the cursor. This ranges between `0` (when the
  1313. * cursor is at baseY) and `Terminal.rows - 1` (when the cursor is on the
  1314. * last row).
  1315. */
  1316. readonly cursorY: number;
  1317. /**
  1318. * The x position of the cursor. This ranges between `0` (left side) and
  1319. * `Terminal.cols` (after last cell of the row).
  1320. */
  1321. readonly cursorX: number;
  1322. /**
  1323. * The line within the buffer where the top of the viewport is.
  1324. */
  1325. readonly viewportY: number;
  1326. /**
  1327. * The line within the buffer where the top of the bottom page is (when
  1328. * fully scrolled down).
  1329. */
  1330. readonly baseY: number;
  1331. /**
  1332. * The amount of lines in the buffer.
  1333. */
  1334. readonly length: number;
  1335. /**
  1336. * Gets a line from the buffer, or undefined if the line index does not
  1337. * exist.
  1338. *
  1339. * Note that the result of this function should be used immediately after
  1340. * calling as when the terminal updates it could lead to unexpected
  1341. * behavior.
  1342. *
  1343. * @param y The line index to get.
  1344. */
  1345. getLine(y: number): IBufferLine | undefined;
  1346. /**
  1347. * Creates an empty cell object suitable as a cell reference in
  1348. * `line.getCell(x, cell)`. Use this to avoid costly recreation of
  1349. * cell objects when dealing with tons of cells.
  1350. */
  1351. getNullCell(): IBufferCell;
  1352. }
  1353. export interface IBufferElementProvider {
  1354. /**
  1355. * Provides a document fragment or HTMLElement containing the buffer
  1356. * elements.
  1357. */
  1358. provideBufferElements(): DocumentFragment | HTMLElement;
  1359. }
  1360. /**
  1361. * Represents the terminal's set of buffers.
  1362. */
  1363. interface IBufferNamespace {
  1364. /**
  1365. * The active buffer, this will either be the normal or alternate buffers.
  1366. */
  1367. readonly active: IBuffer;
  1368. /**
  1369. * The normal buffer.
  1370. */
  1371. readonly normal: IBuffer;
  1372. /**
  1373. * The alternate buffer, this becomes the active buffer when an application
  1374. * enters this mode via DECSET (`CSI ? 4 7 h`)
  1375. */
  1376. readonly alternate: IBuffer;
  1377. /**
  1378. * Adds an event listener for when the active buffer changes.
  1379. * @returns an `IDisposable` to stop listening.
  1380. */
  1381. onBufferChange: IEvent<IBuffer>;
  1382. }
  1383. /**
  1384. * Represents a line in the terminal's buffer.
  1385. */
  1386. interface IBufferLine {
  1387. /**
  1388. * Whether the line is wrapped from the previous line.
  1389. */
  1390. readonly isWrapped: boolean;
  1391. /**
  1392. * The length of the line, all call to getCell beyond the length will result
  1393. * in `undefined`. Note that this may exceed columns as the line array may
  1394. * not be trimmed after a resize, compare against {@link Terminal.cols} to
  1395. * get the actual maximum length of a line.
  1396. */
  1397. readonly length: number;
  1398. /**
  1399. * Gets a cell from the line, or undefined if the line index does not exist.
  1400. *
  1401. * Note that the result of this function should be used immediately after
  1402. * calling as when the terminal updates it could lead to unexpected
  1403. * behavior.
  1404. *
  1405. * @param x The character index to get.
  1406. * @param cell Optional cell object to load data into for performance
  1407. * reasons. This is mainly useful when every cell in the buffer is being
  1408. * looped over to avoid creating new objects for every cell.
  1409. */
  1410. getCell(x: number, cell?: IBufferCell): IBufferCell | undefined;
  1411. /**
  1412. * Gets the line as a string. Note that this is gets only the string for the
  1413. * line, not taking isWrapped into account.
  1414. *
  1415. * @param trimRight Whether to trim any whitespace at the right of the line.
  1416. * @param startColumn The column to start from (inclusive).
  1417. * @param endColumn The column to end at (exclusive).
  1418. */
  1419. translateToString(trimRight?: boolean, startColumn?: number, endColumn?: number): string;
  1420. }
  1421. /**
  1422. * Represents a single cell in the terminal's buffer.
  1423. */
  1424. interface IBufferCell {
  1425. /**
  1426. * The width of the character. Some examples:
  1427. *
  1428. * - `1` for most cells.
  1429. * - `2` for wide character like CJK glyphs.
  1430. * - `0` for cells immediately following cells with a width of `2`.
  1431. */
  1432. getWidth(): number;
  1433. /**
  1434. * The character(s) within the cell. Examples of what this can contain:
  1435. *
  1436. * - A normal width character
  1437. * - A wide character (eg. CJK)
  1438. * - An emoji
  1439. */
  1440. getChars(): string;
  1441. /**
  1442. * Gets the UTF32 codepoint of single characters, if content is a combined
  1443. * string it returns the codepoint of the last character in the string.
  1444. */
  1445. getCode(): number;
  1446. /**
  1447. * Gets the number representation of the foreground color mode, this can be
  1448. * used to perform quick comparisons of 2 cells to see if they're the same.
  1449. * Use `isFgRGB`, `isFgPalette` and `isFgDefault` to check what color mode
  1450. * a cell is.
  1451. */
  1452. getFgColorMode(): number;
  1453. /**
  1454. * Gets the number representation of the background color mode, this can be
  1455. * used to perform quick comparisons of 2 cells to see if they're the same.
  1456. * Use `isBgRGB`, `isBgPalette` and `isBgDefault` to check what color mode
  1457. * a cell is.
  1458. */
  1459. getBgColorMode(): number;
  1460. /**
  1461. * Gets a cell's foreground color number, this differs depending on what the
  1462. * color mode of the cell is:
  1463. *
  1464. * - Default: This should be 0, representing the default foreground color
  1465. * (CSI 39 m).
  1466. * - Palette: This is a number from 0 to 255 of ANSI colors (CSI 3(0-7) m,
  1467. * CSI 9(0-7) m, CSI 38 ; 5 ; 0-255 m).
  1468. * - RGB: A hex value representing a 'true color': 0xRRGGBB.
  1469. * (CSI 3 8 ; 2 ; Pi ; Pr ; Pg ; Pb)
  1470. */
  1471. getFgColor(): number;
  1472. /**
  1473. * Gets a cell's background color number, this differs depending on what the
  1474. * color mode of the cell is:
  1475. *
  1476. * - Default: This should be 0, representing the default background color
  1477. * (CSI 49 m).
  1478. * - Palette: This is a number from 0 to 255 of ANSI colors
  1479. * (CSI 4(0-7) m, CSI 10(0-7) m, CSI 48 ; 5 ; 0-255 m).
  1480. * - RGB: A hex value representing a 'true color': 0xRRGGBB
  1481. * (CSI 4 8 ; 2 ; Pi ; Pr ; Pg ; Pb)
  1482. */
  1483. getBgColor(): number;
  1484. /** Whether the cell has the bold attribute (CSI 1 m). */
  1485. isBold(): number;
  1486. /** Whether the cell has the italic attribute (CSI 3 m). */
  1487. isItalic(): number;
  1488. /** Whether the cell has the dim attribute (CSI 2 m). */
  1489. isDim(): number;
  1490. /** Whether the cell has the underline attribute (CSI 4 m). */
  1491. isUnderline(): number;
  1492. /** Whether the cell has the blink attribute (CSI 5 m). */
  1493. isBlink(): number;
  1494. /** Whether the cell has the inverse attribute (CSI 7 m). */
  1495. isInverse(): number;
  1496. /** Whether the cell has the invisible attribute (CSI 8 m). */
  1497. isInvisible(): number;
  1498. /** Whether the cell has the strikethrough attribute (CSI 9 m). */
  1499. isStrikethrough(): number;
  1500. /** Whether the cell has the overline attribute (CSI 53 m). */
  1501. isOverline(): number;
  1502. /** Whether the cell is using the RGB foreground color mode. */
  1503. isFgRGB(): boolean;
  1504. /** Whether the cell is using the RGB background color mode. */
  1505. isBgRGB(): boolean;
  1506. /** Whether the cell is using the palette foreground color mode. */
  1507. isFgPalette(): boolean;
  1508. /** Whether the cell is using the palette background color mode. */
  1509. isBgPalette(): boolean;
  1510. /** Whether the cell is using the default foreground color mode. */
  1511. isFgDefault(): boolean;
  1512. /** Whether the cell is using the default background color mode. */
  1513. isBgDefault(): boolean;
  1514. /** Whether the cell has the default attribute (no color or style). */
  1515. isAttributeDefault(): boolean;
  1516. }
  1517. /**
  1518. * Data type to register a CSI, DCS or ESC callback in the parser
  1519. * in the form:
  1520. * ESC I..I F
  1521. * CSI Prefix P..P I..I F
  1522. * DCS Prefix P..P I..I F data_bytes ST
  1523. *
  1524. * with these rules/restrictions:
  1525. * - prefix can only be used with CSI and DCS
  1526. * - only one leading prefix byte is recognized by the parser
  1527. * before any other parameter bytes (P..P)
  1528. * - intermediate bytes are recognized up to 2
  1529. *
  1530. * For custom sequences make sure to read ECMA-48 and the resources at
  1531. * vt100.net to not clash with existing sequences or reserved address space.
  1532. * General recommendations:
  1533. * - use private address space (see ECMA-48)
  1534. * - use max one intermediate byte (technically not limited by the spec,
  1535. * in practice there are no sequences with more than one intermediate byte,
  1536. * thus parsers might get confused with more intermediates)
  1537. * - test against other common emulators to check whether they escape/ignore
  1538. * the sequence correctly
  1539. *
  1540. * Notes: OSC command registration is handled differently (see addOscHandler)
  1541. * APC, PM or SOS is currently not supported.
  1542. */
  1543. export interface IFunctionIdentifier {
  1544. /**
  1545. * Optional prefix byte, must be in range \x3c .. \x3f.
  1546. * Usable in CSI and DCS.
  1547. */
  1548. prefix?: string;
  1549. /**
  1550. * Optional intermediate bytes, must be in range \x20 .. \x2f.
  1551. * Usable in CSI, DCS and ESC.
  1552. */
  1553. intermediates?: string;
  1554. /**
  1555. * Final byte, must be in range \x40 .. \x7e for CSI and DCS,
  1556. * \x30 .. \x7e for ESC.
  1557. */
  1558. final: string;
  1559. }
  1560. /**
  1561. * Allows hooking into the parser for custom handling of escape sequences.
  1562. *
  1563. * Note on sync vs. async handlers:
  1564. * xterm.js implements all parser actions with synchronous handlers.
  1565. * In general custom handlers should also operate in sync mode wherever
  1566. * possible to keep the parser fast.
  1567. * Still the exposed interfaces allow to register async handlers by returning
  1568. * a `Promise<boolean>`. Here the parser will pause input processing until
  1569. * the promise got resolved or rejected (in-band blocking). This "full stop"
  1570. * on the input chain allows to implement backpressure from a certain async
  1571. * action while the terminal state will not progress any further from input.
  1572. * It does not mean that the terminal state will not change at all in between,
  1573. * as user actions like resize or reset are still processed immediately.
  1574. * It is an error to assume a stable terminal state while giving back control
  1575. * in between, e.g. by multiple chained `then` calls.
  1576. * Downside of an async handler is a rather bad throughput performance,
  1577. * thus use async handlers only as a last resort or for actions that have
  1578. * to rely on async interfaces itself.
  1579. */
  1580. export interface IParser {
  1581. /**
  1582. * Adds a handler for CSI escape sequences.
  1583. * @param id Specifies the function identifier under which the callback gets
  1584. * registered, e.g. {final: 'm'} for SGR.
  1585. * @param callback The function to handle the sequence. The callback is
  1586. * called with the numerical params. If the sequence has subparams the array
  1587. * will contain subarrays with their numercial values. Return `true` if the
  1588. * sequence was handled, `false` if the parser should try a previous
  1589. * handler. The most recently added handler is tried first.
  1590. * @returns An IDisposable you can call to remove this handler.
  1591. */
  1592. registerCsiHandler(id: IFunctionIdentifier, callback: (params: (number | number[])[]) => boolean | Promise<boolean>): IDisposable;
  1593. /**
  1594. * Adds a handler for DCS escape sequences.
  1595. * @param id Specifies the function identifier under which the callback gets
  1596. * registered, e.g. {intermediates: '$' final: 'q'} for DECRQSS.
  1597. * @param callback The function to handle the sequence. Note that the
  1598. * function will only be called once if the sequence finished sucessfully.
  1599. * There is currently no way to intercept smaller data chunks, data chunks
  1600. * will be stored up until the sequence is finished. Since DCS sequences are
  1601. * not limited by the amount of data this might impose a problem for big
  1602. * payloads. Currently xterm.js limits DCS payload to 10 MB which should
  1603. * give enough room for most use cases. The function gets the payload and
  1604. * numerical parameters as arguments. Return `true` if the sequence was
  1605. * handled, `false` if the parser should try a previous handler. The most
  1606. * recently added handler is tried first.
  1607. * @returns An IDisposable you can call to remove this handler.
  1608. */
  1609. registerDcsHandler(id: IFunctionIdentifier, callback: (data: string, param: (number | number[])[]) => boolean | Promise<boolean>): IDisposable;
  1610. /**
  1611. * Adds a handler for ESC escape sequences.
  1612. * @param id Specifies the function identifier under which the callback gets
  1613. * registered, e.g. {intermediates: '%' final: 'G'} for default charset
  1614. * selection.
  1615. * @param callback The function to handle the sequence.
  1616. * Return `true` if the sequence was handled, `false` if the parser should
  1617. * try a previous handler. The most recently added handler is tried first.
  1618. * @returns An IDisposable you can call to remove this handler.
  1619. */
  1620. registerEscHandler(id: IFunctionIdentifier, handler: () => boolean | Promise<boolean>): IDisposable;
  1621. /**
  1622. * Adds a handler for OSC escape sequences.
  1623. * @param ident The number (first parameter) of the sequence.
  1624. * @param callback The function to handle the sequence. Note that the
  1625. * function will only be called once if the sequence finished sucessfully.
  1626. * There is currently no way to intercept smaller data chunks, data chunks
  1627. * will be stored up until the sequence is finished. Since OSC sequences are
  1628. * not limited by the amount of data this might impose a problem for big
  1629. * payloads. Currently xterm.js limits OSC payload to 10 MB which should
  1630. * give enough room for most use cases. The callback is called with OSC data
  1631. * string. Return `true` if the sequence was handled, `false` if the parser
  1632. * should try a previous handler. The most recently added handler is tried
  1633. * first.
  1634. * @returns An IDisposable you can call to remove this handler.
  1635. */
  1636. registerOscHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable;
  1637. }
  1638. /**
  1639. * (EXPERIMENTAL) Unicode version provider.
  1640. * Used to register custom Unicode versions with `Terminal.unicode.register`.
  1641. */
  1642. export interface IUnicodeVersionProvider {
  1643. /**
  1644. * String indicating the Unicode version provided.
  1645. */
  1646. readonly version: string;
  1647. /**
  1648. * Unicode version dependent wcwidth implementation.
  1649. */
  1650. wcwidth(codepoint: number): 0 | 1 | 2;
  1651. charProperties(codepoint: number, preceding: number): number;
  1652. }
  1653. /**
  1654. * (EXPERIMENTAL) Unicode handling interface.
  1655. */
  1656. export interface IUnicodeHandling {
  1657. /**
  1658. * Register a custom Unicode version provider.
  1659. */
  1660. register(provider: IUnicodeVersionProvider): void;
  1661. /**
  1662. * Registered Unicode versions.
  1663. */
  1664. readonly versions: ReadonlyArray<string>;
  1665. /**
  1666. * Getter/setter for active Unicode version.
  1667. */
  1668. activeVersion: string;
  1669. }
  1670. /**
  1671. * Terminal modes as set by SM/DECSET.
  1672. */
  1673. export interface IModes {
  1674. /**
  1675. * Application Cursor Keys (DECCKM): `CSI ? 1 h`
  1676. */
  1677. readonly applicationCursorKeysMode: boolean;
  1678. /**
  1679. * Application Keypad Mode (DECNKM): `CSI ? 6 6 h`
  1680. */
  1681. readonly applicationKeypadMode: boolean;
  1682. /**
  1683. * Bracketed Paste Mode: `CSI ? 2 0 0 4 h`
  1684. */
  1685. readonly bracketedPasteMode: boolean;
  1686. /**
  1687. * Insert Mode (IRM): `CSI 4 h`
  1688. */
  1689. readonly insertMode: boolean;
  1690. /**
  1691. * Mouse Tracking, this can be one of the following:
  1692. * - none: This is the default value and can be reset with DECRST
  1693. * - x10: Send Mouse X & Y on button press `CSI ? 9 h`
  1694. * - vt200: Send Mouse X & Y on button press and release `CSI ? 1 0 0 0 h`
  1695. * - drag: Use Cell Motion Mouse Tracking `CSI ? 1 0 0 2 h`
  1696. * - any: Use All Motion Mouse Tracking `CSI ? 1 0 0 3 h`
  1697. */
  1698. readonly mouseTrackingMode: 'none' | 'x10' | 'vt200' | 'drag' | 'any';
  1699. /**
  1700. * Origin Mode (DECOM): `CSI ? 6 h`
  1701. */
  1702. readonly originMode: boolean;
  1703. /**
  1704. * Reverse-wraparound Mode: `CSI ? 4 5 h`
  1705. */
  1706. readonly reverseWraparoundMode: boolean;
  1707. /**
  1708. * Send FocusIn/FocusOut events: `CSI ? 1 0 0 4 h`
  1709. */
  1710. readonly sendFocusMode: boolean;
  1711. /**
  1712. * Auto-Wrap Mode (DECAWM): `CSI ? 7 h`
  1713. */
  1714. readonly wraparoundMode: boolean;
  1715. }
  1716. }