@@ -1098,26 +1098,52 @@ function addVtButtons(): void {
10981098 return `\x1b[${ e } ` ;
10991099 }
11001100
1101- const vtCUU = ( ) : void => term . write ( csi ( 'A' ) ) ;
1102- const vtCUD = ( ) : void => term . write ( csi ( 'B' ) ) ;
1103- const vtCUF = ( ) : void => term . write ( csi ( 'C' ) ) ;
1104- const vtCUB = ( ) : void => term . write ( csi ( 'D' ) ) ;
1101+ function createButton ( name : string , description : string , writeCsi : string , paramCount : number = 1 ) : HTMLElement {
1102+ const inputs : HTMLInputElement [ ] = [ ] ;
1103+ for ( let i = 0 ; i < paramCount ; i ++ ) {
1104+ const input = document . createElement ( 'input' ) ;
1105+ input . type = 'number' ;
1106+ input . title = `Input #${ i + 1 } ` ;
1107+ inputs . push ( input ) ;
1108+ }
11051109
1106- function createButton ( name : string , writeCsi : string ) : HTMLElement {
11071110 const element = document . createElement ( 'button' ) ;
11081111 element . textContent = name ;
1109- element . addEventListener ( 'click' , ( ) => term . write ( csi ( writeCsi ) ) ) ;
1110- return element ;
1112+ writeCsi . split ( '' ) ;
1113+ const prefix = writeCsi . length === 2 ? writeCsi [ 0 ] : '' ;
1114+ const suffix = writeCsi [ writeCsi . length - 1 ] ;
1115+ element . addEventListener ( `click` , ( ) => term . write ( csi ( `${ prefix } ${ inputs . map ( e => e . value ) . join ( ';' ) } ${ suffix } ` ) ) ) ;
1116+
1117+ const desc = document . createElement ( 'span' ) ;
1118+ desc . textContent = description ;
1119+
1120+ const container = document . createElement ( 'div' ) ;
1121+ container . classList . add ( 'vt-button' ) ;
1122+ container . append ( element , ...inputs , desc ) ;
1123+ return container ;
11111124 }
11121125 const vtFragment = document . createDocumentFragment ( ) ;
1113- const buttonSpecs : { [ key : string ] : string } = {
1114- A : 'CUU ↑' ,
1115- B : 'CUD ↓' ,
1116- C : 'CUF →' ,
1117- D : 'CUB ←'
1126+ const buttonSpecs : { [ key : string ] : { label : string , description : string , paramCount ?: number } } = {
1127+ A : { label : 'CUU ↑' , description : 'Cursor Up Ps Times' } ,
1128+ B : { label : 'CUD ↓' , description : 'Cursor Down Ps Times' } ,
1129+ C : { label : 'CUF →' , description : 'Cursor Forward Ps Times' } ,
1130+ D : { label : 'CUB ←' , description : 'Cursor Backward Ps Times' } ,
1131+ E : { label : 'CNL' , description : 'Cursor Next Line Ps Times' } ,
1132+ F : { label : 'CPL' , description : 'Cursor Preceding Line Ps Times' } ,
1133+ G : { label : 'CHA' , description : 'Cursor Character Absolute' } ,
1134+ H : { label : 'CUP' , description : 'Cursor Position [row;column]' , paramCount : 2 } ,
1135+ I : { label : 'CHT' , description : 'Cursor Forward Tabulation Ps tab stops' } ,
1136+ J : { label : 'ED' , description : 'Erase in Display' } ,
1137+ '?J' : { label : 'DECSED' , description : 'Erase in Display' } ,
1138+ K : { label : 'EL' , description : 'Erase in Line' } ,
1139+ '?K' : { label : 'DECSEL' , description : 'Erase in Line' } ,
1140+ L : { label : 'IL' , description : 'Insert Ps Line(s)' } ,
1141+ M : { label : 'DL' , description : 'Delete Ps Line(s)' } ,
1142+ P : { label : 'DCH' , description : 'Delete Ps Character(s)' }
11181143 } ;
11191144 for ( const s of Object . keys ( buttonSpecs ) ) {
1120- vtFragment . appendChild ( createButton ( buttonSpecs [ s ] , s ) ) ;
1145+ const spec = buttonSpecs [ s ] ;
1146+ vtFragment . appendChild ( createButton ( spec . label , spec . description , s , spec . paramCount ) ) ;
11211147 }
11221148
11231149 document . querySelector ( '#vt-container' ) . appendChild ( vtFragment ) ;
0 commit comments