示例#1
0
static void
mc_skin_color_check_bw_mode (mc_skin_t * mc_skin)
{
    gchar **groups, **orig_groups;

    if (tty_use_colors () && !mc_args__disable_colors)
        return;

    orig_groups = groups = mc_config_get_groups (mc_skin->config, NULL);

    if (groups == NULL)
        return;

    for (; *groups != NULL; groups++)
    {
        if (mc_skin_color_check_inisection (*groups))
            mc_config_del_group (mc_skin->config, *groups);
    }
    g_strfreev (orig_groups);
    mc_skin_hardcoded_blackwhite_colors (mc_skin);
}
示例#2
0
文件: editdraw.c 项目: ryanlee/mc
static void
edit_draw_this_line (WEdit * edit, long b, long row, long start_col, long end_col)
{
    struct line_s line[MAX_LINE_LEN];
    struct line_s *p = line;

    long m1 = 0, m2 = 0, q, c1, c2;
    int col, start_col_real;
    unsigned int c;
    int color;
    int abn_style;
    int i;
    int utf8lag = 0;
    unsigned int cur_line = 0;
    int book_mark = 0;
    char line_stat[LINE_STATE_WIDTH + 1] = "\0";

    if (row > edit->widget.lines - 1 - EDIT_TEXT_VERTICAL_OFFSET)
        return;

    if (book_mark_query_color (edit, edit->start_line + row, BOOK_MARK_COLOR))
        book_mark = BOOK_MARK_COLOR;
    else if (book_mark_query_color (edit, edit->start_line + row, BOOK_MARK_FOUND_COLOR))
        book_mark = BOOK_MARK_FOUND_COLOR;

    if (book_mark)
        abn_style = book_mark << 16;
    else
        abn_style = MOD_ABNORMAL;

    end_col -= EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;

    edit_get_syntax_color (edit, b - 1, &color);
    q = edit_move_forward3 (edit, b, start_col - edit->start_col, 0);
    start_col_real = (col = (int) edit_move_forward3 (edit, b, 0, q)) + edit->start_col;
    if (option_line_state)
    {
        cur_line = edit->start_line + row;
        if (cur_line <= (unsigned int) edit->total_lines)
        {
            g_snprintf (line_stat, LINE_STATE_WIDTH + 1, "%7i ", cur_line + 1);
        }
        else
        {
            memset (line_stat, ' ', LINE_STATE_WIDTH);
            line_stat[LINE_STATE_WIDTH] = '\0';
        }
        if (book_mark_query_color (edit, cur_line, BOOK_MARK_COLOR))
        {
            g_snprintf (line_stat, 2, "*");
        }
    }

    if (col + 16 > -edit->start_col)
    {
        eval_marks (edit, &m1, &m2);

        if (row <= edit->total_lines - edit->start_line)
        {
            long tws = 0;
            if (tty_use_colors () && visible_tws)
            {
                tws = edit_eol (edit, b);
                while (tws > b && ((c = edit_get_byte (edit, tws - 1)) == ' ' || c == '\t'))
                    tws--;
            }

            while (col <= end_col - edit->start_col)
            {
                int cw = 1;

                p->ch = 0;
                p->style = 0;
                if (q == edit->curs1)
                    p->style |= MOD_CURSOR;
                if (q >= m1 && q < m2)
                {
                    if (edit->column_highlight)
                    {
                        int x;
                        x = edit_move_forward3 (edit, b, 0, q);
                        c1 = min (edit->column1, edit->column2);
                        c2 = max (edit->column1, edit->column2);
                        if (x >= c1 && x < c2)
                            p->style |= MOD_MARKED;
                    }
                    else
                        p->style |= MOD_MARKED;
                }
                if (q == edit->bracket)
                    p->style |= MOD_BOLD;
                if (q >= edit->found_start && q < edit->found_start + edit->found_len)
                    p->style |= MOD_BOLD;

                if (!edit->utf8)
                {
                    c = edit_get_byte (edit, q);
                }
                else
                {
                    c = edit_get_utf (edit, q, &cw);
                }
                /* we don't use bg for mc - fg contains both */
                if (book_mark)
                {
                    p->style |= book_mark << 16;
                }
                else
                {
                    edit_get_syntax_color (edit, q, &color);
                    p->style |= color << 16;
                }
                switch (c)
                {
                case '\n':
                    col = (end_col + utf8lag) - edit->start_col + 1;    /* quit */
                    break;
                case '\t':
                    i = TAB_SIZE - ((int) col % TAB_SIZE);
                    col += i;
                    if (tty_use_colors () &&
                        ((visible_tabs || (visible_tws && q >= tws)) && enable_show_tabs_tws))
                    {
                        if (p->style & MOD_MARKED)
                            c = p->style;
                        else if (book_mark)
                            c |= book_mark << 16;
                        else
                            c = p->style | MOD_WHITESPACE;
                        if (i > 2)
                        {
                            p->ch = '<';
                            p->style = c;
                            p++;
                            while (--i > 1)
                            {
                                p->ch = '-';
                                p->style = c;
                                p++;
                            }
                            p->ch = '>';
                            p->style = c;
                            p++;
                        }
                        else if (i > 1)
                        {
                            p->ch = '<';
                            p->style = c;
                            p++;
                            p->ch = '>';
                            p->style = c;
                            p++;
                        }
                        else
                        {
                            p->ch = '>';
                            p->style = c;
                            p++;
                        }
                    }
                    else if (tty_use_colors () && visible_tws && q >= tws && enable_show_tabs_tws)
                    {
                        p->ch = '.';
                        p->style |= MOD_WHITESPACE;
                        c = p->style & ~MOD_CURSOR;
                        p++;
                        while (--i)
                        {
                            p->ch = ' ';
                            p->style = c;
                            p++;
                        }
                    }
                    else
                    {
                        p->ch |= ' ';
                        c = p->style & ~MOD_CURSOR;
                        p++;
                        while (--i)
                        {
                            p->ch = ' ';
                            p->style = c;
                            p++;
                        }
                    }
                    break;
                case ' ':
                    if (tty_use_colors () && visible_tws && q >= tws && enable_show_tabs_tws)
                    {
                        p->ch = '.';
                        p->style |= MOD_WHITESPACE;
                        p++;
                        col++;
                        break;
                    }
                    /* fallthrough */
                default:
#ifdef HAVE_CHARSET
                    if (mc_global.utf8_display)
                    {
                        if (!edit->utf8)
                        {
                            c = convert_from_8bit_to_utf_c ((unsigned char) c, edit->converter);
                        }
                    }
                    else if (edit->utf8)
                        c = convert_from_utf_to_current_c (c, edit->converter);
                    else
#endif
                        c = convert_to_display_c (c);

                    /* Caret notation for control characters */
                    if (c < 32)
                    {
                        p->ch = '^';
                        p->style = abn_style;
                        p++;
                        p->ch = c + 0x40;
                        p->style = abn_style;
                        p++;
                        col += 2;
                        break;
                    }
                    if (c == 127)
                    {
                        p->ch = '^';
                        p->style = abn_style;
                        p++;
                        p->ch = '?';
                        p->style = abn_style;
                        p++;
                        col += 2;
                        break;
                    }
                    if (!edit->utf8)
                    {
                        if ((mc_global.utf8_display && g_unichar_isprint (c)) ||
                            (!mc_global.utf8_display && is_printable (c)))
                        {
                            p->ch = c;
                            p++;
                        }
                        else
                        {
                            p->ch = '.';
                            p->style = abn_style;
                            p++;
                        }
                    }
                    else
                    {
                        if (g_unichar_isprint (c))
                        {
                            p->ch = c;
                            p++;
                        }
                        else
                        {
                            p->ch = '.';
                            p->style = abn_style;
                            p++;
                        }
                    }
                    col++;
                    break;
                }               /* case */

                q++;
                if (cw > 1)
                {
                    q += cw - 1;
                }
            }
        }
    }
    else
    {
        start_col_real = start_col = 0;
    }

    p->ch = '\0';

    print_to_widget (edit, row, start_col, start_col_real, end_col, line, line_stat, book_mark);
}
示例#3
0
文件: tree.c 项目: sfionov/mc-dev
static void show_tree (WTree *tree)
{
    Dlg_head *h = tree->widget.parent;
    tree_entry *current;
    int i, j, topsublevel;
    int x, y;
    int tree_lines, tree_cols;

    /* Initialize */
    x = y = 0;
    tree_lines = tlines (tree);
    tree_cols  = tree->widget.cols;

    tty_setcolor (TREE_NORMALC (h));
    widget_move ((Widget*)tree, y, x);
    if (tree->is_panel){
	tree_cols  -= 2;
	x = y = 1;
    }

    g_free (tree->tree_shown);
    tree->tree_shown = g_new (tree_entry*, tree_lines);

    for (i = 0; i < tree_lines; i++)
	tree->tree_shown [i] = NULL;
    if (tree->store->tree_first)
	topsublevel = tree->store->tree_first->sublevel;
    else
	topsublevel = 0;
    if (!tree->selected_ptr){
	tree->selected_ptr = tree->store->tree_first;
	tree->topdiff = 0;
    }
    current = tree->selected_ptr;

    /* Calculate the directory which is to be shown on the topmost line */
    if (tree_navigation_flag){
	i = 0;
	while (current->prev && i < tree->topdiff){
	    current = current->prev;
	    if (current->sublevel < tree->selected_ptr->sublevel){
		if (strncmp (current->name, tree->selected_ptr->name,
			     strlen (current->name)) == 0)
		    i++;
	    } else if (current->sublevel == tree->selected_ptr->sublevel){
		for (j = strlen (current->name) - 1; current->name [j] != PATH_SEP; j--);
		if (strncmp (current->name, tree->selected_ptr->name, j) == 0)
		    i++;
	    } else if (current->sublevel == tree->selected_ptr->sublevel + 1
		       && strlen (tree->selected_ptr->name) > 1){
		if (strncmp (current->name, tree->selected_ptr->name,
			     strlen (tree->selected_ptr->name)) == 0)
		    i++;
	    }
	}
	tree->topdiff = i;
    } else
	current = back_ptr (current, &tree->topdiff);

    /* Loop for every line */
    for (i = 0; i < tree_lines; i++){
	/* Move to the beginning of the line */
	tty_draw_hline (tree->widget.y + y + i, tree->widget.x + x, ' ', tree_cols);

	if (!current)
	    continue;

	tree->tree_shown [i] = current;
	if (current->sublevel == topsublevel){

	    /* Top level directory */
	    if (tree->active && current == tree->selected_ptr) {
		if (!tty_use_colors () && !tree->is_panel)
			tty_setcolor (MARKED_COLOR);
		else
			tty_setcolor (SELECTED_COLOR);
	    }

	    /* Show full name */
	    tty_print_string (str_fit_to_term (current->name, tree_cols - 6, J_LEFT_FIT));
	} else{
	    /* Sub level directory */

	    tty_set_alt_charset (TRUE);
	    /* Output branch parts */
	    for (j = 0; j < current->sublevel - topsublevel - 1; j++){
		if (tree_cols - 8 - 3 * j < 9)
		    break;
		tty_print_char (' ');
		if (current->submask & (1 << (j + topsublevel + 1)))
		    tty_print_char (ACS_VLINE);
		else
		    tty_print_char (' ');
		tty_print_char (' ');
	    }
	    tty_print_char (' '); j++;
	    if (!current->next || !(current->next->submask & (1 << current->sublevel)))
		tty_print_char (ACS_LLCORNER);
	    else
		tty_print_char (ACS_LTEE);
	    tty_print_char (ACS_HLINE);
	    tty_set_alt_charset (FALSE);

	    if (tree->active && current == tree->selected_ptr) {
		/* Selected directory -> change color */
		if (!tty_use_colors () && !tree->is_panel)
		    tty_setcolor (MARKED_COLOR);
		else
		    tty_setcolor (SELECTED_COLOR);
	    }

	    /* Show sub-name */
	    tty_print_char (' ');
	    tty_print_string (str_fit_to_term (current->subname, 
		    tree_cols - 2 - 4 - 3 * j, J_LEFT_FIT));
	}
	tty_print_char (' ');

	/* Return to normal color */
	tty_setcolor (TREE_NORMALC (h));

	/* Calculate the next value for current */
	current = current->next;
	if (tree_navigation_flag){
	    while (current){
		if (current->sublevel < tree->selected_ptr->sublevel){
		    if (strncmp (current->name, tree->selected_ptr->name,
				 strlen (current->name)) == 0)
			break;
		} else if (current->sublevel == tree->selected_ptr->sublevel){
		    for (j = strlen (current->name) - 1; current->name [j] != PATH_SEP; j--);
		    if (strncmp (current->name,tree->selected_ptr->name,j)== 0)
			break;
		} else if (current->sublevel == tree->selected_ptr->sublevel+1
			   && strlen (tree->selected_ptr->name) > 1){
		    if (strncmp (current->name, tree->selected_ptr->name,
				 strlen (tree->selected_ptr->name)) == 0)
			break;
		}
		current = current->next;
	    }
	}
    }
    tree_show_mini_info (tree, tree_lines, tree_cols);
}
示例#4
0
static void
edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_col)
{
    Widget *w = WIDGET (edit);

    struct line_s line[MAX_LINE_LEN];
    struct line_s *p = line;

    off_t m1 = 0, m2 = 0, q;
    int col, start_col_real;
    int color;
    int abn_style;
    int book_mark = 0;
    char line_stat[LINE_STATE_WIDTH + 1] = "\0";

    if (row > w->lines - 1 - EDIT_TEXT_VERTICAL_OFFSET - 2 * (edit->fullscreen ? 0 : 1))
        return;

    if (book_mark_query_color (edit, edit->start_line + row, BOOK_MARK_COLOR))
        book_mark = BOOK_MARK_COLOR;
    else if (book_mark_query_color (edit, edit->start_line + row, BOOK_MARK_FOUND_COLOR))
        book_mark = BOOK_MARK_FOUND_COLOR;

    if (book_mark)
        abn_style = book_mark << 16;
    else
        abn_style = MOD_ABNORMAL;

    end_col -= EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
    if (!edit->fullscreen)
    {
        end_col--;
        if (w->x + w->cols <= WIDGET (w->owner)->cols)
            end_col--;
    }

    color = edit_get_syntax_color (edit, b - 1);
    q = edit_move_forward3 (edit, b, start_col - edit->start_col, 0);
    start_col_real = (col = (int) edit_move_forward3 (edit, b, 0, q)) + edit->start_col;

    if (option_line_state)
    {
        unsigned int cur_line;

        cur_line = edit->start_line + row;
        if (cur_line <= (unsigned int) edit->buffer.lines)
        {
            g_snprintf (line_stat, LINE_STATE_WIDTH + 1, "%7i ", cur_line + 1);
        }
        else
        {
            memset (line_stat, ' ', LINE_STATE_WIDTH);
            line_stat[LINE_STATE_WIDTH] = '\0';
        }
        if (book_mark_query_color (edit, cur_line, BOOK_MARK_COLOR))
        {
            g_snprintf (line_stat, 2, "*");
        }
    }

    if (col + 16 > -edit->start_col)
    {
        eval_marks (edit, &m1, &m2);

        if (row <= edit->buffer.lines - edit->start_line)
        {
            off_t tws = 0;
            if (tty_use_colors () && visible_tws)
            {
                unsigned int c;

                tws = edit_buffer_get_eol (&edit->buffer, b);
                while (tws > b
                       && ((c = edit_buffer_get_byte (&edit->buffer, tws - 1)) == ' ' || c == '\t'))
                    tws--;
            }

            while (col <= end_col - edit->start_col)
            {
                int char_length = 1;
                unsigned int c;
                gboolean wide_width_char = FALSE;
                gboolean control_char = FALSE;

                p->ch = 0;
                p->style = 0;
                if (q == edit->buffer.curs1)
                    p->style |= MOD_CURSOR;
                if (q >= m1 && q < m2)
                {
                    if (edit->column_highlight)
                    {
                        long x;
                        long c1, c2;

                        x = (long) edit_move_forward3 (edit, b, 0, q);
                        c1 = min (edit->column1, edit->column2);
                        c2 = max (edit->column1, edit->column2);
                        if (x >= c1 && x < c2)
                            p->style |= MOD_MARKED;
                    }
                    else
                        p->style |= MOD_MARKED;
                }
                if (q == edit->bracket)
                    p->style |= MOD_BOLD;
                if (q >= edit->found_start && q < (off_t) (edit->found_start + edit->found_len))
                    p->style |= MOD_BOLD;

#ifdef HAVE_CHARSET
                if (edit->utf8)
                    c = edit_buffer_get_utf (&edit->buffer, q, &char_length);
                else
#endif
                    c = edit_buffer_get_byte (&edit->buffer, q);

                /* we don't use bg for mc - fg contains both */
                if (book_mark)
                {
                    p->style |= book_mark << 16;
                }
                else
                {
                    color = edit_get_syntax_color (edit, q);
                    p->style |= color << 16;
                }
                switch (c)
                {
                case '\n':
                    col = end_col - edit->start_col + 1;        /* quit */
                    break;
                case '\t':
                    {
                        int tab_over;
                        int i;

                        i = TAB_SIZE - ((int) col % TAB_SIZE);
                        tab_over = (end_col - edit->start_col) - (col + i - 1);
                        if (tab_over < 0)
                            i += tab_over;
                        col += i;
                        if (tty_use_colors () &&
                            ((visible_tabs || (visible_tws && q >= tws)) && enable_show_tabs_tws))
                        {
                            if (p->style & MOD_MARKED)
                                c = p->style;
                            else if (book_mark)
                                c |= book_mark << 16;
                            else
                                c = p->style | MOD_WHITESPACE;
                            if (i > 2)
                            {
                                p->ch = '<';
                                p->style = c;
                                p++;
                                while (--i > 1)
                                {
                                    p->ch = '-';
                                    p->style = c;
                                    p++;
                                }
                                p->ch = '>';
                                p->style = c;
                                p++;
                            }
                            else if (i > 1)
                            {
                                p->ch = '<';
                                p->style = c;
                                p++;
                                p->ch = '>';
                                p->style = c;
                                p++;
                            }
                            else
                            {
                                p->ch = '>';
                                p->style = c;
                                p++;
                            }
                        }
                        else if (tty_use_colors () && visible_tws && q >= tws
                                 && enable_show_tabs_tws)
                        {
                            p->ch = '.';
                            p->style |= MOD_WHITESPACE;
                            c = p->style & ~MOD_CURSOR;
                            p++;
                            while (--i)
                            {
                                p->ch = ' ';
                                p->style = c;
                                p++;
                            }
                        }
                        else
                        {
                            p->ch |= ' ';
                            c = p->style & ~MOD_CURSOR;
                            p++;
                            while (--i)
                            {
                                p->ch = ' ';
                                p->style = c;
                                p++;
                            }
                        }
                    }
                    break;
                case ' ':
                    if (tty_use_colors () && visible_tws && q >= tws && enable_show_tabs_tws)
                    {
                        p->ch = '.';
                        p->style |= MOD_WHITESPACE;
                        p++;
                        col++;
                        break;
                    }
                    /* fallthrough */
                default:
#ifdef HAVE_CHARSET
                    if (mc_global.utf8_display)
                    {
                        if (!edit->utf8)
                        {
                            c = convert_from_8bit_to_utf_c ((unsigned char) c, edit->converter);
                        }
                        else
                        {
                            if (g_unichar_iswide (c))
                            {
                                wide_width_char = TRUE;
                                col++;
                            }
                        }
                    }
                    else if (edit->utf8)
                        c = convert_from_utf_to_current_c (c, edit->converter);
                    else
                        c = convert_to_display_c (c);
#endif

                    /* Caret notation for control characters */
                    if (c < 32)
                    {
                        p->ch = '^';
                        p->style = abn_style;
                        p++;
                        p->ch = c + 0x40;
                        p->style = abn_style;
                        p++;
                        col += 2;
                        control_char = TRUE;
                        break;
                    }
                    if (c == 127)
                    {
                        p->ch = '^';
                        p->style = abn_style;
                        p++;
                        p->ch = '?';
                        p->style = abn_style;
                        p++;
                        col += 2;
                        control_char = TRUE;
                        break;
                    }
#ifdef HAVE_CHARSET
                    if (edit->utf8)
                    {
                        if (g_unichar_isprint (c))
                            p->ch = c;
                        else
                        {
                            p->ch = '.';
                            p->style = abn_style;
                        }
                        p++;
                    }
                    else
#endif
                    {
                        if ((mc_global.utf8_display && g_unichar_isprint (c)) ||
                            (!mc_global.utf8_display && is_printable (c)))
                        {
                            p->ch = c;
                            p++;
                        }
                        else
                        {
                            p->ch = '.';
                            p->style = abn_style;
                            p++;
                        }
                    }
                    col++;
                    break;
                }               /* case */

                q++;
                if (char_length > 1)
                    q += char_length - 1;

                if (col > (end_col - edit->start_col + 1))
                {
                    if (wide_width_char)
                    {
                        p--;
                        break;
                    }
                    if (control_char)
                    {
                        p -= 2;
                        break;
                    }
                }
            }
        }
    }
    else
    {
        start_col_real = start_col = 0;
    }

    p->ch = 0;

    print_to_widget (edit, row, start_col, start_col_real, end_col, line, line_stat, book_mark);
}