mirror of https://github.com/MidnightCommander/mc
Initial step to split NCurses- and SLang-based TTY layers.
This commit is contained in:
parent
389e5bf613
commit
ea0cb38b9e
|
@ -532,6 +532,7 @@ if test -n "$use_smbfs"; then
|
|||
AC_CONFIG_SUBDIRS([vfs/samba])
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL(USE_SCREEN_SLANG, [test x"$with_screen" = xslang])
|
||||
AM_CONDITIONAL(USE_EDIT, [test -n "$use_edit"])
|
||||
AM_CONDITIONAL(USE_VFS, [test "x$use_vfs" = xyes])
|
||||
AM_CONDITIONAL(USE_VFS_NET, [test x"$use_net_code" = xtrue])
|
||||
|
|
|
@ -257,13 +257,6 @@ void edit_scroll_screen_over_cursor (WEdit * edit)
|
|||
|
||||
#define edit_move(x,y) widget_move(edit, y, x);
|
||||
|
||||
/* Set colorpair by index, don't interpret S-Lang "emulated attributes" */
|
||||
#ifdef HAVE_SLANG
|
||||
#define lowlevel_set_color(x) SLsmg_set_color(x & 0x7F)
|
||||
#else
|
||||
#define lowlevel_set_color(x) attrset(MY_COLOR_PAIR(color))
|
||||
#endif
|
||||
|
||||
struct line_s {
|
||||
unsigned int ch;
|
||||
unsigned int style;
|
||||
|
@ -327,7 +320,7 @@ print_to_widget (WEdit *edit, long row, int start_col, int start_col_real,
|
|||
#if 0
|
||||
if (color != EDITOR_NORMAL_COLOR) {
|
||||
textchar = ' ';
|
||||
lowlevel_set_color (color);
|
||||
tty_lowlevel_setcolor (color);
|
||||
} else
|
||||
#endif
|
||||
set_color (EDITOR_WHITESPACE_COLOR);
|
||||
|
@ -338,7 +331,7 @@ print_to_widget (WEdit *edit, long row, int start_col, int start_col_real,
|
|||
} else if (style & MOD_MARKED) {
|
||||
set_color (EDITOR_MARKED_COLOR);
|
||||
} else {
|
||||
lowlevel_set_color (color);
|
||||
tty_lowlevel_setcolor (color);
|
||||
}
|
||||
}
|
||||
if ( textchar > 255 ) {
|
||||
|
|
|
@ -826,7 +826,7 @@ void set_hintbar(const char *str)
|
|||
{
|
||||
label_set_text (the_hint, str);
|
||||
if (ok_to_refresh > 0)
|
||||
refresh();
|
||||
mc_refresh();
|
||||
}
|
||||
|
||||
void print_vfs_message (const char *msg, ...)
|
||||
|
|
|
@ -1,15 +1,28 @@
|
|||
|
||||
noinst_LTLIBRARIES = libmctty.la
|
||||
|
||||
libmctty_la_SOURCES = \
|
||||
if USE_SCREEN_SLANG
|
||||
TTY_SCREEN_SRC = \
|
||||
color-slang.c color-slang.h \
|
||||
tty-slang.c tty-slang.h
|
||||
else
|
||||
TTY_SCREEN_SRC = \
|
||||
color-ncurses.c color-ncurses.h \
|
||||
tty-ncurses.c tty-ncurses.h
|
||||
endif
|
||||
|
||||
TTY_SRC = \
|
||||
color-internal.c color-internal.h\
|
||||
color.c color.h \
|
||||
key.c key.h keyxdef.c \
|
||||
mouse.c mouse.h \
|
||||
myslang.h slint.c \
|
||||
rxvt.c \
|
||||
tty.c tty.h \
|
||||
win.c win.h \
|
||||
x11conn.c x11conn.h
|
||||
|
||||
libmctty_la_SOURCES = $(TTY_SRC) $(TTY_SCREEN_SRC)
|
||||
|
||||
libmctty_la_CFLAGS = -I../ -I$(top_srcdir)/src \
|
||||
$(GLIB_CFLAGS) \
|
||||
-DDATADIR=\""$(pkgdatadir)/"\" -DLOCALEDIR=\""$(localedir)"\"
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
|
||||
/** \file color-internal.c
|
||||
* \brief Source: Internal stuff of color setup
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <sys/types.h> /* size_t */
|
||||
|
||||
#include "../../src/tty/color-internal.h"
|
||||
|
||||
struct color_table_s const color_table [] = {
|
||||
{ "black", COLOR_BLACK },
|
||||
{ "gray", COLOR_BLACK | A_BOLD },
|
||||
{ "red", COLOR_RED },
|
||||
{ "brightred", COLOR_RED | A_BOLD },
|
||||
{ "green", COLOR_GREEN },
|
||||
{ "brightgreen", COLOR_GREEN | A_BOLD },
|
||||
{ "brown", COLOR_YELLOW },
|
||||
{ "yellow", COLOR_YELLOW | A_BOLD },
|
||||
{ "blue", COLOR_BLUE },
|
||||
{ "brightblue", COLOR_BLUE | A_BOLD },
|
||||
{ "magenta", COLOR_MAGENTA },
|
||||
{ "brightmagenta", COLOR_MAGENTA | A_BOLD },
|
||||
{ "cyan", COLOR_CYAN },
|
||||
{ "brightcyan", COLOR_CYAN | A_BOLD },
|
||||
{ "lightgray", COLOR_WHITE },
|
||||
{ "white", COLOR_WHITE | A_BOLD },
|
||||
{ "default", 0 } /* default color of the terminal */
|
||||
};
|
||||
|
||||
struct colorpair color_map [] = {
|
||||
{ "normal=", 0, 0 }, /* normal */ /* 1 */
|
||||
{ "selected=", 0, 0 }, /* selected */
|
||||
{ "marked=", 0, 0 }, /* marked */
|
||||
{ "markselect=", 0, 0 }, /* marked/selected */
|
||||
{ "errors=", 0, 0 }, /* errors */
|
||||
{ "menu=", 0, 0 }, /* menu entry */
|
||||
{ "reverse=", 0, 0 }, /* reverse */
|
||||
|
||||
/* Dialog colors */
|
||||
{ "dnormal=", 0, 0 }, /* Dialog normal */ /* 8 */
|
||||
{ "dfocus=", 0, 0 }, /* Dialog focused */
|
||||
{ "dhotnormal=", 0, 0 }, /* Dialog normal/hot */
|
||||
{ "dhotfocus=", 0, 0 }, /* Dialog focused/hot */
|
||||
|
||||
{ "viewunderline=", 0, 0 }, /* _\b? sequence in view, underline in editor */
|
||||
{ "menusel=", 0, 0 }, /* Menu selected color */ /* 13 */
|
||||
{ "menuhot=", 0, 0 }, /* Color for menu hotkeys */
|
||||
{ "menuhotsel=", 0, 0 }, /* Menu hotkeys/selected entry */
|
||||
|
||||
{ "helpnormal=", 0, 0 }, /* Help normal */ /* 16 */
|
||||
{ "helpitalic=", 0, 0 }, /* Italic in help */
|
||||
{ "helpbold=", 0, 0 }, /* Bold in help */
|
||||
{ "helplink=", 0, 0 }, /* Not selected hyperlink */
|
||||
{ "helpslink=", 0, 0 }, /* Selected hyperlink */
|
||||
|
||||
{ "gauge=", 0, 0 }, /* Color of the progress bar (percentage) *//* 21 */
|
||||
{ "input=", 0, 0 },
|
||||
|
||||
/* Per file types colors */
|
||||
{ "directory=", 0, 0 }, /* 23 */
|
||||
{ "executable=", 0, 0 },
|
||||
{ "link=", 0, 0 }, /* symbolic link (neither stale nor link to directory) */
|
||||
{ "stalelink=", 0, 0 }, /* stale symbolic link */
|
||||
{ "device=", 0, 0 },
|
||||
{ "special=", 0, 0 }, /* sockets, fifo */
|
||||
{ "core=", 0, 0 }, /* core files */ /* 29 */
|
||||
|
||||
{ 0, 0, 0 }, /* not usable (DEFAULT_COLOR_INDEX) *//* 30 */
|
||||
{ 0, 0, 0 }, /* unused */
|
||||
{ 0, 0, 0 }, /* not usable (A_REVERSE) */
|
||||
{ 0, 0, 0 }, /* not usable (A_REVERSE_BOLD) */
|
||||
|
||||
/* editor colors start at 34 */
|
||||
{ "editnormal=", 0, 0 }, /* normal */ /* 34 */
|
||||
{ "editbold=", 0, 0 }, /* search->found */
|
||||
{ "editmarked=", 0, 0 }, /* marked/selected */
|
||||
{ "editwhitespace=", 0, 0 }, /* whitespace */
|
||||
|
||||
/* error dialog colors start at 38 */
|
||||
{ "errdhotnormal=", 0, 0 }, /* Error dialog normal/hot */ /* 38 */
|
||||
{ "errdhotfocus=", 0, 0 }, /* Error dialog focused/hot */
|
||||
};
|
||||
|
||||
size_t
|
||||
color_table_len (void)
|
||||
{
|
||||
return sizeof (color_table)/sizeof(color_table [0]);
|
||||
}
|
||||
|
||||
size_t
|
||||
color_map_len (void)
|
||||
{
|
||||
return sizeof (color_map)/sizeof(color_map [0]);
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
|
||||
/** \file color-internal.h
|
||||
* \brief Header: Internal stuff of color setup
|
||||
*/
|
||||
|
||||
#ifndef MC_COLOR_INTERNAL_H
|
||||
#define MC_COLOR_INTERNAL_H
|
||||
|
||||
#include <sys/types.h> /* size_t */
|
||||
|
||||
#ifdef HAVE_SLANG
|
||||
# include "../../src/tty/tty-slang.h"
|
||||
#else
|
||||
# include "../../src/tty/tty-ncurses.h"
|
||||
#endif /* HAVE_SLANG */
|
||||
|
||||
struct color_table_s {
|
||||
const char *name;
|
||||
int value;
|
||||
};
|
||||
|
||||
extern const struct color_table_s const color_table [];
|
||||
|
||||
#ifdef HAVE_SLANG
|
||||
# define CTYPE const char *
|
||||
#else
|
||||
# define CTYPE int
|
||||
#endif /* HAVE_SLANG */
|
||||
|
||||
struct colorpair {
|
||||
const char *name; /* Name of the entry */
|
||||
CTYPE fg; /* foreground color */
|
||||
CTYPE bg; /* background color */
|
||||
};
|
||||
|
||||
extern struct colorpair color_map [];
|
||||
|
||||
#ifdef HAVE_SLANG
|
||||
# define color_value(i) color_table [i].name
|
||||
# define color_name(i) color_table [i].name
|
||||
|
||||
# define color_map_fg(n) color_map [n].fg
|
||||
# define color_map_bg(n) color_map [n].bg
|
||||
#else
|
||||
# define color_value(i) color_table [i].value
|
||||
# define color_name(i) color_table [i].name
|
||||
|
||||
# define color_map_fg(n) (color_map [n].fg & COLOR_WHITE)
|
||||
# define color_map_bg(n) (color_map [n].bg & COLOR_WHITE)
|
||||
#endif /* HAVE_SLANG */
|
||||
|
||||
static const char default_colors[] = {
|
||||
"normal=lightgray,blue:"
|
||||
"selected=black,cyan:"
|
||||
"marked=yellow,blue:"
|
||||
"markselect=yellow,cyan:"
|
||||
"errors=white,red:"
|
||||
"menu=white,cyan:"
|
||||
"reverse=black,lightgray:"
|
||||
"dnormal=black,lightgray:"
|
||||
"dfocus=black,cyan:"
|
||||
"dhotnormal=blue,lightgray:"
|
||||
"dhotfocus=blue,cyan:"
|
||||
"viewunderline=brightred,blue:"
|
||||
"menuhot=yellow,cyan:"
|
||||
"menusel=white,black:"
|
||||
"menuhotsel=yellow,black:"
|
||||
"helpnormal=black,lightgray:"
|
||||
"helpitalic=red,lightgray:"
|
||||
"helpbold=blue,lightgray:"
|
||||
"helplink=black,cyan:"
|
||||
"helpslink=yellow,blue:"
|
||||
"gauge=white,black:"
|
||||
"input=black,cyan:"
|
||||
"directory=white,blue:"
|
||||
"executable=brightgreen,blue:"
|
||||
"link=lightgray,blue:"
|
||||
"stalelink=brightred,blue:"
|
||||
"device=brightmagenta,blue:"
|
||||
"core=red,blue:"
|
||||
"special=black,blue:"
|
||||
"editnormal=lightgray,blue:"
|
||||
"editbold=yellow,blue:"
|
||||
"editmarked=black,cyan:"
|
||||
"editwhitespace=brightblue,blue:"
|
||||
"errdhotnormal=yellow,red:"
|
||||
"errdhotfocus=yellow,lightgray"
|
||||
};
|
||||
|
||||
struct colors_avail {
|
||||
struct colors_avail *next;
|
||||
char *fg, *bg;
|
||||
int index;
|
||||
};
|
||||
|
||||
extern struct colors_avail c;
|
||||
extern int max_index;
|
||||
|
||||
size_t color_table_len (void);
|
||||
size_t color_map_len (void);
|
||||
|
||||
void configure_colors (void);
|
||||
void load_dialog_colors (void);
|
||||
void get_color (const char *cpp, CTYPE *colp);
|
||||
int alloc_color_pair (CTYPE foreground, CTYPE background);
|
||||
|
||||
#endif /* MC_COLOR_INTERNAL_H */
|
|
@ -0,0 +1,125 @@
|
|||
/* Color setup for NCurses screen library
|
||||
Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
|
||||
2007, 2008, 2009 Free Software Foundation, Inc.
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
|
||||
|
||||
/** \file color-ncurses.c
|
||||
* \brief Source: NCUrses-specific color setup
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h> /* size_t*/
|
||||
|
||||
#include "../../src/global.h"
|
||||
|
||||
#include "../../src/tty/tty-ncurses.h"
|
||||
#include "../../src/tty/color.h" /* variables */
|
||||
#include "../../src/tty/color-internal.h"
|
||||
|
||||
int attr_pairs [MAX_PAIRS];
|
||||
|
||||
void
|
||||
init_colors (void)
|
||||
{
|
||||
if (has_colors () && !disable_colors)
|
||||
use_colors = 1;
|
||||
|
||||
if (use_colors) {
|
||||
const size_t map_len = color_map_len ();
|
||||
size_t i;
|
||||
|
||||
start_color ();
|
||||
configure_colors ();
|
||||
|
||||
if (map_len > MAX_PAIRS) {
|
||||
/* This message should only be seen by the developers */
|
||||
fprintf (stderr,
|
||||
"Too many defined colors, resize MAX_PAIRS on color.c");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (use_colors) {
|
||||
/* Always white on black */
|
||||
mc_init_pair (DEFAULT_COLOR_INDEX, COLOR_WHITE, COLOR_BLACK);
|
||||
}
|
||||
|
||||
for (i = 0; i < map_len; i++)
|
||||
if (color_map [i].name != NULL) {
|
||||
mc_init_pair (i + 1, color_map_fg (i), color_map_bg (i));
|
||||
/*
|
||||
* ncurses doesn't remember bold attribute in the color pairs,
|
||||
* so we should keep track of it in a separate array.
|
||||
*/
|
||||
attr_pairs [i + 1] = color_map [i].fg & A_BOLD;
|
||||
}
|
||||
}
|
||||
|
||||
load_dialog_colors ();
|
||||
}
|
||||
|
||||
/* Functions necessary to implement syntax highlighting */
|
||||
void
|
||||
mc_init_pair (int index, CTYPE foreground, CTYPE background)
|
||||
{
|
||||
init_pair (index, foreground, background);
|
||||
if (index > max_index)
|
||||
max_index = index;
|
||||
}
|
||||
|
||||
int
|
||||
try_alloc_color_pair (const char *fg, const char *bg)
|
||||
{
|
||||
int fg_index, bg_index;
|
||||
int bold_attr;
|
||||
struct colors_avail *p = &c;
|
||||
|
||||
c.index = EDITOR_NORMAL_COLOR_INDEX;
|
||||
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 = g_new (struct colors_avail, 1);
|
||||
p = p->next;
|
||||
p->next = 0;
|
||||
p->fg = fg ? g_strdup (fg) : 0;
|
||||
p->bg = bg ? g_strdup (bg) : 0;
|
||||
if (!fg)
|
||||
/* Index in color_map array = COLOR_INDEX - 1 */
|
||||
fg_index = color_map[EDITOR_NORMAL_COLOR_INDEX - 1].fg;
|
||||
else
|
||||
get_color (fg, &fg_index);
|
||||
|
||||
if (!bg)
|
||||
bg_index = color_map[EDITOR_NORMAL_COLOR_INDEX - 1].bg;
|
||||
else
|
||||
get_color (bg, &bg_index);
|
||||
|
||||
bold_attr = fg_index & A_BOLD;
|
||||
fg_index = fg_index & COLOR_WHITE;
|
||||
bg_index = bg_index & COLOR_WHITE;
|
||||
|
||||
p->index = alloc_color_pair (fg_index, bg_index);
|
||||
attr_pairs [p->index] = bold_attr;
|
||||
return p->index;
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
/** \file color-ncurses.h
|
||||
* \brief Header: NCurses-specific color setup
|
||||
*/
|
||||
|
||||
#ifndef MC_COLOR_NCURSES_H
|
||||
#define MC_COLOR_NCURSES_H
|
||||
|
||||
#define MAX_PAIRS 64
|
||||
extern int attr_pairs [MAX_PAIRS];
|
||||
|
||||
#define MY_COLOR_PAIR(x) (COLOR_PAIR (x) | attr_pairs [x])
|
||||
#define IF_COLOR(co, bw) (use_colors ? MY_COLOR_PAIR (co) : bw)
|
||||
|
||||
#define MARKED_SELECTED_COLOR IF_COLOR (4, A_REVERSE | A_BOLD)
|
||||
|
||||
void mc_init_pair (int index, int foreground, int background);
|
||||
|
||||
#endif /* MC_COLOR_NCURSES_H */
|
|
@ -0,0 +1,111 @@
|
|||
/* Color setup for S_Lang screen library
|
||||
Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
|
||||
2007, 2008, 2009 Free Software Foundation, Inc.
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
|
||||
|
||||
/** \file color-slang.c
|
||||
* \brief Source: S-Lang-specific color setup
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h> /* size_t */
|
||||
|
||||
#include "../../src/global.h"
|
||||
|
||||
#include "../../src/tty/tty-slang.h"
|
||||
#include "../../src/tty/color.h" /* variables */
|
||||
#include "../../src/tty/color-internal.h"
|
||||
|
||||
void
|
||||
init_colors (void)
|
||||
{
|
||||
/* FIXME: if S-Lang is used, has_colors() must be called regardless
|
||||
of whether we are interested in its result */
|
||||
if (has_colors () && !disable_colors)
|
||||
use_colors = 1;
|
||||
|
||||
if (use_colors) {
|
||||
const size_t map_len = color_map_len ();
|
||||
size_t i;
|
||||
|
||||
start_color ();
|
||||
configure_colors ();
|
||||
|
||||
if (use_colors) {
|
||||
/*
|
||||
* We are relying on undocumented feature of
|
||||
* S-Lang to make COLOR_PAIR(DEFAULT_COLOR_INDEX)
|
||||
* the default fg/bg of the terminal.
|
||||
* Hopefully, future versions of S-Lang will
|
||||
* document this feature.
|
||||
*/
|
||||
SLtt_set_color (DEFAULT_COLOR_INDEX, NULL, (char *) "default", (char *) "default");
|
||||
}
|
||||
|
||||
for (i = 0; i < map_len; i++)
|
||||
if (color_map [i].name != NULL)
|
||||
mc_init_pair (i + 1, color_map_fg(i), color_map_bg(i));
|
||||
}
|
||||
|
||||
load_dialog_colors ();
|
||||
}
|
||||
|
||||
/* Functions necessary to implement syntax highlighting */
|
||||
void
|
||||
mc_init_pair (int index, CTYPE foreground, CTYPE background)
|
||||
{
|
||||
if (!background)
|
||||
background = "default";
|
||||
|
||||
if (!foreground)
|
||||
foreground = "default";
|
||||
|
||||
SLtt_set_color (index, (char *) "", (char *) foreground, (char *) background);
|
||||
if (index > max_index)
|
||||
max_index = index;
|
||||
}
|
||||
|
||||
int
|
||||
try_alloc_color_pair (const char *fg, const char *bg)
|
||||
{
|
||||
struct colors_avail *p = &c;
|
||||
|
||||
c.index = EDITOR_NORMAL_COLOR_INDEX;
|
||||
for (;;) {
|
||||
if (((fg && p->fg) ? (strcmp (fg, p->fg) == 0) : (fg == p->fg)) != 0
|
||||
&& ((bg && p->bg) ? (strcmp (bg, p->bg) == 0) : (bg == p->bg)) != 0)
|
||||
return p->index;
|
||||
if (p->next == NULL)
|
||||
break;
|
||||
p = p->next;
|
||||
}
|
||||
p->next = g_new (struct colors_avail, 1);
|
||||
p = p->next;
|
||||
p->next = NULL;
|
||||
p->fg = fg ? g_strdup (fg) : NULL;
|
||||
p->bg = bg ? g_strdup (bg) : NULL;
|
||||
if (fg == NULL
|
||||
/* Index in color_map array = COLOR_INDEX - 1 */
|
||||
fg = color_map[EDITOR_NORMAL_COLOR_INDEX - 1].fg;
|
||||
if (bg == NULL
|
||||
bg = color_map[EDITOR_NORMAL_COLOR_INDEX - 1].bg;
|
||||
p->index = alloc_color_pair (fg, bg);
|
||||
return p->index;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
/** \file color-slang.h
|
||||
* \brief Header: S-Lang-specific color setup
|
||||
*/
|
||||
|
||||
#ifndef MC_COLOR_SLANG_H
|
||||
#define MC_COLOR_SLANG_H
|
||||
|
||||
#define IF_COLOR(co, bw) (use_colors ? COLOR_PAIR (co) : bw)
|
||||
|
||||
#define MARKED_SELECTED_COLOR IF_COLOR (4, (SLtt_Use_Ansi_Colors ? A_BOLD_REVERSE : A_REVERSE | A_BOLD))
|
||||
|
||||
void mc_init_pair (int index, const char *foreground, const char *background);
|
||||
|
||||
#endif /* MC_COLOR_SLANG_H */
|
405
src/tty/color.c
405
src/tty/color.c
|
@ -1,12 +1,12 @@
|
|||
/* Color setup
|
||||
Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
|
||||
2007 Free Software Foundation, Inc.
|
||||
|
||||
2007, 2008, 2009 Free Software Foundation, Inc.
|
||||
|
||||
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
|
||||
|
@ -25,149 +25,46 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h> /* size_t */
|
||||
|
||||
#include "../../src/global.h"
|
||||
|
||||
#include "../../src/tty/tty.h"
|
||||
#include "../../src/setup.h" /* For the externs */
|
||||
#include "../../src/tty/color.h"
|
||||
#include "../../src/tty/color-internal.h"
|
||||
|
||||
/* Set to force black and white display at program startup */
|
||||
int disable_colors = 0;
|
||||
#include "../../src/setup.h" /* setup_color_string, term_color_string */
|
||||
|
||||
/* Set if we are actually using colors */
|
||||
int use_colors = 0;
|
||||
gboolean use_colors = FALSE;
|
||||
|
||||
/* Color styles for normal and error dialogs */
|
||||
int dialog_colors [4];
|
||||
int alarm_colors [4];
|
||||
|
||||
#define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
|
||||
|
||||
#ifdef HAVE_SLANG
|
||||
# define color_map_fg(n) color_map[n].fg
|
||||
# define color_map_bg(n) color_map[n].bg
|
||||
#else
|
||||
# define color_map_fg(n) (color_map[n].fg & COLOR_WHITE)
|
||||
# define color_map_bg(n) (color_map[n].bg & COLOR_WHITE)
|
||||
#endif
|
||||
|
||||
struct colorpair {
|
||||
const char *name; /* Name of the entry */
|
||||
CTYPE fg; /* foreground color */
|
||||
CTYPE bg; /* background color */
|
||||
};
|
||||
|
||||
static struct colorpair color_map [] = {
|
||||
{ "normal=", 0, 0 }, /* normal */ /* 1 */
|
||||
{ "selected=", 0, 0 }, /* selected */
|
||||
{ "marked=", 0, 0 }, /* marked */
|
||||
{ "markselect=", 0, 0 }, /* marked/selected */
|
||||
{ "errors=", 0, 0 }, /* errors */
|
||||
{ "menu=", 0, 0 }, /* menu entry */
|
||||
{ "reverse=", 0, 0 }, /* reverse */
|
||||
|
||||
/* Dialog colors */
|
||||
{ "dnormal=", 0, 0 }, /* Dialog normal */ /* 8 */
|
||||
{ "dfocus=", 0, 0 }, /* Dialog focused */
|
||||
{ "dhotnormal=", 0, 0 }, /* Dialog normal/hot */
|
||||
{ "dhotfocus=", 0, 0 }, /* Dialog focused/hot */
|
||||
|
||||
{ "viewunderline=", 0, 0 }, /* _\b? sequence in view, underline in editor */
|
||||
{ "menusel=", 0, 0 }, /* Menu selected color */ /* 13 */
|
||||
{ "menuhot=", 0, 0 }, /* Color for menu hotkeys */
|
||||
{ "menuhotsel=", 0, 0 }, /* Menu hotkeys/selected entry */
|
||||
|
||||
{ "helpnormal=", 0, 0 }, /* Help normal */ /* 16 */
|
||||
{ "helpitalic=", 0, 0 }, /* Italic in help */
|
||||
{ "helpbold=", 0, 0 }, /* Bold in help */
|
||||
{ "helplink=", 0, 0 }, /* Not selected hyperlink */
|
||||
{ "helpslink=", 0, 0 }, /* Selected hyperlink */
|
||||
|
||||
{ "gauge=", 0, 0 }, /* Color of the progress bar (percentage) *//* 21 */
|
||||
{ "input=", 0, 0 },
|
||||
|
||||
/* Per file types colors */
|
||||
{ "directory=", 0, 0 }, /* 23 */
|
||||
{ "executable=", 0, 0 },
|
||||
{ "link=", 0, 0 }, /* symbolic link (neither stale nor link to directory) */
|
||||
{ "stalelink=", 0, 0 }, /* stale symbolic link */
|
||||
{ "device=", 0, 0 },
|
||||
{ "special=", 0, 0 }, /* sockets, fifo */
|
||||
{ "core=", 0, 0 }, /* core files */ /* 29 */
|
||||
|
||||
{ 0, 0, 0 }, /* not usable (DEFAULT_COLOR_INDEX) *//* 30 */
|
||||
{ 0, 0, 0 }, /* unused */
|
||||
{ 0, 0, 0 }, /* not usable (A_REVERSE) */
|
||||
{ 0, 0, 0 }, /* not usable (A_REVERSE_BOLD) */
|
||||
|
||||
/* editor colors start at 34 */
|
||||
{ "editnormal=", 0, 0 }, /* normal */ /* 34 */
|
||||
{ "editbold=", 0, 0 }, /* search->found */
|
||||
{ "editmarked=", 0, 0 }, /* marked/selected */
|
||||
{ "editwhitespace=", 0, 0 }, /* whitespace */
|
||||
{ "editlinestate=", 0, 0 }, /* line number bar*/
|
||||
|
||||
/* error dialog colors start at 39 */
|
||||
{ "errdhotnormal=", 0, 0 }, /* Error dialog normal/hot */ /* 39 */
|
||||
{ "errdhotfocus=", 0, 0 }, /* Error dialog focused/hot */
|
||||
};
|
||||
|
||||
struct color_table_s {
|
||||
const char *name;
|
||||
int value;
|
||||
};
|
||||
|
||||
|
||||
static struct color_table_s const color_table [] = {
|
||||
{ "black", COLOR_BLACK },
|
||||
{ "gray", COLOR_BLACK | A_BOLD },
|
||||
{ "red", COLOR_RED },
|
||||
{ "brightred", COLOR_RED | A_BOLD },
|
||||
{ "green", COLOR_GREEN },
|
||||
{ "brightgreen", COLOR_GREEN | A_BOLD },
|
||||
{ "brown", COLOR_YELLOW },
|
||||
{ "yellow", COLOR_YELLOW | A_BOLD },
|
||||
{ "blue", COLOR_BLUE },
|
||||
{ "brightblue", COLOR_BLUE | A_BOLD },
|
||||
{ "magenta", COLOR_MAGENTA },
|
||||
{ "brightmagenta", COLOR_MAGENTA | A_BOLD },
|
||||
{ "cyan", COLOR_CYAN },
|
||||
{ "brightcyan", COLOR_CYAN | A_BOLD },
|
||||
{ "lightgray", COLOR_WHITE },
|
||||
{ "white", COLOR_WHITE | A_BOLD },
|
||||
{ "default", 0 } /* default color of the terminal */
|
||||
};
|
||||
|
||||
#ifdef HAVE_SLANG
|
||||
# define color_value(i) color_table [i].name
|
||||
# define color_name(i) color_table [i].name
|
||||
#else
|
||||
# define color_value(i) color_table [i].value
|
||||
# define color_name(i) color_table [i].name
|
||||
#endif
|
||||
|
||||
static void get_color (const char *cpp, CTYPE *colp)
|
||||
void
|
||||
get_color (const char *cpp, CTYPE *colp)
|
||||
{
|
||||
const size_t table_len = color_table_len ();
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < ELEMENTS(color_table); i++){
|
||||
if (strcmp (cpp, color_name (i)) == 0){
|
||||
|
||||
for (i = 0; i < table_len; i++)
|
||||
if (strcmp (cpp, color_name (i)) == 0) {
|
||||
*colp = color_value (i);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void get_two_colors (char **cpp, struct colorpair *colorpairp)
|
||||
static void
|
||||
get_two_colors (char **cpp, struct colorpair *colorpairp)
|
||||
{
|
||||
char *p = *cpp;
|
||||
int state;
|
||||
|
||||
state = 0;
|
||||
|
||||
for (; *p; p++){
|
||||
if (*p == ':'){
|
||||
|
||||
for (; *p; p++) {
|
||||
if (*p == ':') {
|
||||
*p = 0;
|
||||
get_color (*cpp, state ? &colorpairp->bg : &colorpairp->fg);
|
||||
*p = ':';
|
||||
|
@ -175,7 +72,7 @@ static void get_two_colors (char **cpp, struct colorpair *colorpairp)
|
|||
return;
|
||||
}
|
||||
|
||||
if (*p == ','){
|
||||
if (*p == ',') {
|
||||
state = 1;
|
||||
*p = 0;
|
||||
get_color (*cpp, &colorpairp->fg);
|
||||
|
@ -183,88 +80,53 @@ static void get_two_colors (char **cpp, struct colorpair *colorpairp)
|
|||
*cpp = p + 1;
|
||||
}
|
||||
}
|
||||
|
||||
get_color (*cpp, state ? &colorpairp->bg : &colorpairp->fg);
|
||||
}
|
||||
|
||||
static void configure_colors_string (const char *the_color_string)
|
||||
static void
|
||||
configure_colors_string (const char *the_color_string)
|
||||
{
|
||||
const size_t map_len = color_map_len ();
|
||||
char *color_string, *p;
|
||||
size_t i;
|
||||
int found;
|
||||
gboolean found;
|
||||
|
||||
if (!the_color_string)
|
||||
return;
|
||||
|
||||
p = color_string = g_strdup (the_color_string);
|
||||
while (color_string && *color_string){
|
||||
while (color_string && *color_string) {
|
||||
while (*color_string == ' ' || *color_string == '\t')
|
||||
color_string++;
|
||||
|
||||
found = 0;
|
||||
for (i = 0; i < ELEMENTS(color_map); i++){
|
||||
int klen;
|
||||
found = FALSE;
|
||||
for (i = 0; i < map_len; i++){
|
||||
size_t klen;
|
||||
|
||||
if (!color_map [i].name)
|
||||
continue;
|
||||
klen = strlen (color_map [i].name);
|
||||
if (!color_map [i].name)
|
||||
continue;
|
||||
klen = strlen (color_map [i].name);
|
||||
|
||||
if (strncmp (color_string, color_map [i].name, klen) == 0){
|
||||
if (strncmp (color_string, color_map [i].name, klen) == 0) {
|
||||
color_string += klen;
|
||||
get_two_colors (&color_string, &color_map [i]);
|
||||
found = 1;
|
||||
found = TRUE;
|
||||
}
|
||||
}
|
||||
if (!found){
|
||||
while (*color_string && *color_string != ':')
|
||||
color_string++;
|
||||
if (*color_string)
|
||||
color_string++;
|
||||
if (!found) {
|
||||
while (*color_string && *color_string != ':')
|
||||
color_string++;
|
||||
if (*color_string)
|
||||
color_string++;
|
||||
}
|
||||
}
|
||||
g_free (p);
|
||||
}
|
||||
|
||||
static void configure_colors (void)
|
||||
void
|
||||
configure_colors (void)
|
||||
{
|
||||
gchar *default_colors = g_strconcat (
|
||||
"normal=lightgray,blue:"
|
||||
"selected=black,cyan:"
|
||||
"marked=yellow,blue:"
|
||||
"markselect=yellow,cyan:"
|
||||
"errors=white,red:"
|
||||
"menu=white,cyan:"
|
||||
"reverse=black,lightgray:"
|
||||
"dnormal=black,lightgray:"
|
||||
"dfocus=black,cyan:"
|
||||
"dhotnormal=blue,lightgray:"
|
||||
"dhotfocus=blue,cyan:"
|
||||
"viewunderline=brightred,blue:"
|
||||
"menuhot=yellow,cyan:"
|
||||
"menusel=white,black:"
|
||||
"menuhotsel=yellow,black:"
|
||||
"helpnormal=black,lightgray:"
|
||||
"helpitalic=red,lightgray:"
|
||||
"helpbold=blue,lightgray:"
|
||||
"helplink=black,cyan:"
|
||||
"helpslink=yellow,blue:"
|
||||
"gauge=white,black:"
|
||||
"input=black,cyan:"
|
||||
"directory=white,blue:"
|
||||
,
|
||||
"executable=brightgreen,blue:"
|
||||
"link=lightgray,blue:"
|
||||
"stalelink=brightred,blue:"
|
||||
"device=brightmagenta,blue:"
|
||||
"core=red,blue:"
|
||||
"special=black,blue:"
|
||||
"editnormal=lightgray,blue:"
|
||||
"editbold=yellow,blue:"
|
||||
"editmarked=black,cyan:"
|
||||
"editwhitespace=brightblue,blue:"
|
||||
"editlinestate=white,cyan:"
|
||||
"errdhotnormal=yellow,red:"
|
||||
"errdhotfocus=yellow,lightgray", NULL);
|
||||
|
||||
extern char *command_line_colors;
|
||||
|
||||
configure_colors_string (default_colors);
|
||||
|
@ -272,15 +134,9 @@ static void configure_colors (void)
|
|||
configure_colors_string (term_color_string);
|
||||
configure_colors_string (getenv ("MC_COLOR_TABLE"));
|
||||
configure_colors_string (command_line_colors);
|
||||
g_free(default_colors);
|
||||
}
|
||||
|
||||
#ifndef HAVE_SLANG
|
||||
#define MAX_PAIRS 64
|
||||
int attr_pairs [MAX_PAIRS];
|
||||
#endif
|
||||
|
||||
static void
|
||||
void
|
||||
load_dialog_colors (void)
|
||||
{
|
||||
dialog_colors [0] = COLOR_NORMAL;
|
||||
|
@ -294,183 +150,19 @@ load_dialog_colors (void)
|
|||
alarm_colors [3] = ERROR_HOT_FOCUS;
|
||||
}
|
||||
|
||||
void init_colors (void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
int hascolors;
|
||||
|
||||
/* FIXME: if S-Lang is used, this function must be called regardless
|
||||
of whether we are interested in its result */
|
||||
hascolors = has_colors ();
|
||||
|
||||
if (!disable_colors && hascolors){
|
||||
use_colors = 1;
|
||||
}
|
||||
|
||||
if (use_colors){
|
||||
start_color ();
|
||||
#ifndef HAVE_SLANG
|
||||
use_default_colors ();
|
||||
#endif /* !HAVE_SLANG */
|
||||
configure_colors ();
|
||||
|
||||
#ifndef HAVE_SLANG
|
||||
if (ELEMENTS (color_map) > MAX_PAIRS){
|
||||
/* This message should only be seen by the developers */
|
||||
fprintf (stderr,
|
||||
"Too many defined colors, resize MAX_PAIRS on color.c");
|
||||
exit (1);
|
||||
}
|
||||
#endif /* !HAVE_SLANG */
|
||||
|
||||
if (use_colors) {
|
||||
#ifdef HAVE_SLANG
|
||||
/*
|
||||
* We are relying on undocumented feature of
|
||||
* S-Lang to make COLOR_PAIR(DEFAULT_COLOR_INDEX)
|
||||
* the default fg/bg of the terminal.
|
||||
* Hopefully, future versions of S-Lang will
|
||||
* document this feature.
|
||||
*/
|
||||
SLtt_set_color (DEFAULT_COLOR_INDEX, NULL, (char*)"default", (char*)"default");
|
||||
#else
|
||||
/* Use default terminal colors */
|
||||
mc_init_pair (DEFAULT_COLOR_INDEX, -1, -1);
|
||||
#endif /* !HAVE_SLANG */
|
||||
}
|
||||
|
||||
for (i = 0; i < ELEMENTS (color_map); i++){
|
||||
if (!color_map [i].name)
|
||||
continue;
|
||||
|
||||
mc_init_pair (i+1, color_map_fg(i), color_map_bg(i));
|
||||
|
||||
#ifndef HAVE_SLANG
|
||||
/*
|
||||
* ncurses doesn't remember bold attribute in the color pairs,
|
||||
* so we should keep track of it in a separate array.
|
||||
*/
|
||||
attr_pairs [i+1] = color_map [i].fg & A_BOLD;
|
||||
#endif /* !HAVE_SLANG */
|
||||
}
|
||||
}
|
||||
load_dialog_colors ();
|
||||
}
|
||||
|
||||
/* Functions necessary to implement syntax highlighting */
|
||||
struct colors_avail c;
|
||||
int max_index = 0;
|
||||
|
||||
static int max_index = 0;
|
||||
|
||||
static int
|
||||
int
|
||||
alloc_color_pair (CTYPE foreground, CTYPE background)
|
||||
{
|
||||
mc_init_pair (++max_index, foreground, background);
|
||||
return max_index;
|
||||
}
|
||||
|
||||
static struct colors_avail {
|
||||
struct colors_avail *next;
|
||||
char *fg, *bg;
|
||||
int index;
|
||||
} c = { 0, 0, 0, 0 };
|
||||
|
||||
#ifdef HAVE_SLANG
|
||||
void
|
||||
mc_init_pair (int index, CTYPE foreground, CTYPE background)
|
||||
{
|
||||
if (!background)
|
||||
background = "default";
|
||||
|
||||
if (!foreground)
|
||||
foreground = "default";
|
||||
|
||||
SLtt_set_color (index, (char*)"", (char *) foreground, (char *) background);
|
||||
if (index > max_index)
|
||||
max_index = index;
|
||||
}
|
||||
|
||||
int
|
||||
try_alloc_color_pair (const char *fg, const char *bg)
|
||||
{
|
||||
struct colors_avail *p = &c;
|
||||
|
||||
c.index = EDITOR_NORMAL_COLOR_INDEX;
|
||||
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 = g_new (struct colors_avail, 1);
|
||||
p = p->next;
|
||||
p->next = 0;
|
||||
p->fg = fg ? g_strdup (fg) : 0;
|
||||
p->bg = bg ? g_strdup (bg) : 0;
|
||||
if (!fg)
|
||||
/* Index in color_map array = COLOR_INDEX - 1 */
|
||||
fg = color_map[EDITOR_NORMAL_COLOR_INDEX - 1].fg;
|
||||
if (!bg)
|
||||
bg = color_map[EDITOR_NORMAL_COLOR_INDEX - 1].bg;
|
||||
p->index = alloc_color_pair (fg, bg);
|
||||
return p->index;
|
||||
}
|
||||
|
||||
#else /* !HAVE_SLANG */
|
||||
void
|
||||
mc_init_pair (int index, CTYPE foreground, CTYPE background)
|
||||
{
|
||||
init_pair (index, foreground, background == 0 ? -1 : background);
|
||||
if (index > max_index)
|
||||
max_index = index;
|
||||
}
|
||||
|
||||
int
|
||||
try_alloc_color_pair (const char *fg, const char *bg)
|
||||
{
|
||||
int fg_index, bg_index;
|
||||
int bold_attr;
|
||||
struct colors_avail *p = &c;
|
||||
|
||||
c.index = EDITOR_NORMAL_COLOR_INDEX;
|
||||
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 = g_new (struct colors_avail, 1);
|
||||
p = p->next;
|
||||
p->next = 0;
|
||||
p->fg = fg ? g_strdup (fg) : 0;
|
||||
p->bg = bg ? g_strdup (bg) : 0;
|
||||
if (!fg)
|
||||
/* Index in color_map array = COLOR_INDEX - 1 */
|
||||
fg_index = color_map[EDITOR_NORMAL_COLOR_INDEX - 1].fg;
|
||||
else
|
||||
get_color (fg, &fg_index);
|
||||
|
||||
if (!bg)
|
||||
bg_index = color_map[EDITOR_NORMAL_COLOR_INDEX - 1].bg;
|
||||
else
|
||||
get_color (bg, &bg_index);
|
||||
|
||||
bold_attr = fg_index & A_BOLD;
|
||||
fg_index = fg_index & COLOR_WHITE;
|
||||
bg_index = bg_index & COLOR_WHITE;
|
||||
|
||||
p->index = alloc_color_pair (fg_index, bg_index);
|
||||
attr_pairs [p->index] = bold_attr;
|
||||
return p->index;
|
||||
}
|
||||
#endif /* !HAVE_SLANG */
|
||||
|
||||
void
|
||||
done_colors (void)
|
||||
tty_colors_done (void)
|
||||
{
|
||||
struct colors_avail *p, *next;
|
||||
|
||||
|
@ -483,3 +175,8 @@ done_colors (void)
|
|||
c.next = NULL;
|
||||
}
|
||||
|
||||
gboolean
|
||||
tty_use_colors (void)
|
||||
{
|
||||
return use_colors;
|
||||
}
|
||||
|
|
|
@ -6,30 +6,21 @@
|
|||
#ifndef MC_COLOR_H
|
||||
#define MC_COLOR_H
|
||||
|
||||
extern int use_colors;
|
||||
extern int disable_colors;
|
||||
|
||||
extern int attr_pairs [];
|
||||
#ifdef HAVE_SLANG
|
||||
# define MY_COLOR_PAIR(x) COLOR_PAIR(x)
|
||||
# include "../../src/tty/color-slang.h"
|
||||
#else
|
||||
# define MY_COLOR_PAIR(x) (COLOR_PAIR(x) | attr_pairs [x])
|
||||
# include "../../src/tty/color-ncurses.h"
|
||||
#endif
|
||||
|
||||
#define IF_COLOR(co,bw) (use_colors ? MY_COLOR_PAIR(co) : bw)
|
||||
extern int use_colors;
|
||||
extern int disable_colors;
|
||||
|
||||
/* Beware! When using Slang with color, not all the indexes are free.
|
||||
See myslang.h (A_*) */
|
||||
#define NORMAL_COLOR IF_COLOR (1, 0)
|
||||
#define SELECTED_COLOR IF_COLOR (2, A_REVERSE)
|
||||
#define MARKED_COLOR IF_COLOR (3, A_BOLD)
|
||||
|
||||
#ifdef HAVE_SLANG
|
||||
#define MARKED_SELECTED_COLOR IF_COLOR (4, (SLtt_Use_Ansi_Colors ? A_BOLD_REVERSE : A_REVERSE | A_BOLD))
|
||||
#else
|
||||
#define MARKED_SELECTED_COLOR IF_COLOR (4, A_REVERSE | A_BOLD)
|
||||
#endif
|
||||
|
||||
/* MARKED_SELECTED_COLOR is screen library specific */
|
||||
#define ERROR_COLOR IF_COLOR (5, A_BOLD)
|
||||
#define MENU_ENTRY_COLOR IF_COLOR (6, A_REVERSE)
|
||||
#define REVERSE_COLOR IF_COLOR (7, A_REVERSE)
|
||||
|
@ -93,15 +84,8 @@ extern int alarm_colors[4];
|
|||
#define ERROR_HOT_NORMAL IF_COLOR (39, 0)
|
||||
#define ERROR_HOT_FOCUS IF_COLOR (40, 0)
|
||||
|
||||
#ifdef HAVE_SLANG
|
||||
# define CTYPE const char *
|
||||
#else
|
||||
# define CTYPE int
|
||||
#endif
|
||||
|
||||
void init_colors (void);
|
||||
void done_colors (void);
|
||||
void mc_init_pair (int index, CTYPE foreground, CTYPE background);
|
||||
int try_alloc_color_pair (const char *fg, const char *bg);
|
||||
|
||||
#endif
|
||||
#endif /* MC_COLOR_H */
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
|
|
@ -1,124 +0,0 @@
|
|||
|
||||
/** \file myslang.h
|
||||
* \brief Header: slang wrapper module
|
||||
*/
|
||||
|
||||
#ifndef MC_MYSLANG_H
|
||||
#define MC_MYSLANG_H
|
||||
|
||||
#ifdef HAVE_SLANG_SLANG_H
|
||||
# include <slang/slang.h>
|
||||
#else
|
||||
# include <slang.h>
|
||||
#endif /* HAVE_SLANG_SLANG_H */
|
||||
|
||||
enum {
|
||||
KEY_BACKSPACE = 400,
|
||||
KEY_END, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT,
|
||||
KEY_HOME, KEY_A1, KEY_C1, KEY_NPAGE, KEY_PPAGE, KEY_IC,
|
||||
KEY_ENTER, KEY_DC, KEY_SCANCEL, KEY_BTAB
|
||||
};
|
||||
|
||||
#define KEY_F(x) (1000+x)
|
||||
|
||||
#define ACS_VLINE SLSMG_VLINE_CHAR
|
||||
#define ACS_HLINE SLSMG_HLINE_CHAR
|
||||
#define ACS_LTEE SLSMG_LTEE_CHAR
|
||||
#define ACS_RTEE SLSMG_RTEE_CHAR
|
||||
#define ACS_ULCORNER SLSMG_ULCORN_CHAR
|
||||
#define ACS_LLCORNER SLSMG_LLCORN_CHAR
|
||||
#define ACS_URCORNER SLSMG_URCORN_CHAR
|
||||
#define ACS_LRCORNER SLSMG_LRCORN_CHAR
|
||||
|
||||
#define acs() SLsmg_set_char_set(1)
|
||||
#define noacs() SLsmg_set_char_set (0)
|
||||
#define baudrate() SLang_TT_Baud_Rate
|
||||
|
||||
enum {
|
||||
COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE,
|
||||
COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE
|
||||
};
|
||||
|
||||
/* When using Slang with color, we have all the indexes free but
|
||||
* those defined here (A_BOLD, A_UNDERLINE, A_REVERSE, A_BOLD_REVERSE)
|
||||
*/
|
||||
#define A_BOLD 0x40
|
||||
#define A_UNDERLINE 0x40
|
||||
#define A_REVERSE 0x20
|
||||
#define A_BOLD_REVERSE 0x21
|
||||
|
||||
#ifndef A_NORMAL
|
||||
# define A_NORMAL 0x00
|
||||
#endif
|
||||
|
||||
#define COLOR_PAIR(x) x
|
||||
|
||||
#ifndef TRUE
|
||||
# define TRUE 1
|
||||
# define FALSE 0
|
||||
#endif
|
||||
|
||||
void slang_set_raw_mode (void);
|
||||
|
||||
#define doupdate()
|
||||
#define raw() slang_set_raw_mode()
|
||||
#define noraw()
|
||||
#define nodelay(x,val) set_slang_delay(val)
|
||||
#define noecho()
|
||||
#define beep() SLtt_beep ()
|
||||
#define keypad(scr,value) slang_keypad (value)
|
||||
|
||||
#define ungetch(x) SLang_ungetkey(x)
|
||||
#define start_color()
|
||||
#define touchwin(x) SLsmg_touch_lines(0, LINES)
|
||||
#define reset_shell_mode() slang_shell_mode()
|
||||
#define reset_prog_mode() slang_prog_mode()
|
||||
#define flushinp()
|
||||
|
||||
void slint_goto (int y, int x);
|
||||
void attrset (int color);
|
||||
void set_slang_delay (int);
|
||||
void slang_init (void);
|
||||
void slang_prog_mode (void);
|
||||
void hline (int ch, int len);
|
||||
void vline (int ch, int len);
|
||||
int getch (void);
|
||||
void slang_keypad (int set);
|
||||
void slang_shell_mode (void);
|
||||
void slang_shutdown (void);
|
||||
int has_colors (void);
|
||||
|
||||
#define move(x, y) SLsmg_gotorc(x, y)
|
||||
#define getyx(stdscr, row, col) \
|
||||
do { \
|
||||
row = SLsmg_get_row(); \
|
||||
col = SLsmg_get_column(); \
|
||||
} while (0)
|
||||
#define printw SLsmg_printf
|
||||
#define COLS SLtt_Screen_Cols
|
||||
#define LINES SLtt_Screen_Rows
|
||||
#define standend() SLsmg_normal_video()
|
||||
|
||||
#ifdef UTF8
|
||||
/*
|
||||
* Patched S-Lang in Red Hat 8.0 expects wchar_t as the argument to addch()
|
||||
* Avoid conversion by using SLsmg_write_nchars(), which takes char*
|
||||
*/
|
||||
#undef addch
|
||||
static inline void
|
||||
mc_addch (char c)
|
||||
{
|
||||
SLsmg_write_nchars (&c, 1);
|
||||
}
|
||||
#define addch(c) mc_addch(c)
|
||||
#else
|
||||
#define addch(c) SLsmg_write_char(c)
|
||||
#endif
|
||||
|
||||
#define addstr(s) SLsmg_write_string(str_unconst(s))
|
||||
#define refresh() SLsmg_refresh()
|
||||
#define endwin() SLsmg_reset_smg()
|
||||
|
||||
#define SLsmg_draw_double_box(r,c,dr,dc) SLsmg_draw_box ((r), (c), (dr), (dc))
|
||||
|
||||
#endif
|
|
@ -25,7 +25,6 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
|
||||
/** \file
|
||||
* \brief Source: NCurses-based tty layer of Midnight-commander
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "../../src/global.h"
|
||||
|
||||
#ifndef WANT_TERM_H
|
||||
# define WANT_TERM_H
|
||||
#endif
|
||||
|
||||
#include "../../src/tty/color-ncurses.h"
|
||||
#include "../../src/tty/tty-ncurses.h"
|
||||
|
||||
#include "../../src/background.h" /* we_are_background */
|
||||
#include "../../src/strutil.h" /* str_term_form */
|
||||
#include "../../src/util.h" /* str_unconst */
|
||||
|
||||
/* include at last !!! */
|
||||
#ifdef WANT_TERM_H
|
||||
# include <term.h>
|
||||
#endif /* WANT_TERM_H*/
|
||||
|
||||
/*** global variables **************************************************/
|
||||
|
||||
/*** file scope macro definitions **************************************/
|
||||
|
||||
/*** global variables **************************************************/
|
||||
|
||||
/*** file scope type declarations **************************************/
|
||||
|
||||
/*** file scope variables **********************************************/
|
||||
|
||||
/*** file scope functions **********************************************/
|
||||
|
||||
/*** public functions **************************************************/
|
||||
|
||||
void
|
||||
tty_lowlevel_setcolor (int color)
|
||||
{
|
||||
attrset (MY_COLOR_PAIR (color));
|
||||
}
|
||||
|
||||
void
|
||||
tty_gotoyx (int y, int x)
|
||||
{
|
||||
move (y, x);
|
||||
}
|
||||
|
||||
void
|
||||
tty_getyx (int *py, int *px)
|
||||
{
|
||||
getyx (stdscr, *py, *px);
|
||||
}
|
||||
|
||||
void
|
||||
tty_print_char (int c)
|
||||
{
|
||||
addch (c);
|
||||
}
|
||||
|
||||
void
|
||||
tty_print_alt_char (int c)
|
||||
{
|
||||
addch (c);
|
||||
}
|
||||
|
||||
void
|
||||
tty_print_string(const char *s)
|
||||
{
|
||||
addstr (str_term_form (s));
|
||||
}
|
||||
|
||||
void
|
||||
tty_printf (const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start (args, fmt);
|
||||
vw_printw (stdscr, fmt, args);
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
char *
|
||||
tty_tgetstr (const char *cap)
|
||||
{
|
||||
char *unused = NULL;
|
||||
return tgetstr (str_unconst (cap), &unused);
|
||||
}
|
||||
|
||||
void
|
||||
mc_refresh (void)
|
||||
{
|
||||
#ifdef WITH_BACKGROUND
|
||||
if (!we_are_background)
|
||||
#endif /* WITH_BACKGROUND */
|
||||
refresh ();
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
#ifndef MC_TTY_NCURSES_H
|
||||
#define MC_TTY_NCURSES_H
|
||||
|
||||
#ifdef USE_NCURSES
|
||||
# ifdef HAVE_NCURSES_CURSES_H
|
||||
# include <ncurses/curses.h>
|
||||
# elif HAVE_NCURSESW_CURSES_H
|
||||
# include <ncursesw/curses.h>
|
||||
# elif HAVE_NCURSES_H
|
||||
# include <ncurses.h>
|
||||
# else
|
||||
# include <curses.h>
|
||||
# endif
|
||||
#endif /* USE_NCURSES */
|
||||
|
||||
#ifdef USE_NCURSESW
|
||||
# include <ncursesw/curses.h>
|
||||
#endif /* USE_NCURSESW */
|
||||
|
||||
|
||||
#define acs()
|
||||
#define noacs()
|
||||
|
||||
#endif /* MC_TTY_NCURSES_H */
|
|
@ -1,72 +1,56 @@
|
|||
/* Slang interface to the Midnight Commander
|
||||
This emulates some features of ncurses on top of slang
|
||||
|
||||
Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
||||
2005, 2007 Free Software Foundation, Inc.
|
||||
|
||||
Author Miguel de Icaza
|
||||
Norbert Warmuth
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
|
||||
|
||||
/** \file slint.c
|
||||
* \brief Source: slang %interface to the Midnight Commander
|
||||
* \warning This module will be removed soon
|
||||
/** \file
|
||||
* \brief Source: S-Lang-based tty layer of Midnight Commander
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
#include <termios.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h> /* size_t */
|
||||
|
||||
#include "../../src/global.h"
|
||||
|
||||
#include "../../src/tty/tty.h"
|
||||
#include "../../src/tty/tty-slang.h" /* mc-init_pair */
|
||||
#include "../../src/tty/color.h"
|
||||
#include "../../src/tty/mouse.h" /* Gpm_Event is required in key.h */
|
||||
#include "../../src/tty/key.h" /* define_sequence */
|
||||
#include "../../src/tty/win.h" /* do_exit_ca_mode */
|
||||
|
||||
#include "../../src/background.h" /* we_are_background */
|
||||
#include "../../src/util.h" /* str_unconst */
|
||||
#include "../../src/strutil.h" /* str_term_form */
|
||||
#include "../../src/main.h" /* extern: force_colors */
|
||||
#include "../../src/setup.h"
|
||||
#include "../../src/background.h" /* we_are_background */
|
||||
|
||||
#ifdef HAVE_SLANG
|
||||
/*** global variables **************************************************/
|
||||
|
||||
/*** file scope macro definitions **************************************/
|
||||
|
||||
/* Taken from S-Lang's slutty.c */
|
||||
#ifdef ultrix /* Ultrix gets _POSIX_VDISABLE wrong! */
|
||||
# define NULL_VALUE -1
|
||||
# define NULL_VALUE -1
|
||||
#else
|
||||
# ifdef _POSIX_VDISABLE
|
||||
# define NULL_VALUE _POSIX_VDISABLE
|
||||
# else
|
||||
# define NULL_VALUE 255
|
||||
# endif
|
||||
#endif
|
||||
# ifdef _POSIX_VDISABLE
|
||||
# define NULL_VALUE _POSIX_VDISABLE
|
||||
# else
|
||||
# define NULL_VALUE 255
|
||||
# endif
|
||||
#endif /* ultrix */
|
||||
|
||||
#ifndef SA_RESTART
|
||||
# define SA_RESTART 0
|
||||
# define SA_RESTART 0
|
||||
#endif
|
||||
|
||||
/*** file scope type declarations **************************************/
|
||||
|
||||
/*** file scope variables **********************************************/
|
||||
|
||||
/* Various saved termios settings that we control here */
|
||||
static struct termios boot_mode;
|
||||
static struct termios new_mode;
|
||||
|
@ -74,70 +58,164 @@ static struct termios new_mode;
|
|||
/* Controls whether we should wait for input in getch */
|
||||
static int no_slang_delay;
|
||||
|
||||
/* Forward declarations */
|
||||
static void load_terminfo_keys (void);
|
||||
/* This table describes which capabilities we want and which values we
|
||||
* assign to them.
|
||||
*/
|
||||
static const struct {
|
||||
int key_code;
|
||||
const char *key_name;
|
||||
} key_table [] = {
|
||||
{ KEY_F(0), "k0" },
|
||||
{ KEY_F(1), "k1" },
|
||||
{ KEY_F(2), "k2" },
|
||||
{ KEY_F(3), "k3" },
|
||||
{ KEY_F(4), "k4" },
|
||||
{ KEY_F(5), "k5" },
|
||||
{ KEY_F(6), "k6" },
|
||||
{ KEY_F(7), "k7" },
|
||||
{ KEY_F(8), "k8" },
|
||||
{ KEY_F(9), "k9" },
|
||||
{ KEY_F(10), "k;" },
|
||||
{ KEY_F(11), "F1" },
|
||||
{ KEY_F(12), "F2" },
|
||||
{ KEY_F(13), "F3" },
|
||||
{ KEY_F(14), "F4" },
|
||||
{ KEY_F(15), "F5" },
|
||||
{ KEY_F(16), "F6" },
|
||||
{ KEY_F(17), "F7" },
|
||||
{ KEY_F(18), "F8" },
|
||||
{ KEY_F(19), "F9" },
|
||||
{ KEY_F(20), "FA" },
|
||||
{ KEY_IC, "kI" },
|
||||
{ KEY_NPAGE, "kN" },
|
||||
{ KEY_PPAGE, "kP" },
|
||||
{ KEY_LEFT, "kl" },
|
||||
{ KEY_RIGHT, "kr" },
|
||||
{ KEY_UP, "ku" },
|
||||
{ KEY_DOWN, "kd" },
|
||||
{ KEY_DC, "kD" },
|
||||
{ KEY_BACKSPACE, "kb" },
|
||||
{ KEY_HOME, "kh" },
|
||||
{ KEY_END, "@7" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
/*** file scope functions **********************************************/
|
||||
|
||||
#ifndef HAVE_SLANG_PRIVATE
|
||||
/* Private interfaces have been stripped, so we cannot use them */
|
||||
#define SLang_getkey2() SLang_getkey()
|
||||
#define SLang_input_pending2(s) SLang_input_pending(s)
|
||||
/* Private interfaces have been stripped, so we cannot use them */
|
||||
# define SLang_getkey2() SLang_getkey ()
|
||||
# define SLang_input_pending2(s) SLang_input_pending (s)
|
||||
#else
|
||||
/* Copied from ../slang/slgetkey.c, removed the DEC_8Bit_HACK. */
|
||||
extern unsigned char SLang_Input_Buffer [];
|
||||
#if SLANG_VERSION >= 10000
|
||||
extern unsigned int _SLsys_getkey (void);
|
||||
extern int _SLsys_input_pending (int);
|
||||
#else
|
||||
extern unsigned int SLsys_getkey (void);
|
||||
extern int SLsys_input_pending (int);
|
||||
#endif
|
||||
|
||||
static unsigned int SLang_getkey2 (void)
|
||||
static unsigned int
|
||||
SLang_getkey2 (void)
|
||||
{
|
||||
unsigned int imax;
|
||||
unsigned int ch;
|
||||
|
||||
if (SLang_Input_Buffer_Len)
|
||||
{
|
||||
if (SLang_Input_Buffer_Len) {
|
||||
unsigned int ch;
|
||||
unsigned int imax;
|
||||
|
||||
ch = (unsigned int) *SLang_Input_Buffer;
|
||||
SLang_Input_Buffer_Len--;
|
||||
imax = SLang_Input_Buffer_Len;
|
||||
|
||||
memmove ((char *) SLang_Input_Buffer,
|
||||
|
||||
memmove ((char *) SLang_Input_Buffer,
|
||||
(char *) (SLang_Input_Buffer + 1), imax);
|
||||
return(ch);
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
#if SLANG_VERSION >= 10000
|
||||
else return(_SLsys_getkey ());
|
||||
return _SLsys_getkey ();
|
||||
#else
|
||||
else return(SLsys_getkey());
|
||||
return SLsys_getkey();
|
||||
#endif
|
||||
}
|
||||
|
||||
static int SLang_input_pending2 (int tsecs)
|
||||
static int
|
||||
SLang_input_pending2 (int tsecs)
|
||||
{
|
||||
int n, i;
|
||||
unsigned char c;
|
||||
int n, i;
|
||||
unsigned char c;
|
||||
|
||||
if (SLang_Input_Buffer_Len) return (int) SLang_Input_Buffer_Len;
|
||||
#if SLANG_VERSION >= 10000
|
||||
n = _SLsys_input_pending (tsecs);
|
||||
if (SLang_Input_Buffer_Len)
|
||||
return (int) SLang_Input_Buffer_Len;
|
||||
#if SLANG_VERSION >= 10000
|
||||
n = _SLsys_input_pending (tsecs);
|
||||
#else
|
||||
n = SLsys_input_pending (tsecs);
|
||||
n = SLsys_input_pending (tsecs);
|
||||
#endif
|
||||
if (n <= 0) return 0;
|
||||
|
||||
i = SLang_getkey2 ();
|
||||
if (i == SLANG_GETKEY_ERROR)
|
||||
return 0; /* don't put crippled error codes into the input buffer */
|
||||
c = (unsigned char)i;
|
||||
SLang_ungetkey_string (&c, 1);
|
||||
|
||||
return n;
|
||||
}
|
||||
#endif /* HAVE_SLANG_PRIVATE */
|
||||
if (n <= 0)
|
||||
return 0;
|
||||
|
||||
i = SLang_getkey2 ();
|
||||
if (i == SLANG_GETKEY_ERROR)
|
||||
return 0; /* don't put crippled error codes into the input buffer */
|
||||
|
||||
c = (unsigned char) i;
|
||||
SLang_ungetkey_string (&c, 1);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
#endif /* HAVE_SLANG_PRIVATE */
|
||||
|
||||
|
||||
/* HP Terminals have capabilities (pfkey, pfloc, pfx) to program function keys.
|
||||
elm 2.4pl15 invoked with the -K option utilizes these softkeys and the
|
||||
consequence is that function keys don't work in MC sometimes...
|
||||
Unfortunately I don't now the one and only escape sequence to turn off.
|
||||
softkeys (elm uses three different capabilities to turn on softkeys and two.
|
||||
capabilities to turn them off)..
|
||||
Among other things elm uses the pair we already use in slang_keypad. That's.
|
||||
the reason why I call slang_reset_softkeys from slang_keypad. In lack of
|
||||
something better the softkeys are programmed to their defaults from the
|
||||
termcap/terminfo database.
|
||||
The escape sequence to program the softkeys is taken from elm and it is.
|
||||
hardcoded because neither slang nor ncurses 4.1 know how to 'printf' this.
|
||||
sequence. -- Norbert
|
||||
*/
|
||||
|
||||
static void
|
||||
slang_reset_softkeys (void)
|
||||
{
|
||||
int key;
|
||||
char *send;
|
||||
static const char display[] = " ";
|
||||
char tmp[BUF_SMALL];
|
||||
|
||||
for (key = 1; key < 9; key++) {
|
||||
g_snprintf (tmp, sizeof (tmp), "k%d", key);
|
||||
send = (char *) SLtt_tgetstr (tmp);
|
||||
if (send != NULL) {
|
||||
g_snprintf (tmp, sizeof (tmp), "\033&f%dk%dd%dL%s%s", key,
|
||||
(int) (sizeof (display) - 1), (int) strlen (send),
|
||||
display, send);
|
||||
SLtt_write_string (tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
do_define_key (int code, const char *strcap)
|
||||
{
|
||||
char *seq;
|
||||
|
||||
seq = (char *) SLtt_tgetstr ((char *) strcap);
|
||||
if (seq != NULL)
|
||||
define_sequence (code, seq, MCKEY_NOACTION);
|
||||
}
|
||||
|
||||
static void
|
||||
load_terminfo_keys (void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; key_table [i].key_code; i++)
|
||||
do_define_key (key_table [i].key_code, key_table [i].key_name);
|
||||
}
|
||||
|
||||
/*** public functions **************************************************/
|
||||
|
||||
/* Only done the first time */
|
||||
void
|
||||
slang_init (void)
|
||||
{
|
||||
|
@ -152,21 +230,20 @@ slang_init (void)
|
|||
* (as of S-Lang 1.4.4). Detect it and abort. Also detect extremely
|
||||
* small, large and negative screen dimensions.
|
||||
*/
|
||||
if ((COLS < 10) || (LINES < 5) ||
|
||||
(SLang_Version < 10407 && (COLS > 255 || LINES > 255)) ||
|
||||
(SLang_Version >= 10407 && (COLS > 512 || LINES > 512))) {
|
||||
|
||||
if ((COLS < 10) || (LINES < 5)
|
||||
|| ((SLang_Version < 10407) && ((COLS > 255) || (LINES > 255)))
|
||||
|| ((SLang_Version >= 10407) && ((COLS > 512) || (LINES > 512)))) {
|
||||
fprintf (stderr,
|
||||
_("Screen size %dx%d is not supported.\n"
|
||||
"Check the TERM environment variable.\n"),
|
||||
COLS, LINES);
|
||||
_("Screen size %dx%d is not supported.\n"
|
||||
"Check the TERM environment variable.\n"),
|
||||
COLS, LINES);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
tcgetattr (fileno (stdin), &boot_mode);
|
||||
/* 255 = ignore abort char; XCTRL('g') for abort char = ^g */
|
||||
SLang_init_tty (XCTRL('c'), 1, 0);
|
||||
|
||||
SLang_init_tty (XCTRL('c'), 1, 0);
|
||||
|
||||
/* If SLang uses fileno(stderr) for terminal input MC will hang
|
||||
if we call SLang_getkey between calls to open_error_pipe and
|
||||
close_error_pipe, e.g. when we do a growing view of an gzipped
|
||||
|
@ -178,13 +255,14 @@ slang_init (void)
|
|||
SLtt_Has_Alt_Charset = 0;
|
||||
if (tcgetattr (SLang_TT_Read_FD, &new_mode) == 0) {
|
||||
#ifdef VDSUSP
|
||||
new_mode.c_cc[VDSUSP] = NULL_VALUE; /* to ignore ^Y */
|
||||
new_mode.c_cc[VDSUSP] = NULL_VALUE; /* to ignore ^Y */
|
||||
#endif
|
||||
#ifdef VLNEXT
|
||||
new_mode.c_cc[VLNEXT] = NULL_VALUE; /* to ignore ^V */
|
||||
new_mode.c_cc[VLNEXT] = NULL_VALUE; /* to ignore ^V */
|
||||
#endif
|
||||
tcsetattr (SLang_TT_Read_FD, TCSADRAIN, &new_mode);
|
||||
}
|
||||
|
||||
slang_prog_mode ();
|
||||
load_terminfo_keys ();
|
||||
SLtt_Blink_Mode = 0;
|
||||
|
@ -216,66 +294,31 @@ void
|
|||
slang_shutdown (void)
|
||||
{
|
||||
char *op_cap;
|
||||
|
||||
|
||||
slang_shell_mode ();
|
||||
do_exit_ca_mode ();
|
||||
SLang_reset_tty ();
|
||||
|
||||
/* Load the op capability to reset the colors to those that were
|
||||
* active when the program was started up
|
||||
/* Load the op capability to reset the colors to those that were
|
||||
* active when the program was started up
|
||||
*/
|
||||
op_cap = SLtt_tgetstr ((char*)"op");
|
||||
if (op_cap){
|
||||
op_cap = SLtt_tgetstr ((cagr *) "op");
|
||||
if (op_cap != NULL) {
|
||||
fputs (op_cap, stdout);
|
||||
fflush (stdout);
|
||||
}
|
||||
}
|
||||
|
||||
/* HP Terminals have capabilities (pfkey, pfloc, pfx) to program function keys.
|
||||
elm 2.4pl15 invoked with the -K option utilizes these softkeys and the
|
||||
consequence is that function keys don't work in MC sometimes.
|
||||
Unfortunately I don't now the one and only escape sequence to turn off
|
||||
softkeys (elm uses three different capabilities to turn on softkeys and two
|
||||
capabilities to turn them off).
|
||||
Among other things elm uses the pair we already use in slang_keypad. That's
|
||||
the reason why I call slang_reset_softkeys from slang_keypad. In lack of
|
||||
something better the softkeys are programmed to their defaults from the
|
||||
termcap/terminfo database.
|
||||
The escape sequence to program the softkeys is taken from elm and it is
|
||||
hardcoded because neither slang nor ncurses 4.1 know how to 'printf' this
|
||||
sequence. -- Norbert
|
||||
*/
|
||||
|
||||
static void
|
||||
slang_reset_softkeys (void)
|
||||
{
|
||||
int key;
|
||||
char *send;
|
||||
static const char display[] = " ";
|
||||
char tmp[BUF_SMALL];
|
||||
|
||||
for (key = 1; key < 9; key++) {
|
||||
g_snprintf (tmp, sizeof (tmp), "k%d", key);
|
||||
send = (char *) SLtt_tgetstr (tmp);
|
||||
if (send) {
|
||||
g_snprintf (tmp, sizeof (tmp), "\033&f%dk%dd%dL%s%s", key,
|
||||
(int) (sizeof (display) - 1), (int) strlen (send),
|
||||
display, send);
|
||||
SLtt_write_string (tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* keypad routines */
|
||||
void
|
||||
slang_keypad (int set)
|
||||
{
|
||||
const char *keypad_string;
|
||||
extern int reset_hp_softkeys;
|
||||
|
||||
keypad_string = SLtt_tgetstr ((char*)(set ? "ks" : "ke"));
|
||||
if (keypad_string)
|
||||
SLtt_write_string ((char*)keypad_string);
|
||||
|
||||
keypad_string = SLtt_tgetstr ((char *) (set ? "ks" : "ke"));
|
||||
if (keypad_string != NULL)
|
||||
SLtt_write_string ((char *) keypad_string);
|
||||
if (set && reset_hp_softkeys)
|
||||
slang_reset_softkeys ();
|
||||
}
|
||||
|
@ -293,194 +336,192 @@ hline (int ch, int len)
|
|||
|
||||
last_x = SLsmg_get_column ();
|
||||
last_y = SLsmg_get_row ();
|
||||
|
||||
|
||||
if (ch == 0)
|
||||
ch = ACS_HLINE;
|
||||
|
||||
if (ch == ACS_HLINE){
|
||||
if (ch == ACS_HLINE)
|
||||
SLsmg_draw_hline (len);
|
||||
} else {
|
||||
else
|
||||
while (len--)
|
||||
addch (ch);
|
||||
}
|
||||
move (last_y, last_x);
|
||||
|
||||
SLsmg_gotorc (last_y, last_x);
|
||||
}
|
||||
|
||||
void
|
||||
vline (int character, int len)
|
||||
{
|
||||
(void) character;
|
||||
if (!slow_terminal){
|
||||
|
||||
if (!slow_terminal)
|
||||
SLsmg_draw_vline (len);
|
||||
} else {
|
||||
else {
|
||||
int last_x, last_y, pos = 0;
|
||||
|
||||
last_x = SLsmg_get_column ();
|
||||
last_y = SLsmg_get_row ();
|
||||
|
||||
while (len--){
|
||||
while (len--) {
|
||||
move (last_y + pos++, last_x);
|
||||
addch (' ');
|
||||
}
|
||||
move (last_x, last_y);
|
||||
|
||||
SLsmg_gotorc (last_x, last_y);
|
||||
}
|
||||
}
|
||||
|
||||
int has_colors (void)
|
||||
{
|
||||
const char *terminal = getenv ("TERM");
|
||||
char *cts = color_terminal_string, *s;
|
||||
char *cts = color_terminal_string;
|
||||
char *s;
|
||||
size_t i;
|
||||
|
||||
if (force_colors)
|
||||
SLtt_Use_Ansi_Colors = 1;
|
||||
if (NULL != getenv ("COLORTERM"))
|
||||
if (getenv ("COLORTERM") != NULL)
|
||||
SLtt_Use_Ansi_Colors = 1;
|
||||
|
||||
/* We want to allow overwriding */
|
||||
if (!disable_colors){
|
||||
/* check color_terminal_string */
|
||||
if (*cts)
|
||||
{
|
||||
while (*cts)
|
||||
{
|
||||
while (*cts == ' ' || *cts == '\t') cts++;
|
||||
if (!disable_colors) {
|
||||
/* check color_terminal_string */
|
||||
while (*cts != '\0') {
|
||||
while (*cts == ' ' || *cts == '\t')
|
||||
cts++;
|
||||
s = cts;
|
||||
i = 0;
|
||||
|
||||
s = cts;
|
||||
i = 0;
|
||||
while (*cts != '\0' && *cts != ',') {
|
||||
cts++;
|
||||
i++;
|
||||
}
|
||||
|
||||
while (*cts && *cts != ',')
|
||||
{
|
||||
cts++;
|
||||
i++;
|
||||
}
|
||||
if (i && i == strlen(terminal) && strncmp(s, terminal, i) == 0)
|
||||
SLtt_Use_Ansi_Colors = 1;
|
||||
if (i != 0 && i == strlen (terminal)
|
||||
&& strncmp (s, terminal, i) == 0)
|
||||
SLtt_Use_Ansi_Colors = 1;
|
||||
|
||||
if (*cts == ',') cts++;
|
||||
}
|
||||
}
|
||||
if (*cts == ',')
|
||||
cts++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Setup emulated colors */
|
||||
if (SLtt_Use_Ansi_Colors){
|
||||
if (use_colors){
|
||||
if (SLtt_Use_Ansi_Colors) {
|
||||
if (use_colors) {
|
||||
mc_init_pair (A_REVERSE, "black", "white");
|
||||
mc_init_pair (A_BOLD, "white", "black");
|
||||
} else {
|
||||
mc_init_pair (A_REVERSE, "black", "lightgray");
|
||||
mc_init_pair (A_BOLD, "white", "black");
|
||||
mc_init_pair (A_BOLD_REVERSE, "white", "lightgray");
|
||||
}
|
||||
}
|
||||
} 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){
|
||||
if (!SLtt_Use_Ansi_Colors)
|
||||
SLsmg_set_color (color);
|
||||
return;
|
||||
}
|
||||
|
||||
if (color & A_BOLD){
|
||||
else if ((color & A_BOLD) != 0) {
|
||||
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
|
||||
} else
|
||||
SLsmg_set_color (color);
|
||||
}
|
||||
|
||||
/* This table describes which capabilities we want and which values we
|
||||
* assign to them.
|
||||
*/
|
||||
static const struct {
|
||||
int key_code;
|
||||
const char *key_name;
|
||||
} key_table [] = {
|
||||
{ KEY_F(0), "k0" },
|
||||
{ KEY_F(1), "k1" },
|
||||
{ KEY_F(2), "k2" },
|
||||
{ KEY_F(3), "k3" },
|
||||
{ KEY_F(4), "k4" },
|
||||
{ KEY_F(5), "k5" },
|
||||
{ KEY_F(6), "k6" },
|
||||
{ KEY_F(7), "k7" },
|
||||
{ KEY_F(8), "k8" },
|
||||
{ KEY_F(9), "k9" },
|
||||
{ KEY_F(10), "k;" },
|
||||
{ KEY_F(11), "F1" },
|
||||
{ KEY_F(12), "F2" },
|
||||
{ KEY_F(13), "F3" },
|
||||
{ KEY_F(14), "F4" },
|
||||
{ KEY_F(15), "F5" },
|
||||
{ KEY_F(16), "F6" },
|
||||
{ KEY_F(17), "F7" },
|
||||
{ KEY_F(18), "F8" },
|
||||
{ KEY_F(19), "F9" },
|
||||
{ KEY_F(20), "FA" },
|
||||
{ KEY_IC, "kI" },
|
||||
{ KEY_NPAGE, "kN" },
|
||||
{ KEY_PPAGE, "kP" },
|
||||
{ KEY_LEFT, "kl" },
|
||||
{ KEY_RIGHT, "kr" },
|
||||
{ KEY_UP, "ku" },
|
||||
{ KEY_DOWN, "kd" },
|
||||
{ KEY_DC, "kD" },
|
||||
{ KEY_BACKSPACE, "kb" },
|
||||
{ KEY_HOME, "kh" },
|
||||
{ KEY_END, "@7" },
|
||||
{ 0, 0}
|
||||
};
|
||||
|
||||
static void
|
||||
do_define_key (int code, const char *strcap)
|
||||
/* Set colorpair by index, don't interpret S-Lang "emulated attributes" */
|
||||
void
|
||||
tty_lowlevel_setcolor (int color)
|
||||
{
|
||||
char *seq;
|
||||
|
||||
seq = (char *) SLtt_tgetstr ((char*) strcap);
|
||||
if (seq)
|
||||
define_sequence (code, seq, MCKEY_NOACTION);
|
||||
}
|
||||
|
||||
static void
|
||||
load_terminfo_keys (void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; key_table [i].key_code; i++)
|
||||
do_define_key (key_table [i].key_code, key_table [i].key_name);
|
||||
SLsmg_set_color (color & 0x7F);
|
||||
}
|
||||
|
||||
int
|
||||
getch (void)
|
||||
{
|
||||
int c;
|
||||
if (no_slang_delay)
|
||||
if (SLang_input_pending2 (0) == 0)
|
||||
return -1;
|
||||
|
||||
if (no_slang_delay
|
||||
&& (SLang_input_pending2 (0) == 0))
|
||||
return -1;
|
||||
|
||||
c = SLang_getkey2 ();
|
||||
if (c == SLANG_GETKEY_ERROR) {
|
||||
fprintf (stderr,
|
||||
"SLang_getkey returned SLANG_GETKEY_ERROR\n"
|
||||
"Assuming EOF on stdin and exiting\n");
|
||||
"SLang_getkey returned SLANG_GETKEY_ERROR\n"
|
||||
"Assuming EOF on stdin and exiting\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
#endif /* HAVE_SLANG */
|
||||
|
||||
void
|
||||
tty_gotoyx (int y, int x)
|
||||
{
|
||||
SLsmg_gotorc (y, x);
|
||||
}
|
||||
|
||||
void
|
||||
tty_getyx (int *py, int *px)
|
||||
{
|
||||
*px = SLsmg_get_column ();
|
||||
*py = SLsmg_get_row ();
|
||||
}
|
||||
|
||||
void
|
||||
tty_print_char (int c)
|
||||
{
|
||||
/* We cannot use SLsmg_write_char here because the Debian and Redhat
|
||||
* people thought changing the API of an external project was fun,
|
||||
* especially when it depends on the preprocessor symbol UTF8 being
|
||||
* defined or not. Congratulations! At least, they left the API call
|
||||
* for SLsmg_write_nchars as it has always been.
|
||||
*/
|
||||
char ch;
|
||||
|
||||
ch = c;
|
||||
SLsmg_write_nchars(&ch, 1);
|
||||
}
|
||||
|
||||
void
|
||||
tty_print_alt_char (int c)
|
||||
{
|
||||
SLsmg_draw_object (SLsmg_get_row(), SLsmg_get_column(), c);
|
||||
}
|
||||
|
||||
void
|
||||
tty_print_string (const char *s)
|
||||
{
|
||||
SLsmg_write_string (str_unconst (str_term_form (s)));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
tty_printf (const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
SLsmg_vprintf (str_unconst(fmt), args);
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
char *
|
||||
tty_tgetstr (const char *cap)
|
||||
{
|
||||
return SLtt_tgetstr (str_unconst (cap));
|
||||
}
|
||||
|
||||
void
|
||||
mc_refresh (void)
|
||||
|
@ -488,5 +529,5 @@ mc_refresh (void)
|
|||
#ifdef WITH_BACKGROUND
|
||||
if (!we_are_background)
|
||||
#endif /* WITH_BACKGROUND */
|
||||
refresh ();
|
||||
SLsmg_refresh ();
|
||||
}
|
|
@ -0,0 +1,126 @@
|
|||
|
||||
#ifndef MC_TTY_SLANG_H
|
||||
#define MC_TTY_SLANG_H
|
||||
|
||||
#ifdef HAVE_SLANG_SLANG_H
|
||||
# include <slang/slang.h>
|
||||
#else
|
||||
# include <slang.h>
|
||||
#endif /* HAVE_SLANG_SLANG_H */
|
||||
|
||||
#include "../../src/util.h" /* str_unconst*/
|
||||
|
||||
enum {
|
||||
KEY_BACKSPACE = 400,
|
||||
KEY_END, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT,
|
||||
KEY_HOME, KEY_A1, KEY_C1, KEY_NPAGE, KEY_PPAGE, KEY_IC,
|
||||
KEY_ENTER, KEY_DC, KEY_SCANCEL, KEY_BTAB
|
||||
};
|
||||
|
||||
#define KEY_F(x) (1000 + x)
|
||||
|
||||
#define ACS_VLINE SLSMG_VLINE_CHAR
|
||||
#define ACS_HLINE SLSMG_HLINE_CHAR
|
||||
#define ACS_LTEE SLSMG_LTEE_CHAR
|
||||
#define ACS_RTEE SLSMG_RTEE_CHAR
|
||||
#define ACS_ULCORNER SLSMG_ULCORN_CHAR
|
||||
#define ACS_LLCORNER SLSMG_LLCORN_CHAR
|
||||
#define ACS_URCORNER SLSMG_URCORN_CHAR
|
||||
#define ACS_LRCORNER SLSMG_LRCORN_CHAR
|
||||
|
||||
#define acs() SLsmg_set_char_set (1)
|
||||
#define noacs() SLsmg_set_char_set (0)
|
||||
#define baudrate() SLang_TT_Baud_Rate
|
||||
|
||||
enum {
|
||||
COLOR_BLACK = 0,
|
||||
COLOR_RED,
|
||||
COLOR_GREEN,
|
||||
COLOR_YELLOW,
|
||||
COLOR_BLUE,
|
||||
COLOR_MAGENTA,
|
||||
COLOR_CYAN,
|
||||
COLOR_WHITE
|
||||
};
|
||||
|
||||
/* When using Slang with color, we have all the indexes free but
|
||||
* those defined here (A_BOLD, A_UNDERLINE, A_REVERSE, A_BOLD_REVERSE)
|
||||
*/
|
||||
#define A_BOLD 0x40
|
||||
#define A_UNDERLINE 0x40
|
||||
#define A_REVERSE 0x20
|
||||
#define A_BOLD_REVERSE 0x21
|
||||
|
||||
#ifndef A_NORMAL
|
||||
# define A_NORMAL 0x00
|
||||
#endif
|
||||
|
||||
#define COLOR_PAIR(x) x
|
||||
|
||||
#ifndef TRUE
|
||||
# define TRUE 1
|
||||
# define FALSE 0
|
||||
#endif
|
||||
|
||||
void slang_set_raw_mode (void);
|
||||
|
||||
#define doupdate()
|
||||
#define raw() slang_set_raw_mode ()
|
||||
#define noraw()
|
||||
#define nodelay(x, val) set_slang_delay (val)
|
||||
#define noecho()
|
||||
#define beep() SLtt_beep ()
|
||||
#define keypad(scr, value) slang_keypad (value)
|
||||
|
||||
#define ungetch(x) SLang_ungetkey (x)
|
||||
#define start_color()
|
||||
#define touchwin(x) SLsmg_touch_lines (0, LINES)
|
||||
#define reset_shell_mode() slang_shell_mode ()
|
||||
#define reset_prog_mode() slang_prog_mode ()
|
||||
#define flushinp()
|
||||
|
||||
void attrset (int color);
|
||||
void set_slang_delay (int);
|
||||
void slang_init (void);
|
||||
void slang_prog_mode (void);
|
||||
void hline (int ch, int len);
|
||||
void vline (int ch, int len);
|
||||
int getch (void);
|
||||
void slang_keypad (int set);
|
||||
void slang_shell_mode (void);
|
||||
void slang_shutdown (void);
|
||||
int has_colors (void);
|
||||
|
||||
#define move(y, x) SLsmg_gotorc (y, x)
|
||||
#define getyx(stdscr, row, col) \
|
||||
do { \
|
||||
row = SLsmg_get_row(); \
|
||||
col = SLsmg_get_column(); \
|
||||
} while (0)
|
||||
#define printw SLsmg_printf
|
||||
#define COLS SLtt_Screen_Cols
|
||||
#define LINES SLtt_Screen_Rows
|
||||
#define standend() SLsmg_normal_video ()
|
||||
|
||||
#ifdef UTF8
|
||||
/*
|
||||
* Patched S-Lang in Red Hat 8.0 expects wchar_t as the argument to addch()
|
||||
* Avoid conversion by using SLsmg_write_nchars(), which takes char*
|
||||
*/
|
||||
#undef addch
|
||||
static inline void
|
||||
mc_addch (char c)
|
||||
{
|
||||
SLsmg_write_nchars (&c, 1);
|
||||
}
|
||||
#define addch(c) mc_addch (c)
|
||||
#else
|
||||
#define addch(c) SLsmg_write_char (c)
|
||||
#endif
|
||||
|
||||
#define addstr(s) SLsmg_write_string (str_unconst(s))
|
||||
#define endwin() SLsmg_reset_smg ()
|
||||
|
||||
#define SLsmg_draw_double_box(r, c, dr, dc) SLsmg_draw_box ((r), (c), (dr), (dc))
|
||||
|
||||
#endif /* MC_TTY_SLANG_H */
|
104
src/tty/tty.c
104
src/tty/tty.c
|
@ -35,24 +35,17 @@
|
|||
|
||||
#include "../../src/global.h"
|
||||
|
||||
#include "../../src/tty/color.h"
|
||||
#if defined(USE_NCURSES) || defined(USE_NCURSESW)
|
||||
#define WANT_TERM_H
|
||||
#endif
|
||||
#include "../../src/tty/tty.h"
|
||||
#include "../../src/tty/color.h"
|
||||
|
||||
#include "../../src/main.h" /* for slow_terminal */
|
||||
#include "../../src/strutil.h"
|
||||
|
||||
/*** file scope macro definitions **************************************/
|
||||
|
||||
#ifndef HAVE_SLANG
|
||||
# define acs()
|
||||
# define noacs()
|
||||
#endif
|
||||
#include "../../src/background.h" /* we_are_background */
|
||||
|
||||
/*** global variables **************************************************/
|
||||
|
||||
/*** file scope macro definitions **************************************/
|
||||
|
||||
/*** file scope type declarations **************************************/
|
||||
|
||||
/*** file scope variables **********************************************/
|
||||
|
@ -114,74 +107,12 @@ tty_got_interrupt(void)
|
|||
return rv;
|
||||
}
|
||||
|
||||
extern void
|
||||
tty_gotoyx(int y, int x)
|
||||
{
|
||||
#ifdef HAVE_SLANG
|
||||
SLsmg_gotorc(y, x);
|
||||
#else
|
||||
move(y, x);
|
||||
#endif
|
||||
}
|
||||
|
||||
extern void
|
||||
tty_getyx(int *py, int *px)
|
||||
{
|
||||
#ifdef HAVE_SLANG
|
||||
*px = SLsmg_get_column();
|
||||
*py = SLsmg_get_row();
|
||||
#else
|
||||
getyx(stdscr, *py, *px);
|
||||
#endif
|
||||
}
|
||||
|
||||
extern void
|
||||
tty_setcolor(int c)
|
||||
{
|
||||
attrset(c);
|
||||
}
|
||||
|
||||
extern void
|
||||
tty_print_char(int c)
|
||||
{
|
||||
#ifdef HAVE_SLANG
|
||||
/* We cannot use SLsmg_write_char here because the Debian and Redhat
|
||||
* people thought changing the API of an external project was fun,
|
||||
* especially when it depends on the preprocessor symbol UTF8 being
|
||||
* defined or not. Congratulations! At least, they left the API call
|
||||
* for SLsmg_write_nchars as it has always been.
|
||||
*/
|
||||
char ch;
|
||||
|
||||
ch = c;
|
||||
SLsmg_write_nchars(&ch, 1);
|
||||
#else
|
||||
addch(c);
|
||||
#endif
|
||||
}
|
||||
|
||||
extern void
|
||||
tty_print_alt_char(int c)
|
||||
{
|
||||
#ifdef HAVE_SLANG
|
||||
SLsmg_draw_object(SLsmg_get_row(), SLsmg_get_column(), c);
|
||||
#else
|
||||
acs();
|
||||
addch(c);
|
||||
noacs();
|
||||
#endif
|
||||
}
|
||||
|
||||
extern void
|
||||
tty_print_string(const char *s)
|
||||
{
|
||||
#ifdef HAVE_SLANG
|
||||
SLsmg_write_string (str_unconst (str_term_form (s)));
|
||||
#else
|
||||
addstr (str_term_form (s));
|
||||
#endif
|
||||
}
|
||||
|
||||
extern void
|
||||
tty_print_one_hline(void)
|
||||
{
|
||||
|
@ -221,30 +152,3 @@ tty_print_vline(int top, int left, int length)
|
|||
tty_print_one_vline();
|
||||
}
|
||||
}
|
||||
|
||||
extern void
|
||||
tty_printf(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
#ifdef HAVE_SLANG
|
||||
SLsmg_vprintf(str_unconst(fmt), args);
|
||||
#else
|
||||
vw_printw(stdscr, fmt, args);
|
||||
#endif
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
extern char *
|
||||
tty_tgetstr (const char *cap)
|
||||
{
|
||||
#ifdef HAVE_SLANG
|
||||
return SLtt_tgetstr (str_unconst (cap));
|
||||
#else
|
||||
{
|
||||
char *unused = NULL;
|
||||
return tgetstr (str_unconst (cap), &unused);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -3,39 +3,20 @@
|
|||
* \brief Header: %interface to the terminal controlling library
|
||||
*
|
||||
* This file is the %interface to the terminal controlling library:
|
||||
* ncurses, slang or the built-in slang. It provides an additional
|
||||
* layer of abstraction above the "real" libraries to keep the number
|
||||
* of ifdefs in the other files small.
|
||||
* slang or ncurses. It provides an additional layer of abstraction
|
||||
* above the "real" libraries to keep the number of ifdefs in the other
|
||||
* files small.
|
||||
*/
|
||||
|
||||
#ifndef MC_TTY_H
|
||||
#define MC_TTY_H
|
||||
|
||||
#include "../../src/global.h" /* include <glib.h> */
|
||||
|
||||
#ifdef HAVE_SLANG
|
||||
# include "../../src/tty/myslang.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_NCURSES
|
||||
# ifdef HAVE_NCURSES_CURSES_H
|
||||
# include <ncurses/curses.h>
|
||||
# elif HAVE_NCURSESW_CURSES_H
|
||||
# include <ncursesw/curses.h>
|
||||
# elif HAVE_NCURSES_H
|
||||
# include <ncurses.h>
|
||||
# else
|
||||
# include <curses.h>
|
||||
# endif
|
||||
#ifdef WANT_TERM_H
|
||||
# include <term.h>
|
||||
#endif /* WANT_TERM_H */
|
||||
#endif /* USE_NCURSES */
|
||||
|
||||
#ifdef USE_NCURSESW
|
||||
# include <ncursesw/curses.h>
|
||||
#ifdef WANT_TERM_H
|
||||
# include <term.h>
|
||||
#endif
|
||||
# include "../../src/tty/tty-slang.h"
|
||||
#else
|
||||
# include "../../src/tty/tty-ncurses.h"
|
||||
#endif
|
||||
|
||||
/* {{{ Input }}} */
|
||||
|
@ -53,19 +34,20 @@ extern gboolean tty_got_interrupt(void);
|
|||
While SLang provides such a feature, ncurses does not.
|
||||
*/
|
||||
|
||||
extern void tty_gotoyx(int, int);
|
||||
extern void tty_getyx(int *, int *);
|
||||
extern void tty_gotoyx(int y, int x);
|
||||
extern void tty_getyx(int *py, int *px);
|
||||
|
||||
extern void tty_setcolor(int);
|
||||
extern void tty_setcolor(int color);
|
||||
extern void tty_lowlevel_setcolor(int color);
|
||||
|
||||
extern void tty_print_char(int);
|
||||
extern void tty_print_alt_char(int);
|
||||
extern void tty_print_string(const char *);
|
||||
extern void tty_print_char(int c);
|
||||
extern void tty_print_alt_char(int c);
|
||||
extern void tty_print_string(const char *s);
|
||||
extern void tty_print_one_vline(void);
|
||||
extern void tty_print_one_hline(void);
|
||||
extern void tty_print_vline(int top, int left, int length);
|
||||
extern void tty_print_hline(int top, int left, int length);
|
||||
extern void tty_printf(const char *, ...);
|
||||
extern void tty_printf(const char *s, ...);
|
||||
|
||||
extern char *tty_tgetstr (const char *name);
|
||||
|
||||
|
@ -78,15 +60,10 @@ extern char *tty_tgetstr (const char *name);
|
|||
#define one_hline() tty_print_one_hline()
|
||||
#define one_vline() tty_print_one_vline()
|
||||
|
||||
#ifndef HAVE_SLANG
|
||||
# define acs()
|
||||
# define noacs()
|
||||
#endif
|
||||
|
||||
#define KEY_KP_ADD 4001
|
||||
#define KEY_KP_SUBTRACT 4002
|
||||
#define KEY_KP_MULTIPLY 4003
|
||||
|
||||
void mc_refresh (void);
|
||||
|
||||
#endif
|
||||
#endif /* MC_TTY_H */
|
||||
|
|
|
@ -6,10 +6,13 @@
|
|||
#ifndef MC_UTIL_H
|
||||
#define MC_UTIL_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <assert.h>
|
||||
#include "global.h" /* include <glib.h> */
|
||||
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Returns its argument as a "modifiable" string. This function is
|
||||
* intended to pass strings to legacy libraries that don't know yet
|
||||
|
|
Loading…
Reference in New Issue