You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

610 lines
18 KiB

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