slint_pc.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /* Slang interface to the Midnight Commander for Win32
  2. This emulates some features of ncurses on top of slang
  3. S-lang is not fully consistent between its Unix and non-Unix versions.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  15. #include <config.h>
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include "../src/global.h"
  19. #include "../src/tty.h"
  20. #include "../src/color.h"
  21. #include "../src/util.h"
  22. #include "../src/mouse.h" /* Gpm_Event is required in key.h */
  23. #include "../src/key.h" /* define_sequence */
  24. #include "../src/main.h" /* extern: force_colors */
  25. #include "../src/win.h" /* do_exit_ca_mode */
  26. #ifdef HAVE_SLANG
  27. static void slang_sigterm ()
  28. {
  29. SLsmg_reset_smg ();
  30. }
  31. static int slinterrupt;
  32. void enable_interrupt_key(void)
  33. {
  34. SLang_set_abort_signal(NULL);
  35. slinterrupt = 1;
  36. }
  37. void disable_interrupt_key(void)
  38. {
  39. slinterrupt = 0;
  40. }
  41. int got_interrupt ()
  42. {
  43. int t;
  44. int SLKeyboard_Quit=0; /* FIXME!! */
  45. t = slinterrupt ? SLKeyboard_Quit : 0;
  46. /* SLKeyboard_Quit = 0; */
  47. return t;
  48. }
  49. /* Only done the first time */
  50. void slang_init (void)
  51. {
  52. SLtt_get_terminfo ();
  53. SLang_init_tty (XCTRL('c'), 1, 0);
  54. slang_prog_mode ();
  55. load_terminfo_keys ();
  56. }
  57. /* Done each time we come back from done mode */
  58. void slang_prog_mode (void)
  59. {
  60. SLsmg_init_smg ();
  61. SLsmg_touch_lines (0, LINES);
  62. }
  63. /* Called each time we want to shutdown slang screen manager */
  64. void slang_shell_mode (void)
  65. {
  66. }
  67. void slang_shutdown ()
  68. {
  69. slang_shell_mode ();
  70. do_exit_ca_mode ();
  71. SLang_reset_tty ();
  72. /* reset the colors to those that were
  73. * active when the program was started up
  74. (not written)
  75. */
  76. }
  77. /* keypad routines */
  78. void slang_keypad (int set)
  79. {
  80. /* enable keypad strings */
  81. }
  82. static int no_slang_delay;
  83. void set_slang_delay (int v)
  84. {
  85. no_slang_delay = v;
  86. }
  87. void hline (int ch, int len)
  88. {
  89. int last_x, last_y;
  90. last_x = SLsmg_get_column ();
  91. last_y = SLsmg_get_row ();
  92. if (ch == 0)
  93. ch = ACS_HLINE;
  94. if (ch == ACS_HLINE){
  95. SLsmg_draw_hline (len);
  96. } else {
  97. while (len--)
  98. addch (ch);
  99. }
  100. move (last_y, last_x);
  101. }
  102. void vline (int character, int len)
  103. {
  104. if (!slow_terminal){
  105. SLsmg_draw_vline (len);
  106. } else {
  107. int last_x, last_y, pos = 0;
  108. last_x = SLsmg_get_column ();
  109. last_y = SLsmg_get_row ();
  110. while (len--){
  111. move (last_y + pos++, last_x);
  112. addch (' ');
  113. }
  114. move (last_x, last_y);
  115. }
  116. }
  117. int has_colors ()
  118. {
  119. /* No terminals on NT, make default color */
  120. if (!disable_colors)
  121. SLtt_Use_Ansi_Colors = 1;
  122. /* Setup emulated colors */
  123. if (SLtt_Use_Ansi_Colors){
  124. init_pair (A_REVERSE, "black", "white");
  125. } else {
  126. /* SLtt_set_mono (A_BOLD, NULL, SLTT_BOLD_MASK);
  127. SLtt_set_mono (A_REVERSE, NULL, SLTT_REV_MASK);
  128. SLtt_set_mono (A_BOLD|A_REVERSE, NULL, SLTT_BOLD_MASK | SLTT_REV_MASK);
  129. */ }
  130. return SLtt_Use_Ansi_Colors;
  131. }
  132. void attrset (int color)
  133. {
  134. if (!SLtt_Use_Ansi_Colors){
  135. SLsmg_set_color (color);
  136. return;
  137. }
  138. if (color & A_BOLD){
  139. if (color == A_BOLD)
  140. SLsmg_set_color (A_BOLD);
  141. else
  142. SLsmg_set_color ((color & (~A_BOLD)) + 8);
  143. return;
  144. }
  145. if (color == A_REVERSE)
  146. SLsmg_set_color (A_REVERSE);
  147. else
  148. SLsmg_set_color (color);
  149. }
  150. void load_terminfo_keys ()
  151. {
  152. }
  153. int getch ()
  154. {
  155. if (no_slang_delay)
  156. if (SLang_input_pending (0) == 0)
  157. return -1;
  158. return SLang_getkey ();
  159. }
  160. extern int slow_terminal;
  161. #else
  162. /* Non slang builds do not understand got_interrupt */
  163. int got_interrupt ()
  164. {
  165. return 0;
  166. }
  167. #endif /* HAVE_SLANG */
  168. void mc_refresh (void)
  169. {
  170. /* if (!we_are_background) (no background mode yet) */
  171. refresh ();
  172. }
  173. void slang_set_raw_mode (void)
  174. {
  175. return;
  176. }
  177. int max_index = 0;
  178. void
  179. init_pair (int index, char *foreground, char *background)
  180. {
  181. SLtt_set_color (index, "", foreground, background);
  182. if (index > max_index)
  183. max_index = index;
  184. }
  185. int
  186. alloc_color_pair (char *foreground, char *background)
  187. {
  188. init_pair (++max_index, foreground, background);
  189. return max_index;
  190. }
  191. int
  192. try_alloc_color_pair (char *fg, char *bg)
  193. {
  194. static struct colors_avail {
  195. struct colors_avail *next;
  196. char *fg, *bg;
  197. int index;
  198. } *p, c =
  199. {
  200. 0, 0, 0, 0
  201. };
  202. c.index = NORMAL_COLOR;
  203. p = &c;
  204. for (;;) {
  205. if (((fg && p->fg) ? !strcmp (fg, p->fg) : fg == p->fg) != 0
  206. && ((bg && p->bg) ? !strcmp (bg, p->bg) : bg == p->bg) != 0)
  207. return p->index;
  208. if (!p->next)
  209. break;
  210. p = p->next;
  211. }
  212. p->next = malloc (sizeof (c));
  213. p = p->next;
  214. p->next = 0;
  215. p->fg = fg ? strdup (fg) : 0;
  216. p->bg = bg ? strdup (bg) : 0;
  217. if (!fg)
  218. fg = "white";
  219. if (!bg)
  220. bg = "blue";
  221. p->index = alloc_color_pair (fg, bg);
  222. return p->index;
  223. }