@@ -16,7 +16,7 @@ if ('WebAssembly' in window) {
1616 ImageAddon = imageAddon . ImageAddon ;
1717}
1818
19- import { Terminal , ITerminalOptions , type IDisposable } from '@xterm/xterm' ;
19+ import { Terminal , ITerminalOptions , type IDisposable , type ITheme } from '@xterm/xterm' ;
2020import { AttachAddon } from '@xterm/addon-attach' ;
2121import { ClipboardAddon } from '@xterm/addon-clipboard' ;
2222import { FitAddon } from '@xterm/addon-fit' ;
@@ -131,7 +131,7 @@ const xtermjsTheme = {
131131 brightCyan : '#72F0FF' ,
132132 white : '#F8F8F8' ,
133133 brightWhite : '#FFFFFF'
134- } ;
134+ } satisfies ITheme ;
135135function setPadding ( ) : void {
136136 term . element . style . padding = parseInt ( paddingElement . value , 10 ) . toString ( ) + 'px' ;
137137 addons . fit . instance . fit ( ) ;
@@ -366,14 +366,19 @@ function createTerminal(): void {
366366 // Set terminal size again to set the specific dimensions on the demo
367367 updateTerminalSize ( ) ;
368368
369- const res = await fetch ( '/terminals?cols=' + term . cols + '&rows=' + term . rows , { method : 'POST' } ) ;
370- const processId = await res . text ( ) ;
371- pid = processId ;
372- socketURL += processId ;
373- socket = new WebSocket ( socketURL ) ;
374- socket . onopen = runRealTerminal ;
375- socket . onclose = runFakeTerminal ;
376- socket . onerror = runFakeTerminal ;
369+ const useRealTerminal = document . getElementById ( 'use-real-terminal' ) ;
370+ if ( useRealTerminal instanceof HTMLInputElement && ! useRealTerminal . checked ) {
371+ runFakeTerminal ( ) ;
372+ } else {
373+ const res = await fetch ( '/terminals?cols=' + term . cols + '&rows=' + term . rows , { method : 'POST' } ) ;
374+ const processId = await res . text ( ) ;
375+ pid = processId ;
376+ socketURL += processId ;
377+ socket = new WebSocket ( socketURL ) ;
378+ socket . onopen = runRealTerminal ;
379+ socket . onclose = runFakeTerminal ;
380+ socket . onerror = runFakeTerminal ;
381+ }
377382 } , 0 ) ;
378383}
379384
@@ -1261,9 +1266,9 @@ function addVtButtons(): void {
12611266
12621267 const element = document . createElement ( 'button' ) ;
12631268 element . textContent = name ;
1264- writeCsi . split ( '' ) ;
1265- const prefix = writeCsi . length === 2 ? writeCsi [ 0 ] : '' ;
1266- const suffix = writeCsi [ writeCsi . length - 1 ] ;
1269+ const writeCsiSplit = writeCsi . split ( '| ' ) ;
1270+ const prefix = writeCsiSplit . length === 2 ? writeCsiSplit [ 0 ] : '' ;
1271+ const suffix = writeCsiSplit [ writeCsiSplit . length - 1 ] ;
12671272 element . addEventListener ( `click` , ( ) => term . write ( csi ( `${ prefix } ${ inputs . map ( e => e . value ) . join ( ';' ) } ${ suffix } ` ) ) ) ;
12681273
12691274 const desc = document . createElement ( 'span' ) ;
@@ -1276,22 +1281,23 @@ function addVtButtons(): void {
12761281 }
12771282 const vtFragment = document . createDocumentFragment ( ) ;
12781283 const buttonSpecs : { [ key : string ] : { label : string , description : string , paramCount ?: number } } = {
1279- A : { label : 'CUU ↑' , description : 'Cursor Up Ps Times' } ,
1280- B : { label : 'CUD ↓' , description : 'Cursor Down Ps Times' } ,
1281- C : { label : 'CUF →' , description : 'Cursor Forward Ps Times' } ,
1282- D : { label : 'CUB ←' , description : 'Cursor Backward Ps Times' } ,
1283- E : { label : 'CNL' , description : 'Cursor Next Line Ps Times' } ,
1284- F : { label : 'CPL' , description : 'Cursor Preceding Line Ps Times' } ,
1285- G : { label : 'CHA' , description : 'Cursor Character Absolute' } ,
1286- H : { label : 'CUP' , description : 'Cursor Position [row;column]' , paramCount : 2 } ,
1287- I : { label : 'CHT' , description : 'Cursor Forward Tabulation Ps tab stops' } ,
1288- J : { label : 'ED' , description : 'Erase in Display' } ,
1289- '?J' : { label : 'DECSED' , description : 'Erase in Display' } ,
1290- K : { label : 'EL' , description : 'Erase in Line' } ,
1291- '?K' : { label : 'DECSEL' , description : 'Erase in Line' } ,
1292- L : { label : 'IL' , description : 'Insert Ps Line(s)' } ,
1293- M : { label : 'DL' , description : 'Delete Ps Line(s)' } ,
1294- P : { label : 'DCH' , description : 'Delete Ps Character(s)' }
1284+ A : { label : 'CUU ↑' , description : 'Cursor Up Ps Times' } ,
1285+ B : { label : 'CUD ↓' , description : 'Cursor Down Ps Times' } ,
1286+ C : { label : 'CUF →' , description : 'Cursor Forward Ps Times' } ,
1287+ D : { label : 'CUB ←' , description : 'Cursor Backward Ps Times' } ,
1288+ E : { label : 'CNL' , description : 'Cursor Next Line Ps Times' } ,
1289+ F : { label : 'CPL' , description : 'Cursor Preceding Line Ps Times' } ,
1290+ G : { label : 'CHA' , description : 'Cursor Character Absolute' } ,
1291+ H : { label : 'CUP' , description : 'Cursor Position [row;column]' , paramCount : 2 } ,
1292+ I : { label : 'CHT' , description : 'Cursor Forward Tabulation Ps tab stops' } ,
1293+ J : { label : 'ED' , description : 'Erase in Display' } ,
1294+ '?|J' : { label : 'DECSED' , description : 'Erase in Display' } ,
1295+ K : { label : 'EL' , description : 'Erase in Line' } ,
1296+ '?|K' : { label : 'DECSEL' , description : 'Erase in Line' } ,
1297+ L : { label : 'IL' , description : 'Insert Ps Line(s)' } ,
1298+ M : { label : 'DL' , description : 'Delete Ps Line(s)' } ,
1299+ P : { label : 'DCH' , description : 'Delete Ps Character(s)' } ,
1300+ ' q' : { label : 'DECSCUSR' , description : 'Set Cursor Style' , paramCount : 1 }
12951301 } ;
12961302 for ( const s of Object . keys ( buttonSpecs ) ) {
12971303 const spec = buttonSpecs [ s ] ;
0 commit comments