@@ -24,7 +24,7 @@ pub enum Csi {
24
24
Mouse ( MouseReport ) ,
25
25
Keyboard ( Keyboard ) ,
26
26
Device ( Device ) ,
27
- // TODO: Window(Box<Window>),
27
+ Window ( Box < Window > ) ,
28
28
}
29
29
30
30
impl Display for Csi {
@@ -39,6 +39,7 @@ impl Display for Csi {
39
39
Self :: Mouse ( report) => report. fmt ( f) ,
40
40
Self :: Keyboard ( keyboard) => keyboard. fmt ( f) ,
41
41
Self :: Device ( device) => device. fmt ( f) ,
42
+ Self :: Window ( window) => window. fmt ( f) ,
42
43
}
43
44
}
44
45
}
@@ -1220,6 +1221,133 @@ impl Display for Device {
1220
1221
}
1221
1222
}
1222
1223
1224
+ // Window
1225
+
1226
+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
1227
+ pub enum Window {
1228
+ DeIconify ,
1229
+ Iconify ,
1230
+ MoveWindow {
1231
+ x : i64 ,
1232
+ y : i64 ,
1233
+ } ,
1234
+ ResizeWindowPixels {
1235
+ width : Option < i64 > ,
1236
+ height : Option < i64 > ,
1237
+ } ,
1238
+ RaiseWindow ,
1239
+ LowerWindow ,
1240
+ RefreshWindow ,
1241
+ ResizeWindowCells {
1242
+ width : Option < i64 > ,
1243
+ height : Option < i64 > ,
1244
+ } ,
1245
+ RestoreMaximizedWindow ,
1246
+ MaximizeWindow ,
1247
+ MaximizeWindowVertically ,
1248
+ MaximizeWindowHorizontally ,
1249
+ UndoFullScreenMode ,
1250
+ ChangeToFullScreenMode ,
1251
+ ToggleFullScreen ,
1252
+ ReportWindowState ,
1253
+ ReportWindowPosition ,
1254
+ ReportTextAreaPosition ,
1255
+ ReportTextAreaSizePixels ,
1256
+ ReportWindowSizePixels ,
1257
+ ReportScreenSizePixels ,
1258
+ ReportCellSizePixels ,
1259
+ ReportCellSizePixelsResponse {
1260
+ width : Option < i64 > ,
1261
+ height : Option < i64 > ,
1262
+ } ,
1263
+ ReportTextAreaSizeCells ,
1264
+ ReportScreenSizeCells ,
1265
+ ReportIconLabel ,
1266
+ ReportWindowTitle ,
1267
+ PushIconAndWindowTitle ,
1268
+ PushIconTitle ,
1269
+ PushWindowTitle ,
1270
+ PopIconAndWindowTitle ,
1271
+ PopIconTitle ,
1272
+ PopWindowTitle ,
1273
+ /// DECRQCRA; used by esctest
1274
+ ChecksumRectangularArea {
1275
+ request_id : i64 ,
1276
+ page_number : i64 ,
1277
+ top : OneBased ,
1278
+ left : OneBased ,
1279
+ bottom : OneBased ,
1280
+ right : OneBased ,
1281
+ } ,
1282
+ }
1283
+
1284
+ impl Display for Window {
1285
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1286
+ struct NumstrOrEmpty ( Option < i64 > ) ;
1287
+ impl Display for NumstrOrEmpty {
1288
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1289
+ if let Some ( x) = self . 0 {
1290
+ write ! ( f, "{x}" ) ?
1291
+ }
1292
+ Ok ( ( ) )
1293
+ }
1294
+ }
1295
+
1296
+ match self {
1297
+ Window :: DeIconify => write ! ( f, "1t" ) ,
1298
+ Window :: Iconify => write ! ( f, "2t" ) ,
1299
+ Window :: MoveWindow { x, y } => write ! ( f, "3;{x};{y}t" ) ,
1300
+ Window :: ResizeWindowPixels { width, height } => {
1301
+ write ! ( f, "4;{};{}t" , NumstrOrEmpty ( * height) , NumstrOrEmpty ( * width) )
1302
+ }
1303
+ Window :: RaiseWindow => write ! ( f, "5t" ) ,
1304
+ Window :: LowerWindow => write ! ( f, "6t" ) ,
1305
+ Window :: RefreshWindow => write ! ( f, "7t" ) ,
1306
+ Window :: ResizeWindowCells { width, height } => {
1307
+ write ! ( f, "8;{};{}t" , NumstrOrEmpty ( * height) , NumstrOrEmpty ( * width) )
1308
+ }
1309
+ Window :: RestoreMaximizedWindow => write ! ( f, "9;0t" ) ,
1310
+ Window :: MaximizeWindow => write ! ( f, "9;1t" ) ,
1311
+ Window :: MaximizeWindowVertically => write ! ( f, "9;2t" ) ,
1312
+ Window :: MaximizeWindowHorizontally => write ! ( f, "9;3t" ) ,
1313
+ Window :: UndoFullScreenMode => write ! ( f, "10;0t" ) ,
1314
+ Window :: ChangeToFullScreenMode => write ! ( f, "10;1t" ) ,
1315
+ Window :: ToggleFullScreen => write ! ( f, "10;2t" ) ,
1316
+ Window :: ReportWindowState => write ! ( f, "11t" ) ,
1317
+ Window :: ReportWindowPosition => write ! ( f, "13t" ) ,
1318
+ Window :: ReportTextAreaPosition => write ! ( f, "13;2t" ) ,
1319
+ Window :: ReportTextAreaSizePixels => write ! ( f, "14t" ) ,
1320
+ Window :: ReportWindowSizePixels => write ! ( f, "14;2t" ) ,
1321
+ Window :: ReportScreenSizePixels => write ! ( f, "15t" ) ,
1322
+ Window :: ReportCellSizePixels => write ! ( f, "16t" ) ,
1323
+ Window :: ReportCellSizePixelsResponse { width, height } => {
1324
+ write ! ( f, "6;{};{}t" , NumstrOrEmpty ( * height) , NumstrOrEmpty ( * width) )
1325
+ }
1326
+ Window :: ReportTextAreaSizeCells => write ! ( f, "18t" ) ,
1327
+ Window :: ReportScreenSizeCells => write ! ( f, "19t" ) ,
1328
+ Window :: ReportIconLabel => write ! ( f, "20t" ) ,
1329
+ Window :: ReportWindowTitle => write ! ( f, "21t" ) ,
1330
+ Window :: PushIconAndWindowTitle => write ! ( f, "22;0t" ) ,
1331
+ Window :: PushIconTitle => write ! ( f, "22;1t" ) ,
1332
+ Window :: PushWindowTitle => write ! ( f, "22;2t" ) ,
1333
+ Window :: PopIconAndWindowTitle => write ! ( f, "23;0t" ) ,
1334
+ Window :: PopIconTitle => write ! ( f, "23;1t" ) ,
1335
+ Window :: PopWindowTitle => write ! ( f, "23;2t" ) ,
1336
+ Window :: ChecksumRectangularArea {
1337
+ request_id,
1338
+ page_number,
1339
+ top,
1340
+ left,
1341
+ bottom,
1342
+ right,
1343
+ } => write ! (
1344
+ f,
1345
+ "{request_id};{page_number};{top};{left};{bottom};{right}*y"
1346
+ ) ,
1347
+ }
1348
+ }
1349
+ }
1350
+
1223
1351
#[ cfg( test) ]
1224
1352
mod test {
1225
1353
use super :: * ;
@@ -1259,5 +1387,16 @@ mod test {
1259
1387
"\x1b [39m" ,
1260
1388
Csi :: Sgr ( Sgr :: Foreground ( ColorSpec :: Reset ) ) . to_string( ) ,
1261
1389
) ;
1390
+
1391
+ // Push current window title to the terminal's stack.
1392
+ assert_eq ! (
1393
+ "\x1b [22;0t" ,
1394
+ Csi :: Window ( Box :: new( Window :: PushIconAndWindowTitle ) ) . to_string( ) ,
1395
+ ) ;
1396
+ // ... and pop it.
1397
+ assert_eq ! (
1398
+ "\x1b [23;0t" ,
1399
+ Csi :: Window ( Box :: new( Window :: PopIconAndWindowTitle ) ) . to_string( ) ,
1400
+ ) ;
1262
1401
}
1263
1402
}
0 commit comments