@@ -1018,8 +1018,7 @@ describe('attachCustomKeyEventHandler()', () => {
10181018 await term . open ( container ) ;
10191019
10201020 const handler = ( e : KeyboardEvent ) => false ;
1021- term . attachCustomKeyEventHandler ( handler ) ;
1022- expect ( ( ) => term . attachCustomKeyEventHandler ( undefined ) ) . not . toThrow ( ) ;
1021+ expect ( ( ) => term . attachCustomKeyEventHandler ( handler ) ) . not . toThrow ( ) ;
10231022 term . dispose ( ) ;
10241023 } ) ;
10251024 } ) ;
@@ -1179,3 +1178,130 @@ describe('Buffer Access API', () => {
11791178 expect ( term . wasmTerm ?. isRowWrapped ( 999 ) ) . toBe ( false ) ;
11801179 } ) ;
11811180} ) ;
1181+
1182+ describe ( 'Terminal Modes' , ( ) => {
1183+ test ( 'should detect bracketed paste mode' , async ( ) => {
1184+ if ( typeof document === 'undefined' ) return ;
1185+ const term = new Terminal ( { cols : 80 , rows : 24 } ) ;
1186+ const container = document . createElement ( 'div' ) ;
1187+ await term . open ( container ) ;
1188+
1189+ expect ( term . hasBracketedPaste ( ) ) . toBe ( false ) ;
1190+ term . write ( '\x1b[?2004h' ) ;
1191+ expect ( term . hasBracketedPaste ( ) ) . toBe ( true ) ;
1192+ term . write ( '\x1b[?2004l' ) ;
1193+ expect ( term . hasBracketedPaste ( ) ) . toBe ( false ) ;
1194+
1195+ term . dispose ( ) ;
1196+ } ) ;
1197+
1198+ test ( 'paste() should use bracketed paste when enabled' , async ( ) => {
1199+ if ( typeof document === 'undefined' ) return ;
1200+ const term = new Terminal ( { cols : 80 , rows : 24 } ) ;
1201+ const container = document . createElement ( 'div' ) ;
1202+ await term . open ( container ) ;
1203+
1204+ let receivedData = '' ;
1205+ term . onData ( ( data ) => {
1206+ receivedData = data ;
1207+ } ) ;
1208+
1209+ term . paste ( 'test' ) ;
1210+ expect ( receivedData ) . toBe ( 'test' ) ;
1211+
1212+ term . write ( '\x1b[?2004h' ) ;
1213+ term . paste ( 'test2' ) ;
1214+ expect ( receivedData ) . toBe ( '\x1b[200~test2\x1b[201~' ) ;
1215+
1216+ term . dispose ( ) ;
1217+ } ) ;
1218+
1219+ test ( 'should query arbitrary DEC modes' , async ( ) => {
1220+ if ( typeof document === 'undefined' ) return ;
1221+ const term = new Terminal ( { cols : 80 , rows : 24 } ) ;
1222+ const container = document . createElement ( 'div' ) ;
1223+ await term . open ( container ) ;
1224+
1225+ expect ( term . getMode ( 25 ) ) . toBe ( true ) ; // Cursor visible
1226+ term . write ( '\x1b[?25l' ) ;
1227+ expect ( term . getMode ( 25 ) ) . toBe ( false ) ;
1228+
1229+ term . dispose ( ) ;
1230+ } ) ;
1231+
1232+ test ( 'should detect focus event mode' , async ( ) => {
1233+ if ( typeof document === 'undefined' ) return ;
1234+ const term = new Terminal ( { cols : 80 , rows : 24 } ) ;
1235+ const container = document . createElement ( 'div' ) ;
1236+ await term . open ( container ) ;
1237+
1238+ expect ( term . hasFocusEvents ( ) ) . toBe ( false ) ;
1239+ term . write ( '\x1b[?1004h' ) ;
1240+ expect ( term . hasFocusEvents ( ) ) . toBe ( true ) ;
1241+
1242+ term . dispose ( ) ;
1243+ } ) ;
1244+
1245+ test ( 'should detect mouse tracking modes' , async ( ) => {
1246+ if ( typeof document === 'undefined' ) return ;
1247+ const term = new Terminal ( { cols : 80 , rows : 24 } ) ;
1248+ const container = document . createElement ( 'div' ) ;
1249+ await term . open ( container ) ;
1250+
1251+ expect ( term . hasMouseTracking ( ) ) . toBe ( false ) ;
1252+ term . write ( '\x1b[?1000h' ) ;
1253+ expect ( term . hasMouseTracking ( ) ) . toBe ( true ) ;
1254+
1255+ term . dispose ( ) ;
1256+ } ) ;
1257+
1258+ test ( 'should query ANSI modes vs DEC modes' , async ( ) => {
1259+ if ( typeof document === 'undefined' ) return ;
1260+ const term = new Terminal ( { cols : 80 , rows : 24 } ) ;
1261+ const container = document . createElement ( 'div' ) ;
1262+ await term . open ( container ) ;
1263+
1264+ expect ( term . getMode ( 4 , true ) ) . toBe ( false ) ; // Insert mode
1265+ term . write ( '\x1b[4h' ) ;
1266+ expect ( term . getMode ( 4 , true ) ) . toBe ( true ) ;
1267+
1268+ term . dispose ( ) ;
1269+ } ) ;
1270+
1271+ test ( 'should handle multiple modes set simultaneously' , async ( ) => {
1272+ if ( typeof document === 'undefined' ) return ;
1273+ const term = new Terminal ( { cols : 80 , rows : 24 } ) ;
1274+ const container = document . createElement ( 'div' ) ;
1275+ await term . open ( container ) ;
1276+
1277+ term . write ( '\x1b[?2004h\x1b[?1004h\x1b[?1000h' ) ;
1278+ expect ( term . hasBracketedPaste ( ) ) . toBe ( true ) ;
1279+ expect ( term . hasFocusEvents ( ) ) . toBe ( true ) ;
1280+ expect ( term . hasMouseTracking ( ) ) . toBe ( true ) ;
1281+
1282+ term . dispose ( ) ;
1283+ } ) ;
1284+
1285+ test ( 'getMode() throws when terminal not open' , ( ) => {
1286+ const term = new Terminal ( { cols : 80 , rows : 24 } ) ;
1287+ expect ( ( ) => term . getMode ( 25 ) ) . toThrow ( ) ;
1288+ } ) ;
1289+
1290+ test ( 'hasBracketedPaste() throws when terminal not open' , ( ) => {
1291+ const term = new Terminal ( { cols : 80 , rows : 24 } ) ;
1292+ expect ( ( ) => term . hasBracketedPaste ( ) ) . toThrow ( ) ;
1293+ } ) ;
1294+
1295+ test ( 'alternate screen mode via getMode()' , async ( ) => {
1296+ if ( typeof document === 'undefined' ) return ;
1297+ const term = new Terminal ( { cols : 80 , rows : 24 } ) ;
1298+ const container = document . createElement ( 'div' ) ;
1299+ await term . open ( container ) ;
1300+
1301+ expect ( term . getMode ( 1049 ) ) . toBe ( false ) ;
1302+ term . write ( '\x1b[?1049h' ) ;
1303+ expect ( term . getMode ( 1049 ) ) . toBe ( true ) ;
1304+
1305+ term . dispose ( ) ;
1306+ } ) ;
1307+ } ) ;
0 commit comments