Skip to content

Commit c89d236

Browse files
committed
Added 24-bit colour to AnsiNote
1 parent f3b9168 commit c89d236

File tree

1 file changed

+86
-8
lines changed

1 file changed

+86
-8
lines changed

scripting/methods/methods_noting.cpp

Lines changed: 86 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,14 @@ int iCode = 0;
339339
case HAVE_FOREGROUND_256_FINISH:
340340
case HAVE_BACKGROUND_256_START:
341341
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:
342350
iCode *= 10;
343351
iCode += c - '0';
344352
break;
@@ -347,8 +355,9 @@ int iCode = 0;
347355
} // end of digits
348356
break; // end of digits
349357

350-
// either 'm' or ';' terminates the current number, eg. ESC [1;
358+
// one of 'm', ';' or ':' terminates the current number, eg. ESC [1;
351359
case ';':
360+
case ':':
352361
case 'm':
353362

354363
// interpret the previous code in iCode
@@ -464,41 +473,110 @@ int iCode = 0;
464473
break; // end of DOING_CODE
465474

466475

467-
// we now have: ESC [ 38;5;nnn;
476+
// we now have: ESC [ 38;5; or ESC [ 38;2;
468477
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
470479
{
471480
ansiState = HAVE_FOREGROUND_256_FINISH;
472481
iCode = 0; // start collecting the colour number
473482
}
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
475491
ansiState = DOING_CODE; // give up and look for another code
492+
}
476493
break; // end of HAVE_FOREGROUND_256_START
477494

478495
case HAVE_FOREGROUND_256_FINISH:
479496
rgbNormalForeGround = xterm_256_colours [iCode & 0xFF];
480-
rgbBoldForeGround = xterm_256_colours [iCode & 0xFF]; // both the same
497+
rgbBoldForeGround = rgbNormalForeGround; // both the same
481498
SetNoteColourFore (rgbNormalForeGround);
499+
iCode = 0; // starting a new code
482500
ansiState = DOING_CODE; // no longer collecting 256-colours
483501
break; // end of HAVE_FOREGROUND_256_FINISH
484502

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;
486531
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
488533
{
489534
ansiState = HAVE_BACKGROUND_256_FINISH;
490535
iCode = 0; // start collecting the colour number
491536
}
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
493545
ansiState = DOING_CODE; // give up and look for another code
546+
}
494547
break; // end of HAVE_BACKGROUND_256_START
495548

496549
case HAVE_BACKGROUND_256_FINISH:
497550
rgbNormalBackGround = xterm_256_colours [iCode & 0xFF];
498551
SetNoteColourBack (rgbNormalBackGround);
499552
ansiState = DOING_CODE; // no longer collecting 256-colours
553+
iCode = 0; // starting a new code
500554
break; // end of HAVE_FOREGROUND_256_FINISH
501555

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+
502580
default:
503581
// just accumulate the text
504582
break;

0 commit comments

Comments
 (0)