Project

General

Profile

color.patch

sorah (Sorah Fukumori), 11/29/2017 08:56 AM

View differences:

eval_error.c
73 73
}
74 74

  
75 75
static void
76
print_errinfo(const VALUE eclass, const VALUE errat, const VALUE emesg)
76
print_errinfo(const VALUE eclass, const VALUE errat, const VALUE emesg, int colored)
77 77
{
78
    static const char underline[] = "\033[4;1m";
79
    static const char bold[] = "\033[1m";
80
    static const char reset[] = "\033[m";
78 81
    const char *einfo = "";
79 82
    long elen = 0;
80 83
    VALUE mesg;
......
88 91
	    warn_print_str(mesg);
89 92
	    warn_print(": ");
90 93
	}
94
    if (colored) {
95
        warn_print(bold);
96
    }
97

  
91 98

  
92 99
	if (!NIL_P(emesg)) {
93 100
	    einfo = RSTRING_PTR(emesg);
......
96 103
    }
97 104

  
98 105
    if (eclass == rb_eRuntimeError && elen == 0) {
106
        if (colored) {
107
            warn_print(underline);
108
        }
99 109
	warn_print("unhandled exception\n");
100 110
    }
101 111
    else {
......
103 113

  
104 114
	epath = rb_class_name(eclass);
105 115
	if (elen == 0) {
116
      if (colored) warn_print(underline);
106 117
	    warn_print_str(epath);
107 118
	    warn_print("\n");
108 119
	}
......
119 130
	    warn_print_str(tail ? rb_str_subseq(emesg, 0, len) : emesg);
120 131
	    if (epath) {
121 132
		warn_print(" (");
133
    if (colored) warn_print(underline);
122 134
		warn_print_str(epath);
135
    if (colored) warn_print(reset);
136
    if (colored) warn_print(bold);
123 137
		warn_print(")\n");
124 138
	    }
125 139
	    if (tail) {
......
128 142
	    if (tail ? einfo[elen-1] != '\n' : !epath) warn_print2("\n", 1);
129 143
	}
130 144
    }
145
    if (colored) warn_print(reset);
131 146
}
132 147

  
133 148
static void
......
192 207
	}
193 208
    }
194 209
    if (rb_stderr_tty_p()) {
195
	warn_print("Traceback (most recent call last):\n");
210
	warn_print("\033[1mTraceback \033[m(most recent call last):\n");
196 211
	print_backtrace(eclass, errat, TRUE);
197
	print_errinfo(eclass, errat, emesg);
212
	print_errinfo(eclass, errat, emesg, TRUE);
198 213
    }
199 214
    else {
200
	print_errinfo(eclass, errat, emesg);
215
	print_errinfo(eclass, errat, emesg, FALSE);
201 216
	print_backtrace(eclass, errat, FALSE);
202 217
    }
203 218
  error:
204
-