@@ -339,6 +339,14 @@ int iCode = 0;
339
339
case HAVE_FOREGROUND_256_FINISH:
340
340
case HAVE_BACKGROUND_256_START:
341
341
case HAVE_BACKGROUND_256_FINISH:
342
+ case HAVE_FOREGROUND_24B_FINISH:
343
+ case HAVE_FOREGROUND_24BR_FINISH:
344
+ case HAVE_FOREGROUND_24BG_FINISH:
345
+ case HAVE_FOREGROUND_24BB_FINISH:
346
+ case HAVE_BACKGROUND_24B_FINISH:
347
+ case HAVE_BACKGROUND_24BR_FINISH:
348
+ case HAVE_BACKGROUND_24BG_FINISH:
349
+ case HAVE_BACKGROUND_24BB_FINISH:
342
350
iCode *= 10 ;
343
351
iCode += c - ' 0' ;
344
352
break ;
@@ -347,8 +355,9 @@ int iCode = 0;
347
355
} // end of digits
348
356
break ; // end of digits
349
357
350
- // either 'm' or '; ' terminates the current number, eg. ESC [1;
358
+ // one of 'm', ';' or ': ' terminates the current number, eg. ESC [1;
351
359
case ' ;' :
360
+ case ' :' :
352
361
case ' m' :
353
362
354
363
// interpret the previous code in iCode
@@ -464,41 +473,110 @@ int iCode = 0;
464
473
break ; // end of DOING_CODE
465
474
466
475
467
- // we now have: ESC [ 38;5;nnn ;
476
+ // we now have: ESC [ 38;5; or ESC [ 38;2 ;
468
477
case HAVE_FOREGROUND_256_START:
469
- if (iCode == 5 ) // if it isn't 5 I don't know what the hell it is!
478
+ if (iCode == 5 ) // 8-bit colour
470
479
{
471
480
ansiState = HAVE_FOREGROUND_256_FINISH;
472
481
iCode = 0 ; // start collecting the colour number
473
482
}
474
- else
483
+ else if (iCode == 2 ) // 24-bit RGB
484
+ {
485
+ iCode = 0 ; // start collecting the red component
486
+ ansiState = HAVE_FOREGROUND_24B_FINISH;
487
+ }
488
+ else // if it isn't 2 or 5 I don't know what the hell it is!
489
+ {
490
+ iCode = 0 ; // possibly starting a new code
475
491
ansiState = DOING_CODE; // give up and look for another code
492
+ }
476
493
break ; // end of HAVE_FOREGROUND_256_START
477
494
478
495
case HAVE_FOREGROUND_256_FINISH:
479
496
rgbNormalForeGround = xterm_256_colours [iCode & 0xFF ];
480
- rgbBoldForeGround = xterm_256_colours [iCode & 0xFF ] ; // both the same
497
+ rgbBoldForeGround = rgbNormalForeGround ; // both the same
481
498
SetNoteColourFore (rgbNormalForeGround);
499
+ iCode = 0 ; // starting a new code
482
500
ansiState = DOING_CODE; // no longer collecting 256-colours
483
501
break ; // end of HAVE_FOREGROUND_256_FINISH
484
502
485
- // we now have: ESC [ 48;5;nnn;
503
+ // have the red component of a 24-bit colour
504
+ case HAVE_FOREGROUND_24B_FINISH:
505
+ rgbNormalForeGround = RGB (iCode & 0xFF , 0 , 0 );
506
+ rgbBoldForeGround = rgbNormalForeGround; // both the same
507
+ SetNoteColourFore (rgbNormalForeGround);
508
+ ansiState = HAVE_FOREGROUND_24BR_FINISH; // now looking for green
509
+ iCode = 0 ; // start collecting the green component
510
+ break ; // end of HAVE_FOREGROUND_24B_FINISH
511
+
512
+ // have the green component of a 24-bit colour
513
+ case HAVE_FOREGROUND_24BR_FINISH:
514
+ rgbNormalForeGround = RGB (GetRValue (rgbNormalForeGround), iCode & 0xFF , 0 );
515
+ rgbBoldForeGround = rgbNormalForeGround; // both the same
516
+ SetNoteColourFore (rgbNormalForeGround);
517
+ ansiState = HAVE_FOREGROUND_24BG_FINISH; // now looking for blue
518
+ iCode = 0 ; // start collecting the blue component
519
+ break ; // end of HAVE_FOREGROUND_24BR_FINISH
520
+
521
+ // have the blue component of a 24-bit colour
522
+ case HAVE_FOREGROUND_24BG_FINISH:
523
+ rgbNormalForeGround = RGB (GetRValue (rgbNormalForeGround), GetGValue (rgbNormalForeGround), iCode & 0xFF );
524
+ rgbBoldForeGround = rgbNormalForeGround; // both the same
525
+ SetNoteColourFore (rgbNormalForeGround);
526
+ ansiState = DOING_CODE; // no longer collecting 24-bit colours
527
+ iCode = 0 ; // starting a new code
528
+ break ; // end of HAVE_FOREGROUND_24BG_FINISH
529
+
530
+ // we now have: ESC [ 48;5; or ESC [ 48;2;
486
531
case HAVE_BACKGROUND_256_START:
487
- if (iCode == 5 ) // if it isn't 5 I don't know what the hell it is!
532
+ if (iCode == 5 ) // 8-bit colour
488
533
{
489
534
ansiState = HAVE_BACKGROUND_256_FINISH;
490
535
iCode = 0 ; // start collecting the colour number
491
536
}
492
- else
537
+ else if (iCode == 2 ) // 24-bit RGB
538
+ {
539
+ iCode = 0 ; // start collecting the red component
540
+ ansiState = HAVE_BACKGROUND_24B_FINISH;
541
+ }
542
+ else // if it isn't 2 or 5 I don't know what the hell it is!
543
+ {
544
+ iCode = 0 ; // starting a new code
493
545
ansiState = DOING_CODE; // give up and look for another code
546
+ }
494
547
break ; // end of HAVE_BACKGROUND_256_START
495
548
496
549
case HAVE_BACKGROUND_256_FINISH:
497
550
rgbNormalBackGround = xterm_256_colours [iCode & 0xFF ];
498
551
SetNoteColourBack (rgbNormalBackGround);
499
552
ansiState = DOING_CODE; // no longer collecting 256-colours
553
+ iCode = 0 ; // starting a new code
500
554
break ; // end of HAVE_FOREGROUND_256_FINISH
501
555
556
+ // have the red component of a 24-bit colour
557
+ case HAVE_BACKGROUND_24B_FINISH:
558
+ rgbNormalBackGround = RGB (iCode & 0xFF , 0 , 0 );
559
+ SetNoteColourBack (rgbNormalBackGround);
560
+ ansiState = HAVE_BACKGROUND_24BR_FINISH; // now looking for green
561
+ iCode = 0 ; // start collecting the green component
562
+ break ; // end of HAVE_BACKGROUND_24B_FINISH
563
+
564
+ // have the green component of a 24-bit colour
565
+ case HAVE_BACKGROUND_24BR_FINISH:
566
+ rgbNormalBackGround = RGB (GetRValue (rgbNormalBackGround), iCode & 0xFF , 0 );
567
+ SetNoteColourBack (rgbNormalBackGround);
568
+ ansiState = HAVE_BACKGROUND_24BG_FINISH; // now looking for blue
569
+ iCode = 0 ; // start collecting the blue component
570
+ break ; // end of HAVE_BACKGROUND_24BR_FINISH
571
+
572
+ // have the blue component of a 24-bit colour
573
+ case HAVE_BACKGROUND_24BG_FINISH:
574
+ rgbNormalBackGround = RGB (GetRValue (rgbNormalBackGround), GetGValue (rgbNormalBackGround), iCode & 0xFF );
575
+ SetNoteColourBack (rgbNormalBackGround);
576
+ ansiState = DOING_CODE; // no longer collecting 24-bit colours
577
+ iCode = 0 ; // starting a new code
578
+ break ; // end of HAVE_BACKGROUND_24BG_FINISH
579
+
502
580
default :
503
581
// just accumulate the text
504
582
break ;
0 commit comments