void mcview_move_up (WView * view, off_t lines) { if (view->mode_flags.hex) { off_t bytes = lines * view->bytes_per_line; if (view->hex_cursor >= bytes) { view->hex_cursor -= bytes; if (view->hex_cursor < view->dpy_start) { view->dpy_start = mcview_offset_doz (view->dpy_start, bytes); view->dpy_paragraph_skip_lines = 0; view->dpy_wrap_dirty = TRUE; } } else { view->hex_cursor %= view->bytes_per_line; } } else { mcview_ascii_move_up (view, lines); } mcview_movement_fixups (view, TRUE); }
/** * 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++; } }