diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/color.c | 307 | ||||
-rw-r--r-- | src/ui/color.h | 4 | ||||
-rw-r--r-- | src/ui/text.c | 7 |
3 files changed, 282 insertions, 36 deletions
diff --git a/src/ui/color.c b/src/ui/color.c index 2cf7ebbd..332ef696 100644 --- a/src/ui/color.c +++ b/src/ui/color.c | |||
@@ -425,7 +425,269 @@ iHSLColor addSatLum_HSLColor(iHSLColor d, float sat, float lum) { | |||
425 | return d; | 425 | return d; |
426 | } | 426 | } |
427 | 427 | ||
428 | iColor ansi_Color(iRangecc escapeSequence, int fallback) { | 428 | static const iColor ansi8BitColors_[256] = { |
429 | { 0, 0, 0, 255 }, | ||
430 | { 170, 0, 0, 255 }, | ||
431 | { 0, 170, 0, 255 }, | ||
432 | { 170, 85, 0, 255 }, | ||
433 | { 0, 0, 170, 255 }, | ||
434 | { 170, 0, 170, 255 }, | ||
435 | { 0, 170, 170, 255 }, | ||
436 | { 170, 170, 170, 255 }, | ||
437 | |||
438 | { 85, 85, 85, 255 }, | ||
439 | { 255, 85, 85, 255 }, | ||
440 | { 85, 255, 85, 255 }, | ||
441 | { 255, 255, 85, 255 }, | ||
442 | { 85, 85, 255, 255 }, | ||
443 | { 255, 85, 255, 255 }, | ||
444 | { 85, 255, 255, 255 }, | ||
445 | { 255, 255, 255, 255 }, | ||
446 | |||
447 | { 0, 0, 0, 255 }, | ||
448 | { 0, 0, 95, 255 }, | ||
449 | { 0, 0, 135, 255 }, | ||
450 | { 0, 0, 175, 255 }, | ||
451 | { 0, 0, 215, 255 }, | ||
452 | { 0, 0, 255, 255 }, | ||
453 | { 0, 95, 0, 255 }, | ||
454 | { 0, 95, 95, 255 }, | ||
455 | { 0, 95, 135, 255 }, | ||
456 | { 0, 95, 175, 255 }, | ||
457 | { 0, 95, 215, 255 }, | ||
458 | { 0, 95, 255, 255 }, | ||
459 | { 0, 135, 0, 255 }, | ||
460 | { 0, 135, 95, 255 }, | ||
461 | { 0, 135, 135, 255 }, | ||
462 | { 0, 135, 175, 255 }, | ||
463 | { 0, 135, 215, 255 }, | ||
464 | { 0, 135, 255, 255 }, | ||
465 | { 0, 175, 0, 255 }, | ||
466 | { 0, 175, 95, 255 }, | ||
467 | { 0, 175, 135, 255 }, | ||
468 | { 0, 175, 175, 255 }, | ||
469 | { 0, 175, 215, 255 }, | ||
470 | { 0, 175, 255, 255 }, | ||
471 | { 0, 215, 0, 255 }, | ||
472 | { 0, 215, 95, 255 }, | ||
473 | { 0, 215, 135, 255 }, | ||
474 | { 0, 215, 175, 255 }, | ||
475 | { 0, 215, 215, 255 }, | ||
476 | { 0, 215, 255, 255 }, | ||
477 | { 0, 255, 0, 255 }, | ||
478 | { 0, 255, 95, 255 }, | ||
479 | { 0, 255, 135, 255 }, | ||
480 | { 0, 255, 175, 255 }, | ||
481 | { 0, 255, 215, 255 }, | ||
482 | { 0, 255, 255, 255 }, | ||
483 | { 95, 0, 0, 255 }, | ||
484 | { 95, 0, 95, 255 }, | ||
485 | { 95, 0, 135, 255 }, | ||
486 | { 95, 0, 175, 255 }, | ||
487 | { 95, 0, 215, 255 }, | ||
488 | { 95, 0, 255, 255 }, | ||
489 | { 95, 95, 0, 255 }, | ||
490 | { 95, 95, 95, 255 }, | ||
491 | { 95, 95, 135, 255 }, | ||
492 | { 95, 95, 175, 255 }, | ||
493 | { 95, 95, 215, 255 }, | ||
494 | { 95, 95, 255, 255 }, | ||
495 | { 95, 135, 0, 255 }, | ||
496 | { 95, 135, 95, 255 }, | ||
497 | { 95, 135, 135, 255 }, | ||
498 | { 95, 135, 175, 255 }, | ||
499 | { 95, 135, 215, 255 }, | ||
500 | { 95, 135, 255, 255 }, | ||
501 | { 95, 175, 0, 255 }, | ||
502 | { 95, 175, 95, 255 }, | ||
503 | { 95, 175, 135, 255 }, | ||
504 | { 95, 175, 175, 255 }, | ||
505 | { 95, 175, 215, 255 }, | ||
506 | { 95, 175, 255, 255 }, | ||
507 | { 95, 215, 0, 255 }, | ||
508 | { 95, 215, 95, 255 }, | ||
509 | { 95, 215, 135, 255 }, | ||
510 | { 95, 215, 175, 255 }, | ||
511 | { 95, 215, 215, 255 }, | ||
512 | { 95, 215, 255, 255 }, | ||
513 | { 95, 255, 0, 255 }, | ||
514 | { 95, 255, 95, 255 }, | ||
515 | { 95, 255, 135, 255 }, | ||
516 | { 95, 255, 175, 255 }, | ||
517 | { 95, 255, 215, 255 }, | ||
518 | { 95, 255, 255, 255 }, | ||
519 | { 135, 0, 0, 255 }, | ||
520 | { 135, 0, 95, 255 }, | ||
521 | { 135, 0, 135, 255 }, | ||
522 | { 135, 0, 175, 255 }, | ||
523 | { 135, 0, 215, 255 }, | ||
524 | { 135, 0, 255, 255 }, | ||
525 | { 135, 95, 0, 255 }, | ||
526 | { 135, 95, 95, 255 }, | ||
527 | { 135, 95, 135, 255 }, | ||
528 | { 135, 95, 175, 255 }, | ||
529 | { 135, 95, 215, 255 }, | ||
530 | { 135, 95, 255, 255 }, | ||
531 | { 135, 135, 0, 255 }, | ||
532 | { 135, 135, 95, 255 }, | ||
533 | { 135, 135, 135, 255 }, | ||
534 | { 135, 135, 175, 255 }, | ||
535 | { 135, 135, 215, 255 }, | ||
536 | { 135, 135, 255, 255 }, | ||
537 | { 135, 175, 0, 255 }, | ||
538 | { 135, 175, 95, 255 }, | ||
539 | { 135, 175, 135, 255 }, | ||
540 | { 135, 175, 175, 255 }, | ||
541 | { 135, 175, 215, 255 }, | ||
542 | { 135, 175, 255, 255 }, | ||
543 | { 135, 215, 0, 255 }, | ||
544 | { 135, 215, 95, 255 }, | ||
545 | { 135, 215, 135, 255 }, | ||
546 | { 135, 215, 175, 255 }, | ||
547 | { 135, 215, 215, 255 }, | ||
548 | { 135, 215, 255, 255 }, | ||
549 | { 135, 255, 0, 255 }, | ||
550 | { 135, 255, 95, 255 }, | ||
551 | { 135, 255, 135, 255 }, | ||
552 | { 135, 255, 175, 255 }, | ||
553 | { 135, 255, 215, 255 }, | ||
554 | { 135, 255, 255, 255 }, | ||
555 | { 175, 0, 0, 255 }, | ||
556 | { 175, 0, 95, 255 }, | ||
557 | { 175, 0, 135, 255 }, | ||
558 | { 175, 0, 175, 255 }, | ||
559 | { 175, 0, 215, 255 }, | ||
560 | { 175, 0, 255, 255 }, | ||
561 | { 175, 95, 0, 255 }, | ||
562 | { 175, 95, 95, 255 }, | ||
563 | { 175, 95, 135, 255 }, | ||
564 | { 175, 95, 175, 255 }, | ||
565 | { 175, 95, 215, 255 }, | ||
566 | { 175, 95, 255, 255 }, | ||
567 | { 175, 135, 0, 255 }, | ||
568 | { 175, 135, 95, 255 }, | ||
569 | { 175, 135, 135, 255 }, | ||
570 | { 175, 135, 175, 255 }, | ||
571 | { 175, 135, 215, 255 }, | ||
572 | { 175, 135, 255, 255 }, | ||
573 | { 175, 175, 0, 255 }, | ||
574 | { 175, 175, 95, 255 }, | ||
575 | { 175, 175, 135, 255 }, | ||
576 | { 175, 175, 175, 255 }, | ||
577 | { 175, 175, 215, 255 }, | ||
578 | { 175, 175, 255, 255 }, | ||
579 | { 175, 215, 0, 255 }, | ||
580 | { 175, 215, 95, 255 }, | ||
581 | { 175, 215, 135, 255 }, | ||
582 | { 175, 215, 175, 255 }, | ||
583 | { 175, 215, 215, 255 }, | ||
584 | { 175, 215, 255, 255 }, | ||
585 | { 175, 255, 0, 255 }, | ||
586 | { 175, 255, 95, 255 }, | ||
587 | { 175, 255, 135, 255 }, | ||
588 | { 175, 255, 175, 255 }, | ||
589 | { 175, 255, 215, 255 }, | ||
590 | { 175, 255, 255, 255 }, | ||
591 | { 215, 0, 0, 255 }, | ||
592 | { 215, 0, 95, 255 }, | ||
593 | { 215, 0, 135, 255 }, | ||
594 | { 215, 0, 175, 255 }, | ||
595 | { 215, 0, 215, 255 }, | ||
596 | { 215, 0, 255, 255 }, | ||
597 | { 215, 95, 0, 255 }, | ||
598 | { 215, 95, 95, 255 }, | ||
599 | { 215, 95, 135, 255 }, | ||
600 | { 215, 95, 175, 255 }, | ||
601 | { 215, 95, 215, 255 }, | ||
602 | { 215, 95, 255, 255 }, | ||
603 | { 215, 135, 0, 255 }, | ||
604 | { 215, 135, 95, 255 }, | ||
605 | { 215, 135, 135, 255 }, | ||
606 | { 215, 135, 175, 255 }, | ||
607 | { 215, 135, 215, 255 }, | ||
608 | { 215, 135, 255, 255 }, | ||
609 | { 215, 175, 0, 255 }, | ||
610 | { 215, 175, 95, 255 }, | ||
611 | { 215, 175, 135, 255 }, | ||
612 | { 215, 175, 175, 255 }, | ||
613 | { 215, 175, 215, 255 }, | ||
614 | { 215, 175, 255, 255 }, | ||
615 | { 215, 215, 0, 255 }, | ||
616 | { 215, 215, 95, 255 }, | ||
617 | { 215, 215, 135, 255 }, | ||
618 | { 215, 215, 175, 255 }, | ||
619 | { 215, 215, 215, 255 }, | ||
620 | { 215, 215, 255, 255 }, | ||
621 | { 215, 255, 0, 255 }, | ||
622 | { 215, 255, 95, 255 }, | ||
623 | { 215, 255, 135, 255 }, | ||
624 | { 215, 255, 175, 255 }, | ||
625 | { 215, 255, 215, 255 }, | ||
626 | { 215, 255, 255, 255 }, | ||
627 | { 255, 0, 0, 255 }, | ||
628 | { 255, 0, 95, 255 }, | ||
629 | { 255, 0, 135, 255 }, | ||
630 | { 255, 0, 175, 255 }, | ||
631 | { 255, 0, 215, 255 }, | ||
632 | { 255, 0, 255, 255 }, | ||
633 | { 255, 95, 0, 255 }, | ||
634 | { 255, 95, 95, 255 }, | ||
635 | { 255, 95, 135, 255 }, | ||
636 | { 255, 95, 175, 255 }, | ||
637 | { 255, 95, 215, 255 }, | ||
638 | { 255, 95, 255, 255 }, | ||
639 | { 255, 135, 0, 255 }, | ||
640 | { 255, 135, 95, 255 }, | ||
641 | { 255, 135, 135, 255 }, | ||
642 | { 255, 135, 175, 255 }, | ||
643 | { 255, 135, 215, 255 }, | ||
644 | { 255, 135, 255, 255 }, | ||
645 | { 255, 175, 0, 255 }, | ||
646 | { 255, 175, 95, 255 }, | ||
647 | { 255, 175, 135, 255 }, | ||
648 | { 255, 175, 175, 255 }, | ||
649 | { 255, 175, 215, 255 }, | ||
650 | { 255, 175, 255, 255 }, | ||
651 | { 255, 215, 0, 255 }, | ||
652 | { 255, 215, 95, 255 }, | ||
653 | { 255, 215, 135, 255 }, | ||
654 | { 255, 215, 175, 255 }, | ||
655 | { 255, 215, 215, 255 }, | ||
656 | { 255, 215, 255, 255 }, | ||
657 | { 255, 255, 0, 255 }, | ||
658 | { 255, 255, 95, 255 }, | ||
659 | { 255, 255, 135, 255 }, | ||
660 | { 255, 255, 175, 255 }, | ||
661 | { 255, 255, 215, 255 }, | ||
662 | { 255, 255, 255, 255 }, | ||
663 | |||
664 | { 0, 0, 0, 255 }, | ||
665 | { 11, 11, 11, 255 }, | ||
666 | { 22, 22, 22, 255 }, | ||
667 | { 33, 33, 33, 255 }, | ||
668 | { 44, 44, 44, 255 }, | ||
669 | { 55, 55, 55, 255 }, | ||
670 | { 67, 67, 67, 255 }, | ||
671 | { 78, 78, 78, 255 }, | ||
672 | { 89, 89, 89, 255 }, | ||
673 | { 100, 100, 100, 255 }, | ||
674 | { 111, 111, 111, 255 }, | ||
675 | { 122, 122, 122, 255 }, | ||
676 | { 133, 133, 133, 255 }, | ||
677 | { 144, 144, 144, 255 }, | ||
678 | { 155, 155, 155, 255 }, | ||
679 | { 166, 166, 166, 255 }, | ||
680 | { 177, 177, 177, 255 }, | ||
681 | { 188, 188, 188, 255 }, | ||
682 | { 200, 200, 200, 255 }, | ||
683 | { 211, 211, 211, 255 }, | ||
684 | { 222, 222, 222, 255 }, | ||
685 | { 233, 233, 233, 255 }, | ||
686 | { 244, 244, 244, 255 }, | ||
687 | { 255, 255, 255, 255 } | ||
688 | }; | ||
689 | |||
690 | iColor ansiForeground_Color(iRangecc escapeSequence, int fallback) { | ||
429 | iColor clr = get_Color(fallback); | 691 | iColor clr = get_Color(fallback); |
430 | for (const char *ch = escapeSequence.start; ch < escapeSequence.end; ch++) { | 692 | for (const char *ch = escapeSequence.start; ch < escapeSequence.end; ch++) { |
431 | char *endPtr; | 693 | char *endPtr; |
@@ -435,52 +697,35 @@ iColor ansi_Color(iRangecc escapeSequence, int fallback) { | |||
435 | default: | 697 | default: |
436 | break; | 698 | break; |
437 | case 30: | 699 | case 30: |
438 | clr = (iColor){ 0, 0, 0, 255 }; | ||
439 | break; | ||
440 | case 31: | 700 | case 31: |
441 | clr = (iColor){ 170, 0, 0, 255 }; | ||
442 | break; | ||
443 | case 32: | 701 | case 32: |
444 | clr = (iColor){ 0, 170, 0, 255 }; | ||
445 | break; | ||
446 | case 33: | 702 | case 33: |
447 | clr = (iColor){ 170, 85, 0, 255 }; | ||
448 | break; | ||
449 | case 34: | 703 | case 34: |
450 | clr = (iColor){ 0, 0, 170, 255 }; | ||
451 | break; | ||
452 | case 35: | 704 | case 35: |
453 | clr = (iColor){ 170, 0, 170, 255 }; | ||
454 | break; | ||
455 | case 36: | 705 | case 36: |
456 | clr = (iColor){ 0, 170, 170, 255 }; | ||
457 | break; | ||
458 | case 37: | 706 | case 37: |
459 | clr = (iColor){ 170, 170, 170, 255 }; | 707 | clr = ansi8BitColors_[arg - 30]; |
460 | break; | 708 | break; |
461 | case 90: | 709 | case 38: { |
462 | clr = (iColor){ 85, 85, 85, 255 }; | 710 | /* Extended foreground color. */ |
711 | arg = strtoul(ch + 1, &endPtr, 10); | ||
712 | ch = endPtr; | ||
713 | if (arg == 5) /* 8-bit palette */ { | ||
714 | arg = strtoul(ch + 1, &endPtr, 10); | ||
715 | ch = endPtr; | ||
716 | clr = ansi8BitColors_[iClamp(arg, 0, 255)]; | ||
717 | } | ||
463 | break; | 718 | break; |
719 | } | ||
720 | case 90: | ||
464 | case 91: | 721 | case 91: |
465 | clr = (iColor){ 255, 85, 85, 255 }; | ||
466 | break; | ||
467 | case 92: | 722 | case 92: |
468 | clr = (iColor){ 85, 255, 85, 255 }; | ||
469 | break; | ||
470 | case 93: | 723 | case 93: |
471 | clr = (iColor){ 255, 255, 85, 255 }; | ||
472 | break; | ||
473 | case 94: | 724 | case 94: |
474 | clr = (iColor){ 85, 85, 255, 255 }; | ||
475 | break; | ||
476 | case 95: | 725 | case 95: |
477 | clr = (iColor){ 255, 85, 255, 255 }; | ||
478 | break; | ||
479 | case 96: | 726 | case 96: |
480 | clr = (iColor){ 85, 255, 255, 255 }; | ||
481 | break; | ||
482 | case 97: | 727 | case 97: |
483 | clr = (iColor){ 255, 255, 255, 255 }; | 728 | clr = ansi8BitColors_[8 + arg - 90]; |
484 | break; | 729 | break; |
485 | } | 730 | } |
486 | } | 731 | } |
diff --git a/src/ui/color.h b/src/ui/color.h index 2b7fd735..94c38aec 100644 --- a/src/ui/color.h +++ b/src/ui/color.h | |||
@@ -227,5 +227,5 @@ iLocalDef void setHsl_Color(int color, iHSLColor hsl) { | |||
227 | 227 | ||
228 | void setThemePalette_Color (enum iColorTheme theme); | 228 | void setThemePalette_Color (enum iColorTheme theme); |
229 | 229 | ||
230 | iColor ansi_Color (iRangecc escapeSequence, int fallback); | 230 | iColor ansiForeground_Color (iRangecc escapeSequence, int fallback); |
231 | const char * escape_Color (int color); | 231 | const char * escape_Color (int color); |
diff --git a/src/ui/text.c b/src/ui/text.c index d4a6b61d..3d208b68 100644 --- a/src/ui/text.c +++ b/src/ui/text.c | |||
@@ -80,9 +80,9 @@ iChar char_Glyph(const iGlyph *d) { | |||
80 | 80 | ||
81 | iDefineTypeConstructionArgs(Glyph, (iChar ch), ch) | 81 | iDefineTypeConstructionArgs(Glyph, (iChar ch), ch) |
82 | 82 | ||
83 | /*-----------------------------------------------------------------------------------------------*/ | 83 | /*-----------------------------------------------------------------------------------------------*/ |
84 | 84 | ||
85 | struct Impl_Font { | 85 | struct Impl_Font { |
86 | iBlock * data; | 86 | iBlock * data; |
87 | stbtt_fontinfo font; | 87 | stbtt_fontinfo font; |
88 | float scale; | 88 | float scale; |
@@ -628,7 +628,8 @@ static iRect run_Font_(iFont *d, enum iRunMode mode, iRangecc text, size_t maxLe | |||
628 | if (match_RegExp(text_.ansiEscape, chPos, text.end - chPos, &m)) { | 628 | if (match_RegExp(text_.ansiEscape, chPos, text.end - chPos, &m)) { |
629 | if (mode == draw_RunMode) { | 629 | if (mode == draw_RunMode) { |
630 | /* Change the color. */ | 630 | /* Change the color. */ |
631 | const iColor clr = ansi_Color(capturedRange_RegExpMatch(&m, 1), tmParagraph_ColorId); | 631 | const iColor clr = |
632 | ansiForeground_Color(capturedRange_RegExpMatch(&m, 1), tmParagraph_ColorId); | ||
632 | SDL_SetTextureColorMod(text_.cache, clr.r, clr.g, clr.b); | 633 | SDL_SetTextureColorMod(text_.cache, clr.r, clr.g, clr.b); |
633 | } | 634 | } |
634 | chPos = end_RegExpMatch(&m); | 635 | chPos = end_RegExpMatch(&m); |