xterm.d.ts 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625
  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 = '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 to allow the use of proposed API. When false, any usage of APIs
  29. * marked as experimental/proposed will throw an error. This defaults to
  30. * true currently, but will change to false in v5.0.
  31. */
  32. allowProposedApi?: boolean;
  33. /**
  34. * Whether background should support non-opaque color. It must be set before
  35. * executing the `Terminal.open()` method and can't be changed later without
  36. * executing it again. Note that enabling this can negatively impact
  37. * performance.
  38. */
  39. allowTransparency?: boolean;
  40. /**
  41. * If enabled, alt + click will move the prompt cursor to position
  42. * underneath the mouse. The default is true.
  43. */
  44. altClickMovesCursor?: boolean;
  45. /**
  46. * A data uri of the sound to use for the bell when `bellStyle = 'sound'`.
  47. */
  48. bellSound?: string;
  49. /**
  50. * The type of the bell notification the terminal will use.
  51. */
  52. bellStyle?: 'none' | 'sound';
  53. /**
  54. * When enabled the cursor will be set to the beginning of the next line
  55. * with every new line. This is equivalent to sending '\r\n' for each '\n'.
  56. * Normally the termios settings of the underlying PTY deals with the
  57. * translation of '\n' to '\r\n' and this setting should not be used. If you
  58. * deal with data from a non-PTY related source, this settings might be
  59. * useful.
  60. */
  61. convertEol?: boolean;
  62. /**
  63. * The number of columns in the terminal.
  64. */
  65. cols?: number;
  66. /**
  67. * Whether the cursor blinks.
  68. */
  69. cursorBlink?: boolean;
  70. /**
  71. * The style of the cursor.
  72. */
  73. cursorStyle?: 'block' | 'underline' | 'bar';
  74. /**
  75. * The width of the cursor in CSS pixels when `cursorStyle` is set to 'bar'.
  76. */
  77. cursorWidth?: number;
  78. /**
  79. * Whether input should be disabled.
  80. */
  81. disableStdin?: boolean;
  82. /**
  83. * Whether to draw bold text in bright colors. The default is true.
  84. */
  85. drawBoldTextInBrightColors?: boolean;
  86. /**
  87. * The modifier key hold to multiply scroll speed.
  88. */
  89. fastScrollModifier?: 'alt' | 'ctrl' | 'shift' | undefined;
  90. /**
  91. * The scroll speed multiplier used for fast scrolling.
  92. */
  93. fastScrollSensitivity?: number;
  94. /**
  95. * The font size used to render text.
  96. */
  97. fontSize?: number;
  98. /**
  99. * The font family used to render text.
  100. */
  101. fontFamily?: string;
  102. /**
  103. * The font weight used to render non-bold text.
  104. */
  105. fontWeight?: FontWeight;
  106. /**
  107. * The font weight used to render bold text.
  108. */
  109. fontWeightBold?: FontWeight;
  110. /**
  111. * The spacing in whole pixels between characters.
  112. */
  113. letterSpacing?: number;
  114. /**
  115. * The line height used to render text.
  116. */
  117. lineHeight?: number;
  118. /**
  119. * The duration in milliseconds before link tooltip events fire when
  120. * hovering on a link.
  121. * @deprecated This will be removed when the link matcher API is removed.
  122. */
  123. linkTooltipHoverDuration?: number;
  124. /**
  125. * What log level to use, this will log for all levels below and including
  126. * what is set:
  127. *
  128. * 1. debug
  129. * 2. info (default)
  130. * 3. warn
  131. * 4. error
  132. * 5. off
  133. */
  134. logLevel?: LogLevel;
  135. /**
  136. * Whether to treat option as the meta key.
  137. */
  138. macOptionIsMeta?: boolean;
  139. /**
  140. * Whether holding a modifier key will force normal selection behavior,
  141. * regardless of whether the terminal is in mouse events mode. This will
  142. * also prevent mouse events from being emitted by the terminal. For
  143. * example, this allows you to use xterm.js' regular selection inside tmux
  144. * with mouse mode enabled.
  145. */
  146. macOptionClickForcesSelection?: boolean;
  147. /**
  148. * The minimum contrast ratio for text in the terminal, setting this will
  149. * change the foreground color dynamically depending on whether the contrast
  150. * ratio is met. Example values:
  151. *
  152. * - 1: The default, do nothing.
  153. * - 4.5: Minimum for WCAG AA compliance.
  154. * - 7: Minimum for WCAG AAA compliance.
  155. * - 21: White on black or black on white.
  156. */
  157. minimumContrastRatio?: number;
  158. /**
  159. * The type of renderer to use, this allows using the fallback DOM renderer
  160. * when canvas is too slow for the environment. The following features do
  161. * not work when the DOM renderer is used:
  162. *
  163. * - Letter spacing
  164. * - Cursor blink
  165. */
  166. rendererType?: RendererType;
  167. /**
  168. * Whether to select the word under the cursor on right click, this is
  169. * standard behavior in a lot of macOS applications.
  170. */
  171. rightClickSelectsWord?: boolean;
  172. /**
  173. * The number of rows in the terminal.
  174. */
  175. rows?: number;
  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. * The scrolling speed multiplier used for adjusting normal scrolling speed.
  190. */
  191. scrollSensitivity?: number;
  192. /**
  193. * The size of tab stops in the terminal.
  194. */
  195. tabStopWidth?: number;
  196. /**
  197. * The color theme of the terminal.
  198. */
  199. theme?: ITheme;
  200. /**
  201. * Whether "Windows mode" is enabled. Because Windows backends winpty and
  202. * conpty operate by doing line wrapping on their side, xterm.js does not
  203. * have access to wrapped lines. When Windows mode is enabled the following
  204. * changes will be in effect:
  205. *
  206. * - Reflow is disabled.
  207. * - Lines are assumed to be wrapped if the last character of the line is
  208. * not whitespace.
  209. */
  210. windowsMode?: boolean;
  211. /**
  212. * A string containing all characters that are considered word separated by the
  213. * double click to select work logic.
  214. */
  215. wordSeparator?: string;
  216. /**
  217. * Enable various window manipulation and report features.
  218. * All features are disabled by default for security reasons.
  219. */
  220. windowOptions?: IWindowOptions;
  221. }
  222. /**
  223. * Contains colors to theme the terminal with.
  224. */
  225. export interface ITheme {
  226. /** The default foreground color */
  227. foreground?: string;
  228. /** The default background color */
  229. background?: string;
  230. /** The cursor color */
  231. cursor?: string;
  232. /** The accent color of the cursor (fg color for a block cursor) */
  233. cursorAccent?: string;
  234. /** The selection background color (can be transparent) */
  235. selection?: string;
  236. /** ANSI black (eg. `\x1b[30m`) */
  237. black?: string;
  238. /** ANSI red (eg. `\x1b[31m`) */
  239. red?: string;
  240. /** ANSI green (eg. `\x1b[32m`) */
  241. green?: string;
  242. /** ANSI yellow (eg. `\x1b[33m`) */
  243. yellow?: string;
  244. /** ANSI blue (eg. `\x1b[34m`) */
  245. blue?: string;
  246. /** ANSI magenta (eg. `\x1b[35m`) */
  247. magenta?: string;
  248. /** ANSI cyan (eg. `\x1b[36m`) */
  249. cyan?: string;
  250. /** ANSI white (eg. `\x1b[37m`) */
  251. white?: string;
  252. /** ANSI bright black (eg. `\x1b[1;30m`) */
  253. brightBlack?: string;
  254. /** ANSI bright red (eg. `\x1b[1;31m`) */
  255. brightRed?: string;
  256. /** ANSI bright green (eg. `\x1b[1;32m`) */
  257. brightGreen?: string;
  258. /** ANSI bright yellow (eg. `\x1b[1;33m`) */
  259. brightYellow?: string;
  260. /** ANSI bright blue (eg. `\x1b[1;34m`) */
  261. brightBlue?: string;
  262. /** ANSI bright magenta (eg. `\x1b[1;35m`) */
  263. brightMagenta?: string;
  264. /** ANSI bright cyan (eg. `\x1b[1;36m`) */
  265. brightCyan?: string;
  266. /** ANSI bright white (eg. `\x1b[1;37m`) */
  267. brightWhite?: string;
  268. }
  269. /**
  270. * An object containing options for a link matcher.
  271. */
  272. export interface ILinkMatcherOptions {
  273. /**
  274. * The index of the link from the regex.match(text) call. This defaults to 0
  275. * (for regular expressions without capture groups).
  276. */
  277. matchIndex?: number;
  278. /**
  279. * A callback that validates whether to create an individual link, pass
  280. * whether the link is valid to the callback.
  281. */
  282. validationCallback?: (uri: string, callback: (isValid: boolean) => void) => void;
  283. /**
  284. * A callback that fires when the mouse hovers over a link for a period of
  285. * time (defined by {@link ITerminalOptions.linkTooltipHoverDuration}).
  286. */
  287. tooltipCallback?: (event: MouseEvent, uri: string, location: IViewportRange) => boolean | void;
  288. /**
  289. * A callback that fires when the mouse leaves a link. Note that this can
  290. * happen even when tooltipCallback hasn't fired for the link yet.
  291. */
  292. leaveCallback?: () => void;
  293. /**
  294. * The priority of the link matcher, this defines the order in which the
  295. * link matcher is evaluated relative to others, from highest to lowest. The
  296. * default value is 0.
  297. */
  298. priority?: number;
  299. /**
  300. * A callback that fires when the mousedown and click events occur that
  301. * determines whether a link will be activated upon click. This enables
  302. * only activating a link when a certain modifier is held down, if not the
  303. * mouse event will continue propagation (eg. double click to select word).
  304. */
  305. willLinkActivate?: (event: MouseEvent, uri: string) => boolean;
  306. }
  307. /**
  308. * An object that can be disposed via a dispose function.
  309. */
  310. export interface IDisposable {
  311. dispose(): void;
  312. }
  313. /**
  314. * An event that can be listened to.
  315. * @returns an `IDisposable` to stop listening.
  316. */
  317. export interface IEvent<T, U = void> {
  318. (listener: (arg1: T, arg2: U) => any): IDisposable;
  319. }
  320. /**
  321. * Represents a specific line in the terminal that is tracked when scrollback
  322. * is trimmed and lines are added or removed. This is a single line that may
  323. * be part of a larger wrapped line.
  324. */
  325. export interface IMarker extends IDisposable {
  326. /**
  327. * A unique identifier for this marker.
  328. */
  329. readonly id: number;
  330. /**
  331. * Whether this marker is disposed.
  332. */
  333. readonly isDisposed: boolean;
  334. /**
  335. * The actual line index in the buffer at this point in time. This is set to
  336. * -1 if the marker has been disposed.
  337. */
  338. readonly line: number;
  339. /**
  340. * Event listener to get notified when the marker gets disposed. Automatic disposal
  341. * might happen for a marker, that got invalidated by scrolling out or removal of
  342. * a line from the buffer.
  343. */
  344. onDispose: IEvent<void>;
  345. }
  346. /**
  347. * The set of localizable strings.
  348. */
  349. export interface ILocalizableStrings {
  350. /**
  351. * The aria label for the underlying input textarea for the terminal.
  352. */
  353. promptLabel: string;
  354. /**
  355. * Announcement for when line reading is suppressed due to too many lines
  356. * being printed to the terminal when `screenReaderMode` is enabled.
  357. */
  358. tooMuchOutput: string;
  359. }
  360. /**
  361. * Enable various window manipulation and report features (CSI Ps ; Ps ; Ps t).
  362. *
  363. * Most settings have no default implementation, as they heavily rely on
  364. * the embedding environment.
  365. *
  366. * To implement a feature, create a custom CSI hook like this:
  367. * ```ts
  368. * term.parser.addCsiHandler({final: 't'}, params => {
  369. * const ps = params[0];
  370. * switch (ps) {
  371. * case XY:
  372. * ... // your implementation for option XY
  373. * return true; // signal Ps=XY was handled
  374. * }
  375. * return false; // any Ps that was not handled
  376. * });
  377. * ```
  378. *
  379. * Note on security:
  380. * Most features are meant to deal with some information of the host machine
  381. * where the terminal runs on. This is seen as a security risk possibly leaking
  382. * sensitive data of the host to the program in the terminal. Therefore all options
  383. * (even those without a default implementation) are guarded by the boolean flag
  384. * and disabled by default.
  385. */
  386. export interface IWindowOptions {
  387. /**
  388. * Ps=1 De-iconify window.
  389. * No default implementation.
  390. */
  391. restoreWin?: boolean;
  392. /**
  393. * Ps=2 Iconify window.
  394. * No default implementation.
  395. */
  396. minimizeWin?: boolean;
  397. /**
  398. * Ps=3 ; x ; y
  399. * Move window to [x, y].
  400. * No default implementation.
  401. */
  402. setWinPosition?: boolean;
  403. /**
  404. * Ps = 4 ; height ; width
  405. * Resize the window to given `height` and `width` in pixels.
  406. * Omitted parameters should reuse the current height or width.
  407. * Zero parameters should use the display's height or width.
  408. * No default implementation.
  409. */
  410. setWinSizePixels?: boolean;
  411. /**
  412. * Ps=5 Raise the window to the front of the stacking order.
  413. * No default implementation.
  414. */
  415. raiseWin?: boolean;
  416. /**
  417. * Ps=6 Lower the xterm window to the bottom of the stacking order.
  418. * No default implementation.
  419. */
  420. lowerWin?: boolean;
  421. /** Ps=7 Refresh the window. */
  422. refreshWin?: boolean;
  423. /**
  424. * Ps = 8 ; height ; width
  425. * Resize the text area to given height and width in characters.
  426. * Omitted parameters should reuse the current height or width.
  427. * Zero parameters use the display's height or width.
  428. * No default implementation.
  429. */
  430. setWinSizeChars?: boolean;
  431. /**
  432. * Ps=9 ; 0 Restore maximized window.
  433. * Ps=9 ; 1 Maximize window (i.e., resize to screen size).
  434. * Ps=9 ; 2 Maximize window vertically.
  435. * Ps=9 ; 3 Maximize window horizontally.
  436. * No default implementation.
  437. */
  438. maximizeWin?: boolean;
  439. /**
  440. * Ps=10 ; 0 Undo full-screen mode.
  441. * Ps=10 ; 1 Change to full-screen.
  442. * Ps=10 ; 2 Toggle full-screen.
  443. * No default implementation.
  444. */
  445. fullscreenWin?: boolean;
  446. /** Ps=11 Report xterm window state.
  447. * If the xterm window is non-iconified, it returns "CSI 1 t".
  448. * If the xterm window is iconified, it returns "CSI 2 t".
  449. * No default implementation.
  450. */
  451. getWinState?: boolean;
  452. /**
  453. * Ps=13 Report xterm window position. Result is "CSI 3 ; x ; y t".
  454. * Ps=13 ; 2 Report xterm text-area position. Result is "CSI 3 ; x ; y t".
  455. * No default implementation.
  456. */
  457. getWinPosition?: boolean;
  458. /**
  459. * Ps=14 Report xterm text area size in pixels. Result is "CSI 4 ; height ; width t".
  460. * Ps=14 ; 2 Report xterm window size in pixels. Result is "CSI 4 ; height ; width t".
  461. * Has a default implementation.
  462. */
  463. getWinSizePixels?: boolean;
  464. /**
  465. * Ps=15 Report size of the screen in pixels. Result is "CSI 5 ; height ; width t".
  466. * No default implementation.
  467. */
  468. getScreenSizePixels?: boolean;
  469. /**
  470. * Ps=16 Report xterm character cell size in pixels. Result is "CSI 6 ; height ; width t".
  471. * Has a default implementation.
  472. */
  473. getCellSizePixels?: boolean;
  474. /**
  475. * Ps=18 Report the size of the text area in characters. Result is "CSI 8 ; height ; width t".
  476. * Has a default implementation.
  477. */
  478. getWinSizeChars?: boolean;
  479. /**
  480. * Ps=19 Report the size of the screen in characters. Result is "CSI 9 ; height ; width t".
  481. * No default implementation.
  482. */
  483. getScreenSizeChars?: boolean;
  484. /**
  485. * Ps=20 Report xterm window's icon label. Result is "OSC L label ST".
  486. * No default implementation.
  487. */
  488. getIconTitle?: boolean;
  489. /**
  490. * Ps=21 Report xterm window's title. Result is "OSC l label ST".
  491. * No default implementation.
  492. */
  493. getWinTitle?: boolean;
  494. /**
  495. * Ps=22 ; 0 Save xterm icon and window title on stack.
  496. * Ps=22 ; 1 Save xterm icon title on stack.
  497. * Ps=22 ; 2 Save xterm window title on stack.
  498. * All variants have a default implementation.
  499. */
  500. pushTitle?: boolean;
  501. /**
  502. * Ps=23 ; 0 Restore xterm icon and window title from stack.
  503. * Ps=23 ; 1 Restore xterm icon title from stack.
  504. * Ps=23 ; 2 Restore xterm window title from stack.
  505. * All variants have a default implementation.
  506. */
  507. popTitle?: boolean;
  508. /**
  509. * Ps>=24 Resize to Ps lines (DECSLPP).
  510. * DECSLPP is not implemented. This settings is also used to
  511. * enable / disable DECCOLM (earlier variant of DECSLPP).
  512. */
  513. setWinLines?: boolean;
  514. }
  515. /**
  516. * The class that represents an xterm.js terminal.
  517. */
  518. export class Terminal implements IDisposable {
  519. /**
  520. * The element containing the terminal.
  521. */
  522. readonly element: HTMLElement | undefined;
  523. /**
  524. * The textarea that accepts input for the terminal.
  525. */
  526. readonly textarea: HTMLTextAreaElement | undefined;
  527. /**
  528. * The number of rows in the terminal's viewport. Use
  529. * `ITerminalOptions.rows` to set this in the constructor and
  530. * `Terminal.resize` for when the terminal exists.
  531. */
  532. readonly rows: number;
  533. /**
  534. * The number of columns in the terminal's viewport. Use
  535. * `ITerminalOptions.cols` to set this in the constructor and
  536. * `Terminal.resize` for when the terminal exists.
  537. */
  538. readonly cols: number;
  539. /**
  540. * (EXPERIMENTAL) The terminal's current buffer, this might be either the
  541. * normal buffer or the alt buffer depending on what's running in the
  542. * terminal.
  543. */
  544. readonly buffer: IBufferNamespace;
  545. /**
  546. * (EXPERIMENTAL) Get all markers registered against the buffer. If the alt
  547. * buffer is active this will always return [].
  548. */
  549. readonly markers: ReadonlyArray<IMarker>;
  550. /**
  551. * (EXPERIMENTAL) Get the parser interface to register
  552. * custom escape sequence handlers.
  553. */
  554. readonly parser: IParser;
  555. /**
  556. * (EXPERIMENTAL) Get the Unicode handling interface
  557. * to register and switch Unicode version.
  558. */
  559. readonly unicode: IUnicodeHandling;
  560. /**
  561. * Natural language strings that can be localized.
  562. */
  563. static strings: ILocalizableStrings;
  564. /**
  565. * Creates a new `Terminal` object.
  566. *
  567. * @param options An object containing a set of options.
  568. */
  569. constructor(options?: ITerminalOptions);
  570. /**
  571. * Adds an event listener for when a binary event fires. This is used to
  572. * enable non UTF-8 conformant binary messages to be sent to the backend.
  573. * Currently this is only used for a certain type of mouse reports that
  574. * happen to be not UTF-8 compatible.
  575. * The event value is a JS string, pass it to the underlying pty as
  576. * binary data, e.g. `pty.write(Buffer.from(data, 'binary'))`.
  577. * @returns an `IDisposable` to stop listening.
  578. */
  579. onBinary: IEvent<string>;
  580. /**
  581. * Adds an event listener for the cursor moves.
  582. * @returns an `IDisposable` to stop listening.
  583. */
  584. onCursorMove: IEvent<void>;
  585. /**
  586. * Adds an event listener for when a data event fires. This happens for
  587. * example when the user types or pastes into the terminal. The event value
  588. * is whatever `string` results, in a typical setup, this should be passed
  589. * on to the backing pty.
  590. * @returns an `IDisposable` to stop listening.
  591. */
  592. onData: IEvent<string>;
  593. /**
  594. * Adds an event listener for when a key is pressed. The event value contains the
  595. * string that will be sent in the data event as well as the DOM event that
  596. * triggered it.
  597. * @returns an `IDisposable` to stop listening.
  598. */
  599. onKey: IEvent<{ key: string, domEvent: KeyboardEvent }>;
  600. /**
  601. * Adds an event listener for when a line feed is added.
  602. * @returns an `IDisposable` to stop listening.
  603. */
  604. onLineFeed: IEvent<void>;
  605. /**
  606. * Adds an event listener for when a scroll occurs. The event value is the
  607. * new position of the viewport.
  608. * @returns an `IDisposable` to stop listening.
  609. */
  610. onScroll: IEvent<number>;
  611. /**
  612. * Adds an event listener for when a selection change occurs.
  613. * @returns an `IDisposable` to stop listening.
  614. */
  615. onSelectionChange: IEvent<void>;
  616. /**
  617. * Adds an event listener for when rows are rendered. The event value
  618. * contains the start row and end rows of the rendered area (ranges from `0`
  619. * to `Terminal.rows - 1`).
  620. * @returns an `IDisposable` to stop listening.
  621. */
  622. onRender: IEvent<{ start: number, end: number }>;
  623. /**
  624. * Adds an event listener for when the terminal is resized. The event value
  625. * contains the new size.
  626. * @returns an `IDisposable` to stop listening.
  627. */
  628. onResize: IEvent<{ cols: number, rows: number }>;
  629. /**
  630. * Adds an event listener for when an OSC 0 or OSC 2 title change occurs.
  631. * The event value is the new title.
  632. * @returns an `IDisposable` to stop listening.
  633. */
  634. onTitleChange: IEvent<string>;
  635. /**
  636. * Adds an event listener for when the bell is triggered.
  637. * @returns an `IDisposable` to stop listening.
  638. */
  639. onBell: IEvent<void>;
  640. /**
  641. * Unfocus the terminal.
  642. */
  643. blur(): void;
  644. /**
  645. * Focus the terminal.
  646. */
  647. focus(): void;
  648. /**
  649. * Resizes the terminal. It's best practice to debounce calls to resize,
  650. * this will help ensure that the pty can respond to the resize event
  651. * before another one occurs.
  652. * @param x The number of columns to resize to.
  653. * @param y The number of rows to resize to.
  654. */
  655. resize(columns: number, rows: number): void;
  656. /**
  657. * Opens the terminal within an element.
  658. * @param parent The element to create the terminal within. This element
  659. * must be visible (have dimensions) when `open` is called as several DOM-
  660. * based measurements need to be performed when this function is called.
  661. */
  662. open(parent: HTMLElement): void;
  663. /**
  664. * Attaches a custom key event handler which is run before keys are
  665. * processed, giving consumers of xterm.js ultimate control as to what keys
  666. * should be processed by the terminal and what keys should not.
  667. * @param customKeyEventHandler The custom KeyboardEvent handler to attach.
  668. * This is a function that takes a KeyboardEvent, allowing consumers to stop
  669. * propagation and/or prevent the default action. The function returns
  670. * whether the event should be processed by xterm.js.
  671. */
  672. attachCustomKeyEventHandler(customKeyEventHandler: (event: KeyboardEvent) => boolean): void;
  673. /**
  674. * (EXPERIMENTAL) Registers a link matcher, allowing custom link patterns to
  675. * be matched and handled.
  676. * @deprecated The link matcher API is now deprecated in favor of the link
  677. * provider API, see `registerLinkProvider`.
  678. * @param regex The regular expression to search for, specifically this
  679. * searches the textContent of the rows. You will want to use \s to match a
  680. * space ' ' character for example.
  681. * @param handler The callback when the link is called.
  682. * @param options Options for the link matcher.
  683. * @return The ID of the new matcher, this can be used to deregister.
  684. */
  685. registerLinkMatcher(regex: RegExp, handler: (event: MouseEvent, uri: string) => void, options?: ILinkMatcherOptions): number;
  686. /**
  687. * (EXPERIMENTAL) Deregisters a link matcher if it has been registered.
  688. * @deprecated The link matcher API is now deprecated in favor of the link
  689. * provider API, see `registerLinkProvider`.
  690. * @param matcherId The link matcher's ID (returned after register)
  691. */
  692. deregisterLinkMatcher(matcherId: number): void;
  693. /**
  694. * (EXPERIMENTAL) Registers a link provider, allowing a custom parser to
  695. * be used to match and handle links. Multiple link providers can be used,
  696. * they will be asked in the order in which they are registered.
  697. * @param linkProvider The link provider to use to detect links.
  698. */
  699. registerLinkProvider(linkProvider: ILinkProvider): IDisposable;
  700. /**
  701. * (EXPERIMENTAL) Registers a character joiner, allowing custom sequences of
  702. * characters to be rendered as a single unit. This is useful in particular
  703. * for rendering ligatures and graphemes, among other things.
  704. *
  705. * Each registered character joiner is called with a string of text
  706. * representing a portion of a line in the terminal that can be rendered as
  707. * a single unit. The joiner must return a sorted array, where each entry is
  708. * itself an array of length two, containing the start (inclusive) and end
  709. * (exclusive) index of a substring of the input that should be rendered as
  710. * a single unit. When multiple joiners are provided, the results of each
  711. * are collected. If there are any overlapping substrings between them, they
  712. * are combined into one larger unit that is drawn together.
  713. *
  714. * All character joiners that are registered get called every time a line is
  715. * rendered in the terminal, so it is essential for the handler function to
  716. * run as quickly as possible to avoid slowdowns when rendering. Similarly,
  717. * joiners should strive to return the smallest possible substrings to
  718. * render together, since they aren't drawn as optimally as individual
  719. * characters.
  720. *
  721. * NOTE: character joiners are only used by the canvas renderer.
  722. *
  723. * @param handler The function that determines character joins. It is called
  724. * with a string of text that is eligible for joining and returns an array
  725. * where each entry is an array containing the start (inclusive) and end
  726. * (exclusive) indexes of ranges that should be rendered as a single unit.
  727. * @return The ID of the new joiner, this can be used to deregister
  728. */
  729. registerCharacterJoiner(handler: (text: string) => [number, number][]): number;
  730. /**
  731. * (EXPERIMENTAL) Deregisters the character joiner if one was registered.
  732. * NOTE: character joiners are only used by the canvas renderer.
  733. * @param joinerId The character joiner's ID (returned after register)
  734. */
  735. deregisterCharacterJoiner(joinerId: number): void;
  736. /**
  737. * (EXPERIMENTAL) Adds a marker to the normal buffer and returns it. If the
  738. * alt buffer is active, undefined is returned.
  739. * @param cursorYOffset The y position offset of the marker from the cursor.
  740. * @returns The new marker or undefined.
  741. */
  742. registerMarker(cursorYOffset: number): IMarker | undefined;
  743. /**
  744. * @deprecated use `registerMarker` instead.
  745. */
  746. addMarker(cursorYOffset: number): IMarker | undefined;
  747. /**
  748. * Gets whether the terminal has an active selection.
  749. */
  750. hasSelection(): boolean;
  751. /**
  752. * Gets the terminal's current selection, this is useful for implementing
  753. * copy behavior outside of xterm.js.
  754. */
  755. getSelection(): string;
  756. /**
  757. * Gets the selection position or undefined if there is no selection.
  758. */
  759. getSelectionPosition(): ISelectionPosition | undefined;
  760. /**
  761. * Clears the current terminal selection.
  762. */
  763. clearSelection(): void;
  764. /**
  765. * Selects text within the terminal.
  766. * @param column The column the selection starts at.
  767. * @param row The row the selection starts at.
  768. * @param length The length of the selection.
  769. */
  770. select(column: number, row: number, length: number): void;
  771. /**
  772. * Selects all text within the terminal.
  773. */
  774. selectAll(): void;
  775. /**
  776. * Selects text in the buffer between 2 lines.
  777. * @param start The 0-based line index to select from (inclusive).
  778. * @param end The 0-based line index to select to (inclusive).
  779. */
  780. selectLines(start: number, end: number): void;
  781. /*
  782. * Disposes of the terminal, detaching it from the DOM and removing any
  783. * active listeners.
  784. */
  785. dispose(): void;
  786. /**
  787. * Scroll the display of the terminal
  788. * @param amount The number of lines to scroll down (negative scroll up).
  789. */
  790. scrollLines(amount: number): void;
  791. /**
  792. * Scroll the display of the terminal by a number of pages.
  793. * @param pageCount The number of pages to scroll (negative scrolls up).
  794. */
  795. scrollPages(pageCount: number): void;
  796. /**
  797. * Scrolls the display of the terminal to the top.
  798. */
  799. scrollToTop(): void;
  800. /**
  801. * Scrolls the display of the terminal to the bottom.
  802. */
  803. scrollToBottom(): void;
  804. /**
  805. * Scrolls to a line within the buffer.
  806. * @param line The 0-based line index to scroll to.
  807. */
  808. scrollToLine(line: number): void;
  809. /**
  810. * Clear the entire buffer, making the prompt line the new first line.
  811. */
  812. clear(): void;
  813. /**
  814. * Write data to the terminal.
  815. * @param data The data to write to the terminal. This can either be raw
  816. * bytes given as Uint8Array from the pty or a string. Raw bytes will always
  817. * be treated as UTF-8 encoded, string data as UTF-16.
  818. * @param callback Optional callback that fires when the data was processed
  819. * by the parser.
  820. */
  821. write(data: string | Uint8Array, callback?: () => void): void;
  822. /**
  823. * Writes data to the terminal, followed by a break line character (\n).
  824. * @param data The data to write to the terminal. This can either be raw
  825. * bytes given as Uint8Array from the pty or a string. Raw bytes will always
  826. * be treated as UTF-8 encoded, string data as UTF-16.
  827. * @param callback Optional callback that fires when the data was processed
  828. * by the parser.
  829. */
  830. writeln(data: string | Uint8Array, callback?: () => void): void;
  831. /**
  832. * Write UTF8 data to the terminal.
  833. * @param data The data to write to the terminal.
  834. * @param callback Optional callback when data was processed.
  835. * @deprecated use `write` instead
  836. */
  837. writeUtf8(data: Uint8Array, callback?: () => void): void;
  838. /**
  839. * Writes text to the terminal, performing the necessary transformations for pasted text.
  840. * @param data The text to write to the terminal.
  841. */
  842. paste(data: string): void;
  843. /**
  844. * Retrieves an option's value from the terminal.
  845. * @param key The option key.
  846. */
  847. getOption(key: 'bellSound' | 'bellStyle' | 'cursorStyle' | 'fontFamily' | 'logLevel' | 'rendererType' | 'termName' | 'wordSeparator'): string;
  848. /**
  849. * Retrieves an option's value from the terminal.
  850. * @param key The option key.
  851. */
  852. getOption(key: 'allowTransparency' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord' | 'popOnBell' | 'visualBell' | 'windowsMode'): boolean;
  853. /**
  854. * Retrieves an option's value from the terminal.
  855. * @param key The option key.
  856. */
  857. getOption(key: 'cols' | 'fontSize' | 'letterSpacing' | 'lineHeight' | 'rows' | 'tabStopWidth' | 'scrollback'): number;
  858. /**
  859. * Retrieves an option's value from the terminal.
  860. * @param key The option key.
  861. */
  862. getOption(key: 'fontWeight' | 'fontWeightBold'): FontWeight;
  863. /**
  864. * Retrieves an option's value from the terminal.
  865. * @param key The option key.
  866. */
  867. getOption(key: string): any;
  868. /**
  869. * Sets an option on the terminal.
  870. * @param key The option key.
  871. * @param value The option value.
  872. */
  873. setOption(key: 'fontFamily' | 'termName' | 'bellSound' | 'wordSeparator', value: string): void;
  874. /**
  875. * Sets an option on the terminal.
  876. * @param key The option key.
  877. * @param value The option value.
  878. */
  879. setOption(key: 'fontWeight' | 'fontWeightBold', value: null | 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900' | number): void;
  880. /**
  881. * Sets an option on the terminal.
  882. * @param key The option key.
  883. * @param value The option value.
  884. */
  885. setOption(key: 'logLevel', value: LogLevel): void;
  886. /**
  887. * Sets an option on the terminal.
  888. * @param key The option key.
  889. * @param value The option value.
  890. */
  891. setOption(key: 'bellStyle', value: null | 'none' | 'visual' | 'sound' | 'both'): void;
  892. /**
  893. * Sets an option on the terminal.
  894. * @param key The option key.
  895. * @param value The option value.
  896. */
  897. setOption(key: 'cursorStyle', value: null | 'block' | 'underline' | 'bar'): void;
  898. /**
  899. * Sets an option on the terminal.
  900. * @param key The option key.
  901. * @param value The option value.
  902. */
  903. setOption(key: 'allowTransparency' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'popOnBell' | 'rightClickSelectsWord' | 'visualBell' | 'windowsMode', value: boolean): void;
  904. /**
  905. * Sets an option on the terminal.
  906. * @param key The option key.
  907. * @param value The option value.
  908. */
  909. setOption(key: 'fontSize' | 'letterSpacing' | 'lineHeight' | 'tabStopWidth' | 'scrollback', value: number): void;
  910. /**
  911. * Sets an option on the terminal.
  912. * @param key The option key.
  913. * @param value The option value.
  914. */
  915. setOption(key: 'theme', value: ITheme): void;
  916. /**
  917. * Sets an option on the terminal.
  918. * @param key The option key.
  919. * @param value The option value.
  920. */
  921. setOption(key: 'cols' | 'rows', value: number): void;
  922. /**
  923. * Sets an option on the terminal.
  924. * @param key The option key.
  925. * @param value The option value.
  926. */
  927. setOption(key: string, value: any): void;
  928. /**
  929. * Tells the renderer to refresh terminal content between two rows
  930. * (inclusive) at the next opportunity.
  931. * @param start The row to start from (between 0 and this.rows - 1).
  932. * @param end The row to end at (between start and this.rows - 1).
  933. */
  934. refresh(start: number, end: number): void;
  935. /**
  936. * Perform a full reset (RIS, aka '\x1bc').
  937. */
  938. reset(): void;
  939. /**
  940. * Loads an addon into this instance of xterm.js.
  941. * @param addon The addon to load.
  942. */
  943. loadAddon(addon: ITerminalAddon): void;
  944. }
  945. /**
  946. * An addon that can provide additional functionality to the terminal.
  947. */
  948. export interface ITerminalAddon extends IDisposable {
  949. /**
  950. * This is called when the addon is activated.
  951. */
  952. activate(terminal: Terminal): void;
  953. }
  954. /**
  955. * An object representing a selection within the terminal.
  956. */
  957. interface ISelectionPosition {
  958. /**
  959. * The start column of the selection.
  960. */
  961. startColumn: number;
  962. /**
  963. * The start row of the selection.
  964. */
  965. startRow: number;
  966. /**
  967. * The end column of the selection.
  968. */
  969. endColumn: number;
  970. /**
  971. * The end row of the selection.
  972. */
  973. endRow: number;
  974. }
  975. /**
  976. * An object representing a range within the viewport of the terminal.
  977. */
  978. export interface IViewportRange {
  979. /**
  980. * The start of the range.
  981. */
  982. start: IViewportRangePosition;
  983. /**
  984. * The end of the range.
  985. */
  986. end: IViewportRangePosition;
  987. }
  988. /**
  989. * An object representing a cell position within the viewport of the terminal.
  990. */
  991. interface IViewportRangePosition {
  992. /**
  993. * The x position of the cell. This is a 0-based index that refers to the
  994. * space in between columns, not the column itself. Index 0 refers to the
  995. * left side of the viewport, index `Terminal.cols` refers to the right side
  996. * of the viewport. This can be thought of as how a cursor is positioned in
  997. * a text editor.
  998. */
  999. x: number;
  1000. /**
  1001. * The y position of the cell. This is a 0-based index that refers to a
  1002. * specific row.
  1003. */
  1004. y: number;
  1005. }
  1006. /**
  1007. * A custom link provider.
  1008. */
  1009. interface ILinkProvider {
  1010. /**
  1011. * Provides a link a buffer position
  1012. * @param bufferLineNumber The y position of the buffer to check for links
  1013. * within.
  1014. * @param callback The callback to be fired when ready with the resulting
  1015. * link(s) for the line or `undefined`.
  1016. */
  1017. provideLinks(bufferLineNumber: number, callback: (links: ILink[] | undefined) => void): void;
  1018. }
  1019. /**
  1020. * A link within the terminal.
  1021. */
  1022. interface ILink {
  1023. /**
  1024. * The buffer range of the link.
  1025. */
  1026. range: IBufferRange;
  1027. /**
  1028. * The text of the link.
  1029. */
  1030. text: string;
  1031. /**
  1032. * What link decorations to show when hovering the link, this property is tracked and changes
  1033. * made after the link is provided will trigger changes. If not set, all decroations will be
  1034. * enabled.
  1035. */
  1036. decorations?: ILinkDecorations;
  1037. /**
  1038. * Calls when the link is activated.
  1039. * @param event The mouse event triggering the callback.
  1040. * @param text The text of the link.
  1041. */
  1042. activate(event: MouseEvent, text: string): void;
  1043. /**
  1044. * Called when the mouse hovers the link. To use this to create a DOM-based hover tooltip,
  1045. * create the hover element within `Terminal.element` and add the `xterm-hover` class to it,
  1046. * that will cause mouse events to not fall through and activate other links.
  1047. * @param event The mouse event triggering the callback.
  1048. * @param text The text of the link.
  1049. */
  1050. hover?(event: MouseEvent, text: string): void;
  1051. /**
  1052. * Called when the mouse leaves the link.
  1053. * @param event The mouse event triggering the callback.
  1054. * @param text The text of the link.
  1055. */
  1056. leave?(event: MouseEvent, text: string): void;
  1057. /**
  1058. * Called when the link is released and no longer used by xterm.js.
  1059. */
  1060. dispose?(): void;
  1061. }
  1062. /**
  1063. * A set of decorations that can be applied to links.
  1064. */
  1065. interface ILinkDecorations {
  1066. /**
  1067. * Whether the cursor is set to pointer.
  1068. */
  1069. pointerCursor: boolean;
  1070. /**
  1071. * Whether the underline is visible
  1072. */
  1073. underline: boolean;
  1074. }
  1075. /**
  1076. * A range within a buffer.
  1077. */
  1078. interface IBufferRange {
  1079. /**
  1080. * The start position of the range.
  1081. */
  1082. start: IBufferCellPosition;
  1083. /**
  1084. * The end position of the range.
  1085. */
  1086. end: IBufferCellPosition;
  1087. }
  1088. /**
  1089. * A position within a buffer.
  1090. */
  1091. interface IBufferCellPosition {
  1092. /**
  1093. * The x position within the buffer.
  1094. */
  1095. x: number;
  1096. /**
  1097. * The y position within the buffer.
  1098. */
  1099. y: number;
  1100. }
  1101. /**
  1102. * Represents a terminal buffer.
  1103. */
  1104. interface IBuffer {
  1105. /**
  1106. * The type of the buffer.
  1107. */
  1108. readonly type: 'normal' | 'alternate';
  1109. /**
  1110. * The y position of the cursor. This ranges between `0` (when the
  1111. * cursor is at baseY) and `Terminal.rows - 1` (when the cursor is on the
  1112. * last row).
  1113. */
  1114. readonly cursorY: number;
  1115. /**
  1116. * The x position of the cursor. This ranges between `0` (left side) and
  1117. * `Terminal.cols` (after last cell of the row).
  1118. */
  1119. readonly cursorX: number;
  1120. /**
  1121. * The line within the buffer where the top of the viewport is.
  1122. */
  1123. readonly viewportY: number;
  1124. /**
  1125. * The line within the buffer where the top of the bottom page is (when
  1126. * fully scrolled down).
  1127. */
  1128. readonly baseY: number;
  1129. /**
  1130. * The amount of lines in the buffer.
  1131. */
  1132. readonly length: number;
  1133. /**
  1134. * Gets a line from the buffer, or undefined if the line index does not
  1135. * exist.
  1136. *
  1137. * Note that the result of this function should be used immediately after
  1138. * calling as when the terminal updates it could lead to unexpected
  1139. * behavior.
  1140. *
  1141. * @param y The line index to get.
  1142. */
  1143. getLine(y: number): IBufferLine | undefined;
  1144. /**
  1145. * Creates an empty cell object suitable as a cell reference in
  1146. * `line.getCell(x, cell)`. Use this to avoid costly recreation of
  1147. * cell objects when dealing with tons of cells.
  1148. */
  1149. getNullCell(): IBufferCell;
  1150. }
  1151. /**
  1152. * Represents the terminal's set of buffers.
  1153. */
  1154. interface IBufferNamespace {
  1155. /**
  1156. * The active buffer, this will either be the normal or alternate buffers.
  1157. */
  1158. readonly active: IBuffer;
  1159. /**
  1160. * The normal buffer.
  1161. */
  1162. readonly normal: IBuffer;
  1163. /**
  1164. * The alternate buffer, this becomes the active buffer when an application
  1165. * enters this mode via DECSET (`CSI ? 4 7 h`)
  1166. */
  1167. readonly alternate: IBuffer;
  1168. /**
  1169. * Adds an event listener for when the active buffer changes.
  1170. * @returns an `IDisposable` to stop listening.
  1171. */
  1172. onBufferChange: IEvent<IBuffer>;
  1173. }
  1174. /**
  1175. * Represents a line in the terminal's buffer.
  1176. */
  1177. interface IBufferLine {
  1178. /**
  1179. * Whether the line is wrapped from the previous line.
  1180. */
  1181. readonly isWrapped: boolean;
  1182. /**
  1183. * The length of the line, all call to getCell beyond the length will result
  1184. * in `undefined`.
  1185. */
  1186. readonly length: number;
  1187. /**
  1188. * Gets a cell from the line, or undefined if the line index does not exist.
  1189. *
  1190. * Note that the result of this function should be used immediately after
  1191. * calling as when the terminal updates it could lead to unexpected
  1192. * behavior.
  1193. *
  1194. * @param x The character index to get.
  1195. * @param cell Optional cell object to load data into for performance
  1196. * reasons. This is mainly useful when every cell in the buffer is being
  1197. * looped over to avoid creating new objects for every cell.
  1198. */
  1199. getCell(x: number, cell?: IBufferCell): IBufferCell | undefined;
  1200. /**
  1201. * Gets the line as a string. Note that this is gets only the string for the
  1202. * line, not taking isWrapped into account.
  1203. *
  1204. * @param trimRight Whether to trim any whitespace at the right of the line.
  1205. * @param startColumn The column to start from (inclusive).
  1206. * @param endColumn The column to end at (exclusive).
  1207. */
  1208. translateToString(trimRight?: boolean, startColumn?: number, endColumn?: number): string;
  1209. }
  1210. /**
  1211. * Represents a single cell in the terminal's buffer.
  1212. */
  1213. interface IBufferCell {
  1214. /**
  1215. * The width of the character. Some examples:
  1216. *
  1217. * - `1` for most cells.
  1218. * - `2` for wide character like CJK glyphs.
  1219. * - `0` for cells immediately following cells with a width of `2`.
  1220. */
  1221. getWidth(): number;
  1222. /**
  1223. * The character(s) within the cell. Examples of what this can contain:
  1224. *
  1225. * - A normal width character
  1226. * - A wide character (eg. CJK)
  1227. * - An emoji
  1228. */
  1229. getChars(): string;
  1230. /**
  1231. * Gets the UTF32 codepoint of single characters, if content is a combined
  1232. * string it returns the codepoint of the last character in the string.
  1233. */
  1234. getCode(): number;
  1235. /**
  1236. * Gets the number representation of the foreground color mode, this can be
  1237. * used to perform quick comparisons of 2 cells to see if they're the same.
  1238. * Use `isFgRGB`, `isFgPalette` and `isFgDefault` to check what color mode
  1239. * a cell is.
  1240. */
  1241. getFgColorMode(): number;
  1242. /**
  1243. * Gets the number representation of the background color mode, this can be
  1244. * used to perform quick comparisons of 2 cells to see if they're the same.
  1245. * Use `isBgRGB`, `isBgPalette` and `isBgDefault` to check what color mode
  1246. * a cell is.
  1247. */
  1248. getBgColorMode(): number;
  1249. /**
  1250. * Gets a cell's foreground color number, this differs depending on what the
  1251. * color mode of the cell is:
  1252. *
  1253. * - Default: This should be 0, representing the default foreground color
  1254. * (CSI 39 m).
  1255. * - Palette: This is a number from 0 to 255 of ANSI colors (CSI 3(0-7) m,
  1256. * CSI 9(0-7) m, CSI 38 ; 5 ; 0-255 m).
  1257. * - RGB: A hex value representing a 'true color': 0xRRGGBB.
  1258. * (CSI 3 8 ; 2 ; Pi ; Pr ; Pg ; Pb)
  1259. */
  1260. getFgColor(): number;
  1261. /**
  1262. * Gets a cell's background color number, this differs depending on what the
  1263. * color mode of the cell is:
  1264. *
  1265. * - Default: This should be 0, representing the default background color
  1266. * (CSI 49 m).
  1267. * - Palette: This is a number from 0 to 255 of ANSI colors
  1268. * (CSI 4(0-7) m, CSI 10(0-7) m, CSI 48 ; 5 ; 0-255 m).
  1269. * - RGB: A hex value representing a 'true color': 0xRRGGBB
  1270. * (CSI 4 8 ; 2 ; Pi ; Pr ; Pg ; Pb)
  1271. */
  1272. getBgColor(): number;
  1273. /** Whether the cell has the bold attribute (CSI 1 m). */
  1274. isBold(): number;
  1275. /** Whether the cell has the inverse attribute (CSI 3 m). */
  1276. isItalic(): number;
  1277. /** Whether the cell has the inverse attribute (CSI 2 m). */
  1278. isDim(): number;
  1279. /** Whether the cell has the underline attribute (CSI 4 m). */
  1280. isUnderline(): number;
  1281. /** Whether the cell has the inverse attribute (CSI 5 m). */
  1282. isBlink(): number;
  1283. /** Whether the cell has the inverse attribute (CSI 7 m). */
  1284. isInverse(): number;
  1285. /** Whether the cell has the inverse attribute (CSI 8 m). */
  1286. isInvisible(): number;
  1287. /** Whether the cell is using the RGB foreground color mode. */
  1288. isFgRGB(): boolean;
  1289. /** Whether the cell is using the RGB background color mode. */
  1290. isBgRGB(): boolean;
  1291. /** Whether the cell is using the palette foreground color mode. */
  1292. isFgPalette(): boolean;
  1293. /** Whether the cell is using the palette background color mode. */
  1294. isBgPalette(): boolean;
  1295. /** Whether the cell is using the default foreground color mode. */
  1296. isFgDefault(): boolean;
  1297. /** Whether the cell is using the default background color mode. */
  1298. isBgDefault(): boolean;
  1299. /** Whether the cell has the default attribute (no color or style). */
  1300. isAttributeDefault(): boolean;
  1301. }
  1302. /**
  1303. * Data type to register a CSI, DCS or ESC callback in the parser
  1304. * in the form:
  1305. * ESC I..I F
  1306. * CSI Prefix P..P I..I F
  1307. * DCS Prefix P..P I..I F data_bytes ST
  1308. *
  1309. * with these rules/restrictions:
  1310. * - prefix can only be used with CSI and DCS
  1311. * - only one leading prefix byte is recognized by the parser
  1312. * before any other parameter bytes (P..P)
  1313. * - intermediate bytes are recognized up to 2
  1314. *
  1315. * For custom sequences make sure to read ECMA-48 and the resources at
  1316. * vt100.net to not clash with existing sequences or reserved address space.
  1317. * General recommendations:
  1318. * - use private address space (see ECMA-48)
  1319. * - use max one intermediate byte (technically not limited by the spec,
  1320. * in practice there are no sequences with more than one intermediate byte,
  1321. * thus parsers might get confused with more intermediates)
  1322. * - test against other common emulators to check whether they escape/ignore
  1323. * the sequence correctly
  1324. *
  1325. * Notes: OSC command registration is handled differently (see addOscHandler)
  1326. * APC, PM or SOS is currently not supported.
  1327. */
  1328. export interface IFunctionIdentifier {
  1329. /**
  1330. * Optional prefix byte, must be in range \x3c .. \x3f.
  1331. * Usable in CSI and DCS.
  1332. */
  1333. prefix?: string;
  1334. /**
  1335. * Optional intermediate bytes, must be in range \x20 .. \x2f.
  1336. * Usable in CSI, DCS and ESC.
  1337. */
  1338. intermediates?: string;
  1339. /**
  1340. * Final byte, must be in range \x40 .. \x7e for CSI and DCS,
  1341. * \x30 .. \x7e for ESC.
  1342. */
  1343. final: string;
  1344. }
  1345. /**
  1346. * Allows hooking into the parser for custom handling of escape sequences.
  1347. *
  1348. * Note on sync vs. async handlers:
  1349. * xterm.js implements all parser actions with synchronous handlers.
  1350. * In general custom handlers should also operate in sync mode wherever
  1351. * possible to keep the parser fast.
  1352. * Still the exposed interfaces allow to register async handlers by returning
  1353. * a `Promise<boolean>`. Here the parser will pause input processing until
  1354. * the promise got resolved or rejected (in-band blocking). This "full stop"
  1355. * on the input chain allows to implement backpressure from a certain async
  1356. * action while the terminal state will not progress any further from input.
  1357. * It does not mean that the terminal state will not change at all in between,
  1358. * as user actions like resize or reset are still processed immediately.
  1359. * It is an error to assume a stable terminal state while giving back control
  1360. * in between, e.g. by multiple chained `then` calls.
  1361. * Downside of an async handler is a rather bad throughput performance,
  1362. * thus use async handlers only as a last resort or for actions that have
  1363. * to rely on async interfaces itself.
  1364. */
  1365. export interface IParser {
  1366. /**
  1367. * Adds a handler for CSI escape sequences.
  1368. * @param id Specifies the function identifier under which the callback
  1369. * gets registered, e.g. {final: 'm'} for SGR.
  1370. * @param callback The function to handle the sequence. The callback is
  1371. * called with the numerical params. If the sequence has subparams the
  1372. * array will contain subarrays with their numercial values.
  1373. * Return `true` if the sequence was handled, `false` if the parser should try
  1374. * a previous handler. The most recently added handler is tried first.
  1375. * @return An IDisposable you can call to remove this handler.
  1376. */
  1377. registerCsiHandler(id: IFunctionIdentifier, callback: (params: (number | number[])[]) => boolean | Promise<boolean>): IDisposable;
  1378. /**
  1379. * Adds a handler for DCS escape sequences.
  1380. * @param id Specifies the function identifier under which the callback
  1381. * gets registered, e.g. {intermediates: '$' final: 'q'} for DECRQSS.
  1382. * @param callback The function to handle the sequence. Note that the
  1383. * function will only be called once if the sequence finished sucessfully.
  1384. * There is currently no way to intercept smaller data chunks, data chunks
  1385. * will be stored up until the sequence is finished. Since DCS sequences
  1386. * are not limited by the amount of data this might impose a problem for
  1387. * big payloads. Currently xterm.js limits DCS payload to 10 MB
  1388. * which should give enough room for most use cases.
  1389. * The function gets the payload and numerical parameters as arguments.
  1390. * Return `true` if the sequence was handled, `false` if the parser should try
  1391. * a previous handler. The most recently added handler is tried first.
  1392. * @return An IDisposable you can call to remove this handler.
  1393. */
  1394. registerDcsHandler(id: IFunctionIdentifier, callback: (data: string, param: (number | number[])[]) => boolean | Promise<boolean>): IDisposable;
  1395. /**
  1396. * Adds a handler for ESC escape sequences.
  1397. * @param id Specifies the function identifier under which the callback
  1398. * gets registered, e.g. {intermediates: '%' final: 'G'} for
  1399. * default charset selection.
  1400. * @param callback The function to handle the sequence.
  1401. * Return `true` if the sequence was handled, `false` if the parser should try
  1402. * a previous handler. The most recently added handler is tried first.
  1403. * @return An IDisposable you can call to remove this handler.
  1404. */
  1405. registerEscHandler(id: IFunctionIdentifier, handler: () => boolean | Promise<boolean>): IDisposable;
  1406. /**
  1407. * Adds a handler for OSC escape sequences.
  1408. * @param ident The number (first parameter) of the sequence.
  1409. * @param callback The function to handle the sequence. Note that the
  1410. * function will only be called once if the sequence finished sucessfully.
  1411. * There is currently no way to intercept smaller data chunks, data chunks
  1412. * will be stored up until the sequence is finished. Since OSC sequences
  1413. * are not limited by the amount of data this might impose a problem for
  1414. * big payloads. Currently xterm.js limits OSC payload to 10 MB
  1415. * which should give enough room for most use cases.
  1416. * The callback is called with OSC data string.
  1417. * Return `true` if the sequence was handled, `false` if the parser should try
  1418. * a previous handler. The most recently added handler is tried first.
  1419. * @return An IDisposable you can call to remove this handler.
  1420. */
  1421. registerOscHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable;
  1422. }
  1423. /**
  1424. * (EXPERIMENTAL) Unicode version provider.
  1425. * Used to register custom Unicode versions with `Terminal.unicode.register`.
  1426. */
  1427. export interface IUnicodeVersionProvider {
  1428. /**
  1429. * String indicating the Unicode version provided.
  1430. */
  1431. readonly version: string;
  1432. /**
  1433. * Unicode version dependent wcwidth implementation.
  1434. */
  1435. wcwidth(codepoint: number): 0 | 1 | 2;
  1436. }
  1437. /**
  1438. * (EXPERIMENTAL) Unicode handling interface.
  1439. */
  1440. export interface IUnicodeHandling {
  1441. /**
  1442. * Register a custom Unicode version provider.
  1443. */
  1444. register(provider: IUnicodeVersionProvider): void;
  1445. /**
  1446. * Registered Unicode versions.
  1447. */
  1448. readonly versions: ReadonlyArray<string>;
  1449. /**
  1450. * Getter/setter for active Unicode version.
  1451. */
  1452. activeVersion: string;
  1453. }
  1454. }