Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

614 rader
18 KiB

  1. /*
  2. * libcaca Colour ASCII-Art library
  3. * Copyright (c) 2002-2009 Sam Hocevar <sam@hocevar.net>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This library is free software. It comes without any warranty, to
  9. * the extent permitted by applicable law. You can redistribute it
  10. * and/or modify it under the terms of the Do What The Fuck You Want
  11. * To Public License, Version 2, as published by Sam Hocevar. See
  12. * http://sam.zoy.org/wtfpl/COPYING for more details.
  13. */
  14. /*
  15. * This file contains the libcaca SLang input and output driver
  16. */
  17. #include "config.h"
  18. #if defined(USE_SLANG)
  19. #if defined(HAVE_SLANG_SLANG_H)
  20. # include <slang/slang.h>
  21. #else
  22. # include <slang.h>
  23. #endif
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #if defined(HAVE_SIGNAL_H)
  27. # include <signal.h>
  28. #endif
  29. #include "caca.h"
  30. #include "caca_internals.h"
  31. /*
  32. * Global variables
  33. */
  34. /* Tables generated by tools/optipal.c */
  35. static int const slang_palette[2*16*16] =
  36. {
  37. 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0,
  38. 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 0, 8,
  39. 8, 7, 7, 8, 15, 7, 7, 15, 15, 9, 9, 15, 1, 9, 9, 1,
  40. 7, 9, 9, 7, 8, 1, 1, 8, 0, 1, 15, 10, 10, 15, 2, 10,
  41. 10, 2, 7, 10, 10, 7, 8, 2, 2, 8, 0, 2, 15, 11, 11, 15,
  42. 3, 11, 11, 3, 7, 11, 11, 7, 8, 3, 3, 8, 0, 3, 15, 12,
  43. 12, 15, 4, 12, 12, 4, 7, 12, 12, 7, 8, 4, 4, 8, 0, 4,
  44. 15, 13, 13, 15, 5, 13, 13, 5, 7, 13, 13, 7, 8, 5, 5, 8,
  45. 0, 5, 15, 14, 14, 15, 6, 14, 14, 6, 7, 14, 14, 7, 8, 6,
  46. 6, 8, 0, 6, 4, 6, 6, 4, 12, 14, 14, 12, 6, 2, 2, 6,
  47. 14, 10, 10, 14, 2, 3, 3, 2, 10, 11, 11, 10, 3, 1, 1, 3,
  48. 11, 9, 9, 11, 1, 5, 5, 1, 9, 13, 13, 9, 5, 4, 4, 5,
  49. 13, 12, 12, 13, 4, 14, 6, 12, 12, 6, 14, 4, 6, 10, 2, 14,
  50. 14, 2, 10, 6, 2, 11, 3, 10, 10, 3, 11, 2, 3, 9, 1, 11,
  51. 11, 1, 9, 3, 1, 13, 5, 9, 9, 5, 13, 1, 5, 12, 4, 13,
  52. 13, 4, 12, 5, 0, 7, 0, 15, 15, 8, 8, 15, 15, 1, 7, 1,
  53. 1, 6, 2, 5, 3, 4, 4, 3, 5, 2, 6, 1, 0, 0, 1, 1,
  54. 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 2, 2, 3, 3,
  55. 4, 4, 5, 5, 6, 6, 7, 7, 14, 9, 1, 15, 8, 9, 8, 8,
  56. 9, 9, 1, 7, 0, 9, 9, 8, 6, 9, 13, 10, 2, 15, 8, 10,
  57. 7, 2, 15, 2, 2, 7, 0, 10, 10, 8, 5, 10, 12, 11, 3, 15,
  58. 8, 11, 7, 3, 15, 3, 3, 7, 0, 11, 11, 8, 4, 11, 11, 12,
  59. 4, 15, 8, 12, 7, 4, 15, 4, 4, 7, 0, 12, 12, 8, 3, 12,
  60. 10, 13, 5, 15, 8, 13, 7, 5, 15, 5, 5, 7, 0, 13, 13, 8,
  61. 2, 13, 9, 14, 6, 15, 8, 14, 7, 6, 15, 6, 6, 7, 0, 14,
  62. 14, 8, 1, 14, 5, 6, 2, 4, 13, 14, 10, 12, 4, 2, 3, 6,
  63. 12, 10, 11, 14, 6, 3, 1, 2, 14, 11, 9, 10, 2, 1, 5, 3,
  64. 10, 9, 13, 11, 3, 5, 4, 1, 11, 13, 12, 9, 1, 4, 6, 5,
  65. 9, 12, 14, 13, 5, 14, 2, 12, 13, 6, 10, 4, 4, 10, 3, 14,
  66. 12, 2, 11, 6, 6, 11, 1, 10, 14, 3, 9, 2, 2, 9, 5, 11,
  67. 10, 1, 13, 3, 3, 13, 4, 9, 11, 5, 12, 1, 1, 12, 6, 13,
  68. 9, 4, 14, 5, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15,
  69. };
  70. static int const slang_assoc[16*16] =
  71. {
  72. 134, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  73. 28, 135, 214, 86, 219, 91, 133, 127, 26, 23, 240, 112, 245, 117, 141, 126,
  74. 37, 211, 142, 83, 206, 132, 78, 160, 35, 237, 32, 109, 232, 140, 104, 161,
  75. 46, 87, 82, 143, 131, 215, 210, 169, 44, 113, 108, 41, 139, 241, 236, 170,
  76. 55, 222, 203, 130, 144, 94, 75, 178, 53, 248, 229, 138, 50, 120, 101, 179,
  77. 64, 90, 129, 218, 95, 145, 223, 187, 62, 116, 137, 244, 121, 59, 249, 188,
  78. 73, 128, 79, 207, 74, 202, 146, 196, 71, 136, 105, 233, 100, 228, 68, 197,
  79. 122, 153, 162, 171, 180, 189, 198, 147, 16, 25, 34, 43, 52, 61, 70, 18,
  80. 15, 27, 36, 45, 54, 63, 72, 17, 151, 155, 164, 173, 182, 191, 200, 124,
  81. 154, 22, 238, 110, 243, 115, 156, 24, 150, 152, 216, 88, 221, 93, 148, 20,
  82. 163, 235, 31, 107, 230, 165, 102, 33, 159, 213, 250, 85, 208, 157, 80, 29,
  83. 172, 111, 106, 40, 174, 239, 234, 42, 168, 89, 84, 251, 166, 217, 212, 38,
  84. 181, 246, 227, 183, 49, 118, 99, 51, 177, 224, 205, 175, 252, 96, 77, 47,
  85. 190, 114, 192, 242, 119, 58, 247, 60, 186, 92, 184, 220, 97, 253, 225, 56,
  86. 199, 201, 103, 231, 98, 226, 67, 69, 195, 193, 81, 209, 76, 204, 254, 65,
  87. 123, 149, 158, 167, 176, 185, 194, 19, 125, 21, 30, 39, 48, 57, 66, 255,
  88. };
  89. /*
  90. * Local functions
  91. */
  92. static void slang_init_palette(void);
  93. static void slang_write_utf32(uint32_t);
  94. #if defined(HAVE_SIGNAL)
  95. static RETSIGTYPE sigwinch_handler(int);
  96. static caca_display_t *sigwinch_d; /* FIXME: we ought to get rid of this */
  97. #endif
  98. #if defined(HAVE_GETENV) && defined(HAVE_PUTENV)
  99. static void slang_install_terminal(caca_display_t *);
  100. static void slang_uninstall_terminal(caca_display_t *);
  101. #endif
  102. struct driver_private
  103. {
  104. char *term;
  105. unsigned int sigint_event;
  106. };
  107. static void default_sigint (int sig)
  108. {
  109. /* Warn the caller that we got SIGINT. */
  110. sigwinch_d->drv.p->sigint_event++;
  111. }
  112. static int slang_init_graphics(caca_display_t *dp)
  113. {
  114. dp->drv.p = malloc(sizeof(struct driver_private));
  115. dp->drv.p->sigint_event = 0;
  116. #if defined(HAVE_GETENV) && defined(HAVE_PUTENV)
  117. slang_install_terminal(dp);
  118. #endif
  119. #if defined(HAVE_SIGNAL)
  120. sigwinch_d = dp;
  121. signal(SIGWINCH, sigwinch_handler);
  122. #endif
  123. _caca_set_term_title("caca for S-Lang");
  124. /* Initialise slang library */
  125. SLsig_block_signals();
  126. /* Disable SLang's own SIGINT on ctrl-c */
  127. SLang_set_abort_signal(default_sigint);
  128. SLtt_get_terminfo();
  129. if(SLkp_init() == -1)
  130. {
  131. SLsig_unblock_signals();
  132. return -1;
  133. }
  134. SLang_init_tty(-1, 0, 1);
  135. if(SLsmg_init_smg() == -1)
  136. {
  137. SLsig_unblock_signals();
  138. return -1;
  139. }
  140. SLsmg_cls();
  141. SLtt_set_cursor_visibility(0);
  142. SLkp_define_keysym("\e[M", 1001);
  143. SLtt_set_mouse_mode(1, 0);
  144. SLsmg_refresh();
  145. /* Disable scrolling so that hashmap scrolling optimization code
  146. * does not cause ugly refreshes due to slow terminals */
  147. SLtt_Term_Cannot_Scroll = 1;
  148. slang_init_palette();
  149. #if defined(VMS) || defined(REAL_UNIX_SYSTEM)
  150. /* Disable alt charset support so that we get a chance to have all
  151. * 256 colour pairs */
  152. SLtt_Has_Alt_Charset = 0;
  153. #endif
  154. #ifdef HAVE_SLSMG_UTF8_ENABLE
  155. SLsmg_utf8_enable(1); /* 1 == force, 0 == disable, -1 == autodetect */
  156. SLtt_utf8_enable(1);
  157. #endif
  158. caca_add_dirty_rect(dp->cv, 0, 0, dp->cv->width, dp->cv->height);
  159. dp->resize.allow = 1;
  160. caca_set_canvas_size(dp->cv, SLtt_Screen_Cols, SLtt_Screen_Rows);
  161. dp->resize.allow = 0;
  162. SLsig_unblock_signals();
  163. return 0;
  164. }
  165. static int slang_end_graphics(caca_display_t *dp)
  166. {
  167. _caca_set_term_title("");
  168. SLtt_set_mouse_mode(0, 0);
  169. SLtt_set_cursor_visibility(1);
  170. SLang_reset_tty();
  171. SLsig_block_signals();
  172. SLsmg_reset_smg();
  173. SLsig_unblock_signals();
  174. #if defined HAVE_GETENV && defined HAVE_PUTENV
  175. slang_uninstall_terminal(dp);
  176. #endif
  177. free(dp->drv.p);
  178. return 0;
  179. }
  180. static int slang_set_display_title(caca_display_t *dp, char const *title)
  181. {
  182. _caca_set_term_title(title);
  183. return 0;
  184. }
  185. static int slang_get_display_width(caca_display_t const *dp)
  186. {
  187. /* Fallback to a 6x10 font */
  188. return caca_get_canvas_width(dp->cv) * 6;
  189. }
  190. static int slang_get_display_height(caca_display_t const *dp)
  191. {
  192. /* Fallback to a 6x10 font */
  193. return caca_get_canvas_height(dp->cv) * 10;
  194. }
  195. static void slang_display(caca_display_t *dp)
  196. {
  197. int x, y, i;
  198. SLsig_block_signals();
  199. for(i = 0; i < caca_get_dirty_rect_count(dp->cv); i++)
  200. {
  201. uint32_t const *cvchars, *cvattrs;
  202. int dx, dy, dw, dh;
  203. caca_get_dirty_rect(dp->cv, i, &dx, &dy, &dw, &dh);
  204. cvchars = (uint32_t const *)caca_get_canvas_chars(dp->cv)
  205. + dx + dy * dp->cv->width;
  206. cvattrs = (uint32_t const *)caca_get_canvas_attrs(dp->cv)
  207. + dx + dy * dp->cv->width;
  208. for(y = dy; y < dy + dh; y++)
  209. {
  210. SLsmg_gotorc(y, dx);
  211. for(x = dx; x < dx + dw; x++)
  212. {
  213. uint32_t ch = *cvchars++;
  214. #if defined(OPTIMISE_SLANG_PALETTE)
  215. /* If foreground == background, just don't use this colour
  216. * pair, and print a space instead of the real character. */
  217. /* XXX: disabled, because I can't remember what it was
  218. * here for, and in cases where SLang does not render
  219. * bright backgrounds, it's just fucked up. */
  220. #if 0
  221. uint8_t fgcolor = caca_attr_to_ansi_fg(*cvattrs);
  222. uint8_t bgcolor = caca_attr_to_ansi_bg(*cvattrs);
  223. if(fgcolor >= 0x10)
  224. fgcolor = CACA_LIGHTGRAY;
  225. if(bgcolor >= 0x10)
  226. bgcolor = CACA_BLACK; /* FIXME: handle transparency */
  227. if(fgcolor == bgcolor)
  228. {
  229. if(fgcolor == CACA_BLACK)
  230. fgcolor = CACA_WHITE;
  231. else if(fgcolor == CACA_WHITE
  232. || fgcolor <= CACA_LIGHTGRAY)
  233. fgcolor = CACA_BLACK;
  234. else
  235. fgcolor = CACA_WHITE;
  236. SLsmg_set_color(slang_assoc[fgcolor + 16 * bgcolor]);
  237. SLsmg_write_char(' ');
  238. cvattrs++;
  239. }
  240. else
  241. #endif
  242. {
  243. SLsmg_set_color(slang_assoc[caca_attr_to_ansi(*cvattrs++)]);
  244. slang_write_utf32(ch);
  245. }
  246. #else
  247. SLsmg_set_color(caca_attr_to_ansi(*cvattrs++));
  248. slang_write_utf32(ch);
  249. #endif
  250. }
  251. cvchars += dp->cv->width - dw;
  252. cvattrs += dp->cv->width - dw;
  253. }
  254. }
  255. SLsmg_gotorc(caca_wherey(dp->cv), caca_wherex(dp->cv));
  256. SLsmg_refresh();
  257. SLsig_unblock_signals();
  258. }
  259. static void slang_handle_resize(caca_display_t *dp)
  260. {
  261. SLtt_get_screen_size();
  262. dp->resize.w = SLtt_Screen_Cols;
  263. dp->resize.h = SLtt_Screen_Rows;
  264. SLsig_block_signals();
  265. if(dp->resize.w != caca_get_canvas_width(dp->cv)
  266. || dp->resize.h != caca_get_canvas_height(dp->cv))
  267. SLsmg_reinit_smg();
  268. SLsig_unblock_signals();
  269. }
  270. static int slang_get_event(caca_display_t *dp, caca_privevent_t *ev)
  271. {
  272. int intkey;
  273. /* If SIGINT was caught, we pass it to the application as Ctrl-C. */
  274. if(dp->drv.p->sigint_event > 0)
  275. {
  276. ev->type = CACA_EVENT_KEY_PRESS;
  277. ev->data.key.ch = CACA_KEY_CTRL_C;
  278. ev->data.key.utf32 = 0x03;
  279. ev->data.key.utf8[0] = 0x03;
  280. ev->data.key.utf8[1] = 0;
  281. dp->drv.p->sigint_event--;
  282. return 1;
  283. }
  284. if(!SLang_input_pending(0))
  285. {
  286. ev->type = CACA_EVENT_NONE;
  287. return 0;
  288. }
  289. /* We first use SLang_getkey() to see whether Esc was pressed
  290. * alone, then (if it wasn't) we unget the key and use SLkp_getkey()
  291. * instead, so that escape sequences are interpreted. */
  292. intkey = SLang_getkey();
  293. if(intkey != 0x1b /* Esc */ || SLang_input_pending(0))
  294. {
  295. SLang_ungetkey(intkey);
  296. intkey = SLkp_getkey();
  297. }
  298. /* If the key was ASCII, return it immediately */
  299. if(intkey < 0x7f)
  300. {
  301. ev->type = CACA_EVENT_KEY_PRESS;
  302. ev->data.key.ch = intkey;
  303. ev->data.key.utf32 = intkey;
  304. ev->data.key.utf8[0] = intkey;
  305. ev->data.key.utf8[1] = '\0';
  306. return 1;
  307. }
  308. /* If the key was UTF-8, parse the whole sequence */
  309. if(intkey >= 0x80 && intkey < 0x100)
  310. {
  311. int keys[7]; /* Necessary for ungetkey(); */
  312. char utf8[7];
  313. uint32_t utf32;
  314. size_t i, bytes = 0;
  315. keys[0] = intkey;
  316. utf8[0] = intkey;
  317. for(i = 1; i < 6; i++)
  318. {
  319. if(!SLang_input_pending(0))
  320. break;
  321. keys[i] = SLang_getkey();
  322. utf8[i] = (unsigned char)keys[i];
  323. }
  324. utf8[i] = '\0';
  325. utf32 = caca_utf8_to_utf32(utf8, &bytes);
  326. while(i > bytes)
  327. SLang_ungetkey(keys[--i]);
  328. if(bytes)
  329. {
  330. ev->type = CACA_EVENT_KEY_PRESS;
  331. ev->data.key.ch = 0;
  332. ev->data.key.utf32 = utf32;
  333. strcpy(ev->data.key.utf8, utf8);
  334. return 1;
  335. }
  336. }
  337. if(intkey == 0x3e9)
  338. {
  339. int button = (SLang_getkey() - ' ' + 1) & 0xf;
  340. int x = SLang_getkey() - '!';
  341. int y = SLang_getkey() - '!';
  342. ev->data.mouse.button = button;
  343. ev->type = CACA_EVENT_MOUSE_PRESS;
  344. _push_event(dp, ev);
  345. ev->type = CACA_EVENT_MOUSE_RELEASE;
  346. _push_event(dp, ev);
  347. if(dp->mouse.x == x && dp->mouse.y == y)
  348. return _pop_event(dp, ev);
  349. dp->mouse.x = x;
  350. dp->mouse.y = y;
  351. ev->type = CACA_EVENT_MOUSE_MOTION;
  352. ev->data.mouse.x = dp->mouse.x;
  353. ev->data.mouse.y = dp->mouse.y;
  354. return 1;
  355. }
  356. switch(intkey)
  357. {
  358. case SL_KEY_UP: ev->data.key.ch = CACA_KEY_UP; break;
  359. case SL_KEY_DOWN: ev->data.key.ch = CACA_KEY_DOWN; break;
  360. case SL_KEY_LEFT: ev->data.key.ch = CACA_KEY_LEFT; break;
  361. case SL_KEY_RIGHT: ev->data.key.ch = CACA_KEY_RIGHT; break;
  362. case SL_KEY_IC: ev->data.key.ch = CACA_KEY_INSERT; break;
  363. case SL_KEY_DELETE: ev->data.key.ch = CACA_KEY_DELETE; break;
  364. case 0x7f:
  365. case SL_KEY_BACKSPACE: ev->data.key.ch = CACA_KEY_BACKSPACE; break;
  366. case SL_KEY_HOME: ev->data.key.ch = CACA_KEY_HOME; break;
  367. case SL_KEY_END: ev->data.key.ch = CACA_KEY_END; break;
  368. case SL_KEY_PPAGE: ev->data.key.ch = CACA_KEY_PAGEUP; break;
  369. case SL_KEY_NPAGE: ev->data.key.ch = CACA_KEY_PAGEDOWN; break;
  370. case SL_KEY_F(1): ev->data.key.ch = CACA_KEY_F1; break;
  371. case SL_KEY_F(2): ev->data.key.ch = CACA_KEY_F2; break;
  372. case SL_KEY_F(3): ev->data.key.ch = CACA_KEY_F3; break;
  373. case SL_KEY_F(4): ev->data.key.ch = CACA_KEY_F4; break;
  374. case SL_KEY_F(5): ev->data.key.ch = CACA_KEY_F5; break;
  375. case SL_KEY_F(6): ev->data.key.ch = CACA_KEY_F6; break;
  376. case SL_KEY_F(7): ev->data.key.ch = CACA_KEY_F7; break;
  377. case SL_KEY_F(8): ev->data.key.ch = CACA_KEY_F8; break;
  378. case SL_KEY_F(9): ev->data.key.ch = CACA_KEY_F9; break;
  379. case SL_KEY_F(10): ev->data.key.ch = CACA_KEY_F10; break;
  380. case SL_KEY_F(11): ev->data.key.ch = CACA_KEY_F11; break;
  381. case SL_KEY_F(12): ev->data.key.ch = CACA_KEY_F12; break;
  382. default:
  383. /* Unknown key */
  384. ev->type = CACA_EVENT_NONE; return 0;
  385. }
  386. ev->type = CACA_EVENT_KEY_PRESS;
  387. ev->data.key.utf32 = 0;
  388. ev->data.key.utf8[0] = '\0';
  389. return 1;
  390. }
  391. static void slang_set_cursor(caca_display_t *dp, int flags)
  392. {
  393. SLtt_set_cursor_visibility(flags ? 1 : 0);
  394. }
  395. /*
  396. * XXX: following functions are local
  397. */
  398. static void slang_init_palette(void)
  399. {
  400. /* See SLang ref., 5.4.4. */
  401. static char *slang_colors[16] =
  402. {
  403. /* Standard colours */
  404. "black",
  405. "blue",
  406. "green",
  407. "cyan",
  408. "red",
  409. "magenta",
  410. "brown",
  411. "lightgray",
  412. /* Bright colours */
  413. "gray",
  414. "brightblue",
  415. "brightgreen",
  416. "brightcyan",
  417. "brightred",
  418. "brightmagenta",
  419. "yellow",
  420. "white",
  421. };
  422. #if defined(OPTIMISE_SLANG_PALETTE)
  423. int i;
  424. for(i = 0; i < 16 * 16; i++)
  425. SLtt_set_color(i, NULL, slang_colors[slang_palette[i * 2]],
  426. slang_colors[slang_palette[i * 2 + 1]]);
  427. #else
  428. int fg, bg;
  429. for(bg = 0; bg < 16; bg++)
  430. for(fg = 0; fg < 16; fg++)
  431. {
  432. int i = fg + 16 * bg;
  433. SLtt_set_color(i, NULL, slang_colors[fg], slang_colors[bg]);
  434. }
  435. #endif
  436. }
  437. static void slang_write_utf32(uint32_t ch)
  438. {
  439. #ifdef HAVE_SLSMG_UTF8_ENABLE
  440. char buf[10];
  441. int bytes;
  442. #else
  443. char ascii;
  444. #endif
  445. if(ch == CACA_MAGIC_FULLWIDTH)
  446. return;
  447. #ifdef HAVE_SLSMG_UTF8_ENABLE
  448. bytes = caca_utf32_to_utf8(buf, ch);
  449. buf[bytes] = '\0';
  450. SLsmg_write_string(buf);
  451. #else
  452. ascii = caca_utf32_to_ascii(ch);
  453. SLsmg_write_char(ascii);
  454. if(caca_utf32_is_fullwidth(ch))
  455. SLsmg_write_char(ascii);
  456. #endif
  457. }
  458. #if defined(HAVE_SIGNAL)
  459. static RETSIGTYPE sigwinch_handler(int sig)
  460. {
  461. sigwinch_d->resize.resized = 1;
  462. signal(SIGWINCH, sigwinch_handler);
  463. }
  464. #endif
  465. #if defined(HAVE_GETENV) && defined(HAVE_PUTENV)
  466. static void slang_install_terminal(caca_display_t *dp)
  467. {
  468. char *term, *colorterm;
  469. dp->drv.p->term = NULL;
  470. term = getenv("TERM");
  471. colorterm = getenv("COLORTERM");
  472. if(!term || strcmp(term, "xterm"))
  473. return;
  474. /* If we are using gnome-terminal, it's really a 16 colour terminal.
  475. * Ditto if we are using xfce4-terminal, or Konsole. */
  476. if((colorterm && (!strcmp(colorterm, "gnome-terminal")
  477. || !strcmp(colorterm, "Terminal")))
  478. || getenv("KONSOLE_DCOP_SESSION"))
  479. {
  480. (void)putenv("TERM=xterm-16color");
  481. dp->drv.p->term = strdup(term);
  482. return;
  483. }
  484. }
  485. static void slang_uninstall_terminal(caca_display_t *dp)
  486. {
  487. /* Needs to be persistent because we use putenv() */
  488. static char termenv[1024];
  489. if(!dp->drv.p->term)
  490. return;
  491. snprintf(termenv, 1023, "TERM=%s", dp->drv.p->term);
  492. free(dp->drv.p->term);
  493. (void)putenv(termenv);
  494. }
  495. #endif
  496. /*
  497. * Driver initialisation
  498. */
  499. int slang_install(caca_display_t *dp)
  500. {
  501. dp->drv.id = CACA_DRIVER_SLANG;
  502. dp->drv.driver = "slang";
  503. dp->drv.init_graphics = slang_init_graphics;
  504. dp->drv.end_graphics = slang_end_graphics;
  505. dp->drv.set_display_title = slang_set_display_title;
  506. dp->drv.get_display_width = slang_get_display_width;
  507. dp->drv.get_display_height = slang_get_display_height;
  508. dp->drv.display = slang_display;
  509. dp->drv.handle_resize = slang_handle_resize;
  510. dp->drv.get_event = slang_get_event;
  511. dp->drv.set_mouse = NULL;
  512. dp->drv.set_cursor = slang_set_cursor;
  513. return 0;
  514. }
  515. #endif /* USE_SLANG */