Ejemplo n.º 1
0
void
mcview_display_nroff (mcview_t * view)
{
    const screen_dimen left = view->data_area.left;
    const screen_dimen top = view->data_area.top;
    const screen_dimen width = view->data_area.width;
    const screen_dimen height = view->data_area.height;
    screen_dimen row, col;
    off_t from;
    int cw = 1;
    int c;
    int c_prev = 0;
    int c_next = 0;
    struct hexedit_change_node *curr = view->change_list;

    mcview_display_clean (view);
    mcview_display_ruler (view);

    /* Find the first displayable changed byte */
    from = view->dpy_start;
    while (curr && (curr->offset < from))
    {
        curr = curr->next;
    }

    tty_setcolor (NORMAL_COLOR);
    for (row = 0, col = 0; row < height;)
    {
#ifdef HAVE_CHARSET
        if (view->utf8)
        {
            gboolean read_res = TRUE;
            c = mcview_get_utf (view, from, &cw, &read_res);
            if (!read_res)
                break;
        }
        else
#endif
        {
            if (!mcview_get_byte (view, from, &c))
                break;
        }
        from++;
        if (cw > 1)
            from += cw - 1;

        if (c == '\b')
        {
            if (from > 1)
            {
#ifdef HAVE_CHARSET
                if (view->utf8)
                {
                    gboolean read_res;
                    c_next = mcview_get_utf (view, from, &cw, &read_res);
                }
                else
#endif
                    mcview_get_byte (view, from, &c_next);
            }
            if (g_unichar_isprint (c_prev) && g_unichar_isprint (c_next)
                && (c_prev == c_next || c_prev == '_' || (c_prev == '+' && c_next == 'o')))
            {
                if (col == 0)
                {
                    if (row == 0)
                    {
                        /* We're inside an nroff character sequence at the
                         * beginning of the screen -- just skip the
                         * backspace and continue with the next character. */
                        continue;
                    }
                    row--;
                    col = width;
                }
                col--;
                if (c_prev == '_'
                    && (c_next != '_' || mcview_count_backspaces (view, from + 1) == 1))
                    tty_setcolor (VIEW_UNDERLINED_COLOR);
                else
                    tty_setcolor (VIEW_BOLD_COLOR);
                continue;
            }
        }

        if ((c == '\n') || (col >= width && view->text_wrap_mode))
        {
            col = 0;
            row++;
            if (c == '\n' || row >= height)
                continue;
        }

        if (c == '\r')
        {
            mcview_get_byte_indexed (view, from, 1, &c);
            if (c == '\r' || c == '\n')
                continue;
            col = 0;
            row++;
            continue;
        }

        if (c == '\t')
        {
            off_t line, column;
            mcview_offset_to_coord (view, &line, &column, from);
            col += (option_tab_spacing - col % option_tab_spacing);
            if (view->text_wrap_mode && col >= width && width != 0)
            {
                row += col / width;
                col %= width;
            }
            continue;
        }

        if (view->search_start <= from && from < view->search_end)
        {
            tty_setcolor (SELECTED_COLOR);
        }

        c_prev = c;

        if ((off_t) col >= view->dpy_text_column
            && (off_t) col - view->dpy_text_column < (off_t) width)
        {
            widget_move (view, top + row, left + ((off_t) col - view->dpy_text_column));
#ifdef HAVE_CHARSET
            if (mc_global.utf8_display)
            {
                if (!view->utf8)
                {
                    c = convert_from_8bit_to_utf_c ((unsigned char) c, view->converter);
                }
                if (!g_unichar_isprint (c))
                    c = '.';
            }
            else if (view->utf8)
                c = convert_from_utf_to_current_c (c, view->converter);
            else
                c = convert_to_display_c (c);
#endif
            tty_print_anychar (c);
        }
        col++;
#ifdef HAVE_CHARSET
        if (view->utf8)
        {
            if (g_unichar_iswide (c))
                col++;
            else if (g_unichar_iszerowidth (c))
                col--;
        }
#endif
        tty_setcolor (NORMAL_COLOR);
    }
    view->dpy_end = from;
}
Ejemplo n.º 2
0
/**
 * In both wrap and unwrap modes, dpy_start points to the beginning of the paragraph.
 *
 * In unwrap mode, start displaying from this position, probably applying an additional horizontal
 * scroll.
 *
 * In wrap mode, an additional dpy_paragraph_skip_lines lines are skipped from the top of this
 * paragraph. dpy_state_top contains the position and parser-formatter state corresponding to the
 * top left corner so we can just start rendering from here. Unless dpy_wrap_dirty is set in which
 * case dpy_state_top is invalid and we need to recompute first.
 */
