You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1844 lines
59 KiB

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