summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2013-09-21 18:10:48 +0200
committerBoris Faure <billiob@gmail.com>2013-09-21 18:54:57 +0200
commit02e42a747b5e27da8f487452a136b904790d86f2 (patch)
treed34034f9a16801525d581640d9cc606ace6c2f8c
parentac76c0fae2dd85af3c84ce82240374c10f7b5f56 (diff)
esc: export color_set to its own function
-rw-r--r--src/bin/termptyesc.c445
1 files changed, 227 insertions, 218 deletions
diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index 5356ffa..f7b90bf 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -108,11 +108,236 @@ _handle_cursor_control(Termpty *ty, Eina_Unicode *cc)
108 } 108 }
109} 109}
110 110
111static void
112_handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
113{
114 Eina_Unicode *b = *ptr;
115 int first = 1;
116
117 if (b && (*b == '>'))
118 { // key resources used by xterm
119 ERR("TODO: set/reset key resources used by xterm");
120 return;
121 }
122 DBG("color set");
123 while (b)
124 {
125 int arg = _csi_arg_get(&b);
126 if ((first) && (!b))
127 _termpty_reset_att(&(ty->state.att));
128 else if (b)
129 {
130 first = 0;
131 switch (arg)
132 {
133 case 0: // reset to normal
134 _termpty_reset_att(&(ty->state.att));
135 break;
136 case 1: // bold/bright
137 ty->state.att.bold = 1;
138 break;
139 case 2: // faint
140 ty->state.att.faint = 1;
141 break;
142 case 3: // italic
143#if defined(SUPPORT_ITALIC)
144 ty->state.att.italic = 1;
145#endif
146 break;
147 case 4: // underline
148 ty->state.att.underline = 1;
149 break;
150 case 5: // blink
151 ty->state.att.blink = 1;
152 break;
153 case 6: // blink rapid
154 ty->state.att.blink2 = 1;
155 break;
156 case 7: // reverse
157 ty->state.att.inverse = 1;
158 break;
159 case 8: // invisible
160 ty->state.att.invisible = 1;
161 break;
162 case 9: // strikethrough
163 ty->state.att.strike = 1;
164 break;
165 case 21: // no bold/bright
166 ty->state.att.bold = 0;
167 break;
168 case 22: // no faint
169 ty->state.att.faint = 0;
170 break;
171 case 23: // no italic
172#if defined(SUPPORT_ITALIC)
173 ty->state.att.italic = 0;
174#endif
175 break;
176 case 24: // no underline
177 ty->state.att.underline = 0;
178 break;
179 case 25: // no blink
180 ty->state.att.blink = 0;
181 ty->state.att.blink2 = 0;
182 break;
183 case 27: // no reverse
184 ty->state.att.inverse = 0;
185 break;
186 case 28: // no invisible
187 ty->state.att.invisible = 0;
188 break;
189 case 29: // no strikethrough
190 ty->state.att.strike = 0;
191 break;
192 case 30: // fg
193 case 31:
194 case 32:
195 case 33:
196 case 34:
197 case 35:
198 case 36:
199 case 37:
200 ty->state.att.fg256 = 0;
201 ty->state.att.fg = (arg - 30) + COL_BLACK;
202 ty->state.att.fgintense = 0;
203 break;
204 case 38: // xterm 256 fg color ???
205 // now check if next arg is 5
206 arg = _csi_arg_get(&b);
207 if (arg != 5) ERR("Failed xterm 256 color fg esc 5 (got %d)", arg);
208 else
209 {
210 // then get next arg - should be color index 0-255
211 arg = _csi_arg_get(&b);
212 if (!b) ERR("Failed xterm 256 color fg esc val");
213 else
214 {
215 ty->state.att.fg256 = 1;
216 ty->state.att.fg = arg;
217 }
218 }
219 ty->state.att.fgintense = 0;
220 break;
221 case 39: // default fg color
222 ty->state.att.fg256 = 0;
223 ty->state.att.fg = COL_DEF;
224 ty->state.att.fgintense = 0;
225 break;
226 case 40: // bg
227 case 41:
228 case 42:
229 case 43:
230 case 44:
231 case 45:
232 case 46:
233 case 47:
234 ty->state.att.bg256 = 0;
235 ty->state.att.bg = (arg - 40) + COL_BLACK;
236 ty->state.att.bgintense = 0;
237 break;
238 case 48: // xterm 256 bg color ???
239 // now check if next arg is 5
240 arg = _csi_arg_get(&b);
241 if (arg != 5) ERR("Failed xterm 256 color bg esc 5 (got %d)", arg);
242 else
243 {
244 // then get next arg - should be color index 0-255
245 arg = _csi_arg_get(&b);
246 if (!b) ERR("Failed xterm 256 color bg esc val");
247 else
248 {
249 ty->state.att.bg256 = 1;
250 ty->state.att.bg = arg;
251 }
252 }
253 ty->state.att.bgintense = 0;
254 break;
255 case 49: // default bg color
256 ty->state.att.bg256 = 0;
257 ty->state.att.bg = COL_DEF;
258 ty->state.att.bgintense = 0;
259 break;
260 case 90: // fg
261 case 91:
262 case 92:
263 case 93:
264 case 94:
265 case 95:
266 case 96:
267 case 97:
268 ty->state.att.fg256 = 0;
269 ty->state.att.fg = (arg - 90) + COL_BLACK;
270 ty->state.att.fgintense = 1;
271 break;
272 case 98: // xterm 256 fg color ???
273 // now check if next arg is 5
274 arg = _csi_arg_get(&b);
275 if (arg != 5) ERR("Failed xterm 256 color fg esc 5 (got %d)", arg);
276 else
277 {
278 // then get next arg - should be color index 0-255
279 arg = _csi_arg_get(&b);
280 if (!b) ERR("Failed xterm 256 color fg esc val");
281 else
282 {
283 ty->state.att.fg256 = 1;
284 ty->state.att.fg = arg;
285 }
286 }
287 ty->state.att.fgintense = 1;
288 break;
289 case 99: // default fg color
290 ty->state.att.fg256 = 0;
291 ty->state.att.fg = COL_DEF;
292 ty->state.att.fgintense = 1;
293 break;
294 case 100: // bg
295 case 101:
296 case 102:
297 case 103:
298 case 104:
299 case 105:
300 case 106:
301 case 107:
302 ty->state.att.bg256 = 0;
303 ty->state.att.bg = (arg - 100) + COL_BLACK;
304 ty->state.att.bgintense = 1;
305 break;
306 case 108: // xterm 256 bg color ???
307 // now check if next arg is 5
308 arg = _csi_arg_get(&b);
309 if (arg != 5) ERR("Failed xterm 256 color bg esc 5 (got %d)", arg);
310 else
311 {
312 // then get next arg - should be color index 0-255
313 arg = _csi_arg_get(&b);
314 if (!b) ERR("Failed xterm 256 color bg esc val");
315 else
316 {
317 ty->state.att.bg256 = 1;
318 ty->state.att.bg = arg;
319 }
320 }
321 ty->state.att.bgintense = 1;
322 break;
323 case 109: // default bg color
324 ty->state.att.bg256 = 0;
325 ty->state.att.bg = COL_DEF;
326 ty->state.att.bgintense = 1;
327 break;
328 default: // not handled???
329 ERR(" color cmd [%i] not handled", arg);
330 break;
331 }
332 }
333 }
334}
335
111static int 336static int
112_handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce) 337_handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
113{ 338{
114 Eina_Unicode *cc; 339 Eina_Unicode *cc;
115 int arg, first = 1, i; 340 int arg, i;
116 Eina_Unicode buf[4096], *b; 341 Eina_Unicode buf[4096], *b;
117 342
118 cc = (Eina_Unicode *)c; 343 cc = (Eina_Unicode *)c;
@@ -131,223 +356,7 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
131 switch (*cc) 356 switch (*cc)
132 { 357 {
133 case 'm': // color set 358 case 'm': // color set
134 if (b && (*b == '>')) 359 _handle_esc_csi_color_set(ty, &b);
135 { // key resources used by xterm
136 ERR("TODO: set/reset key resources used by xterm");
137 break;
138 }
139 DBG("color set");
140 while (b)
141 {
142 arg = _csi_arg_get(&b);
143 if ((first) && (!b))
144 _termpty_reset_att(&(ty->state.att));
145 else if (b)
146 {
147 first = 0;
148 switch (arg)
149 {
150 case 0: // reset to normal
151 _termpty_reset_att(&(ty->state.att));
152 break;
153 case 1: // bold/bright
154 ty->state.att.bold = 1;
155 break;
156 case 2: // faint
157 ty->state.att.faint = 1;
158 break;
159 case 3: // italic
160#if defined(SUPPORT_ITALIC)
161 ty->state.att.italic = 1;
162#endif
163 break;
164 case 4: // underline
165 ty->state.att.underline = 1;
166 break;
167 case 5: // blink
168 ty->state.att.blink = 1;
169 break;
170 case 6: // blink rapid
171 ty->state.att.blink2 = 1;
172 break;
173 case 7: // reverse
174 ty->state.att.inverse = 1;
175 break;
176 case 8: // invisible
177 ty->state.att.invisible = 1;
178 break;
179 case 9: // strikethrough
180 ty->state.att.strike = 1;
181 break;
182 case 21: // no bold/bright
183 ty->state.att.bold = 0;
184 break;
185 case 22: // no faint
186 ty->state.att.faint = 0;
187 break;
188 case 23: // no italic
189#if defined(SUPPORT_ITALIC)
190 ty->state.att.italic = 0;
191#endif
192 break;
193 case 24: // no underline
194 ty->state.att.underline = 0;
195 break;
196 case 25: // no blink
197 ty->state.att.blink = 0;
198 ty->state.att.blink2 = 0;
199 break;
200 case 27: // no reverse
201 ty->state.att.inverse = 0;
202 break;
203 case 28: // no invisible
204 ty->state.att.invisible = 0;
205 break;
206 case 29: // no strikethrough
207 ty->state.att.strike = 0;
208 break;
209 case 30: // fg
210 case 31:
211 case 32:
212 case 33:
213 case 34:
214 case 35:
215 case 36:
216 case 37:
217 ty->state.att.fg256 = 0;
218 ty->state.att.fg = (arg - 30) + COL_BLACK;
219 ty->state.att.fgintense = 0;
220 break;
221 case 38: // xterm 256 fg color ???
222 // now check if next arg is 5
223 arg = _csi_arg_get(&b);
224 if (arg != 5) ERR("Failed xterm 256 color fg esc 5");
225 else
226 {
227 // then get next arg - should be color index 0-255
228 arg = _csi_arg_get(&b);
229 if (!b) ERR("Failed xterm 256 color fg esc val");
230 else
231 {
232 ty->state.att.fg256 = 1;
233 ty->state.att.fg = arg;
234 }
235 }
236 ty->state.att.fgintense = 0;
237 break;
238 case 39: // default fg color
239 ty->state.att.fg256 = 0;
240 ty->state.att.fg = COL_DEF;
241 ty->state.att.fgintense = 0;
242 break;
243 case 40: // bg
244 case 41:
245 case 42:
246 case 43:
247 case 44:
248 case 45:
249 case 46:
250 case 47:
251 ty->state.att.bg256 = 0;
252 ty->state.att.bg = (arg - 40) + COL_BLACK;
253 ty->state.att.bgintense = 0;
254 break;
255 case 48: // xterm 256 bg color ???
256 // now check if next arg is 5
257 arg = _csi_arg_get(&b);
258 if (arg != 5) ERR("Failed xterm 256 color bg esc 5");
259 else
260 {
261 // then get next arg - should be color index 0-255
262 arg = _csi_arg_get(&b);
263 if (!b) ERR("Failed xterm 256 color bg esc val");
264 else
265 {
266 ty->state.att.bg256 = 1;
267 ty->state.att.bg = arg;
268 }
269 }
270 ty->state.att.bgintense = 0;
271 break;
272 case 49: // default bg color
273 ty->state.att.bg256 = 0;
274 ty->state.att.bg = COL_DEF;
275 ty->state.att.bgintense = 0;
276 break;
277 case 90: // fg
278 case 91:
279 case 92:
280 case 93:
281 case 94:
282 case 95:
283 case 96:
284 case 97:
285 ty->state.att.fg256 = 0;
286 ty->state.att.fg = (arg - 90) + COL_BLACK;
287 ty->state.att.fgintense = 1;
288 break;
289 case 98: // xterm 256 fg color ???
290 // now check if next arg is 5
291 arg = _csi_arg_get(&b);
292 if (arg != 5) ERR("Failed xterm 256 color fg esc 5");
293 else
294 {
295 // then get next arg - should be color index 0-255
296 arg = _csi_arg_get(&b);
297 if (!b) ERR("Failed xterm 256 color fg esc val");
298 else
299 {
300 ty->state.att.fg256 = 1;
301 ty->state.att.fg = arg;
302 }
303 }
304 ty->state.att.fgintense = 1;
305 break;
306 case 99: // default fg color
307 ty->state.att.fg256 = 0;
308 ty->state.att.fg = COL_DEF;
309 ty->state.att.fgintense = 1;
310 break;
311 case 100: // bg
312 case 101:
313 case 102:
314 case 103:
315 case 104:
316 case 105:
317 case 106:
318 case 107:
319 ty->state.att.bg256 = 0;
320 ty->state.att.bg = (arg - 100) + COL_BLACK;
321 ty->state.att.bgintense = 1;
322 break;
323 case 108: // xterm 256 bg color ???
324 // now check if next arg is 5
325 arg = _csi_arg_get(&b);
326 if (arg != 5) ERR("Failed xterm 256 color bg esc 5");
327 else
328 {
329 // then get next arg - should be color index 0-255
330 arg = _csi_arg_get(&b);
331 if (!b) ERR("Failed xterm 256 color bg esc val");
332 else
333 {
334 ty->state.att.bg256 = 1;
335 ty->state.att.bg = arg;
336 }
337 }
338 ty->state.att.bgintense = 1;
339 break;
340 case 109: // default bg color
341 ty->state.att.bg256 = 0;
342 ty->state.att.bg = COL_DEF;
343 ty->state.att.bgintense = 1;
344 break;
345 default: // not handled???
346 ERR(" color cmd [%i] not handled", arg);
347 break;
348 }
349 }
350 }
351 break; 360 break;
352 case '@': // insert N blank chars 361 case '@': // insert N blank chars
353 arg = _csi_arg_get(&b); 362 arg = _csi_arg_get(&b);