tty-slang.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. /*
  2. Interface to the terminal controlling library.
  3. Slang wrapper.
  4. Copyright (C) 2005-2024
  5. Free Software Foundation, Inc.
  6. Written by:
  7. Andrew Borodin <aborodin@vmail.ru>, 2009
  8. Egmont Koblinger <egmont@gmail.com>, 2010
  9. This file is part of the Midnight Commander.
  10. The Midnight Commander is free software: you can redistribute it
  11. and/or modify it under the terms of the GNU General Public License as
  12. published by the Free Software Foundation, either version 3 of the License,
  13. or (at your option) any later version.
  14. The Midnight Commander is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU General Public License for more details.
  18. You should have received a copy of the GNU General Public License
  19. along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /** \file
  22. * \brief Source: S-Lang-based tty layer of Midnight Commander
  23. */
  24. #include <config.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <sys/types.h> /* size_t */
  29. #include <unistd.h>
  30. #ifdef HAVE_SYS_IOCTL_H
  31. #include <sys/ioctl.h>
  32. #endif
  33. #include <termios.h>
  34. #include "lib/global.h"
  35. #include "lib/strutil.h" /* str_term_form */
  36. #include "lib/util.h" /* is_printable() */
  37. #include "tty-internal.h" /* mc_tty_normalize_from_utf8() */
  38. #include "tty.h"
  39. #include "color.h"
  40. #include "color-slang.h"
  41. #include "color-internal.h"
  42. #include "mouse.h" /* Gpm_Event is required in key.h */
  43. #include "key.h" /* define_sequence */
  44. #include "win.h"
  45. /*** global variables ****************************************************************************/
  46. /* If true program softkeys (HP terminals only) on startup and after every
  47. command ran in the subshell to the description found in the termcap/terminfo
  48. database */
  49. int reset_hp_softkeys = 0;
  50. /*** file scope macro definitions ****************************************************************/
  51. #ifndef SLTT_MAX_SCREEN_COLS
  52. #define SLTT_MAX_SCREEN_COLS 512
  53. #endif
  54. #ifndef SLTT_MAX_SCREEN_ROWS
  55. #define SLTT_MAX_SCREEN_ROWS 512
  56. #endif
  57. /*** file scope type declarations ****************************************************************/
  58. /*** forward declarations (file scope functions) *************************************************/
  59. /*** file scope variables ************************************************************************/
  60. /* Various saved termios settings that we control here */
  61. static struct termios boot_mode;
  62. static struct termios new_mode;
  63. /* Controls whether we should wait for input in tty_lowlevel_getch */
  64. static gboolean no_slang_delay;
  65. static gboolean slsmg_active = FALSE;
  66. /* This table describes which capabilities we want and which values we
  67. * assign to them.
  68. */
  69. static const struct
  70. {
  71. int key_code;
  72. const char *key_name;
  73. } key_table[] = {
  74. /* *INDENT-OFF* */
  75. { KEY_F (0), "k0" }, { KEY_F (1), "k1" }, { KEY_F (2), "k2" }, { KEY_F (3), "k3" },
  76. { KEY_F (4), "k4" }, { KEY_F (5), "k5" }, { KEY_F (6), "k6" }, { KEY_F (7), "k7" },
  77. { KEY_F (8), "k8" }, { KEY_F (9), "k9" }, { KEY_F (10), "k;" }, { KEY_F (11), "F1" },
  78. { KEY_F (12), "F2" }, { KEY_F (13), "F3" }, { KEY_F (14), "F4" }, { KEY_F (15), "F5" },
  79. { KEY_F (16), "F6" }, { KEY_F (17), "F7" }, { KEY_F (18), "F8" }, { KEY_F (19), "F9" },
  80. { KEY_F (20), "FA" }, { KEY_IC, "kI" }, { KEY_NPAGE, "kN" }, { KEY_PPAGE, "kP" },
  81. { KEY_LEFT, "kl" }, { KEY_RIGHT, "kr" }, { KEY_UP, "ku" }, { KEY_DOWN, "kd" },
  82. { KEY_DC, "kD" }, { KEY_BACKSPACE, "kb" }, { KEY_HOME, "kh" }, { KEY_END, "@7" },
  83. { 0, NULL }
  84. /* *INDENT-ON* */
  85. };
  86. /* --------------------------------------------------------------------------------------------- */
  87. /*** file scope functions ************************************************************************/
  88. /* --------------------------------------------------------------------------------------------- */
  89. static void
  90. tty_setup_sigwinch (void (*handler) (int))
  91. {
  92. (void) SLsignal (SIGWINCH, handler);
  93. tty_create_winch_pipe ();
  94. }
  95. /* --------------------------------------------------------------------------------------------- */
  96. static void
  97. sigwinch_handler (int dummy)
  98. {
  99. ssize_t n = 0;
  100. (void) dummy;
  101. n = write (sigwinch_pipe[1], "", 1);
  102. (void) n;
  103. (void) SLsignal (SIGWINCH, sigwinch_handler);
  104. }
  105. /* --------------------------------------------------------------------------------------------- */
  106. /* HP Terminals have capabilities (pfkey, pfloc, pfx) to program function keys.
  107. elm 2.4pl15 invoked with the -K option utilizes these softkeys and the
  108. consequence is that function keys don't work in MC sometimes...
  109. Unfortunately I don't now the one and only escape sequence to turn off.
  110. softkeys (elm uses three different capabilities to turn on softkeys and two.
  111. capabilities to turn them off)..
  112. Among other things elm uses the pair we already use in slang_keypad. That's.
  113. the reason why I call slang_reset_softkeys from slang_keypad. In lack of
  114. something better the softkeys are programmed to their defaults from the
  115. termcap/terminfo database.
  116. The escape sequence to program the softkeys is taken from elm and it is.
  117. hardcoded because neither slang nor ncurses 4.1 know how to 'printf' this.
  118. sequence. -- Norbert
  119. */
  120. static void
  121. slang_reset_softkeys (void)
  122. {
  123. int key;
  124. static const char display[] = " ";
  125. char tmp[BUF_SMALL];
  126. for (key = 1; key < 9; key++)
  127. {
  128. char *send;
  129. g_snprintf (tmp, sizeof (tmp), "k%d", key);
  130. send = SLtt_tgetstr (tmp);
  131. if (send != NULL)
  132. {
  133. g_snprintf (tmp, sizeof (tmp), ESC_STR "&f%dk%dd%dL%s%s", key,
  134. (int) (sizeof (display) - 1), (int) strlen (send), display, send);
  135. SLtt_write_string (tmp);
  136. }
  137. }
  138. }
  139. /* --------------------------------------------------------------------------------------------- */
  140. static void
  141. do_define_key (int code, const char *strcap)
  142. {
  143. char *seq;
  144. seq = SLtt_tgetstr ((SLFUTURE_CONST char *) strcap);
  145. if (seq != NULL)
  146. define_sequence (code, seq, MCKEY_NOACTION);
  147. }
  148. /* --------------------------------------------------------------------------------------------- */
  149. static void
  150. load_terminfo_keys (void)
  151. {
  152. int i;
  153. for (i = 0; key_table[i].key_code; i++)
  154. do_define_key (key_table[i].key_code, key_table[i].key_name);
  155. }
  156. /* --------------------------------------------------------------------------------------------- */
  157. /*** public functions ****************************************************************************/
  158. /* --------------------------------------------------------------------------------------------- */
  159. int
  160. mc_tty_normalize_lines_char (const char *str)
  161. {
  162. char *str2;
  163. int res;
  164. struct mc_tty_lines_struct
  165. {
  166. const char *line;
  167. int line_code;
  168. } const lines_codes[] = { { "\342\224\214", SLSMG_ULCORN_CHAR },
  169. { "\342\224\220", SLSMG_URCORN_CHAR },
  170. { "\342\224\224", SLSMG_LLCORN_CHAR },
  171. { "\342\224\230", SLSMG_LRCORN_CHAR },
  172. { "\342\224\234", SLSMG_LTEE_CHAR },
  173. { "\342\224\244", SLSMG_RTEE_CHAR },
  174. { "\342\224\254", SLSMG_UTEE_CHAR },
  175. { "\342\224\264", SLSMG_DTEE_CHAR },
  176. { "\342\224\200", SLSMG_HLINE_CHAR },
  177. { "\342\224\202", SLSMG_VLINE_CHAR },
  178. { "\342\224\274", SLSMG_PLUS_CHAR },
  179. { NULL, 0 } };
  180. if (!str)
  181. return (int) ' ';
  182. for (res = 0; lines_codes[res].line; res++)
  183. {
  184. if (strcmp (str, lines_codes[res].line) == 0)
  185. return lines_codes[res].line_code;
  186. }
  187. str2 = mc_tty_normalize_from_utf8 (str);
  188. res = g_utf8_get_char_validated (str2, -1);
  189. if (res < 0)
  190. res = (unsigned char) str2[0];
  191. g_free (str2);
  192. return res;
  193. }
  194. /* --------------------------------------------------------------------------------------------- */
  195. void
  196. tty_init (gboolean mouse_enable, gboolean is_xterm)
  197. {
  198. SLtt_Ignore_Beep = 1;
  199. SLutf8_enable (-1); /* has to be called first before any of the other functions. */
  200. SLtt_get_terminfo ();
  201. /*
  202. * If the terminal in not in terminfo but begins with a well-known
  203. * string such as "linux" or "xterm" S-Lang will go on, but the
  204. * terminal size and several other variables won't be initialized
  205. * (as of S-Lang 1.4.4). Detect it and abort. Also detect extremely
  206. * small screen dimensions.
  207. */
  208. if ((COLS < 10)
  209. || (LINES < 5)
  210. #if SLANG_VERSION < 20303
  211. /* Beginning from pre2.3.3-8 (55f58798c267d76a1b93d0d916027b71a10ac1ee),
  212. these limitations were eliminated. */
  213. || (COLS > SLTT_MAX_SCREEN_COLS) || (LINES > SLTT_MAX_SCREEN_ROWS)
  214. #endif
  215. )
  216. {
  217. fprintf (stderr,
  218. _ ("Screen size %dx%d is not supported.\n"
  219. "Check the TERM environment variable.\n"),
  220. COLS, LINES);
  221. exit (EXIT_FAILURE);
  222. }
  223. tcgetattr (fileno (stdin), &boot_mode);
  224. /* 255 = ignore abort char; XCTRL('g') for abort char = ^g */
  225. SLang_init_tty (XCTRL ('g'), 1, 0);
  226. if (mc_global.tty.ugly_line_drawing)
  227. SLtt_Has_Alt_Charset = 0;
  228. tcgetattr (SLang_TT_Read_FD, &new_mode);
  229. tty_reset_prog_mode ();
  230. load_terminfo_keys ();
  231. SLtt_Blink_Mode = (tty_use_256colors (NULL) || tty_use_truecolors (NULL)) ? 1 : 0;
  232. tty_start_interrupt_key ();
  233. /* It's the small part from the previous init_key() */
  234. init_key_input_fd ();
  235. /* For 8-bit locales, NCurses handles 154 (0x9A) symbol properly, while S-Lang
  236. * requires SLsmg_Display_Eight_Bit >= 154 (OR manual filtering if xterm display
  237. * detected - but checking TERM would fail under screen, OR running xterm
  238. * with allowC1Printable).
  239. */
  240. tty_display_8bit (FALSE);
  241. SLsmg_init_smg ();
  242. slsmg_active = TRUE;
  243. if (!mouse_enable)
  244. use_mouse_p = MOUSE_DISABLED;
  245. tty_init_xterm_support (is_xterm); /* do it before tty_enter_ca_mode() call */
  246. tty_enter_ca_mode ();
  247. tty_keypad (TRUE);
  248. tty_nodelay (FALSE);
  249. tty_setup_sigwinch (sigwinch_handler);
  250. }
  251. /* --------------------------------------------------------------------------------------------- */
  252. void
  253. tty_shutdown (void)
  254. {
  255. char *op_cap;
  256. tty_destroy_winch_pipe ();
  257. tty_reset_shell_mode ();
  258. tty_noraw_mode ();
  259. tty_keypad (FALSE);
  260. tty_reset_screen ();
  261. tty_exit_ca_mode ();
  262. SLang_reset_tty ();
  263. slsmg_active = FALSE;
  264. /* Load the op capability to reset the colors to those that were
  265. * active when the program was started up
  266. */
  267. op_cap = SLtt_tgetstr ((SLFUTURE_CONST char *) "op");
  268. if (op_cap != NULL)
  269. {
  270. fputs (op_cap, stdout);
  271. fflush (stdout);
  272. }
  273. }
  274. /* --------------------------------------------------------------------------------------------- */
  275. void
  276. tty_enter_ca_mode (void)
  277. {
  278. /* S-Lang handles alternate screen switching and cursor position saving */
  279. }
  280. /* --------------------------------------------------------------------------------------------- */
  281. void
  282. tty_exit_ca_mode (void)
  283. {
  284. /* S-Lang handles alternate screen switching and cursor position restoring */
  285. }
  286. /* --------------------------------------------------------------------------------------------- */
  287. void
  288. tty_change_screen_size (void)
  289. {
  290. SLtt_get_screen_size ();
  291. if (slsmg_active)
  292. SLsmg_reinit_smg ();
  293. #ifdef ENABLE_SUBSHELL
  294. if (mc_global.tty.use_subshell)
  295. tty_resize (mc_global.tty.subshell_pty);
  296. #endif
  297. }
  298. /* --------------------------------------------------------------------------------------------- */
  299. /* Done each time we come back from done mode */
  300. void
  301. tty_reset_prog_mode (void)
  302. {
  303. tcsetattr (SLang_TT_Read_FD, TCSANOW, &new_mode);
  304. SLsmg_init_smg ();
  305. slsmg_active = TRUE;
  306. SLsmg_touch_lines (0, LINES);
  307. }
  308. /* --------------------------------------------------------------------------------------------- */
  309. /* Called each time we want to shutdown slang screen manager */
  310. void
  311. tty_reset_shell_mode (void)
  312. {
  313. tcsetattr (SLang_TT_Read_FD, TCSANOW, &boot_mode);
  314. }
  315. /* --------------------------------------------------------------------------------------------- */
  316. void
  317. tty_raw_mode (void)
  318. {
  319. tcsetattr (SLang_TT_Read_FD, TCSANOW, &new_mode);
  320. }
  321. /* --------------------------------------------------------------------------------------------- */
  322. void
  323. tty_noraw_mode (void)
  324. {
  325. }
  326. /* --------------------------------------------------------------------------------------------- */
  327. void
  328. tty_noecho (void)
  329. {
  330. }
  331. /* --------------------------------------------------------------------------------------------- */
  332. int
  333. tty_flush_input (void)
  334. {
  335. return 0; /* OK */
  336. }
  337. /* --------------------------------------------------------------------------------------------- */
  338. void
  339. tty_keypad (gboolean set)
  340. {
  341. char *keypad_string;
  342. keypad_string = SLtt_tgetstr ((SLFUTURE_CONST char *) (set ? "ks" : "ke"));
  343. if (keypad_string != NULL)
  344. SLtt_write_string (keypad_string);
  345. if (set && reset_hp_softkeys)
  346. slang_reset_softkeys ();
  347. }
  348. /* --------------------------------------------------------------------------------------------- */
  349. void
  350. tty_nodelay (gboolean set)
  351. {
  352. no_slang_delay = set;
  353. }
  354. /* --------------------------------------------------------------------------------------------- */
  355. int
  356. tty_baudrate (void)
  357. {
  358. return SLang_TT_Baud_Rate;
  359. }
  360. /* --------------------------------------------------------------------------------------------- */
  361. int
  362. tty_lowlevel_getch (void)
  363. {
  364. int c;
  365. if (no_slang_delay && (SLang_input_pending (0) == 0))
  366. return -1;
  367. c = SLang_getkey ();
  368. if (c == SLANG_GETKEY_ERROR)
  369. {
  370. fprintf (stderr,
  371. "SLang_getkey returned SLANG_GETKEY_ERROR\n"
  372. "Assuming EOF on stdin and exiting\n");
  373. exit (EXIT_FAILURE);
  374. }
  375. return c;
  376. }
  377. /* --------------------------------------------------------------------------------------------- */
  378. int
  379. tty_reset_screen (void)
  380. {
  381. SLsmg_reset_smg ();
  382. slsmg_active = FALSE;
  383. return 0; /* OK */
  384. }
  385. /* --------------------------------------------------------------------------------------------- */
  386. void
  387. tty_touch_screen (void)
  388. {
  389. SLsmg_touch_lines (0, LINES);
  390. }
  391. /* --------------------------------------------------------------------------------------------- */
  392. void
  393. tty_gotoyx (int y, int x)
  394. {
  395. SLsmg_gotorc (y, x);
  396. }
  397. /* --------------------------------------------------------------------------------------------- */
  398. void
  399. tty_getyx (int *py, int *px)
  400. {
  401. *py = SLsmg_get_row ();
  402. *px = SLsmg_get_column ();
  403. }
  404. /* --------------------------------------------------------------------------------------------- */
  405. void
  406. tty_draw_hline (int y, int x, int ch, int len)
  407. {
  408. int x1;
  409. if (y < 0 || y >= LINES || x >= COLS)
  410. return;
  411. x1 = x;
  412. if (x < 0)
  413. {
  414. len += x;
  415. if (len <= 0)
  416. return;
  417. x = 0;
  418. }
  419. if (ch == ACS_HLINE)
  420. ch = mc_tty_frm[MC_TTY_FRM_HORIZ];
  421. if (ch == 0)
  422. ch = ACS_HLINE;
  423. SLsmg_gotorc (y, x);
  424. if (ch == ACS_HLINE)
  425. SLsmg_draw_hline (len);
  426. else
  427. while (len-- != 0)
  428. tty_print_char (ch);
  429. SLsmg_gotorc (y, x1);
  430. }
  431. /* --------------------------------------------------------------------------------------------- */
  432. void
  433. tty_draw_vline (int y, int x, int ch, int len)
  434. {
  435. int y1;
  436. if (x < 0 || x >= COLS || y >= LINES)
  437. return;
  438. y1 = y;
  439. if (y < 0)
  440. {
  441. len += y;
  442. if (len <= 0)
  443. return;
  444. y = 0;
  445. }
  446. if (ch == ACS_VLINE)
  447. ch = mc_tty_frm[MC_TTY_FRM_VERT];
  448. if (ch == 0)
  449. ch = ACS_VLINE;
  450. SLsmg_gotorc (y, x);
  451. if (ch == ACS_VLINE)
  452. SLsmg_draw_vline (len);
  453. else
  454. {
  455. int pos = 0;
  456. while (len-- != 0)
  457. {
  458. SLsmg_gotorc (y + pos, x);
  459. tty_print_char (ch);
  460. pos++;
  461. }
  462. }
  463. SLsmg_gotorc (y1, x);
  464. }
  465. /* --------------------------------------------------------------------------------------------- */
  466. void
  467. tty_fill_region (int y, int x, int rows, int cols, unsigned char ch)
  468. {
  469. SLsmg_fill_region (y, x, rows, cols, ch);
  470. }
  471. /* --------------------------------------------------------------------------------------------- */
  472. void
  473. tty_colorize_area (int y, int x, int rows, int cols, int color)
  474. {
  475. if (use_colors)
  476. SLsmg_set_color_in_region (color, y, x, rows, cols);
  477. }
  478. /* --------------------------------------------------------------------------------------------- */
  479. void
  480. tty_set_alt_charset (gboolean alt_charset)
  481. {
  482. SLsmg_set_char_set ((int) alt_charset);
  483. }
  484. /* --------------------------------------------------------------------------------------------- */
  485. void
  486. tty_display_8bit (gboolean what)
  487. {
  488. SLsmg_Display_Eight_Bit = what ? 128 : 160;
  489. }
  490. /* --------------------------------------------------------------------------------------------- */
  491. void
  492. tty_print_char (int c)
  493. {
  494. SLsmg_write_char ((SLwchar_Type) ((unsigned int) c));
  495. }
  496. /* --------------------------------------------------------------------------------------------- */
  497. void
  498. tty_print_alt_char (int c, gboolean single)
  499. {
  500. #define DRAW(x, y) \
  501. (x == y) ? SLsmg_draw_object (SLsmg_get_row (), SLsmg_get_column (), x) \
  502. : SLsmg_write_char ((unsigned int) y)
  503. switch (c)
  504. {
  505. case ACS_VLINE:
  506. DRAW (c, mc_tty_frm[single ? MC_TTY_FRM_VERT : MC_TTY_FRM_DVERT]);
  507. break;
  508. case ACS_HLINE:
  509. DRAW (c, mc_tty_frm[single ? MC_TTY_FRM_HORIZ : MC_TTY_FRM_DHORIZ]);
  510. break;
  511. case ACS_LTEE:
  512. DRAW (c, mc_tty_frm[single ? MC_TTY_FRM_LEFTMIDDLE : MC_TTY_FRM_DLEFTMIDDLE]);
  513. break;
  514. case ACS_RTEE:
  515. DRAW (c, mc_tty_frm[single ? MC_TTY_FRM_RIGHTMIDDLE : MC_TTY_FRM_DRIGHTMIDDLE]);
  516. break;
  517. case ACS_TTEE:
  518. DRAW (c, mc_tty_frm[single ? MC_TTY_FRM_TOPMIDDLE : MC_TTY_FRM_DTOPMIDDLE]);
  519. break;
  520. case ACS_BTEE:
  521. DRAW (c, mc_tty_frm[single ? MC_TTY_FRM_BOTTOMMIDDLE : MC_TTY_FRM_DBOTTOMMIDDLE]);
  522. break;
  523. case ACS_ULCORNER:
  524. DRAW (c, mc_tty_frm[single ? MC_TTY_FRM_LEFTTOP : MC_TTY_FRM_DLEFTTOP]);
  525. break;
  526. case ACS_LLCORNER:
  527. DRAW (c, mc_tty_frm[single ? MC_TTY_FRM_LEFTBOTTOM : MC_TTY_FRM_DLEFTBOTTOM]);
  528. break;
  529. case ACS_URCORNER:
  530. DRAW (c, mc_tty_frm[single ? MC_TTY_FRM_RIGHTTOP : MC_TTY_FRM_DRIGHTTOP]);
  531. break;
  532. case ACS_LRCORNER:
  533. DRAW (c, mc_tty_frm[single ? MC_TTY_FRM_RIGHTBOTTOM : MC_TTY_FRM_DRIGHTBOTTOM]);
  534. break;
  535. case ACS_PLUS:
  536. DRAW (c, mc_tty_frm[MC_TTY_FRM_CROSS]);
  537. break;
  538. default:
  539. SLsmg_write_char ((unsigned int) c);
  540. }
  541. #undef DRAW
  542. }
  543. /* --------------------------------------------------------------------------------------------- */
  544. void
  545. tty_print_anychar (int c)
  546. {
  547. if (c > 255)
  548. {
  549. char str[UTF8_CHAR_LEN + 1];
  550. int res;
  551. res = g_unichar_to_utf8 (c, str);
  552. if (res == 0)
  553. {
  554. str[0] = '.';
  555. str[1] = '\0';
  556. }
  557. else
  558. {
  559. str[res] = '\0';
  560. }
  561. SLsmg_write_string ((char *) str_term_form (str));
  562. }
  563. else
  564. {
  565. if (!is_printable (c))
  566. c = '.';
  567. SLsmg_write_char ((SLwchar_Type) ((unsigned int) c));
  568. }
  569. }
  570. /* --------------------------------------------------------------------------------------------- */
  571. void
  572. tty_print_string (const char *s)
  573. {
  574. SLsmg_write_string ((char *) str_term_form (s));
  575. }
  576. /* --------------------------------------------------------------------------------------------- */
  577. void
  578. tty_printf (const char *fmt, ...)
  579. {
  580. va_list args;
  581. va_start (args, fmt);
  582. SLsmg_vprintf ((char *) fmt, args);
  583. va_end (args);
  584. }
  585. /* --------------------------------------------------------------------------------------------- */
  586. char *
  587. tty_tgetstr (const char *cap)
  588. {
  589. return SLtt_tgetstr ((SLFUTURE_CONST char *) cap);
  590. }
  591. /* --------------------------------------------------------------------------------------------- */
  592. void
  593. tty_refresh (void)
  594. {
  595. SLsmg_refresh ();
  596. }
  597. /* --------------------------------------------------------------------------------------------- */
  598. void
  599. tty_beep (void)
  600. {
  601. SLtt_beep ();
  602. }
  603. /* --------------------------------------------------------------------------------------------- */