summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2018-11-20 10:34:37 +0100
committerBoris Faure <billiob@gmail.com>2018-11-20 10:34:37 +0100
commit8fb44906cc8ec326664352670b35a7de4efad67a (patch)
tree8163985a26ba3ec5b9119a6fdccd5a98c636785f
parent3f432544dfc50f68d8a03a8c41185133031ef3c1 (diff)
Revert "termpty: better handle ';' in escape sequences. Closes T7475"
This reverts commit 3f432544dfc50f68d8a03a8c41185133031ef3c1.
-rw-r--r--src/bin/termptyesc.c587
1 files changed, 290 insertions, 297 deletions
diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index 0354257..0a43458 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -104,11 +104,9 @@ _csi_arg_get(Eina_Unicode **ptr)
104 *ptr = b; 104 *ptr = b;
105 return -1; 105 return -1;
106 } 106 }
107 if (*b == '\0') 107
108 { 108 if (!*b)
109 *ptr = NULL; 109 goto error;
110 return -1;
111 }
112 110
113 while ((*b >= '0') && (*b <= '9')) 111 while ((*b >= '0') && (*b <= '9'))
114 { 112 {
@@ -121,21 +119,15 @@ _csi_arg_get(Eina_Unicode **ptr)
121 119
122 if (*b == ';') 120 if (*b == ';')
123 { 121 {
124 if (b[1]) 122 b++;
125 b++;
126 *ptr = b;
127 }
128 else if (*b == '\0')
129 {
130 *ptr = NULL;
131 } 123 }
132 else 124
133 *ptr = b; 125 *ptr = b;
134 return sum; 126 return sum;
135 127
136error: 128error:
137 *ptr = NULL; 129 *ptr = NULL;
138 return -2; 130 return -1;
139} 131}
140 132
141static void 133static void
@@ -653,10 +645,10 @@ _handle_esc_csi_truecolor_cmyk(Termpty *ty, Eina_Unicode **ptr)
653} 645}
654 646
655static void 647static void
656_handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr, 648_handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
657 const Eina_Unicode * const end)
658{ 649{
659 Eina_Unicode *b = *ptr; 650 Eina_Unicode *b = *ptr;
651 int first = 1;
660 652
661 if (b && (*b == '>')) 653 if (b && (*b == '>'))
662 { // key resources used by xterm 654 { // key resources used by xterm
@@ -664,293 +656,296 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr,
664 return; 656 return;
665 } 657 }
666 DBG("color set"); 658 DBG("color set");
667 while (b && b <= end) 659 while (b)
668 { 660 {
669 int arg = _csi_arg_get(&b); 661 int arg = _csi_arg_get(&b);
670 DBG("arg=%d b:%p", arg, b); 662 if ((first) && (!b))
671 switch (arg) 663 termpty_reset_att(&(ty->termstate.att));
664 else if (b)
672 { 665 {
673 case -1: 666 first = 0;
674 EINA_FALLTHROUGH; 667 switch (arg)
675 case 0: // reset to normal 668 {
676 termpty_reset_att(&(ty->termstate.att)); 669 case 0: // reset to normal
677 break; 670 termpty_reset_att(&(ty->termstate.att));
678 case 1: // bold/bright 671 break;
679 ty->termstate.att.bold = 1; 672 case 1: // bold/bright
680 break; 673 ty->termstate.att.bold = 1;
681 case 2: // faint 674 break;
682 ty->termstate.att.faint = 1; 675 case 2: // faint
683 break; 676 ty->termstate.att.faint = 1;
684 case 3: // italic 677 break;
685 ty->termstate.att.italic = 1; 678 case 3: // italic
686 break; 679 ty->termstate.att.italic = 1;
687 case 4: // underline 680 break;
688 ty->termstate.att.underline = 1; 681 case 4: // underline
689 break; 682 ty->termstate.att.underline = 1;
690 case 5: // blink 683 break;
691 ty->termstate.att.blink = 1; 684 case 5: // blink
692 break; 685 ty->termstate.att.blink = 1;
693 case 6: // blink rapid 686 break;
694 ty->termstate.att.blink2 = 1; 687 case 6: // blink rapid
695 break; 688 ty->termstate.att.blink2 = 1;
696 case 7: // reverse 689 break;
697 ty->termstate.att.inverse = 1; 690 case 7: // reverse
698 break; 691 ty->termstate.att.inverse = 1;
699 case 8: // invisible 692 break;
700 ty->termstate.att.invisible = 1; 693 case 8: // invisible
701 break; 694 ty->termstate.att.invisible = 1;
702 case 9: // strikethrough 695 break;
703 ty->termstate.att.strike = 1; 696 case 9: // strikethrough
704 break; 697 ty->termstate.att.strike = 1;
705 case 20: // fraktur! 698 break;
706 ty->termstate.att.fraktur = 1; 699 case 20: // fraktur!
707 break; 700 ty->termstate.att.fraktur = 1;
708 case 21: // no bold/bright 701 break;
709 ty->termstate.att.bold = 0; 702 case 21: // no bold/bright
710 break; 703 ty->termstate.att.bold = 0;
711 case 22: // no bold/bright, no faint 704 break;
712 ty->termstate.att.bold = 0; 705 case 22: // no bold/bright, no faint
713 ty->termstate.att.faint = 0; 706 ty->termstate.att.bold = 0;
714 break; 707 ty->termstate.att.faint = 0;
715 case 23: // no italic, not fraktur 708 break;
716 ty->termstate.att.italic = 0; 709 case 23: // no italic, not fraktur
717 ty->termstate.att.fraktur = 0; 710 ty->termstate.att.italic = 0;
718 break; 711 ty->termstate.att.fraktur = 0;
719 case 24: // no underline 712 break;
720 ty->termstate.att.underline = 0; 713 case 24: // no underline
721 break; 714 ty->termstate.att.underline = 0;
722 case 25: // no blink 715 break;
723 ty->termstate.att.blink = 0; 716 case 25: // no blink
724 ty->termstate.att.blink2 = 0; 717 ty->termstate.att.blink = 0;
725 break; 718 ty->termstate.att.blink2 = 0;
726 case 27: // no reverse 719 break;
727 ty->termstate.att.inverse = 0; 720 case 27: // no reverse
728 break; 721 ty->termstate.att.inverse = 0;
729 case 28: // no invisible 722 break;
730 ty->termstate.att.invisible = 0; 723 case 28: // no invisible
731 break; 724 ty->termstate.att.invisible = 0;
732 case 29: // no strikethrough 725 break;
733 ty->termstate.att.strike = 0; 726 case 29: // no strikethrough
734 break; 727 ty->termstate.att.strike = 0;
735 case 30: // fg 728 break;
736 case 31: 729 case 30: // fg
737 case 32: 730 case 31:
738 case 33: 731 case 32:
739 case 34: 732 case 33:
740 case 35: 733 case 34:
741 case 36: 734 case 35:
742 case 37: 735 case 36:
743 ty->termstate.att.fg256 = 0; 736 case 37:
744 ty->termstate.att.fg = (arg - 30) + COL_BLACK; 737 ty->termstate.att.fg256 = 0;
745 ty->termstate.att.fgintense = 0; 738 ty->termstate.att.fg = (arg - 30) + COL_BLACK;
746 break; 739 ty->termstate.att.fgintense = 0;
747 case 38: // xterm 256 fg color ??? 740 break;
748 arg = _csi_arg_get(&b); 741 case 38: // xterm 256 fg color ???
749 switch (arg) 742 arg = _csi_arg_get(&b);
750 { 743 switch (arg)
751 case 1: 744 {
752 ty->termstate.att.fg256 = 0; 745 case 1:
753 ty->termstate.att.fg = COL_INVIS; 746 ty->termstate.att.fg256 = 0;
754 break; 747 ty->termstate.att.fg = COL_INVIS;
755 case 2: 748 break;
756 ty->termstate.att.fg256 = 1; 749 case 2:
757 ty->termstate.att.fg =
758 _handle_esc_csi_truecolor_rgb(ty, &b);
759 DBG("truecolor RGB fg: approximation got color %d",
760 ty->termstate.att.fg);
761 break;
762 case 3:
763 ty->termstate.att.fg256 = 1;
764 ty->termstate.att.fg =
765 _handle_esc_csi_truecolor_cmy(ty, &b);
766 DBG("truecolor CMY fg: approximation got color %d",
767 ty->termstate.att.fg);
768 break;
769 case 4:
770 ty->termstate.att.fg256 = 1;
771 ty->termstate.att.fg =
772 _handle_esc_csi_truecolor_cmyk(ty, &b);
773 DBG("truecolor CMYK fg: approximation got color %d",
774 ty->termstate.att.fg);
775 break;
776 case 5:
777 // then get next arg - should be color index 0-255
778 arg = _csi_arg_get(&b);
779 if (!b) ERR("Failed xterm 256 color fg esc val");
780 else if (arg < 0 || arg > 255)
781 ERR("Invalid fg color %d", arg);
782 else
783 {
784 ty->termstate.att.fg256 = 1; 750 ty->termstate.att.fg256 = 1;
785 ty->termstate.att.fg = arg; 751 ty->termstate.att.fg =
786 } 752 _handle_esc_csi_truecolor_rgb(ty, &b);
787 break; 753 DBG("truecolor RGB fg: approximation got color %d",
788 default: 754 ty->termstate.att.fg);
789 ERR("Failed xterm 256 color fg (got %d)", arg); 755 break;
790 } 756 case 3:
791 ty->termstate.att.fgintense = 0; 757 ty->termstate.att.fg256 = 1;
792 break; 758 ty->termstate.att.fg =
793 case 39: // default fg color 759 _handle_esc_csi_truecolor_cmy(ty, &b);
794 ty->termstate.att.fg256 = 0; 760 DBG("truecolor CMY fg: approximation got color %d",
795 ty->termstate.att.fg = COL_DEF; 761 ty->termstate.att.fg);
796 ty->termstate.att.fgintense = 0; 762 break;
797 break; 763 case 4:
798 case 40: // bg 764 ty->termstate.att.fg256 = 1;
799 case 41: 765 ty->termstate.att.fg =
800 case 42: 766 _handle_esc_csi_truecolor_cmyk(ty, &b);
801 case 43: 767 DBG("truecolor CMYK fg: approximation got color %d",
802 case 44: 768 ty->termstate.att.fg);
803 case 45: 769 break;
804 case 46: 770 case 5:
805 case 47: 771 // then get next arg - should be color index 0-255
806 ty->termstate.att.bg256 = 0; 772 arg = _csi_arg_get(&b);
807 ty->termstate.att.bg = (arg - 40) + COL_BLACK; 773 if (!b) ERR("Failed xterm 256 color fg esc val");
808 ty->termstate.att.bgintense = 0; 774 else if (arg < 0 || arg > 255)
809 break; 775 ERR("Invalid fg color %d", arg);
810 case 48: // xterm 256 bg color ??? 776 else
811 arg = _csi_arg_get(&b); 777 {
812 switch (arg) 778 ty->termstate.att.fg256 = 1;
813 { 779 ty->termstate.att.fg = arg;
814 case 1: 780 }
815 ty->termstate.att.bg256 = 0; 781 break;
816 ty->termstate.att.bg = COL_INVIS; 782 default:
817 break; 783 ERR("Failed xterm 256 color fg (got %d)", arg);
818 case 2: 784 }
819 ty->termstate.att.bg256 = 1; 785 ty->termstate.att.fgintense = 0;
820 ty->termstate.att.bg = 786 break;
821 _handle_esc_csi_truecolor_rgb(ty, &b); 787 case 39: // default fg color
822 DBG("truecolor RGB bg: approximation got color %d", 788 ty->termstate.att.fg256 = 0;
823 ty->termstate.att.bg); 789 ty->termstate.att.fg = COL_DEF;
824 break; 790 ty->termstate.att.fgintense = 0;
825 case 3: 791 break;
826 ty->termstate.att.bg256 = 1; 792 case 40: // bg
827 ty->termstate.att.bg = 793 case 41:
828 _handle_esc_csi_truecolor_cmy(ty, &b); 794 case 42:
829 DBG("truecolor CMY bg: approximation got color %d", 795 case 43:
830 ty->termstate.att.bg); 796 case 44:
831 break; 797 case 45:
832 case 4: 798 case 46:
833 ty->termstate.att.bg256 = 1; 799 case 47:
834 ty->termstate.att.bg = 800 ty->termstate.att.bg256 = 0;
835 _handle_esc_csi_truecolor_cmyk(ty, &b); 801 ty->termstate.att.bg = (arg - 40) + COL_BLACK;
836 DBG("truecolor CMYK bg: approximation got color %d", 802 ty->termstate.att.bgintense = 0;
837 ty->termstate.att.bg); 803 break;
838 break; 804 case 48: // xterm 256 bg color ???
839 case 5: 805 arg = _csi_arg_get(&b);
840 // then get next arg - should be color index 0-255 806 switch (arg)
841 arg = _csi_arg_get(&b); 807 {
842 if (!b) ERR("Failed xterm 256 color bg esc val"); 808 case 1:
843 else if (arg < 0 || arg > 255) 809 ty->termstate.att.bg256 = 0;
844 ERR("Invalid bg color %d", arg); 810 ty->termstate.att.bg = COL_INVIS;
845 else 811 break;
846 { 812 case 2:
847 ty->termstate.att.bg256 = 1; 813 ty->termstate.att.bg256 = 1;
848 ty->termstate.att.bg = arg; 814 ty->termstate.att.bg =
849 } 815 _handle_esc_csi_truecolor_rgb(ty, &b);
850 break; 816 DBG("truecolor RGB bg: approximation got color %d",
851 default: 817 ty->termstate.att.bg);
852 ERR("Failed xterm 256 color bg (got %d)", arg); 818 break;
853 } 819 case 3:
854 ty->termstate.att.bgintense = 0; 820 ty->termstate.att.bg256 = 1;
855 break; 821 ty->termstate.att.bg =
856 case 49: // default bg color 822 _handle_esc_csi_truecolor_cmy(ty, &b);
857 ty->termstate.att.bg256 = 0; 823 DBG("truecolor CMY bg: approximation got color %d",
858 ty->termstate.att.bg = COL_DEF; 824 ty->termstate.att.bg);
859 ty->termstate.att.bgintense = 0; 825 break;
860 break; 826 case 4:
861 case 51: 827 ty->termstate.att.bg256 = 1;
862 WRN("TODO: support SGR 51 - framed attribute"); 828 ty->termstate.att.bg =
863 ty->termstate.att.framed = 1; 829 _handle_esc_csi_truecolor_cmyk(ty, &b);
864 break; 830 DBG("truecolor CMYK bg: approximation got color %d",
865 case 52: 831 ty->termstate.att.bg);
866 ty->termstate.att.encircled = 1; 832 break;
867 break; 833 case 5:
868 case 53: 834 // then get next arg - should be color index 0-255
869 WRN("TODO: support SGR 51 - overlined attribute"); 835 arg = _csi_arg_get(&b);
870 ty->termstate.att.overlined = 1; 836 if (!b) ERR("Failed xterm 256 color bg esc val");
871 break; 837 else if (arg < 0 || arg > 255)
872 case 54: 838 ERR("Invalid bg color %d", arg);
873 ty->termstate.att.framed = 0; 839 else
874 ty->termstate.att.encircled = 0; 840 {
875 break; 841 ty->termstate.att.bg256 = 1;
876 case 55: 842 ty->termstate.att.bg = arg;
877 ty->termstate.att.overlined = 0; 843 }
878 break; 844 break;
879 case 90: // fg 845 default:
880 case 91: 846 ERR("Failed xterm 256 color bg (got %d)", arg);
881 case 92: 847 }
882 case 93: 848 ty->termstate.att.bgintense = 0;
883 case 94: 849 break;
884 case 95: 850 case 49: // default bg color
885 case 96: 851 ty->termstate.att.bg256 = 0;
886 case 97: 852 ty->termstate.att.bg = COL_DEF;
887 ty->termstate.att.fg256 = 0; 853 ty->termstate.att.bgintense = 0;
888 ty->termstate.att.fg = (arg - 90) + COL_BLACK; 854 break;
889 ty->termstate.att.fgintense = 1; 855 case 51:
890 break; 856 WRN("TODO: support SGR 51 - framed attribute");
891 case 98: // xterm 256 fg color ??? 857 ty->termstate.att.framed = 1;
892 // now check if next arg is 5 858 break;
893 arg = _csi_arg_get(&b); 859 case 52:
894 if (arg != 5) ERR("Failed xterm 256 color fg esc 5 (got %d)", arg); 860 ty->termstate.att.encircled = 1;
895 else 861 break;
896 { 862 case 53:
897 // then get next arg - should be color index 0-255 863 WRN("TODO: support SGR 51 - overlined attribute");
864 ty->termstate.att.overlined = 1;
865 break;
866 case 54:
867 ty->termstate.att.framed = 0;
868 ty->termstate.att.encircled = 0;
869 break;
870 case 55:
871 ty->termstate.att.overlined = 0;
872 break;
873 case 90: // fg
874 case 91:
875 case 92:
876 case 93:
877 case 94:
878 case 95:
879 case 96:
880 case 97:
881 ty->termstate.att.fg256 = 0;
882 ty->termstate.att.fg = (arg - 90) + COL_BLACK;
883 ty->termstate.att.fgintense = 1;
884 break;
885 case 98: // xterm 256 fg color ???
886 // now check if next arg is 5
898 arg = _csi_arg_get(&b); 887 arg = _csi_arg_get(&b);
899 if (!b) ERR("Failed xterm 256 color fg esc val"); 888 if (arg != 5) ERR("Failed xterm 256 color fg esc 5 (got %d)", arg);
900 else if (arg < 0 || arg > 255)
901 ERR("Invalid fg color %d", arg);
902 else 889 else
903 { 890 {
904 ty->termstate.att.fg256 = 1; 891 // then get next arg - should be color index 0-255
905 ty->termstate.att.fg = arg; 892 arg = _csi_arg_get(&b);
893 if (!b) ERR("Failed xterm 256 color fg esc val");
894 else if (arg < 0 || arg > 255)
895 ERR("Invalid fg color %d", arg);
896 else
897 {
898 ty->termstate.att.fg256 = 1;
899 ty->termstate.att.fg = arg;
900 }
906 } 901 }
907 } 902 ty->termstate.att.fgintense = 1;
908 ty->termstate.att.fgintense = 1; 903 break;
909 break; 904 case 99: // default fg color
910 case 99: // default fg color 905 ty->termstate.att.fg256 = 0;
911 ty->termstate.att.fg256 = 0; 906 ty->termstate.att.fg = COL_DEF;
912 ty->termstate.att.fg = COL_DEF; 907 ty->termstate.att.fgintense = 1;
913 ty->termstate.att.fgintense = 1; 908 break;
914 break; 909 case 100: // bg
915 case 100: // bg 910 case 101:
916 case 101: 911 case 102:
917 case 102: 912 case 103:
918 case 103: 913 case 104:
919 case 104: 914 case 105:
920 case 105: 915 case 106:
921 case 106: 916 case 107:
922 case 107: 917 ty->termstate.att.bg256 = 0;
923 ty->termstate.att.bg256 = 0; 918 ty->termstate.att.bg = (arg - 100) + COL_BLACK;
924 ty->termstate.att.bg = (arg - 100) + COL_BLACK; 919 ty->termstate.att.bgintense = 1;
925 ty->termstate.att.bgintense = 1; 920 break;
926 break; 921 case 108: // xterm 256 bg color ???
927 case 108: // xterm 256 bg color ??? 922 // now check if next arg is 5
928 // now check if next arg is 5
929 arg = _csi_arg_get(&b);
930 if (arg != 5) ERR("Failed xterm 256 color bg esc 5 (got %d)", arg);
931 else
932 {
933 // then get next arg - should be color index 0-255
934 arg = _csi_arg_get(&b); 923 arg = _csi_arg_get(&b);
935 if (!b) ERR("Failed xterm 256 color bg esc val"); 924 if (arg != 5) ERR("Failed xterm 256 color bg esc 5 (got %d)", arg);
936 else if (arg < 0 || arg > 255)
937 ERR("Invalid bg color %d", arg);
938 else 925 else
939 { 926 {
940 ty->termstate.att.bg256 = 1; 927 // then get next arg - should be color index 0-255
941 ty->termstate.att.bg = arg; 928 arg = _csi_arg_get(&b);
929 if (!b) ERR("Failed xterm 256 color bg esc val");
930 else if (arg < 0 || arg > 255)
931 ERR("Invalid bg color %d", arg);
932 else
933 {
934 ty->termstate.att.bg256 = 1;
935 ty->termstate.att.bg = arg;
936 }
942 } 937 }
943 } 938 ty->termstate.att.bgintense = 1;
944 ty->termstate.att.bgintense = 1; 939 break;
945 break; 940 case 109: // default bg color
946 case 109: // default bg color 941 ty->termstate.att.bg256 = 0;
947 ty->termstate.att.bg256 = 0; 942 ty->termstate.att.bg = COL_DEF;
948 ty->termstate.att.bg = COL_DEF; 943 ty->termstate.att.bgintense = 1;
949 ty->termstate.att.bgintense = 1; 944 break;
950 break; 945 default: // not handled???
951 default: // not handled??? 946 WRN("Unhandled color cmd [%i]", arg);
952 WRN("Unhandled color cmd [%i]", arg); 947 break;
953 break; 948 }
954 } 949 }
955 } 950 }
956} 951}
@@ -1260,9 +1255,8 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
1260 ERR("csi parsing overflowed, skipping the whole buffer (binary data?)"); 1255 ERR("csi parsing overflowed, skipping the whole buffer (binary data?)");
1261 return cc - c; 1256 return cc - c;
1262 } 1257 }
1263 if (cc == ce) 1258 if (cc == ce) return 0;
1264 return 0; 1259 *b = 0;
1265 *b = '\0';
1266 be = b; 1260 be = b;
1267 b = buf; 1261 b = buf;
1268 DBG(" CSI: '%s' args '%s'", _safechar(*cc), (char *) buf); 1262 DBG(" CSI: '%s' args '%s'", _safechar(*cc), (char *) buf);
@@ -1290,8 +1284,7 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
1290 case 'A': // cursor up N (CUU) 1284 case 'A': // cursor up N (CUU)
1291CUU: 1285CUU:
1292 arg = _csi_arg_get(&b); 1286 arg = _csi_arg_get(&b);
1293 if (arg < 1) 1287 if (arg < 1) arg = 1;
1294 arg = 1;
1295 DBG("cursor up %d", arg); 1288 DBG("cursor up %d", arg);
1296 ty->termstate.wrapnext = 0; 1289 ty->termstate.wrapnext = 0;
1297 ty->cursor_state.cy = MAX(0, ty->cursor_state.cy - arg); 1290 ty->cursor_state.cy = MAX(0, ty->cursor_state.cy - arg);
@@ -1632,7 +1625,7 @@ HVP:
1632 _handle_esc_csi_reset_mode(ty, *cc, b); 1625 _handle_esc_csi_reset_mode(ty, *cc, b);
1633 break; 1626 break;
1634 case 'm': // color set 1627 case 'm': // color set
1635 _handle_esc_csi_color_set(ty, &b, be); 1628 _handle_esc_csi_color_set(ty, &b);
1636 break; 1629 break;
1637 case 'n': 1630 case 'n':
1638 _handle_esc_csi_dsr(ty, b); 1631 _handle_esc_csi_dsr(ty, b);