@@ -362,12 +362,13 @@ static void Close_StdIO_Local(void)
362
362
if (c [0 ] == '\e' ) {
363
363
evt .type = EVT_CONTROL ;
364
364
// Escape sequences... is there really some system in it?!
365
+ // This may be helpful: https://stackoverflow.com/a/71659748
365
366
if (poll (& poller , 1 , 0 ) <= 0 ) {
366
367
// no any other char
367
368
evt .data = EVK_ESCAPE ;
368
369
goto throw_event ;
369
370
}
370
- read (Std_Inp , & c , 2 );
371
+ if ( 2 != read (Std_Inp , & c , 2 )) break ;
371
372
//printf(" %s ", c);
372
373
if (c [0 ] == '[' ) {
373
374
switch (c [1 ]){
@@ -379,9 +380,10 @@ static void Close_StdIO_Local(void)
379
380
case 'H' : evt .data = EVK_HOME ; goto throw_event ;
380
381
}
381
382
if (c [1 ] == '1' ) {
382
- read (Std_Inp , & c [2 ], 2 );
383
+ if ( 2 != read (Std_Inp , & c [2 ], 2 )) break ;
383
384
//printf("%s ", c);
384
- if (c [3 ] == '~' ) {
385
+ if (c [3 ] == '~' || c [3 ] == '^' ) {
386
+ if (c [3 ] == '^' ) SET_FLAG (evt .flags , EVF_CONTROL );
385
387
switch (c [2 ]){
386
388
case '1' : evt .data = EVK_F1 ; goto throw_event ; //== "\e[11~"
387
389
case '2' : evt .data = EVK_F2 ; goto throw_event ; //== "\e[12~"
@@ -395,20 +397,20 @@ static void Close_StdIO_Local(void)
395
397
}
396
398
else if (c [2 ] == ';' && c [3 ] == '2' ) {
397
399
SET_FLAG (evt .flags , EVF_SHIFT );
398
- read (Std_Inp , & c [4 ], 1 );
400
+ if ( 1 != read (Std_Inp , & c [4 ], 1 )) break ;
399
401
switch (c [4 ]){
400
402
case 'C' : evt .data = EVK_RIGHT ; goto throw_event ; //== "\e[1;2C"
401
403
case 'D' : evt .data = EVK_LEFT ; goto throw_event ; //== "\e[1;2D"
402
404
}
403
405
}
404
406
}
405
407
else if (c [1 ] == '2' ) {
406
- read (Std_Inp , & c [2 ], 1 );
408
+ if ( 1 != read (Std_Inp , & c [2 ], 1 )) break ;
407
409
//printf("%s ", c);
408
410
if (c [2 ] == '~' ) {
409
411
evt .data = EVK_INSERT ; goto throw_event ; //== "\e[2~"
410
412
}
411
- read (Std_Inp , & c [3 ], 1 );
413
+ if ( 1 != read (Std_Inp , & c [3 ], 1 )) break ;
412
414
//printf("%s ", c);
413
415
if (c [3 ] == '~' ) {
414
416
switch (c [2 ]){
@@ -425,8 +427,24 @@ static void Close_StdIO_Local(void)
425
427
case '9' : evt .data = EVK_F8 ; goto throw_event ;
426
428
}
427
429
}
430
+ if (c [3 ] == '^' ) {
431
+ SET_FLAG (evt .flags , EVF_CONTROL );
432
+ switch (c [2 ]){
433
+ case '0' : evt .data = EVK_F9 ; goto throw_event ; //== "\e[20^"
434
+ case '1' : evt .data = EVK_F10 ; goto throw_event ;
435
+ case '3' : evt .data = EVK_F11 ; goto throw_event ;
436
+ case '4' : evt .data = EVK_F12 ; goto throw_event ;
437
+ }
438
+ SET_FLAG (evt .flags , EVF_SHIFT );
439
+ switch (c [2 ]){
440
+ case '5' : evt .data = EVK_F5 ; goto throw_event ; //== "\e[25^"
441
+ case '6' : evt .data = EVK_F6 ; goto throw_event ;
442
+ case '8' : evt .data = EVK_F7 ; goto throw_event ;
443
+ case '9' : evt .data = EVK_F8 ; goto throw_event ;
444
+ }
445
+ }
428
446
else {
429
- read (Std_Inp , & c [4 ], 1 );
447
+ if ( 1 != read (Std_Inp , & c [4 ], 1 )) break ;
430
448
if (c [4 ] == '~' && c [2 ] == '0' ) {
431
449
switch (c [3 ]){
432
450
case '0' : evt .data = EVK_PASTE_START ; goto throw_event ; //== "\e[200~"
@@ -436,7 +454,7 @@ static void Close_StdIO_Local(void)
436
454
}
437
455
}
438
456
else if (c [1 ] > '2' && c [1 ] <= '8' ) {
439
- read (Std_Inp , & c [2 ], 1 );
457
+ if ( 1 != read (Std_Inp , & c [2 ], 1 )) break ;
440
458
//printf("%s ", c);
441
459
if (c [2 ] == '~' ) {
442
460
switch (c [1 ]){
@@ -449,7 +467,7 @@ static void Close_StdIO_Local(void)
449
467
}
450
468
}
451
469
else if (c [1 ] == '3' ) {
452
- read (Std_Inp , & c [3 ], 1 );
470
+ if ( 1 != read (Std_Inp , & c [3 ], 1 )) break ;
453
471
//printf("%s ", c);
454
472
if (c [3 ] == '~' ) {
455
473
SET_FLAG (evt .flags , EVF_SHIFT );
@@ -483,7 +501,7 @@ static void Close_StdIO_Local(void)
483
501
if ((c [0 ] & 0xE0 ) == 0xC0 ) len = 1 ; // `len` as a number of missing bytes!
484
502
else if ((c [0 ] & 0xF0 ) == 0xE0 ) len = 2 ;
485
503
else if ((c [0 ] & 0xF8 ) == 0xF0 ) len = 3 ;
486
- read (Std_Inp , & c [1 ], len );
504
+ if ( len != read (Std_Inp , & c [1 ], len )) break ;
487
505
evt .data = RL_Decode_UTF8_Char (c , & len );
488
506
}
489
507
throw_event :
0 commit comments