void
mcview_display_text (WView * view)
{
    const screen_dimen left = view->data_area.left;
    const screen_dimen top = view->data_area.top;
    const screen_dimen height = view->data_area.height;
    int row;
    mcview_state_machine_t state;
    gboolean again;

    do
    {
        int n;

        again = FALSE;

        mcview_display_clean (view);
        mcview_display_ruler (view);

        if (!view->text_wrap_mode)
            mcview_state_machine_init (&state, view->dpy_start);
        else
        {
            mcview_wrap_fixup (view);
            state = view->dpy_state_top;
        }

        for (row = 0; row < (int) height; row += n)
        {
            n = mcview_display_paragraph (view, &state, row);
            if (n == 0)
            {
                /* In the rare case that displaying didn't start at the beginning
                 * of the file, yet there are some empty lines at the bottom,
                 * scroll the file and display again. This happens when e.g. the
                 * window is made bigger, or the file becomes shorter due to
                 * charset change or enabling nroff. */
                if ((view->text_wrap_mode ? view->dpy_state_top.offset : view->dpy_start) > 0)
                {
                    mcview_ascii_move_up (view, height - row);
                    again = TRUE;
                }
                break;
            }
        }
    }
    while (again);

    view->dpy_end = state.offset;
    view->dpy_state_bottom = state;

    tty_setcolor (VIEW_NORMAL_COLOR);
    if (mcview_show_eof != NULL && mcview_show_eof[0] != '\0')
        while (row < (int) height)
        {
            widget_move (view, top + row, left);
            /* TODO: should make it no wider than the viewport */
            tty_print_string (mcview_show_eof);
            row++;
        }
}
Ejemplo n.º 3
0
Archivo: plain.c Proyecto: BrEacK/mc
void
mcview_display_text (mcview_t * view)
{
    const screen_dimen left = view->data_area.left;
    const screen_dimen top = view->data_area.top;
    const screen_dimen width = view->data_area.width;
    const screen_dimen height = view->data_area.height;
    screen_dimen row = 0, col = 0;
    off_t from;
    int cw = 1;
    int c, prev_ch = 0;
    gboolean last_row = TRUE;
    struct hexedit_change_node *curr = view->change_list;

    mcview_display_clean (view);
    mcview_display_ruler (view);

    /* Find the first displayable changed byte */
    from = view->dpy_start;
    while ((curr != NULL) && (curr->offset < from))
        curr = curr->next;

    while (TRUE)
    {
        tty_setcolor (NORMAL_COLOR);

        if (row >= height)
            break;

#ifdef HAVE_CHARSET
        if (view->utf8)
        {
            gboolean read_res = TRUE;

            c = mcview_get_utf (view, from, &cw, &read_res);
            if (!read_res)
                break;
        }
        else
#endif
        if (!mcview_get_byte (view, from, &c))
            break;

        last_row = FALSE;
        from++;
        if (cw > 1)
            from += cw - 1;

        if (c != '\n' && prev_ch == '\r')
        {
            if (++row >= height)
                break;

            col = 0;
            /* tty_print_anychar ('\n'); */
        }

        prev_ch = c;
        if (c == '\r')
            continue;

        if (c == '\n')
        {
            col = 0;
            row++;
            continue;
        }

        if (col >= width && view->text_wrap_mode)
        {
            col = 0;
            if (++row >= height)
                break;
        }

        if (c == '\t')
        {
            col += (option_tab_spacing - col % option_tab_spacing);
            if (view->text_wrap_mode && col >= width && width != 0)
            {
                row += col / width;
                col %= width;
            }
            continue;
        }

        if (view->search_start <= from && from < view->search_end)
            tty_setcolor (SELECTED_COLOR);

        if (((off_t) col >= view->dpy_text_column)
            && ((off_t) col - view->dpy_text_column < (off_t) width))
        {
            widget_move (view, top + row, left + ((off_t) col - view->dpy_text_column));
#ifdef HAVE_CHARSET
            if (mc_global.utf8_display)
            {
                if (!view->utf8)
                    c = convert_from_8bit_to_utf_c ((unsigned char) c, view->converter);
                if (!g_unichar_isprint (c))
                    c = '.';
            }
            else if (view->utf8)
                c = convert_from_utf_to_current_c (c, view->converter);
            else
#endif
            {
#ifdef HAVE_CHARSET
                c = convert_to_display_c (c);
#endif
                if (!is_printable (c))
                    c = '.';
            }

            tty_print_anychar (c);
        }

        col++;

#ifdef HAVE_CHARSET
        if (view->utf8)
        {
            if (g_unichar_iswide (c))
                col++;
            else if (g_unichar_iszerowidth (c))
                col--;
        }
#endif
    }

    view->dpy_end = from;
    if (mcview_show_eof != NULL && mcview_show_eof[0] != '\0')
    {
        if (last_row && mcview_get_byte (view, from - 1, &c))
            if (c != '\n')
                row--;
        while (++row < height)
        {
            widget_move (view, top + row, left);
            tty_print_string (mcview_show_eof);
        }
    }
}