123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- /* Slang interface to the Midnight Commander for Windows NT and OS/2
- This emulates some features of ncurses on top of slang
- S-lang is not fully consistent between its Unix and non-Unix versions.
-
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
- #include <config.h>
- #include <stdio.h>
- #include <string.h>
- #include "../src/global.h"
- #include "../src/tty.h"
- #include "../src/mad.h"
- #include "../src/color.h"
- #include "../src/util.h"
- #include "../src/mouse.h" /* Gpm_Event is required in key.h */
- #include "../src/key.h" /* define_sequence */
- #include "../src/main.h" /* extern: force_colors */
- #include "../src/win.h" /* do_exit_ca_mode */
- #ifdef HAVE_SLANG
- static void slang_sigterm ()
- {
- SLsmg_reset_smg ();
- }
- static int slinterrupt;
- void enable_interrupt_key(void)
- {
- SLang_set_abort_signal(NULL);
- slinterrupt = 1;
- }
- void disable_interrupt_key(void)
- {
- slinterrupt = 0;
- }
- int got_interrupt ()
- {
- int t;
- int SLKeyboard_Quit=0; /* FIXME!! */
- t = slinterrupt ? SLKeyboard_Quit : 0;
- /* SLKeyboard_Quit = 0; */
- return t;
- }
- /* Only done the first time */
- void slang_init (void)
- {
- SLtt_get_terminfo ();
- SLang_init_tty (XCTRL('c'), 1, 0);
- slang_prog_mode ();
- load_terminfo_keys ();
- }
- /* Done each time we come back from done mode */
- void slang_prog_mode (void)
- {
- SLsmg_init_smg ();
- SLsmg_touch_lines (0, LINES);
- }
- /* Called each time we want to shutdown slang screen manager */
- void slang_shell_mode (void)
- {
- }
- void slang_shutdown ()
- {
- slang_shell_mode ();
- do_exit_ca_mode ();
- SLang_reset_tty ();
- /* reset the colors to those that were
- * active when the program was started up
- (not written)
- */
- }
- /* keypad routines */
- void slang_keypad (int set)
- {
- /* enable keypad strings */
- }
- static int no_slang_delay;
- void set_slang_delay (int v)
- {
- no_slang_delay = v;
- }
- void hline (int ch, int len)
- {
- int last_x, last_y;
- last_x = SLsmg_get_column ();
- last_y = SLsmg_get_row ();
-
- if (ch == 0)
- ch = ACS_HLINE;
- if (ch == ACS_HLINE){
- SLsmg_draw_hline (len);
- } else {
- while (len--)
- addch (ch);
- }
- move (last_y, last_x);
- }
- void vline (int character, int len)
- {
- if (!slow_terminal){
- SLsmg_draw_vline (len);
- } else {
- int last_x, last_y, pos = 0;
- last_x = SLsmg_get_column ();
- last_y = SLsmg_get_row ();
- while (len--){
- move (last_y + pos++, last_x);
- addch (' ');
- }
- move (last_x, last_y);
- }
- }
- int has_colors ()
- {
- /* No terminals on NT, make default color */
- if (!disable_colors)
- SLtt_Use_Ansi_Colors = 1;
-
- /* Setup emulated colors */
- if (SLtt_Use_Ansi_Colors){
- init_pair (A_REVERSE, "black", "white");
- } else {
- /* SLtt_set_mono (A_BOLD, NULL, SLTT_BOLD_MASK);
- SLtt_set_mono (A_REVERSE, NULL, SLTT_REV_MASK);
- SLtt_set_mono (A_BOLD|A_REVERSE, NULL, SLTT_BOLD_MASK | SLTT_REV_MASK);
- */ }
- return SLtt_Use_Ansi_Colors;
- }
- void attrset (int color)
- {
- if (!SLtt_Use_Ansi_Colors){
- SLsmg_set_color (color);
- return;
- }
-
- if (color & A_BOLD){
- if (color == A_BOLD)
- SLsmg_set_color (A_BOLD);
- else
- SLsmg_set_color ((color & (~A_BOLD)) + 8);
- return;
- }
- if (color == A_REVERSE)
- SLsmg_set_color (A_REVERSE);
- else
- SLsmg_set_color (color);
- }
-
- void load_terminfo_keys ()
- {
- }
- int getch ()
- {
- if (no_slang_delay)
- if (SLang_input_pending (0) == 0)
- return -1;
- return SLang_getkey ();
- }
- extern int slow_terminal;
- #else
- /* Non slang builds do not understand got_interrupt */
- int got_interrupt ()
- {
- return 0;
- }
- #endif /* HAVE_SLANG */
- void mc_refresh (void)
- {
- /* if (!we_are_background) (no background mode yet) */
- refresh ();
- }
- void slang_set_raw_mode (void)
- {
- return;
- }
- int max_index = 0;
- void
- init_pair (int index, char *foreground, char *background)
- {
- SLtt_set_color (index, "", foreground, background);
- if (index > max_index)
- max_index = index;
- }
- int
- alloc_color_pair (char *foreground, char *background)
- {
- init_pair (++max_index, foreground, background);
- return max_index;
- }
- int
- try_alloc_color_pair (char *fg, char *bg)
- {
- static struct colors_avail {
- struct colors_avail *next;
- char *fg, *bg;
- int index;
- } *p, c =
- {
- 0, 0, 0, 0
- };
- c.index = NORMAL_COLOR;
- p = &c;
- for (;;) {
- if (((fg && p->fg) ? !strcmp (fg, p->fg) : fg == p->fg) != 0
- && ((bg && p->bg) ? !strcmp (bg, p->bg) : bg == p->bg) != 0)
- return p->index;
- if (!p->next)
- break;
- p = p->next;
- }
- p->next = malloc (sizeof (c));
- p = p->next;
- p->next = 0;
- p->fg = fg ? strdup (fg) : 0;
- p->bg = bg ? strdup (bg) : 0;
- if (!fg)
- fg = "white";
- if (!bg)
- bg = "blue";
- p->index = alloc_color_pair (fg, bg);
- return p->index;
- }
|