mirror of https://github.com/MidnightCommander/mc
fix: draw nroff text
This commit is contained in:
parent
b119f489ab
commit
bb7cbfe0db
|
@ -232,6 +232,8 @@ mcview_display (mcview_t * view)
|
|||
mcview_compute_areas (view);
|
||||
if (view->hex_mode) {
|
||||
mcview_display_hex (view);
|
||||
} else if (view->text_nroff_mode) {
|
||||
mcview_display_nroff (view);
|
||||
} else {
|
||||
mcview_display_text (view);
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ enum view_ds {
|
|||
/* Offset in bytes into a file */
|
||||
typedef enum {
|
||||
INVALID_OFFSET = ((off_t) - 1),
|
||||
OFFSETTYPE_MAX = (~((off_t) 0))
|
||||
OFFSETTYPE_MAX = ((off_t)(1 << (sizeof (off_t) * 8 - 1) - 1))
|
||||
} mcview_offset_t;
|
||||
|
||||
enum ccache_type {
|
||||
|
@ -271,6 +271,7 @@ void mcview_place_cursor (mcview_t *);
|
|||
void mcview_moveto_match (mcview_t *);
|
||||
|
||||
/* nforr.c: */
|
||||
void mcview_display_nroff (mcview_t *);
|
||||
int mcview__get_nroff_real_len (mcview_t *, off_t, off_t);
|
||||
|
||||
/* plain.c: */
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
/*** global variables ****************************************************************************/
|
||||
|
||||
int mcview_default_hex_mode = 0;
|
||||
int mcview_default_nroff_flag = 1;
|
||||
int mcview_default_nroff_flag = 0;
|
||||
int mcview_global_wrap_mode = 1;
|
||||
int mcview_default_magic_flag = 1;
|
||||
|
||||
|
|
|
@ -38,8 +38,13 @@
|
|||
#include <config.h>
|
||||
|
||||
#include "../src/global.h"
|
||||
#include "../src/myslang.h"
|
||||
#include "../src/main.h"
|
||||
#include "../src/color.h"
|
||||
#include "../src/charsets.h"
|
||||
#include "../src/viewer/internal.h"
|
||||
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
@ -54,6 +59,132 @@
|
|||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
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;
|
||||
gboolean read_res = 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 && (curr->offset < from)) {
|
||||
curr = curr->next;
|
||||
}
|
||||
|
||||
tty_setcolor (NORMAL_COLOR);
|
||||
for (row = 0, col = 0; row < height;) {
|
||||
#ifdef HAVE_CHARSET
|
||||
if (view->utf8) {
|
||||
c = mcview_get_utf (view, from, &cw, &read_res);
|
||||
if (!read_res)
|
||||
break;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
if ((c = mcview_get_byte (view, from)) == -1)
|
||||
break;
|
||||
}
|
||||
from++;
|
||||
if (cw > 1)
|
||||
from += cw - 1;
|
||||
|
||||
if (c == '\b') {
|
||||
int c_prev;
|
||||
int c_next;
|
||||
if (from > 1) {
|
||||
c_prev = mcview_get_byte (view, from - 2);
|
||||
c_next = mcview_get_byte (view, from);
|
||||
}
|
||||
if (g_ascii_isprint (c_prev) && g_ascii_isprint (c_prev)
|
||||
&& (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 (MARKED_COLOR);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ((c == '\n') || (col >= width && view->text_wrap_mode)) {
|
||||
col = 0;
|
||||
row++;
|
||||
if (c == '\n' || row >= height)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c == '\r') {
|
||||
c = mcview_get_byte_indexed (view, from, 1);
|
||||
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 += (8 - column % 8);
|
||||
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 (col >= view->dpy_text_column && col - view->dpy_text_column < width) {
|
||||
widget_move (view, top + row, left + (col - view->dpy_text_column));
|
||||
#ifdef HAVE_CHARSET
|
||||
if (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
|
||||
c = convert_to_display_c (c);
|
||||
#ifdef HAVE_CHARSET
|
||||
}
|
||||
}
|
||||
#endif
|
||||
tty_print_anychar (c);
|
||||
}
|
||||
col++;
|
||||
tty_setcolor (NORMAL_COLOR);
|
||||
}
|
||||
view->dpy_end = from;
|
||||
}
|
||||
|
||||
int
|
||||
mcview__get_nroff_real_len (mcview_t * view, off_t start, off_t length)
|
||||
{
|
||||
|
|
|
@ -98,33 +98,6 @@ mcview_display_text (mcview_t * view)
|
|||
if (cw > 1)
|
||||
from += cw - 1;
|
||||
|
||||
if (view->text_nroff_mode && c == '\b') {
|
||||
int c_prev;
|
||||
int c_next;
|
||||
|
||||
if ((c_next = mcview_get_byte_indexed (view, from, 1)) != -1 && g_ascii_isprint (c_next)
|
||||
&& from >= 1
|
||||
&& (c_prev = mcview_get_byte (view, from - 1)) != -1 && g_ascii_isprint (c_prev)
|
||||
&& (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))
|
||||
tty_setcolor (VIEW_UNDERLINED_COLOR);
|
||||
else
|
||||
tty_setcolor (MARKED_COLOR);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ((c == '\n') || (col >= width && view->text_wrap_mode)) {
|
||||
col = 0;
|
||||
row++;
|
||||
|
|
Loading…
Reference in New Issue