Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

xterm.d.ts 35KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  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 representing text font weight.
  13. */
  14. export type FontWeight = 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';
  15. /**
  16. * A string representing log level.
  17. */
  18. export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'off';
  19. /**
  20. * A string representing a renderer type.
  21. */
  22. export type RendererType = 'dom' | 'canvas';
  23. /**
  24. * An object containing start up options for the terminal.
  25. */
  26. export interface ITerminalOptions {
  27. /**
  28. * Whether background should support non-opaque color. It must be set before
  29. * executing the `Terminal.open()` method and can't be changed later without
  30. * executing it again. Note that enabling this can negatively impact
  31. * performance.
  32. */
  33. allowTransparency?: boolean;
  34. /**
  35. * A data uri of the sound to use for the bell when `bellStyle = 'sound'`.
  36. */
  37. bellSound?: string;
  38. /**
  39. * The type of the bell notification the terminal will use.
  40. */
  41. bellStyle?: 'none' /*| 'visual'*/ | 'sound' /*| 'both'*/;
  42. /**
  43. * When enabled the cursor will be set to the beginning of the next line
  44. * with every new line. This equivalent to sending '\r\n' for each '\n'.
  45. * Normally the termios settings of the underlying PTY deals with the
  46. * translation of '\n' to '\r\n' and this setting should not be used. If you
  47. * deal with data from a non-PTY related source, this settings might be
  48. * useful.
  49. */
  50. convertEol?: boolean;
  51. /**
  52. * The number of columns in the terminal.
  53. */
  54. cols?: number;
  55. /**
  56. * Whether the cursor blinks.
  57. */
  58. cursorBlink?: boolean;
  59. /**
  60. * The style of the cursor.
  61. */
  62. cursorStyle?: 'block' | 'underline' | 'bar';
  63. /**
  64. * Whether input should be disabled.
  65. */
  66. disableStdin?: boolean;
  67. /**
  68. * Whether to draw bold text in bright colors. The default is true.
  69. */
  70. drawBoldTextInBrightColors?: boolean;
  71. /**
  72. * The modifier key hold to multiply scroll speed.
  73. */
  74. fastScrollModifier?: 'alt' | 'ctrl' | 'shift' | undefined;
  75. /**
  76. * The scroll speed multiplier used for fast scrolling.
  77. */
  78. fastScrollSensitivity?: number;
  79. /**
  80. * The font size used to render text.
  81. */
  82. fontSize?: number;
  83. /**
  84. * The font family used to render text.
  85. */
  86. fontFamily?: string;
  87. /**
  88. * The font weight used to render non-bold text.
  89. */
  90. fontWeight?: FontWeight;
  91. /**
  92. * The font weight used to render bold text.
  93. */
  94. fontWeightBold?: FontWeight;
  95. /**
  96. * The spacing in whole pixels between characters..
  97. */
  98. letterSpacing?: number;
  99. /**
  100. * The line height used to render text.
  101. */
  102. lineHeight?: number;
  103. /**
  104. * What log level to use, this will log for all levels below and including
  105. * what is set:
  106. *
  107. * 1. debug
  108. * 2. info (default)
  109. * 3. warn
  110. * 4. error
  111. * 5. off
  112. */
  113. logLevel?: LogLevel;
  114. /**
  115. * Whether to treat option as the meta key.
  116. */
  117. macOptionIsMeta?: boolean;
  118. /**
  119. * Whether holding a modifier key will force normal selection behavior,
  120. * regardless of whether the terminal is in mouse events mode. This will
  121. * also prevent mouse events from being emitted by the terminal. For
  122. * example, this allows you to use xterm.js' regular selection inside tmux
  123. * with mouse mode enabled.
  124. */
  125. macOptionClickForcesSelection?: boolean;
  126. /**
  127. * The type of renderer to use, this allows using the fallback DOM renderer
  128. * when canvas is too slow for the environment. The following features do
  129. * not work when the DOM renderer is used:
  130. *
  131. * - Letter spacing
  132. * - Cursor blink
  133. */
  134. rendererType?: RendererType;
  135. /**
  136. * Whether to select the word under the cursor on right click, this is
  137. * standard behavior in a lot of macOS applications.
  138. */
  139. rightClickSelectsWord?: boolean;
  140. /**
  141. * The number of rows in the terminal.
  142. */
  143. rows?: number;
  144. /**
  145. * Whether screen reader support is enabled. When on this will expose
  146. * supporting elements in the DOM to support NVDA on Windows and VoiceOver
  147. * on macOS.
  148. */
  149. screenReaderMode?: boolean;
  150. /**
  151. * The amount of scrollback in the terminal. Scrollback is the amount of
  152. * rows that are retained when lines are scrolled beyond the initial
  153. * viewport.
  154. */
  155. scrollback?: number;
  156. /**
  157. * The scrolling speed multiplier used for adjusting normal scrolling speed.
  158. */
  159. scrollSensitivity?: number;
  160. /**
  161. * The size of tab stops in the terminal.
  162. */
  163. tabStopWidth?: number;
  164. /**
  165. * The color theme of the terminal.
  166. */
  167. theme?: ITheme;
  168. /**
  169. * Whether "Windows mode" is enabled. Because Windows backends winpty and
  170. * conpty operate by doing line wrapping on their side, xterm.js does not
  171. * have access to wrapped lines. When Windows mode is enabled the following
  172. * changes will be in effect:
  173. *
  174. * - Reflow is disabled.
  175. * - Lines are assumed to be wrapped if the last character of the line is
  176. * not whitespace.
  177. */
  178. windowsMode?: boolean;
  179. /**
  180. * A string containing all characters that are considered word separated by the
  181. * double click to select work logic.
  182. */
  183. wordSeparator?: string;
  184. }
  185. /**
  186. * Contains colors to theme the terminal with.
  187. */
  188. export interface ITheme {
  189. /** The default foreground color */
  190. foreground?: string;
  191. /** The default background color */
  192. background?: string;
  193. /** The cursor color */
  194. cursor?: string;
  195. /** The accent color of the cursor (fg color for a block cursor) */
  196. cursorAccent?: string;
  197. /** The selection background color (can be transparent) */
  198. selection?: string;
  199. /** ANSI black (eg. `\x1b[30m`) */
  200. black?: string;
  201. /** ANSI red (eg. `\x1b[31m`) */
  202. red?: string;
  203. /** ANSI green (eg. `\x1b[32m`) */
  204. green?: string;
  205. /** ANSI yellow (eg. `\x1b[33m`) */
  206. yellow?: string;
  207. /** ANSI blue (eg. `\x1b[34m`) */
  208. blue?: string;
  209. /** ANSI magenta (eg. `\x1b[35m`) */
  210. magenta?: string;
  211. /** ANSI cyan (eg. `\x1b[36m`) */
  212. cyan?: string;
  213. /** ANSI white (eg. `\x1b[37m`) */
  214. white?: string;
  215. /** ANSI bright black (eg. `\x1b[1;30m`) */
  216. brightBlack?: string;
  217. /** ANSI bright red (eg. `\x1b[1;31m`) */
  218. brightRed?: string;
  219. /** ANSI bright green (eg. `\x1b[1;32m`) */
  220. brightGreen?: string;
  221. /** ANSI bright yellow (eg. `\x1b[1;33m`) */
  222. brightYellow?: string;
  223. /** ANSI bright blue (eg. `\x1b[1;34m`) */
  224. brightBlue?: string;
  225. /** ANSI bright magenta (eg. `\x1b[1;35m`) */
  226. brightMagenta?: string;
  227. /** ANSI bright cyan (eg. `\x1b[1;36m`) */
  228. brightCyan?: string;
  229. /** ANSI bright white (eg. `\x1b[1;37m`) */
  230. brightWhite?: string;
  231. }
  232. /**
  233. * An object containing options for a link matcher.
  234. */
  235. export interface ILinkMatcherOptions {
  236. /**
  237. * The index of the link from the regex.match(text) call. This defaults to 0
  238. * (for regular expressions without capture groups).
  239. */
  240. matchIndex?: number;
  241. /**
  242. * A callback that validates whether to create an individual link, pass
  243. * whether the link is valid to the callback.
  244. */
  245. validationCallback?: (uri: string, callback: (isValid: boolean) => void) => void;
  246. /**
  247. * A callback that fires when the mouse hovers over a link for a moment.
  248. */
  249. tooltipCallback?: (event: MouseEvent, uri: string, location: IViewportRange) => boolean | void;
  250. /**
  251. * A callback that fires when the mouse leaves a link. Note that this can
  252. * happen even when tooltipCallback hasn't fired for the link yet.
  253. */
  254. leaveCallback?: () => void;
  255. /**
  256. * The priority of the link matcher, this defines the order in which the
  257. * link matcher is evaluated relative to others, from highest to lowest. The
  258. * default value is 0.
  259. */
  260. priority?: number;
  261. /**
  262. * A callback that fires when the mousedown and click events occur that
  263. * determines whether a link will be activated upon click. This enables
  264. * only activating a link when a certain modifier is held down, if not the
  265. * mouse event will continue propagation (eg. double click to select word).
  266. */
  267. willLinkActivate?: (event: MouseEvent, uri: string) => boolean;
  268. }
  269. /**
  270. * An object that can be disposed via a dispose function.
  271. */
  272. export interface IDisposable {
  273. dispose(): void;
  274. }
  275. /**
  276. * An event that can be listened to.
  277. * @returns an `IDisposable` to stop listening.
  278. */
  279. export interface IEvent<T> {
  280. (listener: (e: T) => any): IDisposable;
  281. }
  282. /**
  283. * Represents a specific line in the terminal that is tracked when scrollback
  284. * is trimmed and lines are added or removed. This is a single line that may
  285. * be part of a larger wrapped line.
  286. */
  287. export interface IMarker extends IDisposable {
  288. /**
  289. * A unique identifier for this marker.
  290. */
  291. readonly id: number;
  292. /**
  293. * Whether this marker is disposed.
  294. */
  295. readonly isDisposed: boolean;
  296. /**
  297. * The actual line index in the buffer at this point in time. This is set to
  298. * -1 if the marker has been disposed.
  299. */
  300. readonly line: number;
  301. }
  302. /**
  303. * The set of localizable strings.
  304. */
  305. export interface ILocalizableStrings {
  306. /**
  307. * The aria label for the underlying input textarea for the terminal.
  308. */
  309. promptLabel: string;
  310. /**
  311. * Announcement for when line reading is suppressed due to too many lines
  312. * being printed to the terminal when `screenReaderMode` is enabled.
  313. */
  314. tooMuchOutput: string;
  315. }
  316. /**
  317. * The class that represents an xterm.js terminal.
  318. */
  319. export class Terminal implements IDisposable {
  320. /**
  321. * The element containing the terminal.
  322. */
  323. readonly element: HTMLElement | undefined;
  324. /**
  325. * The textarea that accepts input for the terminal.
  326. */
  327. readonly textarea: HTMLTextAreaElement | undefined;
  328. /**
  329. * The number of rows in the terminal's viewport. Use
  330. * `ITerminalOptions.rows` to set this in the constructor and
  331. * `Terminal.resize` for when the terminal exists.
  332. */
  333. readonly rows: number;
  334. /**
  335. * The number of columns in the terminal's viewport. Use
  336. * `ITerminalOptions.cols` to set this in the constructor and
  337. * `Terminal.resize` for when the terminal exists.
  338. */
  339. readonly cols: number;
  340. /**
  341. * (EXPERIMENTAL) The terminal's current buffer, this might be either the
  342. * normal buffer or the alt buffer depending on what's running in the
  343. * terminal.
  344. */
  345. readonly buffer: IBuffer;
  346. /**
  347. * (EXPERIMENTAL) Get all markers registered against the buffer. If the alt
  348. * buffer is active this will always return [].
  349. */
  350. readonly markers: ReadonlyArray<IMarker>;
  351. /**
  352. * (EXPERIMENTAL) Get the parser interface to register
  353. * custom escape sequence handlers.
  354. */
  355. readonly parser: IParser;
  356. /**
  357. * Natural language strings that can be localized.
  358. */
  359. static strings: ILocalizableStrings;
  360. /**
  361. * Creates a new `Terminal` object.
  362. *
  363. * @param options An object containing a set of options.
  364. */
  365. constructor(options?: ITerminalOptions);
  366. /**
  367. * Adds an event listener for the cursor moves.
  368. * @returns an `IDisposable` to stop listening.
  369. */
  370. onCursorMove: IEvent<void>;
  371. /**
  372. * Adds an event listener for when a data event fires. This happens for
  373. * example when the user types or pastes into the terminal. The event value
  374. * is whatever `string` results, in a typical setup, this should be passed
  375. * on to the backing pty.
  376. * @returns an `IDisposable` to stop listening.
  377. */
  378. onData: IEvent<string>;
  379. /**
  380. * Adds an event listener for a key is pressed. The event value contains the
  381. * string that will be sent in the data event as well as the DOM event that
  382. * triggered it.
  383. * @returns an `IDisposable` to stop listening.
  384. */
  385. onKey: IEvent<{ key: string, domEvent: KeyboardEvent }>;
  386. /**
  387. * Adds an event listener for when a line feed is added.
  388. * @returns an `IDisposable` to stop listening.
  389. */
  390. onLineFeed: IEvent<void>;
  391. /**
  392. * Adds an event listener for when a scroll occurs. The event value is the
  393. * new position of the viewport.
  394. * @returns an `IDisposable` to stop listening.
  395. */
  396. onScroll: IEvent<number>;
  397. /**
  398. * Adds an event listener for when a selection change occurs.
  399. * @returns an `IDisposable` to stop listening.
  400. */
  401. onSelectionChange: IEvent<void>;
  402. /**
  403. * Adds an event listener for when rows are rendered. The event value
  404. * contains the start row and end rows of the rendered area (ranges from `0`
  405. * to `Terminal.rows - 1`).
  406. * @returns an `IDisposable` to stop listening.
  407. */
  408. onRender: IEvent<{ start: number, end: number }>;
  409. /**
  410. * Adds an event listener for when the terminal is resized. The event value
  411. * contains the new size.
  412. * @returns an `IDisposable` to stop listening.
  413. */
  414. onResize: IEvent<{ cols: number, rows: number }>;
  415. /**
  416. * Adds an event listener for when an OSC 0 or OSC 2 title change occurs.
  417. * The event value is the new title.
  418. * @returns an `IDisposable` to stop listening.
  419. */
  420. onTitleChange: IEvent<string>;
  421. /**
  422. * Unfocus the terminal.
  423. */
  424. blur(): void;
  425. /**
  426. * Focus the terminal.
  427. */
  428. focus(): void;
  429. /**
  430. * Resizes the terminal. It's best practice to debounce calls to resize,
  431. * this will help ensure that the pty can respond to the resize event
  432. * before another one occurs.
  433. * @param x The number of columns to resize to.
  434. * @param y The number of rows to resize to.
  435. */
  436. resize(columns: number, rows: number): void;
  437. /**
  438. * Opens the terminal within an element.
  439. * @param parent The element to create the terminal within. This element
  440. * must be visible (have dimensions) when `open` is called as several DOM-
  441. * based measurements need to be performed when this function is called.
  442. */
  443. open(parent: HTMLElement): void;
  444. /**
  445. * Attaches a custom key event handler which is run before keys are
  446. * processed, giving consumers of xterm.js ultimate control as to what keys
  447. * should be processed by the terminal and what keys should not.
  448. * @param customKeyEventHandler The custom KeyboardEvent handler to attach.
  449. * This is a function that takes a KeyboardEvent, allowing consumers to stop
  450. * propagation and/or prevent the default action. The function returns
  451. * whether the event should be processed by xterm.js.
  452. */
  453. attachCustomKeyEventHandler(customKeyEventHandler: (event: KeyboardEvent) => boolean): void;
  454. /**
  455. * (EXPERIMENTAL) Registers a link matcher, allowing custom link patterns to
  456. * be matched and handled.
  457. * @param regex The regular expression to search for, specifically this
  458. * searches the textContent of the rows. You will want to use \s to match a
  459. * space ' ' character for example.
  460. * @param handler The callback when the link is called.
  461. * @param options Options for the link matcher.
  462. * @return The ID of the new matcher, this can be used to deregister.
  463. */
  464. registerLinkMatcher(regex: RegExp, handler: (event: MouseEvent, uri: string) => void, options?: ILinkMatcherOptions): number;
  465. /**
  466. * (EXPERIMENTAL) Deregisters a link matcher if it has been registered.
  467. * @param matcherId The link matcher's ID (returned after register)
  468. */
  469. deregisterLinkMatcher(matcherId: number): void;
  470. /**
  471. * (EXPERIMENTAL) Registers a character joiner, allowing custom sequences of
  472. * characters to be rendered as a single unit. This is useful in particular
  473. * for rendering ligatures and graphemes, among other things.
  474. *
  475. * Each registered character joiner is called with a string of text
  476. * representing a portion of a line in the terminal that can be rendered as
  477. * a single unit. The joiner must return a sorted array, where each entry is
  478. * itself an array of length two, containing the start (inclusive) and end
  479. * (exclusive) index of a substring of the input that should be rendered as
  480. * a single unit. When multiple joiners are provided, the results of each
  481. * are collected. If there are any overlapping substrings between them, they
  482. * are combined into one larger unit that is drawn together.
  483. *
  484. * All character joiners that are registered get called every time a line is
  485. * rendered in the terminal, so it is essential for the handler function to
  486. * run as quickly as possible to avoid slowdowns when rendering. Similarly,
  487. * joiners should strive to return the smallest possible substrings to
  488. * render together, since they aren't drawn as optimally as individual
  489. * characters.
  490. *
  491. * NOTE: character joiners are only used by the canvas renderer.
  492. *
  493. * @param handler The function that determines character joins. It is called
  494. * with a string of text that is eligible for joining and returns an array
  495. * where each entry is an array containing the start (inclusive) and end
  496. * (exclusive) indexes of ranges that should be rendered as a single unit.
  497. * @return The ID of the new joiner, this can be used to deregister
  498. */
  499. registerCharacterJoiner(handler: (text: string) => [number, number][]): number;
  500. /**
  501. * (EXPERIMENTAL) Deregisters the character joiner if one was registered.
  502. * NOTE: character joiners are only used by the canvas renderer.
  503. * @param joinerId The character joiner's ID (returned after register)
  504. */
  505. deregisterCharacterJoiner(joinerId: number): void;
  506. /**
  507. * (EXPERIMENTAL) Adds a marker to the normal buffer and returns it. If the
  508. * alt buffer is active, undefined is returned.
  509. * @param cursorYOffset The y position offset of the marker from the cursor.
  510. */
  511. addMarker(cursorYOffset: number): IMarker;
  512. /**
  513. * Gets whether the terminal has an active selection.
  514. */
  515. hasSelection(): boolean;
  516. /**
  517. * Gets the terminal's current selection, this is useful for implementing
  518. * copy behavior outside of xterm.js.
  519. */
  520. getSelection(): string;
  521. /**
  522. * Gets the selection position or undefined if there is no selection.
  523. */
  524. getSelectionPosition(): ISelectionPosition | undefined;
  525. /**
  526. * Clears the current terminal selection.
  527. */
  528. clearSelection(): void;
  529. /**
  530. * Selects text within the terminal.
  531. * @param column The column the selection starts at..
  532. * @param row The row the selection starts at.
  533. * @param length The length of the selection.
  534. */
  535. select(column: number, row: number, length: number): void;
  536. /**
  537. * Selects all text within the terminal.
  538. */
  539. selectAll(): void;
  540. /**
  541. * Selects text in the buffer between 2 lines.
  542. * @param start The 0-based line index to select from (inclusive).
  543. * @param end The 0-based line index to select to (inclusive).
  544. */
  545. selectLines(start: number, end: number): void;
  546. /*
  547. * Disposes of the terminal, detaching it from the DOM and removing any
  548. * active listeners.
  549. */
  550. dispose(): void;
  551. /**
  552. * Scroll the display of the terminal
  553. * @param amount The number of lines to scroll down (negative scroll up).
  554. */
  555. scrollLines(amount: number): void;
  556. /**
  557. * Scroll the display of the terminal by a number of pages.
  558. * @param pageCount The number of pages to scroll (negative scrolls up).
  559. */
  560. scrollPages(pageCount: number): void;
  561. /**
  562. * Scrolls the display of the terminal to the top.
  563. */
  564. scrollToTop(): void;
  565. /**
  566. * Scrolls the display of the terminal to the bottom.
  567. */
  568. scrollToBottom(): void;
  569. /**
  570. * Scrolls to a line within the buffer.
  571. * @param line The 0-based line index to scroll to.
  572. */
  573. scrollToLine(line: number): void;
  574. /**
  575. * Clear the entire buffer, making the prompt line the new first line.
  576. */
  577. clear(): void;
  578. /**
  579. * Write data to the terminal.
  580. * @param data The data to write to the terminal. This can either be raw
  581. * bytes given as Uint8Array from the pty or a string. Raw bytes will always
  582. * be treated as UTF-8 encoded, string data as UTF-16.
  583. * @param callback Optional callback that fires when the data was processed
  584. * by the parser.
  585. */
  586. write(data: string | Uint8Array, callback?: () => void): void;
  587. /**
  588. * Writes data to the terminal, followed by a break line character (\n).
  589. * @param data The data to write to the terminal. This can either be raw
  590. * bytes given as Uint8Array from the pty or a string. Raw bytes will always
  591. * be treated as UTF-8 encoded, string data as UTF-16.
  592. * @param callback Optional callback that fires when the data was processed
  593. * by the parser.
  594. */
  595. writeln(data: string | Uint8Array, callback?: () => void): void;
  596. /**
  597. * Write UTF8 data to the terminal.
  598. * @param data The data to write to the terminal.
  599. * @param callback Optional callback when data was processed.
  600. * @deprecated use `write` instead
  601. */
  602. writeUtf8(data: Uint8Array, callback?: () => void): void;
  603. /**
  604. * Writes text to the terminal, performing the necessary transformations for pasted text.
  605. * @param data The text to write to the terminal.
  606. */
  607. paste(data: string): void;
  608. /**
  609. * Retrieves an option's value from the terminal.
  610. * @param key The option key.
  611. */
  612. getOption(key: 'bellSound' | 'bellStyle' | 'cursorStyle' | 'fontFamily' | 'fontWeight' | 'fontWeightBold' | 'logLevel' | 'rendererType' | 'termName' | 'wordSeparator'): string;
  613. /**
  614. * Retrieves an option's value from the terminal.
  615. * @param key The option key.
  616. */
  617. getOption(key: 'allowTransparency' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord' | 'popOnBell' | 'screenKeys' | 'useFlowControl' | 'visualBell' | 'windowsMode'): boolean;
  618. /**
  619. * Retrieves an option's value from the terminal.
  620. * @param key The option key.
  621. */
  622. getOption(key: 'colors'): string[];
  623. /**
  624. * Retrieves an option's value from the terminal.
  625. * @param key The option key.
  626. */
  627. getOption(key: 'cols' | 'fontSize' | 'letterSpacing' | 'lineHeight' | 'rows' | 'tabStopWidth' | 'scrollback'): number;
  628. /**
  629. * Retrieves an option's value from the terminal.
  630. * @param key The option key.
  631. */
  632. getOption(key: 'handler'): (data: string) => void;
  633. /**
  634. * Retrieves an option's value from the terminal.
  635. * @param key The option key.
  636. */
  637. getOption(key: string): any;
  638. /**
  639. * Sets an option on the terminal.
  640. * @param key The option key.
  641. * @param value The option value.
  642. */
  643. setOption(key: 'fontFamily' | 'termName' | 'bellSound' | 'wordSeparator', value: string): void;
  644. /**
  645. * Sets an option on the terminal.
  646. * @param key The option key.
  647. * @param value The option value.
  648. */
  649. setOption(key: 'fontWeight' | 'fontWeightBold', value: null | 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900'): void;
  650. /**
  651. * Sets an option on the terminal.
  652. * @param key The option key.
  653. * @param value The option value.
  654. */
  655. setOption(key: 'logLevel', value: LogLevel): void;
  656. /**
  657. * Sets an option on the terminal.
  658. * @param key The option key.
  659. * @param value The option value.
  660. */
  661. setOption(key: 'bellStyle', value: null | 'none' | 'visual' | 'sound' | 'both'): void;
  662. /**
  663. * Sets an option on the terminal.
  664. * @param key The option key.
  665. * @param value The option value.
  666. */
  667. setOption(key: 'cursorStyle', value: null | 'block' | 'underline' | 'bar'): void;
  668. /**
  669. * Sets an option on the terminal.
  670. * @param key The option key.
  671. * @param value The option value.
  672. */
  673. setOption(key: 'allowTransparency' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'popOnBell' | 'rightClickSelectsWord' | 'screenKeys' | 'useFlowControl' | 'visualBell' | 'windowsMode', value: boolean): void;
  674. /**
  675. * Sets an option on the terminal.
  676. * @param key The option key.
  677. * @param value The option value.
  678. */
  679. setOption(key: 'colors', value: string[]): void;
  680. /**
  681. * Sets an option on the terminal.
  682. * @param key The option key.
  683. * @param value The option value.
  684. */
  685. setOption(key: 'fontSize' | 'letterSpacing' | 'lineHeight' | 'tabStopWidth' | 'scrollback', value: number): void;
  686. /**
  687. * Sets an option on the terminal.
  688. * @param key The option key.
  689. * @param value The option value.
  690. */
  691. setOption(key: 'handler', value: (data: string) => void): void;
  692. /**
  693. * Sets an option on the terminal.
  694. * @param key The option key.
  695. * @param value The option value.
  696. */
  697. setOption(key: 'theme', value: ITheme): void;
  698. /**
  699. * Sets an option on the terminal.
  700. * @param key The option key.
  701. * @param value The option value.
  702. */
  703. setOption(key: 'cols' | 'rows', value: number): void;
  704. /**
  705. * Sets an option on the terminal.
  706. * @param key The option key.
  707. * @param value The option value.
  708. */
  709. setOption(key: string, value: any): void;
  710. /**
  711. * Tells the renderer to refresh terminal content between two rows
  712. * (inclusive) at the next opportunity.
  713. * @param start The row to start from (between 0 and this.rows - 1).
  714. * @param end The row to end at (between start and this.rows - 1).
  715. */
  716. refresh(start: number, end: number): void;
  717. /**
  718. * Perform a full reset (RIS, aka '\x1bc').
  719. */
  720. reset(): void;
  721. /**
  722. * Loads an addon into this instance of xterm.js.
  723. * @param addon The addon to load.
  724. */
  725. loadAddon(addon: ITerminalAddon): void;
  726. }
  727. /**
  728. * An addon that can provide additional functionality to the terminal.
  729. */
  730. export interface ITerminalAddon extends IDisposable {
  731. /**
  732. * This is called when the addon is activated.
  733. */
  734. activate(terminal: Terminal): void;
  735. }
  736. /**
  737. * An object representing a selection within the terminal.
  738. */
  739. interface ISelectionPosition {
  740. /**
  741. * The start column of the selection.
  742. */
  743. startColumn: number;
  744. /**
  745. * The start row of the selection.
  746. */
  747. startRow: number;
  748. /**
  749. * The end column of the selection.
  750. */
  751. endColumn: number;
  752. /**
  753. * The end row of the selection.
  754. */
  755. endRow: number;
  756. }
  757. /**
  758. * An object representing a range within the viewport of the terminal.
  759. */
  760. export interface IViewportRange {
  761. /**
  762. * The start of the range.
  763. */
  764. start: IViewportRangePosition;
  765. /**
  766. * The end of the range.
  767. */
  768. end: IViewportRangePosition;
  769. }
  770. /**
  771. * An object representing a cell position within the viewport of the terminal.
  772. */
  773. interface IViewportRangePosition {
  774. /**
  775. * The x position of the cell. This is a 0-based index that refers to the
  776. * space in between columns, not the column itself. Index 0 refers to the
  777. * left side of the viewport, index `Terminal.cols` refers to the right side
  778. * of the viewport. This can be thought of as how a cursor is positioned in
  779. * a text editor.
  780. */
  781. x: number;
  782. /**
  783. * The y position of the cell. This is a 0-based index that refers to a
  784. * specific row.
  785. */
  786. y: number;
  787. }
  788. /**
  789. * Represents a terminal buffer.
  790. */
  791. interface IBuffer {
  792. /**
  793. * The y position of the cursor. This ranges between `0` (when the
  794. * cursor is at baseY) and `Terminal.rows - 1` (when the cursor is on the
  795. * last row).
  796. */
  797. readonly cursorY: number;
  798. /**
  799. * The x position of the cursor. This ranges between `0` (left side) and
  800. * `Terminal.cols - 1` (right side).
  801. */
  802. readonly cursorX: number;
  803. /**
  804. * The line within the buffer where the top of the viewport is.
  805. */
  806. readonly viewportY: number;
  807. /**
  808. * The line within the buffer where the top of the bottom page is (when
  809. * fully scrolled down);
  810. */
  811. readonly baseY: number;
  812. /**
  813. * The amount of lines in the buffer.
  814. */
  815. readonly length: number;
  816. /**
  817. * Gets a line from the buffer, or undefined if the line index does not
  818. * exist.
  819. *
  820. * Note that the result of this function should be used immediately after
  821. * calling as when the terminal updates it could lead to unexpected
  822. * behavior.
  823. *
  824. * @param y The line index to get.
  825. */
  826. getLine(y: number): IBufferLine | undefined;
  827. }
  828. /**
  829. * Represents a line in the terminal's buffer.
  830. */
  831. interface IBufferLine {
  832. /**
  833. * Whether the line is wrapped from the previous line.
  834. */
  835. readonly isWrapped: boolean;
  836. /**
  837. * Gets a cell from the line, or undefined if the line index does not exist.
  838. *
  839. * Note that the result of this function should be used immediately after
  840. * calling as when the terminal updates it could lead to unexpected
  841. * behavior.
  842. *
  843. * @param x The character index to get.
  844. */
  845. getCell(x: number): IBufferCell | undefined;
  846. /**
  847. * Gets the line as a string. Note that this is gets only the string for the
  848. * line, not taking isWrapped into account.
  849. *
  850. * @param trimRight Whether to trim any whitespace at the right of the line.
  851. * @param startColumn The column to start from (inclusive).
  852. * @param endColumn The column to end at (exclusive).
  853. */
  854. translateToString(trimRight?: boolean, startColumn?: number, endColumn?: number): string;
  855. }
  856. /**
  857. * Represents a single cell in the terminal's buffer.
  858. */
  859. interface IBufferCell {
  860. /**
  861. * The character within the cell.
  862. */
  863. readonly char: string;
  864. /**
  865. * The width of the character. Some examples:
  866. *
  867. * - This is `1` for most cells.
  868. * - This is `2` for wide character like CJK glyphs.
  869. * - This is `0` for cells immediately following cells with a width of `2`.
  870. */
  871. readonly width: number;
  872. }
  873. /**
  874. * (EXPERIMENTAL) Data type to register a CSI, DCS or ESC callback in the parser
  875. * in the form:
  876. * ESC I..I F
  877. * CSI Prefix P..P I..I F
  878. * DCS Prefix P..P I..I F data_bytes ST
  879. *
  880. * with these rules/restrictions:
  881. * - prefix can only be used with CSI and DCS
  882. * - only one leading prefix byte is recognized by the parser
  883. * before any other parameter bytes (P..P)
  884. * - intermediate bytes are recognized up to 2
  885. *
  886. * For custom sequences make sure to read ECMA-48 and the resources at
  887. * vt100.net to not clash with existing sequences or reserved address space.
  888. * General recommendations:
  889. * - use private address space (see ECMA-48)
  890. * - use max one intermediate byte (technically not limited by the spec,
  891. * in practice there are no sequences with more than one intermediate byte,
  892. * thus parsers might get confused with more intermediates)
  893. * - test against other common emulators to check whether they escape/ignore
  894. * the sequence correctly
  895. *
  896. * Notes: OSC command registration is handled differently (see addOscHandler)
  897. * APC, PM or SOS is currently not supported.
  898. */
  899. export interface IFunctionIdentifier {
  900. /**
  901. * Optional prefix byte, must be in range \x3c .. \x3f.
  902. * Usable in CSI and DCS.
  903. */
  904. prefix?: string;
  905. /**
  906. * Optional intermediate bytes, must be in range \x20 .. \x2f.
  907. * Usable in CSI, DCS and ESC.
  908. */
  909. intermediates?: string;
  910. /**
  911. * Final byte, must be in range \x40 .. \x7e for CSI and DCS,
  912. * \x30 .. \x7e for ESC.
  913. */
  914. final: string;
  915. }
  916. /**
  917. * (EXPERIMENTAL) Parser interface.
  918. */
  919. export interface IParser {
  920. /**
  921. * Adds a handler for CSI escape sequences.
  922. * @param id Specifies the function identifier under which the callback
  923. * gets registered, e.g. {final: 'm'} for SGR.
  924. * @param callback The function to handle the sequence. The callback is
  925. * called with the numerical params. If the sequence has subparams the
  926. * array will contain subarrays with their numercial values.
  927. * Return true if the sequence was handled; false if we should try
  928. * a previous handler (set by addCsiHandler or setCsiHandler).
  929. * The most recently-added handler is tried first.
  930. * @return An IDisposable you can call to remove this handler.
  931. */
  932. addCsiHandler(id: IFunctionIdentifier, callback: (params: (number | number[])[]) => boolean): IDisposable;
  933. /**
  934. * Adds a handler for DCS escape sequences.
  935. * @param id Specifies the function identifier under which the callback
  936. * gets registered, e.g. {intermediates: '$' final: 'q'} for DECRQSS.
  937. * @param callback The function to handle the sequence. Note that the
  938. * function will only be called once if the sequence finished sucessfully.
  939. * There is currently no way to intercept smaller data chunks, data chunks
  940. * will be stored up until the sequence is finished. Since DCS sequences
  941. * are not limited by the amount of data this might impose a problem for
  942. * big payloads. Currently xterm.js limits DCS payload to 10 MB
  943. * which should give enough room for most use cases.
  944. * The function gets the payload and numerical parameters as arguments.
  945. * Return true if the sequence was handled; false if we should try
  946. * a previous handler (set by addDcsHandler or setDcsHandler).
  947. * The most recently-added handler is tried first.
  948. * @return An IDisposable you can call to remove this handler.
  949. */
  950. addDcsHandler(id: IFunctionIdentifier, callback: (data: string, param: (number | number[])[]) => boolean): IDisposable;
  951. /**
  952. * Adds a handler for ESC escape sequences.
  953. * @param id Specifies the function identifier under which the callback
  954. * gets registered, e.g. {intermediates: '%' final: 'G'} for
  955. * default charset selection.
  956. * @param callback The function to handle the sequence.
  957. * Return true if the sequence was handled; false if we should try
  958. * a previous handler (set by addEscHandler or setEscHandler).
  959. * The most recently-added handler is tried first.
  960. * @return An IDisposable you can call to remove this handler.
  961. */
  962. addEscHandler(id: IFunctionIdentifier, handler: () => boolean): IDisposable;
  963. /**
  964. * Adds a handler for OSC escape sequences.
  965. * @param ident The number (first parameter) of the sequence.
  966. * @param callback The function to handle the sequence. Note that the
  967. * function will only be called once if the sequence finished sucessfully.
  968. * There is currently no way to intercept smaller data chunks, data chunks
  969. * will be stored up until the sequence is finished. Since OSC sequences
  970. * are not limited by the amount of data this might impose a problem for
  971. * big payloads. Currently xterm.js limits OSC payload to 10 MB
  972. * which should give enough room for most use cases.
  973. * The callback is called with OSC data string.
  974. * Return true if the sequence was handled; false if we should try
  975. * a previous handler (set by addOscHandler or setOscHandler).
  976. * The most recently-added handler is tried first.
  977. * @return An IDisposable you can call to remove this handler.
  978. */
  979. addOscHandler(ident: number, callback: (data: string) => boolean): IDisposable;
  980. }
  981. }