Box lines drawing. Now reading from skins. With ncurses don't work!
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
Этот коммит содержится в:
родитель
d0457bbe9f
Коммит
da6a25afc7
44
src/setup.c
44
src/setup.c
@ -552,48 +552,6 @@ setup__move_panels_config_into_separate_file(const char*profile)
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
setup_srt_to_char (char* str)
|
||||
{
|
||||
int res = -1;
|
||||
|
||||
if (!str)
|
||||
return (int) ' ';
|
||||
res = g_utf8_get_char_validated (str, -1);
|
||||
|
||||
if ( res < 0 ) {
|
||||
return (int) *str;
|
||||
} else {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
static inline int
|
||||
setup_load_lines_frm(const char *name)
|
||||
{
|
||||
int ret;
|
||||
char *frm_val = NULL;
|
||||
frm_val = mc_config_get_string(mc_main_config, "Lines", name, " ");
|
||||
ret = setup_srt_to_char (frm_val);
|
||||
g_free (frm_val);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
setup_load_lines_tty(void)
|
||||
{
|
||||
mc_tty_ugly_frm[MC_TTY_FRM_horiz] = setup_load_lines_frm("horiz");
|
||||
mc_tty_ugly_frm[MC_TTY_FRM_vert] = setup_load_lines_frm("vert");
|
||||
mc_tty_ugly_frm[MC_TTY_FRM_lefttop] = setup_load_lines_frm("lefttop");
|
||||
mc_tty_ugly_frm[MC_TTY_FRM_righttop] = setup_load_lines_frm("righttop");
|
||||
mc_tty_ugly_frm[MC_TTY_FRM_leftbottom] = setup_load_lines_frm("leftbottom");
|
||||
mc_tty_ugly_frm[MC_TTY_FRM_rightbottom] = setup_load_lines_frm("rightbottom");
|
||||
mc_tty_ugly_frm[MC_TTY_FRM_thinvert] = setup_load_lines_frm("thinvert");
|
||||
mc_tty_ugly_frm[MC_TTY_FRM_thinhoriz] = setup_load_lines_frm("thinhoriz");
|
||||
mc_tty_ugly_frm[MC_TTY_FRM_rightmiddle] = setup_load_lines_frm("rightmiddle");
|
||||
mc_tty_ugly_frm[MC_TTY_FRM_leftmiddle] = setup_load_lines_frm("leftmiddle");
|
||||
}
|
||||
|
||||
char *
|
||||
setup_init (void)
|
||||
{
|
||||
@ -725,8 +683,6 @@ load_setup (void)
|
||||
utf8_display = str_isutf8 (get_codepage_id( display_codepage ));
|
||||
#endif /* HAVE_CHARSET */
|
||||
|
||||
if (!mc_args__ugly_line_drawing)
|
||||
setup_load_lines_tty();
|
||||
}
|
||||
|
||||
#if defined(USE_VFS) && defined (USE_NETCODE)
|
||||
|
@ -6,6 +6,7 @@ libmcskin_la_SOURCES = \
|
||||
common.c \
|
||||
hc-skins.c \
|
||||
ini-file.c \
|
||||
lines.c \
|
||||
skin.h \
|
||||
internal.h
|
||||
|
||||
|
@ -107,7 +107,7 @@ mc_skin_hardcoded_ugly_lines(mc_skin_t *mc_skin)
|
||||
set_lines("rightmiddle", "|");
|
||||
set_lines("centermiddle", "+");
|
||||
set_lines("horiz", "-");
|
||||
set_lines("vert", "-");
|
||||
set_lines("vert", "|");
|
||||
set_lines("thinhoriz", "-");
|
||||
set_lines("thinvert", "|");
|
||||
}
|
||||
|
@ -123,6 +123,8 @@ mc_skin_ini_file_parce(mc_skin_t *mc_skin)
|
||||
if (! mc_skin_color_parce_ini_file(mc_skin))
|
||||
return FALSE;
|
||||
|
||||
mc_skin_lines_parce_ini_file(mc_skin);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -140,3 +142,4 @@ mc_skin_set_hardcoded_skin(mc_skin_t *mc_skin)
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
|
@ -33,4 +33,6 @@ void mc_skin_hardcoded_ugly_lines(mc_skin_t *);
|
||||
void mc_skin_hardcoded_space_lines(mc_skin_t *);
|
||||
void mc_skin_hardcoded_blackwhite_colors(mc_skin_t *);
|
||||
|
||||
void mc_skin_lines_parce_ini_file(mc_skin_t *);
|
||||
|
||||
#endif
|
||||
|
109
src/skin/lines.c
Обычный файл
109
src/skin/lines.c
Обычный файл
@ -0,0 +1,109 @@
|
||||
/*
|
||||
Skins engine.
|
||||
Work with line draving chars.
|
||||
|
||||
Copyright (C) 2009 The Free Software Foundation, Inc.
|
||||
|
||||
Written by:
|
||||
Slava Zanko <slavazanko@gmail.com>, 2009.
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
The Midnight Commander 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.
|
||||
|
||||
The Midnight Commander 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.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../src/global.h"
|
||||
#include "../src/args.h"
|
||||
#include "../src/tty/tty.h"
|
||||
#include "skin.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
mc_skin_lines_srt_to_char (char* str)
|
||||
{
|
||||
int res = -1;
|
||||
|
||||
if (!str)
|
||||
return (int) ' ';
|
||||
res = g_utf8_get_char_validated (str, -1);
|
||||
|
||||
if ( res < 0 ) {
|
||||
return (int) *str;
|
||||
} else {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
mc_skin_lines_load_frm(mc_skin_t *mc_skin, const char *name)
|
||||
{
|
||||
int ret;
|
||||
char *frm_val = NULL;
|
||||
frm_val = mc_config_get_string(mc_skin->config, "Lines", name, " ");
|
||||
ret = mc_skin_lines_srt_to_char (frm_val);
|
||||
g_free (frm_val);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
mc_skin_lines_parce_ini_file(mc_skin_t *mc_skin)
|
||||
{
|
||||
if (mc_args__slow_terminal)
|
||||
{
|
||||
mc_skin_hardcoded_space_lines(mc_skin);
|
||||
} else if (mc_args__ugly_line_drawing)
|
||||
{
|
||||
mc_skin_hardcoded_ugly_lines(mc_skin);
|
||||
}
|
||||
|
||||
mc_tty_ugly_frm[MC_TTY_FRM_horiz] = mc_skin_lines_load_frm(mc_skin, "horiz");
|
||||
mc_tty_ugly_frm[MC_TTY_FRM_vert] = mc_skin_lines_load_frm(mc_skin, "vert");
|
||||
mc_tty_ugly_frm[MC_TTY_FRM_lefttop] = mc_skin_lines_load_frm(mc_skin, "lefttop");
|
||||
mc_tty_ugly_frm[MC_TTY_FRM_righttop] = mc_skin_lines_load_frm(mc_skin, "righttop");
|
||||
mc_tty_ugly_frm[MC_TTY_FRM_leftbottom] = mc_skin_lines_load_frm(mc_skin, "leftbottom");
|
||||
mc_tty_ugly_frm[MC_TTY_FRM_rightbottom] = mc_skin_lines_load_frm(mc_skin, "rightbottom");
|
||||
mc_tty_ugly_frm[MC_TTY_FRM_thinvert] = mc_skin_lines_load_frm(mc_skin, "thinvert");
|
||||
mc_tty_ugly_frm[MC_TTY_FRM_thinhoriz] = mc_skin_lines_load_frm(mc_skin, "thinhoriz");
|
||||
mc_tty_ugly_frm[MC_TTY_FRM_rightmiddle] = mc_skin_lines_load_frm(mc_skin, "rightmiddle");
|
||||
mc_tty_ugly_frm[MC_TTY_FRM_centertop] = mc_skin_lines_load_frm(mc_skin, "centertop");
|
||||
mc_tty_ugly_frm[MC_TTY_FRM_centerbottom] = mc_skin_lines_load_frm(mc_skin, "centerbottom");
|
||||
mc_tty_ugly_frm[MC_TTY_FRM_leftmiddle] = mc_skin_lines_load_frm(mc_skin, "leftmiddle");
|
||||
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -33,6 +33,8 @@
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
gboolean mc_tty_color_disable;
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
@ -62,6 +64,12 @@ mc_tty_color_table_t const color_table [] = {
|
||||
{ "lightgray", COLOR_WHITE },
|
||||
{ "white", COLOR_WHITE | A_BOLD },
|
||||
{ "default", 0 }, /* default color of the terminal */
|
||||
/* special colors */
|
||||
{ "A_REVERSE", SPEC_A_REVERSE },
|
||||
{ "A_BOLD", SPEC_A_BOLD},
|
||||
{ "A_BOLD_REVERSE", SPEC_A_BOLD_REVERSE },
|
||||
{ "A_UNDERLINE", SPEC_A_UNDERLINE },
|
||||
/* End of list */
|
||||
{ NULL, 0}
|
||||
};
|
||||
|
||||
|
@ -17,6 +17,8 @@
|
||||
#endif /* HAVE_SLANG */
|
||||
|
||||
extern gboolean use_colors;
|
||||
extern gboolean mc_tty_color_disable;
|
||||
|
||||
|
||||
#ifdef HAVE_SLANG
|
||||
# define CTYPE const char *
|
||||
@ -32,6 +34,13 @@ typedef struct mc_color_pair_struct {
|
||||
int pair_index;
|
||||
} mc_color_pair_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SPEC_A_REVERSE = -100,
|
||||
SPEC_A_BOLD = -101,
|
||||
SPEC_A_BOLD_REVERSE = -102,
|
||||
SPEC_A_UNDERLINE = -103
|
||||
} mc_tty_color_special_t;
|
||||
|
||||
const char *mc_tty_color_get_valid_name(const char *);
|
||||
int mc_tty_color_get_index_by_name(const char *);
|
||||
|
@ -41,12 +41,13 @@
|
||||
static int
|
||||
has_colors (gboolean disable, gboolean force)
|
||||
{
|
||||
mc_tty_color_disable = disable;
|
||||
|
||||
if (force || (getenv ("COLORTERM") != NULL))
|
||||
SLtt_Use_Ansi_Colors = 1;
|
||||
|
||||
#if 0
|
||||
/* We want to allow overwriding */
|
||||
if (!disable) {
|
||||
if (!mc_tty_color_disable)
|
||||
{
|
||||
const char *terminal = getenv ("TERM");
|
||||
const size_t len = strlen (terminal);
|
||||
|
||||
@ -73,25 +74,32 @@ has_colors (gboolean disable, gboolean force)
|
||||
cts++;
|
||||
}
|
||||
}
|
||||
/* Setup emulated colors */
|
||||
if (SLtt_Use_Ansi_Colors != 0) {
|
||||
if (!disable) {
|
||||
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);
|
||||
}
|
||||
#endif
|
||||
return SLtt_Use_Ansi_Colors;
|
||||
}
|
||||
|
||||
static void
|
||||
mc_tty_color_pair_init_special(mc_color_pair_t *mc_color_pair,
|
||||
const char *fg1, const char *bg1,
|
||||
const char *fg2, const char *bg2,
|
||||
SLtt_Char_Type mask)
|
||||
{
|
||||
if (SLtt_Use_Ansi_Colors != 0)
|
||||
{
|
||||
if (!mc_tty_color_disable)
|
||||
{
|
||||
SLtt_set_color (mc_color_pair->pair_index, (char *) "", (char *) fg1, (char *) bg1);
|
||||
}
|
||||
else
|
||||
{
|
||||
SLtt_set_color (mc_color_pair->pair_index, (char *) "", (char *) fg2, (char *) bg2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SLtt_set_mono (mc_color_pair->pair_index, NULL, mask);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
mc_tty_color_init_lib (gboolean disable, gboolean force)
|
||||
{
|
||||
@ -105,7 +113,48 @@ mc_tty_color_init_lib (gboolean disable, gboolean force)
|
||||
void
|
||||
mc_tty_color_try_alloc_pair_lib (mc_color_pair_t *mc_color_pair)
|
||||
{
|
||||
if (mc_color_pair->ifg <= (int) SPEC_A_REVERSE)
|
||||
{
|
||||
switch(mc_color_pair->ifg)
|
||||
{
|
||||
case SPEC_A_REVERSE:
|
||||
mc_tty_color_pair_init_special(
|
||||
mc_color_pair,
|
||||
"black", "white",
|
||||
"black", "lightgray",
|
||||
SLTT_REV_MASK
|
||||
);
|
||||
break;
|
||||
case SPEC_A_BOLD:
|
||||
mc_tty_color_pair_init_special(
|
||||
mc_color_pair,
|
||||
"white", "black",
|
||||
"white", "black",
|
||||
SLTT_BOLD_MASK
|
||||
);
|
||||
break;
|
||||
case SPEC_A_BOLD_REVERSE:
|
||||
mc_tty_color_pair_init_special(
|
||||
mc_color_pair,
|
||||
"white", "black",
|
||||
"white", "black",
|
||||
SLTT_BOLD_MASK | SLTT_REV_MASK
|
||||
);
|
||||
break;
|
||||
case SPEC_A_UNDERLINE:
|
||||
mc_tty_color_pair_init_special(
|
||||
mc_color_pair,
|
||||
"white", "black",
|
||||
"white", "black",
|
||||
SLTT_ULINE_MASK
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SLtt_set_color (mc_color_pair->pair_index, (char *) "", (char *) mc_color_pair->cfg, (char *) mc_color_pair->cbg);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -115,7 +115,7 @@ int tty_try_alloc_color_pair (const char *fg, const char *bg)
|
||||
c_fg = mc_tty_color_get_valid_name(fg);
|
||||
c_bg = mc_tty_color_get_valid_name(bg);
|
||||
|
||||
color_pair = g_strdup_printf("%s.%s",fg,bg);
|
||||
color_pair = g_strdup_printf("%s.%s",c_fg,c_bg);
|
||||
if (color_pair == NULL)
|
||||
return 0;
|
||||
|
||||
|
@ -216,7 +216,7 @@ tty_getyx (int *py, int *px)
|
||||
void
|
||||
tty_draw_hline (int y, int x, int ch, int len)
|
||||
{
|
||||
if (ch == ACS_HLINE && slow_tty) {
|
||||
if (ch == ACS_HLINE) {
|
||||
ch = ugly_frm_thinhoriz;
|
||||
}
|
||||
|
||||
@ -237,10 +237,8 @@ tty_draw_vline (int y, int x, int ch, int len)
|
||||
void
|
||||
tty_draw_box (int y, int x, int rows, int cols)
|
||||
{
|
||||
if (slow_tty) {
|
||||
tty_draw_box_slow (y, x, rows, cols);
|
||||
} else {
|
||||
#define waddc(_y, _x, c) move (_y, _x); addch (c)
|
||||
!!!!!!
|
||||
waddc (y, x, ACS_ULCORNER);
|
||||
hline (ACS_HLINE, cols - 2);
|
||||
waddc (y + rows - 1, x, ACS_LLCORNER);
|
||||
@ -255,7 +253,6 @@ tty_draw_box (int y, int x, int rows, int cols)
|
||||
move (y + 1, x + cols - 1);
|
||||
vline (ACS_VLINE, rows - 2);
|
||||
#undef waddc
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -294,11 +291,11 @@ tty_print_anychar (int c)
|
||||
{
|
||||
unsigned char str[6 + 1];
|
||||
|
||||
if (c == ACS_RTEE && (ugly_line_drawing || slow_tty)) {
|
||||
if (c == ACS_RTEE ) {
|
||||
c = ugly_frm_rightmiddle;
|
||||
}
|
||||
|
||||
if (c == ACS_LTEE && (ugly_line_drawing || slow_tty)) {
|
||||
if (c == ACS_LTEE ) {
|
||||
c = ugly_frm_leftmiddle;
|
||||
}
|
||||
|
||||
|
@ -387,7 +387,7 @@ tty_getyx (int *py, int *px)
|
||||
void
|
||||
tty_draw_hline (int y, int x, int ch, int len)
|
||||
{
|
||||
if (ch == ACS_HLINE && (ugly_line_drawing || slow_tty)) {
|
||||
if (ch == ACS_HLINE) {
|
||||
ch = mc_tty_ugly_frm[MC_TTY_FRM_thinhoriz];
|
||||
}
|
||||
|
||||
@ -441,10 +441,7 @@ void
|
||||
tty_draw_box (int y, int x, int rows, int cols)
|
||||
{
|
||||
/* this fix slang drawing stickchars bug */
|
||||
if (ugly_line_drawing || slow_tty)
|
||||
tty_draw_box_slow (y, x, rows, cols);
|
||||
else
|
||||
SLsmg_draw_box (y, x, rows, cols);
|
||||
}
|
||||
|
||||
void
|
||||
@ -469,23 +466,22 @@ void
|
||||
tty_print_char (int c)
|
||||
{
|
||||
SLsmg_write_char ((SLwchar_Type) ((unsigned int) c));
|
||||
|
||||
/* FIXME: or SLsmg_draw_object (SLsmg_get_row(), SLsmg_get_column(), c); ? */
|
||||
}
|
||||
|
||||
void
|
||||
tty_print_alt_char (int c)
|
||||
{
|
||||
if (c == ACS_RTEE && (ugly_line_drawing || slow_tty)) {
|
||||
if (c == ACS_RTEE) {
|
||||
c = mc_tty_ugly_frm[MC_TTY_FRM_rightmiddle];
|
||||
}
|
||||
|
||||
if (c == ACS_LTEE && (ugly_line_drawing || slow_tty)) {
|
||||
if (c == ACS_LTEE) {
|
||||
c = mc_tty_ugly_frm[MC_TTY_FRM_leftmiddle];
|
||||
}
|
||||
if (ugly_line_drawing || slow_tty) {
|
||||
|
||||
tty_print_char (c);
|
||||
} else {
|
||||
SLsmg_draw_object (SLsmg_get_row(), SLsmg_get_column(), c);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -49,7 +49,7 @@ gboolean slow_tty = FALSE;
|
||||
/* If true use +, -, | for line drawing */
|
||||
gboolean ugly_line_drawing = FALSE;
|
||||
|
||||
int mc_tty_ugly_frm[] = { '|', '-', '|', '-', '+', '+', '+', '+', '+', '+'};
|
||||
int mc_tty_ugly_frm[MC_TTY_FRM_MAX];
|
||||
|
||||
/*** file scope macro definitions **************************************/
|
||||
|
||||
@ -123,19 +123,13 @@ tty_got_interrupt(void)
|
||||
void
|
||||
tty_print_one_hline (void)
|
||||
{
|
||||
if (ugly_line_drawing || slow_tty)
|
||||
tty_print_char (mc_tty_ugly_frm[MC_TTY_FRM_thinhoriz]);
|
||||
else
|
||||
tty_print_alt_char (ACS_HLINE);
|
||||
}
|
||||
|
||||
void
|
||||
tty_print_one_vline (void)
|
||||
{
|
||||
if (ugly_line_drawing || slow_tty)
|
||||
tty_print_char (mc_tty_ugly_frm[MC_TTY_FRM_thinvert]);
|
||||
else
|
||||
tty_print_alt_char (ACS_VLINE);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -88,8 +88,11 @@ typedef enum{
|
||||
MC_TTY_FRM_righttop,
|
||||
MC_TTY_FRM_leftbottom,
|
||||
MC_TTY_FRM_rightbottom,
|
||||
MC_TTY_FRM_centertop,
|
||||
MC_TTY_FRM_centerbottom,
|
||||
MC_TTY_FRM_leftmiddle,
|
||||
MC_TTY_FRM_rightmiddle
|
||||
MC_TTY_FRM_rightmiddle,
|
||||
MC_TTY_FRM_MAX
|
||||
} mc_tty_frm_t;
|
||||
|
||||
extern char *tty_tgetstr (const char *name);
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user