static void tree_show_mini_info (WTree *tree, int tree_lines, int tree_cols) { Dlg_head *h = tree->widget.parent; int line; /* Show mini info */ if (tree->is_panel){ if (!show_mini_info) return; line = tree_lines+2; } else line = tree_lines+1; tty_draw_hline (tree->widget.y + line, tree->widget.x + 1, ' ', tree_cols); widget_move (&tree->widget, line, 1); if (tree->searching){ /* Show search string */ tty_setcolor (TREE_NORMALC (h)); tty_setcolor (DLG_FOCUSC (h)); tty_print_char (PATH_SEP); tty_print_string (str_fit_to_term (tree->search_buffer, tree_cols - 2, J_LEFT_FIT)); tty_print_char (' '); tty_setcolor (DLG_FOCUSC (h)); } else { /* Show full name of selected directory */ tty_print_string (str_fit_to_term (tree->selected_ptr->name, tree_cols, J_LEFT_FIT)); } }
static void print_flags (void) { int i; tty_setcolor (COLOR_NORMAL); for (i = 0; i < 3; i++){ dlg_move (ch_dlg, BY+1, 9+i); tty_print_char (ch_flags [i]); } for (i = 0; i < 3; i++){ dlg_move (ch_dlg, BY + 1, 17 + i); tty_print_char (ch_flags [i+3]); } for (i = 0; i < 3; i++){ dlg_move (ch_dlg, BY + 1, 25 + i); tty_print_char (ch_flags [i+6]); } update_permissions (); for (i = 0; i < 15; i++){ dlg_move (ch_dlg, BY+1, 35+i); tty_print_char (ch_flags[9]); } for (i = 0; i < 15; i++){ dlg_move (ch_dlg, BY + 1, 53 + i); tty_print_char (ch_flags[10]); } }
void tty_draw_hline (int y, int x, int ch, int len) { if (ch == ACS_HLINE) ch = mc_tty_frm[MC_TTY_FRM_HORIZ]; if ((y < 0) || (x < 0)) { y = SLsmg_get_row (); x = SLsmg_get_column (); } else SLsmg_gotorc (y, x); if (ch == 0) ch = ACS_HLINE; if (ch == ACS_HLINE) SLsmg_draw_hline (len); else while (len-- != 0) tty_print_char (ch); SLsmg_gotorc (y, x); }
void tty_draw_vline (int y, int x, int ch, int len) { if (ch == ACS_VLINE) ch = mc_tty_frm[MC_TTY_FRM_VERT]; if ((y < 0) || (x < 0)) { y = SLsmg_get_row (); x = SLsmg_get_column (); } else SLsmg_gotorc (y, x); if (ch == 0) ch = ACS_VLINE; if (ch == ACS_VLINE) SLsmg_draw_vline (len); else { int pos = 0; while (len-- != 0) { SLsmg_gotorc (y + pos, x); tty_print_char (ch); pos++; } } SLsmg_gotorc (y, x); }
static void update_split (const WDialog * h) { /* Check split has to be done before testing if it changed, since it can change due to calling check_split() as well */ check_split (&panels_layout); if (panels_layout.horizontal_split) check_options[0].widget->state = panels_layout.horizontal_equal ? 1 : 0; else check_options[0].widget->state = panels_layout.vertical_equal ? 1 : 0; widget_redraw (WIDGET (check_options[0].widget)); tty_setcolor (check_options[0].widget->state & C_BOOL ? DISABLED_COLOR : COLOR_NORMAL); widget_move (h, 6, 5); if (panels_layout.horizontal_split) tty_printf ("%03d", panels_layout.top_panel_size); else tty_printf ("%03d", panels_layout.left_panel_size); widget_move (h, 6, 17); if (panels_layout.horizontal_split) tty_printf ("%03d", height - panels_layout.top_panel_size); else tty_printf ("%03d", COLS - panels_layout.left_panel_size); widget_move (h, 6, 12); tty_print_char ('='); }
void tty_draw_hline (int y, int x, int ch, int len) { int x1; if (y < 0 || y >= LINES || x >= COLS) return; x1 = x; if (x < 0) { len += x; if (len <= 0) return; x = 0; } if (ch == ACS_HLINE) ch = mc_tty_frm[MC_TTY_FRM_HORIZ]; if (ch == 0) ch = ACS_HLINE; SLsmg_gotorc (y, x); if (ch == ACS_HLINE) SLsmg_draw_hline (len); else while (len-- != 0) tty_print_char (ch); SLsmg_gotorc (y, x1); }
extern void tty_print_one_vline(void) { if (slow_terminal) tty_print_char(' '); else tty_print_alt_char(ACS_VLINE); }
static void menubar_paint_idx (WMenuBar * menubar, unsigned int idx, int color) { const Menu *menu = g_list_nth_data (menubar->menu, menubar->selected); const menu_entry_t *entry = g_list_nth_data (menu->entries, idx); const int y = 2 + idx; int x = menu->start_x; if (x + menu->max_entry_len + 4 > (gsize) menubar->widget.cols) x = menubar->widget.cols - menu->max_entry_len - 4; if (entry == NULL) { /* menu separator */ tty_setcolor (MENU_ENTRY_COLOR); widget_move (&menubar->widget, y, x - 1); tty_print_alt_char (ACS_LTEE, FALSE); tty_draw_hline (menubar->widget.y + y, menubar->widget.x + x, ACS_HLINE, menu->max_entry_len + 3); widget_move (&menubar->widget, y, x + menu->max_entry_len + 3); tty_print_alt_char (ACS_RTEE, FALSE); } else { int yt, xt; /* menu text */ tty_setcolor (color); widget_move (&menubar->widget, y, x); tty_print_char ((unsigned char) entry->first_letter); tty_getyx (&yt, &xt); tty_draw_hline (yt, xt, ' ', menu->max_entry_len + 2); /* clear line */ tty_print_string (entry->text.start); if (entry->text.hotkey != NULL) { tty_setcolor (color == MENU_SELECTED_COLOR ? MENU_HOTSEL_COLOR : MENU_HOT_COLOR); tty_print_string (entry->text.hotkey); tty_setcolor (color); } if (entry->text.end != NULL) tty_print_string (entry->text.end); if (entry->shortcut != NULL) { widget_move (&menubar->widget, y, x + menu->max_hotkey_len + 3); tty_print_string (entry->shortcut); } /* move cursor to the start of entry text */ widget_move (&menubar->widget, y, x + 1); } }
static void chmod_toggle_select (Dlg_head * h, int Id) { tty_setcolor (COLOR_NORMAL); check_perm[Id].selected = !check_perm[Id].selected; dlg_move (h, PY + check_perm_num - Id, PX + 1); tty_print_char (check_perm[Id].selected ? '*' : ' '); dlg_move (h, PY + check_perm_num - Id, PX + 3); }
static void chmod_toggle_select (Dlg_head * h, int Id) { tty_setcolor (COLOR_NORMAL); check_perm[Id].selected ^= 1; dlg_move (h, PY + PERMISSIONS - Id, PX + 1); tty_print_char ((check_perm[Id].selected) ? '*' : ' '); dlg_move (h, PY + PERMISSIONS - Id, PX + 3); }
static void menubar_draw (WMenuBar * menubar) { Widget *w = WIDGET (menubar); GList *i; /* First draw the complete menubar */ tty_setcolor (menubar->is_active ? MENU_ENTRY_COLOR : MENU_INACTIVE_COLOR); tty_draw_hline (w->y, w->x, ' ', w->cols); /* Now each one of the entries */ for (i = menubar->menu; i != NULL; i = g_list_next (i)) { menu_t *menu = MENU (i->data); gboolean is_selected = (menubar->selected == (gsize) g_list_position (menubar->menu, i)); menubar_set_color (menubar, is_selected, FALSE); widget_move (w, 0, menu->start_x); tty_print_char (' '); tty_print_string (menu->text.start); if (menu->text.hotkey != NULL) { menubar_set_color (menubar, is_selected, TRUE); tty_print_string (menu->text.hotkey); menubar_set_color (menubar, is_selected, FALSE); } if (menu->text.end != NULL) tty_print_string (menu->text.end); tty_print_char (' '); } if (menubar->is_dropped) menubar_draw_drop (menubar); else widget_move (w, 0, MENU (g_list_nth_data (menubar->menu, menubar->selected))->start_x); }
static void tree_show_mini_info (WTree * tree, int tree_lines, int tree_cols) { Dlg_head *h = tree->widget.owner; int line; /* Show mini info */ if (tree->is_panel) { if (!panels_options.show_mini_info) return; line = tree_lines + 2; } else line = tree_lines + 1; if (tree->searching) { /* Show search string */ tty_setcolor (INPUT_COLOR); tty_draw_hline (tree->widget.y + line, tree->widget.x + 1, ' ', tree_cols); widget_move (&tree->widget, line, 1); tty_print_char (PATH_SEP); tty_print_string (str_fit_to_term (tree->search_buffer, tree_cols - 2, J_LEFT_FIT)); tty_print_char (' '); } else { /* Show full name of selected directory */ char *tmp_path; tty_setcolor (tree->is_panel ? NORMAL_COLOR : TREE_NORMALC (h)); tty_draw_hline (tree->widget.y + line, tree->widget.x + 1, ' ', tree_cols); widget_move (&tree->widget, line, 1); tmp_path = vfs_path_to_str (tree->selected_ptr->name); tty_print_string (str_fit_to_term (tmp_path, tree_cols, J_LEFT_FIT)); g_free (tmp_path); } }
static void tree_show_mini_info (WTree * tree, int tree_lines, int tree_cols) { Widget *w = WIDGET (tree); int line; /* Show mini info */ if (tree->is_panel) { if (!panels_options.show_mini_info) return; line = tree_lines + 2; } else line = tree_lines + 1; if (tree->searching) { /* Show search string */ tty_setcolor (INPUT_COLOR); tty_draw_hline (w->y + line, w->x + 1, ' ', tree_cols); widget_move (w, line, 1); tty_print_char (PATH_SEP); tty_print_string (str_fit_to_term (tree->search_buffer, tree_cols - 2, J_LEFT_FIT)); tty_print_char (' '); } else { /* Show full name of selected directory */ WDialog *h = w->owner; tty_setcolor (tree->is_panel ? NORMAL_COLOR : TREE_NORMALC (h)); tty_draw_hline (w->y + line, w->x + 1, ' ', tree_cols); widget_move (w, line, 1); tty_print_string (str_fit_to_term (vfs_path_as_str (tree->selected_ptr->name), tree_cols, J_LEFT_FIT)); } }
static void listbox_drawscroll (WListbox * l) { Widget *w = WIDGET (l); int max_line = w->lines - 1; int line = 0; int i; int length; /* Are we at the top? */ widget_move (w, 0, w->cols); if (l->top == 0) tty_print_one_vline (TRUE); else tty_print_char ('^'); length = g_queue_get_length (l->list); /* Are we at the bottom? */ widget_move (w, max_line, w->cols); if (l->top + w->lines == length || w->lines >= length) tty_print_one_vline (TRUE); else tty_print_char ('v'); /* Now draw the nice relative pointer */ if (!g_queue_is_empty (l->list)) line = 1 + ((l->pos * (w->lines - 2)) / length); for (i = 1; i < max_line; i++) { widget_move (w, i, w->cols); if (i != line) tty_print_one_vline (TRUE); else tty_print_char ('*'); } }
void rotate_dash (void) { static const char rotating_dash[] = "|/-\\"; static size_t pos = 0; if (!nice_rotating_dash || (ok_to_refresh <= 0)) return; if (pos >= sizeof (rotating_dash) - 1) pos = 0; tty_gotoyx (0, COLS - 1); tty_setcolor (NORMAL_COLOR); tty_print_char (rotating_dash[pos]); mc_refresh (); pos++; }
static void draw_history_button (WInput * in) { char c; gboolean disabled = (((Widget *) in)->options & W_DISABLED) != 0; c = in->history->next ? (in->history->prev ? '|' : 'v') : '^'; widget_move (&in->widget, 0, in->field_width - HISTORY_BUTTON_WIDTH); tty_setcolor (disabled ? DISABLED_COLOR : in->color[WINPUTC_HISTORY]); #ifdef LARGE_HISTORY_BUTTON { Dlg_head *h; h = in->widget.owner; tty_print_string ("[ ]"); widget_move (&in->widget, 0, in->field_width - HISTORY_BUTTON_WIDTH + 1); } #endif tty_print_char (c); }
static void help_print_word (WDialog * h, GString * word, int *col, int *line, gboolean add_space) { if (*line >= help_lines) g_string_set_size (word, 0); else { int w; w = str_term_width1 (word->str); if (*col + w >= HELP_WINDOW_WIDTH) { *col = 0; (*line)++; } if (*line >= help_lines) g_string_set_size (word, 0); else { widget_move (h, *line + 2, *col + 2); tty_print_string (word->str); g_string_set_size (word, 0); *col += w; } } if (add_space) { if (*col < HELP_WINDOW_WIDTH - 1) { tty_print_char (' '); (*col)++; } else { *col = 0; (*line)++; } } }
void tty_draw_vline (int y, int x, int ch, int len) { int y1; if (x < 0 || x >= COLS || y >= LINES) return; y1 = y; if (y < 0) { len += y; if (len <= 0) return; y = 0; } if (ch == ACS_VLINE) ch = mc_tty_frm[MC_TTY_FRM_VERT]; if (ch == 0) ch = ACS_VLINE; SLsmg_gotorc (y, x); if (ch == ACS_VLINE) SLsmg_draw_vline (len); else { int pos = 0; while (len-- != 0) { SLsmg_gotorc (y + pos, x); tty_print_char (ch); pos++; } } SLsmg_gotorc (y1, x); }
static void update_split (const Dlg_head * h) { /* Check split has to be done before testing if it changed, since it can change due to calling _check_split() as well */ _check_split (); tty_setcolor (check_options[6].widget->state & C_BOOL ? DISABLED_COLOR : COLOR_NORMAL); dlg_move (h, 6, 5); tty_printf ("%03d", _first_panel_size); dlg_move (h, 6, 17); if (_horizontal_split) tty_printf ("%03d", height - _first_panel_size); else tty_printf ("%03d", COLS - _first_panel_size); dlg_move (h, 6, 12); tty_print_char ('='); }
void mcview_display_ruler (mcview_t * view) { static const char ruler_chars[] = "|----*----"; const screen_dimen top = view->ruler_area.top; const screen_dimen left = view->ruler_area.left; const screen_dimen width = view->ruler_area.width; const screen_dimen height = view->ruler_area.height; const screen_dimen line_row = (ruler == RULER_TOP) ? 0 : 1; const screen_dimen nums_row = (ruler == RULER_TOP) ? 1 : 0; char r_buff[10]; off_t cl; screen_dimen c; if (ruler == RULER_NONE || height < 1) return; tty_setcolor (VIEW_BOLD_COLOR); for (c = 0; c < width; c++) { cl = view->dpy_text_column + c; if (line_row < height) { widget_move (view, top + line_row, left + c); tty_print_char (ruler_chars[cl % 10]); } if ((cl != 0) && (cl % 10) == 0) { g_snprintf (r_buff, sizeof (r_buff), "%" PRIuMAX, (uintmax_t) cl); if (nums_row < height) { widget_move (view, top + nums_row, left + c - 1); tty_print_string (r_buff); } } } tty_setcolor (NORMAL_COLOR); }
void show_rxvt_contents (int starty, unsigned char y1, unsigned char y2) { unsigned char *k; int bytes, i, j, cols = 0; y1 += (keybar_visible != 0); /* i don't knwo why we need this - paul */ y2 += (keybar_visible != 0); while (anything_ready ()) tty_lowlevel_getch (); /* my own wierd protocol base 26 - paul */ printf ("\033CL%c%c%c%c\n", (y1 / 26) + 'A', (y1 % 26) + 'A', (y2 / 26) + 'A', (y2 % 26) + 'A'); bytes = (y2 - y1) * (COLS + 1) + 1; /* *should* be the number of bytes read */ j = 0; k = g_malloc (bytes); for (;;) { int c; c = rxvt_getc (); if (c < 0) break; if (j < bytes) k[j++] = c; for (cols = 1;; cols++) { c = rxvt_getc (); if (c < 0) break; if (j < bytes) k[j++] = c; } } for (i = 0; i < j; i++) { if ((i % cols) == 0) tty_gotoyx (starty + (i / cols), 0); tty_print_char (is_printable (k[i]) ? k[i] : ' '); } g_free (k); }
void rotate_dash (gboolean show) { static const char rotating_dash[4] = "|/-\\"; static size_t pos = 0; Widget *w = WIDGET (midnight_dlg); if (!nice_rotating_dash || (ok_to_refresh <= 0)) return; widget_move (w, (menubar_visible != 0) ? 1 : 0, w->cols - 1); tty_setcolor (NORMAL_COLOR); if (!show) tty_print_alt_char (ACS_URCORNER, FALSE); else { tty_print_char (rotating_dash[pos]); pos = (pos + 1) % sizeof (rotating_dash); } mc_refresh (); }
static void draw_history_button (WInput * in) { char c; gboolean disabled = (WIDGET (in)->options & W_DISABLED) != 0; if (g_list_next (in->history.current) == NULL) c = '^'; else if (g_list_previous (in->history.current) == NULL) c = 'v'; else c = '|'; widget_move (in, 0, WIDGET (in)->cols - HISTORY_BUTTON_WIDTH); tty_setcolor (disabled ? DISABLED_COLOR : in->color[WINPUTC_HISTORY]); #ifdef LARGE_HISTORY_BUTTON tty_print_string ("[ ]"); widget_move (in, 0, WIDGET (in)->cols - HISTORY_BUTTON_WIDTH + 1); #endif tty_print_char (c); }
static void help_show (WDialog * h, const char *paint_start) { const char *p, *n; int col, line, c; gboolean painting = TRUE; gboolean acs; /* Flag: Alternate character set active? */ gboolean repeat_paint; int active_col, active_line; /* Active link position */ char buff[MB_LEN_MAX + 1]; GString *word; word = g_string_sized_new (32); tty_setcolor (HELP_NORMAL_COLOR); do { line = col = active_col = active_line = 0; repeat_paint = FALSE; acs = FALSE; clear_link_areas (); if ((int) (selected_item - paint_start) < 0) selected_item = NULL; p = paint_start; n = paint_start; while ((n[0] != '\0') && (n[0] != CHAR_NODE_END) && (line < help_lines)) { p = n; n = str_cget_next_char (p); memcpy (buff, p, n - p); buff[n - p] = '\0'; c = (unsigned char) buff[0]; switch (c) { case CHAR_LINK_START: if (selected_item == NULL) selected_item = p; if (p != selected_item) tty_setcolor (HELP_LINK_COLOR); else { tty_setcolor (HELP_SLINK_COLOR); /* Store the coordinates of the link */ active_col = col + 2; active_line = line + 2; } start_link_area (col, line, p); break; case CHAR_LINK_POINTER: painting = FALSE; break; case CHAR_LINK_END: painting = TRUE; help_print_word (h, word, &col, &line, FALSE); end_link_area (col - 1, line); tty_setcolor (HELP_NORMAL_COLOR); break; case CHAR_ALTERNATE: acs = TRUE; break; case CHAR_NORMAL: acs = FALSE; break; case CHAR_VERSION: widget_move (h, line + 2, col + 2); tty_print_string (VERSION); col += str_term_width1 (VERSION); break; case CHAR_FONT_BOLD: tty_setcolor (HELP_BOLD_COLOR); break; case CHAR_FONT_ITALIC: tty_setcolor (HELP_ITALIC_COLOR); break; case CHAR_FONT_NORMAL: help_print_word (h, word, &col, &line, FALSE); tty_setcolor (HELP_NORMAL_COLOR); break; case '\n': if (painting) help_print_word (h, word, &col, &line, FALSE); line++; col = 0; break; case '\t': col = (col / 8 + 1) * 8; if (col >= HELP_WINDOW_WIDTH) { line++; col = 8; } break; case ' ': /* word delimiter */ if (painting) help_print_word (h, word, &col, &line, TRUE); break; default: if (painting && (line < help_lines)) { if (!acs) /* accumulate symbols in a word */ g_string_append (word, buff); else if (col < HELP_WINDOW_WIDTH) { widget_move (h, line + 2, col + 2); if ((c == ' ') || (c == '.')) tty_print_char (c); else #ifndef HAVE_SLANG tty_print_char (acs_map[c]); #else SLsmg_draw_object (WIDGET (h)->y + line + 2, WIDGET (h)->x + col + 2, c); #endif col++; } } } } /* print last word */ if (n[0] == CHAR_NODE_END) help_print_word (h, word, &col, &line, FALSE); last_shown = p; end_of_node = line < help_lines; tty_setcolor (HELP_NORMAL_COLOR); if ((int) (selected_item - last_shown) >= 0) { if ((link_area == NULL) || (link_area->data == NULL)) selected_item = NULL; else { selected_item = ((Link_Area *) link_area->data)->link_name; repeat_paint = TRUE; } } } while (repeat_paint); g_string_free (word, TRUE); /* Position the cursor over a nice link */ if (active_col) widget_move (h, active_line, active_col); }
static inline void print_to_widget (WEdit * edit, long row, int start_col, int start_col_real, long end_col, struct line_s line[], char *status, int bookmarked) { struct line_s *p; int x = start_col_real; int x1 = start_col + EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width; int y = row + EDIT_TEXT_VERTICAL_OFFSET; int cols_to_skip = abs (x); int i; int wrap_start; int len; tty_setcolor (EDITOR_NORMAL_COLOR); if (bookmarked != 0) tty_setcolor (bookmarked); len = end_col + 1 - start_col; wrap_start = option_word_wrap_line_length + edit->start_col; if (len > 0 && edit->widget.y + y >= 0) { if (!show_right_margin || wrap_start > end_col) tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', len); else if (wrap_start < 0) { tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR); tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', len); } else { if (wrap_start > 0) tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', wrap_start); len -= wrap_start; if (len > 0) { tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR); tty_draw_hline (edit->widget.y + y, edit->widget.x + x1 + wrap_start, ' ', len); } } } if (option_line_state) { tty_setcolor (LINE_STATE_COLOR); for (i = 0; i < LINE_STATE_WIDTH; i++) { edit_move (x1 + i - option_line_state_width, y); if (status[i] == '\0') status[i] = ' '; tty_print_char (status[i]); } } edit_move (x1, y); p = line; i = 1; while (p->ch) { int style; unsigned int textchar; int color; if (cols_to_skip) { p++; cols_to_skip--; continue; } style = p->style & 0xFF00; textchar = p->ch; color = p->style >> 16; if (style & MOD_ABNORMAL) { /* Non-printable - use black background */ color = 0; } if (style & MOD_WHITESPACE) { if (style & MOD_MARKED) { textchar = ' '; tty_setcolor (EDITOR_MARKED_COLOR); } else { #if 0 if (color != EDITOR_NORMAL_COLOR) { textchar = ' '; tty_lowlevel_setcolor (color); } else #endif tty_setcolor (EDITOR_WHITESPACE_COLOR); } } else { if (style & MOD_BOLD) { tty_setcolor (EDITOR_BOLD_COLOR); } else if (style & MOD_MARKED) { tty_setcolor (EDITOR_MARKED_COLOR); } else { tty_lowlevel_setcolor (color); } } if (show_right_margin) { if (i > option_word_wrap_line_length + edit->start_col) tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR); i++; } tty_print_anychar (textchar); p++; } }
static void show_tree (WTree * tree) { Widget *w = WIDGET (tree); WDialog *h = w->owner; tree_entry *current; int i, j, topsublevel; int x = 0, y = 0; int tree_lines, tree_cols; /* Initialize */ tree_lines = tlines (tree); tree_cols = w->cols; widget_move (w, y, x); if (tree->is_panel) { tree_cols -= 2; x = y = 1; } g_free (tree->tree_shown); tree->tree_shown = g_new0 (tree_entry *, tree_lines); 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) current = back_ptr (current, &tree->topdiff); else { i = 0; while (current->prev && i < tree->topdiff) { current = current->prev; if (current->sublevel < tree->selected_ptr->sublevel) { if (vfs_path_equal (current->name, tree->selected_ptr->name)) i++; } else if (current->sublevel == tree->selected_ptr->sublevel) { const char *cname; cname = vfs_path_as_str (current->name); for (j = strlen (cname) - 1; !IS_PATH_SEP (cname[j]); j--) ; if (vfs_path_equal_len (current->name, tree->selected_ptr->name, j)) i++; } else if (current->sublevel == tree->selected_ptr->sublevel + 1) { j = vfs_path_len (tree->selected_ptr->name); if (j > 1 && vfs_path_equal_len (current->name, tree->selected_ptr->name, j)) i++; } } tree->topdiff = i; } /* Loop for every line */ for (i = 0; i < tree_lines; i++) { tty_setcolor (tree->is_panel ? NORMAL_COLOR : TREE_NORMALC (h)); /* Move to the beginning of the line */ tty_draw_hline (w->y + y + i, w->x + x, ' ', tree_cols); if (current == NULL) continue; if (tree->is_panel) tty_setcolor (widget_get_state (w, WST_FOCUSED) && current == tree->selected_ptr ? SELECTED_COLOR : NORMAL_COLOR); else tty_setcolor (current == tree->selected_ptr ? TREE_CURRENTC (h) : TREE_NORMALC (h)); tree->tree_shown[i] = current; if (current->sublevel == topsublevel) /* Show full name */ tty_print_string (str_fit_to_term (vfs_path_as_str (current->name), tree_cols + (tree->is_panel ? 0 : 1), 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); /* Show sub-name */ tty_print_char (' '); tty_print_string (str_fit_to_term (current->subname, tree_cols - x - 3 * j, J_LEFT_FIT)); } /* Calculate the next value for current */ current = current->next; if (tree_navigation_flag) { while (current != NULL) { if (current->sublevel < tree->selected_ptr->sublevel) { if (vfs_path_equal_len (current->name, tree->selected_ptr->name, vfs_path_len (current->name))) break; } else if (current->sublevel == tree->selected_ptr->sublevel) { const char *cname; cname = vfs_path_as_str (current->name); for (j = strlen (cname) - 1; !IS_PATH_SEP (cname[j]); j--) ; if (vfs_path_equal_len (current->name, tree->selected_ptr->name, j)) break; } else if (current->sublevel == tree->selected_ptr->sublevel + 1 && vfs_path_len (tree->selected_ptr->name) > 1) { if (vfs_path_equal_len (current->name, tree->selected_ptr->name, vfs_path_len (tree->selected_ptr->name))) break; } current = current->next; } } } tree_show_mini_info (tree, tree_lines, tree_cols); }
/** * Parse, format and possibly display one visual line of text. * * Formatting starts at the given "state" (which encodes the file offset and parser and formatter's * internal state). In unwrap mode, this should point to the beginning of the paragraph with the * default state, the additional horizontal scrolling is added here. In wrap mode, this should * point to the beginning of the line, with the proper state at that point. * * In wrap mode, if a line ends in a newline, it is consumed, even if it's exactly at the right * edge. In unwrap mode, the whole remaining line, including the newline is consumed. Displaying * the next line should start at "state"'s new value, or if we displayed the bottom line then * state->offset tells the file offset to be shown in the top bar. * * If "row" is offscreen, don't actually display the line but still update "state" and return the * proper value. This is used by mcview_wrap_move_down to advance in the file. * * @param view ... * @param state the parser-formatter state machine's state, updated * @param row print to this row * @param paragraph_ended store TRUE if paragraph ended by newline or EOF, FALSE if wraps to next * line * @param linewidth store the width of the line here * @return the number of rows, that is, 0 if we were already at EOF, otherwise 1 */ static int mcview_display_line (WView * view, mcview_state_machine_t * state, int row, gboolean * paragraph_ended, off_t * linewidth) { 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; off_t dpy_text_column = view->text_wrap_mode ? 0 : view->dpy_text_column; screen_dimen col = 0; int cs[1 + MAX_COMBINING_CHARS]; char str[(1 + MAX_COMBINING_CHARS) * UTF8_CHAR_LEN + 1]; int i, j; if (paragraph_ended != NULL) *paragraph_ended = TRUE; if (!view->text_wrap_mode && (row < 0 || row >= (int) height) && linewidth == NULL) { /* Optimization: Fast forward to the end of the line, rather than carefully * parsing and then not actually displaying it. */ off_t eol; int retval; eol = mcview_eol (view, state->offset, mcview_get_filesize (view)); retval = (eol > state->offset) ? 1 : 0; mcview_state_machine_init (state, eol); return retval; } while (TRUE) { int charwidth = 0; mcview_state_machine_t state_saved; int n; int color; state_saved = *state; n = mcview_next_combining_char_sequence (view, state, cs, 1 + MAX_COMBINING_CHARS, &color); if (n == 0) { if (linewidth != NULL) *linewidth = col; return (col > 0) ? 1 : 0; } if (view->search_start <= state->offset && state->offset < view->search_end) color = VIEW_SELECTED_COLOR; if (cs[0] == '\n') { /* New line: reset all formatting state for the next paragraph. */ mcview_state_machine_init (state, state->offset); if (linewidth != NULL) *linewidth = col; return 1; } if (mcview_is_non_spacing_mark (view, cs[0])) { /* Lonely combining character. Probably leftover after too many combining chars. Just ignore. */ continue; } /* Nonprintable, or lonely spacing mark */ if ((!mcview_isprint (view, cs[0]) || mcview_ismark (view, cs[0])) && cs[0] != '\t') cs[0] = '.'; for (i = 0; i < n; i++) charwidth += mcview_wcwidth (view, cs[i]); /* Adjust the width for TAB. It's handled below along with the normal characters, * so that it's wrapped consistently with them, and is painted with the proper * attributes (although currently it can't have a special color). */ if (cs[0] == '\t') { charwidth = option_tab_spacing - state->unwrapped_column % option_tab_spacing; state->print_lonely_combining = TRUE; } else state->print_lonely_combining = FALSE; /* In wrap mode only: We're done with this row if the character sequence wouldn't fit. * Except if at the first column, because then it wouldn't fit in the next row either. * In this extreme case let the unwrapped code below do its best to display it. */ if (view->text_wrap_mode && (off_t) col + charwidth > dpy_text_column + (off_t) width && col > 0) { *state = state_saved; if (paragraph_ended != NULL) *paragraph_ended = FALSE; if (linewidth != NULL) *linewidth = col; return 1; } /* Display, unless outside of the viewport. */ if (row >= 0 && row < (int) height) { if ((off_t) col >= dpy_text_column && (off_t) col + charwidth <= dpy_text_column + (off_t) width) { /* The combining character sequence fits entirely in the viewport. Print it. */ tty_setcolor (color); widget_move (view, top + row, left + ((off_t) col - dpy_text_column)); if (cs[0] == '\t') { for (i = 0; i < charwidth; i++) tty_print_char (' '); } else { j = 0; for (i = 0; i < n; i++) j += mcview_char_display (view, cs[i], str + j); str[j] = '\0'; /* This is probably a bug in our tty layer, but tty_print_string * normalizes the string, whereas tty_printf doesn't. Don't normalize, * since we handle combining characters ourselves correctly, it's * better if they are copy-pasted correctly. Ticket 3255. */ tty_printf ("%s", str); } } else if ((off_t) col < dpy_text_column && (off_t) col + charwidth > dpy_text_column) { /* The combining character sequence would cross the left edge of the viewport. * This cannot happen with wrap mode. Print replacement character(s), * or spaces with the correct attributes for partial Tabs. */ tty_setcolor (color); for (i = dpy_text_column; i < (off_t) col + charwidth && i < dpy_text_column + (off_t) width; i++) { widget_move (view, top + row, left + (i - dpy_text_column)); tty_print_anychar ((cs[0] == '\t') ? ' ' : PARTIAL_CJK_AT_LEFT_MARGIN); } } else if ((off_t) col < dpy_text_column + (off_t) width && (off_t) col + charwidth > dpy_text_column + (off_t) width) { /* The combining character sequence would cross the right edge of the viewport * and we're not wrapping. Print replacement character(s), * or spaces with the correct attributes for partial Tabs. */ tty_setcolor (color); for (i = col; i < dpy_text_column + (off_t) width; i++) { widget_move (view, top + row, left + (i - dpy_text_column)); tty_print_anychar ((cs[0] == '\t') ? ' ' : PARTIAL_CJK_AT_RIGHT_MARGIN); } } } col += charwidth; state->unwrapped_column += charwidth; if (!view->text_wrap_mode && (off_t) col >= dpy_text_column + (off_t) width && linewidth == NULL) { /* Optimization: Fast forward to the end of the line, rather than carefully * parsing and then not actually displaying it. */ off_t eol; eol = mcview_eol (view, state->offset, mcview_get_filesize (view)); mcview_state_machine_init (state, eol); return 1; } } }
static cb_ret_t gauge_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) { WGauge *g = GAUGE (w); WDialog *h = w->owner; switch (msg) { case MSG_INIT: return MSG_HANDLED; /* We don't want to get the focus */ case MSG_FOCUS: return MSG_NOT_HANDLED; case MSG_DRAW: widget_move (w, 0, 0); if (!g->shown) { tty_setcolor (h->color[DLG_COLOR_NORMAL]); tty_printf ("%*s", w->cols, ""); } else { int gauge_len; int percentage, columns; long total = g->max; long done = g->current; if (total <= 0 || done < 0) { done = 0; total = 100; } if (done > total) done = total; while (total > 65535) { total /= 256; done /= 256; } gauge_len = w->cols - 7; /* 7 positions for percentage */ percentage = (200 * done / total + 1) / 2; columns = (2 * gauge_len * done / total + 1) / 2; tty_print_char ('['); if (g->from_left_to_right) { tty_setcolor (GAUGE_COLOR); tty_printf ("%*s", columns, ""); tty_setcolor (h->color[DLG_COLOR_NORMAL]); tty_printf ("%*s] %3d%%", gauge_len - columns, "", percentage); } else { tty_setcolor (h->color[DLG_COLOR_NORMAL]); tty_printf ("%*s", gauge_len - columns, ""); tty_setcolor (GAUGE_COLOR); tty_printf ("%*s", columns, ""); tty_setcolor (h->color[DLG_COLOR_NORMAL]); tty_printf ("] %3d%%", percentage); } } return MSG_HANDLED; default: return widget_default_callback (w, sender, msg, parm, data); } }
static int view_display_file (WDiff *view, int ord, int r, int c, int height, int width, #if !VERTICAL_SPLIT int total_height, #endif /* !VERTICAL_SPLIT */ int owidth) { int i, j, k; char buf[BUFSIZ]; const char *data = view->df[ord].data; const char *diffs = view->diffs; off_t offset = view->df[ord].offs; int nbytes = view->nbytes; off_t mask = 0; int available = width - (nbytes * 4 + 1); if (owidth > available - 1) { owidth = available - 1; if (owidth < 0) { owidth = 0; } } if (owidth > 0) { mask = ((((off_t)1 << ((owidth - 1) * 4)) - 1) << 4) | 0xF; owidth++; } if ((int)sizeof(buf) <= width) { /* abnormal, but avoid buffer overflow */ return -1; } for (j = 0; j < height; j++) { int ch; int stop = 1; tty_gotoyx(r + j, c); if (owidth > 0) { sprintf(buf, "%0*llX ", owidth - 1, offset & mask); tty_setcolor(MARKED_COLOR); tty_print_nstring(buf, owidth); } for (i = owidth, k = 0; k < nbytes; k++, i += 3) { ch = *data++; if (diffs[k] & (1 << ord)) { stop = 0; sprintf(buf + i, "%02X ", ch & 0xFF); ch = convert_to_display_c(ch & 0xFF); if (!is_printable(ch)) { ch = '.'; } } else { buf[i + 0] = ' '; buf[i + 1] = ' '; buf[i + 2] = ' '; buf[i + 3] = '\0'; ch = ' '; } buf[owidth + 3 * nbytes + 1 + k] = ch; if (diffs[k] & XDIFF_DIFFERENT) { tty_setcolor(VIEW_UNDERLINED_COLOR); } else { tty_setcolor(NORMAL_COLOR); } tty_print_nstring(buf + i, 3); } tty_setcolor(NORMAL_COLOR); if (i < width) { buf[i] = ' '; tty_print_char(buf[i]); i++; } for (k = 0; k < nbytes; k++, i++) { if (*diffs++ & XDIFF_DIFFERENT) { tty_setcolor(VIEW_UNDERLINED_COLOR); } else { tty_setcolor(NORMAL_COLOR); } tty_print_char(buf[i] & 0xFF); } tty_setcolor(NORMAL_COLOR); for (; i < width; i++) { buf[i] = ' '; tty_print_char(buf[i]); } buf[width] = '\0'; /* XXX we fully construct the buffer, but don't necessarily have to */ offset += nbytes; if (stop) { break; } } #if !VERTICAL_SPLIT height = total_height; #endif /* !VERTICAL_SPLIT */ if (j < height) { memset(buf, ' ', width); buf[width] = '\0'; for (; j < height; j++) { tty_gotoyx(r + j, c); tty_print_nstring(buf, width); } } return 0; }
void mcview_display_hex (mcview_t * view) { const screen_dimen top = view->data_area.top; const screen_dimen left = view->data_area.left; const screen_dimen height = view->data_area.height; const screen_dimen width = view->data_area.width; const int ngroups = view->bytes_per_line / 4; const screen_dimen text_start = 8 + 13 * ngroups + ((width < 80) ? 0 : (ngroups - 1 + 1)); /* 8 characters are used for the file offset, and every hex group * takes 13 characters. On "big" screens, the groups are separated * by an extra vertical line, and there is an extra space before the * text column. */ screen_dimen row; off_t from; int c; mark_t boldflag = MARK_NORMAL; struct hexedit_change_node *curr = view->change_list; #ifdef HAVE_CHARSET int ch = 0; #endif /* HAVE_CHARSET */ char hex_buff[10]; /* A temporary buffer for sprintf and mvwaddstr */ int bytes; /* Number of bytes already printed on the line */ mcview_display_clean (view); /* Find the first displayable changed byte */ from = view->dpy_start; while (curr && (curr->offset < from)) { curr = curr->next; } for (row = 0; mcview_get_byte (view, from, NULL) == TRUE && row < height; row++) { screen_dimen col = 0; size_t i; col = 0; /* Print the hex offset */ g_snprintf (hex_buff, sizeof (hex_buff), "%08" PRIXMAX " ", (uintmax_t) from); widget_move (view, top + row, left); tty_setcolor (VIEW_BOLD_COLOR); for (i = 0; col < width && hex_buff[i] != '\0'; i++) { tty_print_char (hex_buff[i]); /* tty_print_char(hex_buff[i]); */ col += 1; } tty_setcolor (VIEW_NORMAL_COLOR); for (bytes = 0; bytes < view->bytes_per_line; bytes++, from++) { #ifdef HAVE_CHARSET if (view->utf8) { int cw = 1; gboolean read_res = TRUE; ch = mcview_get_utf (view, from, &cw, &read_res); if (!read_res) break; /* char width is greater 0 bytes */ if (cw != 0) { int cnt; char corr_buf[UTF8_CHAR_LEN + 1]; struct hexedit_change_node *corr = curr; int res; res = g_unichar_to_utf8 (ch, (char *) corr_buf); for (cnt = 0; cnt < cw; cnt++) { if (curr != NULL && from + cnt == curr->offset) { /* replace only changed bytes in array of multibyte char */ corr_buf[cnt] = curr->value; curr = curr->next; } } corr_buf[res] = '\0'; /* Determine the state of the current multibyte char */ ch = utf8_to_int ((char *) corr_buf, &cw, &read_res); curr = corr; } } #endif /* HAVE_CHARSET */ if (!mcview_get_byte (view, from, &c)) break; /* Save the cursor position for mcview_place_cursor() */ if (from == view->hex_cursor && !view->hexview_in_text) { view->cursor_row = row; view->cursor_col = col; } /* Determine the state of the current byte */ boldflag = mcview_hex_calculate_boldflag (view, from, curr); /* Determine the value of the current byte */ if (curr != NULL && from == curr->offset) { c = curr->value; curr = curr->next; } /* Select the color for the hex number */ tty_setcolor (boldflag == MARK_NORMAL ? VIEW_NORMAL_COLOR : boldflag == MARK_SELECTED ? VIEW_BOLD_COLOR : boldflag == MARK_CHANGED ? VIEW_UNDERLINED_COLOR : /* boldflag == MARK_CURSOR */ view->hexview_in_text ? VIEW_SELECTED_COLOR : VIEW_UNDERLINED_COLOR); /* Print the hex number */ widget_move (view, top + row, left + col); if (col < width) { tty_print_char (hex_char[c / 16]); col += 1; } if (col < width) { tty_print_char (hex_char[c % 16]); col += 1; } /* Print the separator */ tty_setcolor (VIEW_NORMAL_COLOR); if (bytes != view->bytes_per_line - 1) { if (col < width) { tty_print_char (' '); col += 1; } /* After every four bytes, print a group separator */ if (bytes % 4 == 3) { if (view->data_area.width >= 80 && col < width) { tty_print_one_vline (TRUE); col += 1; } if (col < width) { tty_print_char (' '); col += 1; } } } /* Select the color for the character; this differs from the * hex color when boldflag == MARK_CURSOR */ tty_setcolor (boldflag == MARK_NORMAL ? VIEW_NORMAL_COLOR : boldflag == MARK_SELECTED ? VIEW_BOLD_COLOR : boldflag == MARK_CHANGED ? VIEW_UNDERLINED_COLOR : /* boldflag == MARK_CURSOR */ view->hexview_in_text ? VIEW_SELECTED_COLOR : MARKED_SELECTED_COLOR); #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) ch = convert_from_utf_to_current_c (ch, view->converter); else #endif { #ifdef HAVE_CHARSET c = convert_to_display_c (c); #endif if (!is_printable (c)) c = '.'; } /* Print corresponding character on the text side */ if (text_start + bytes < width) { widget_move (view, top + row, left + text_start + bytes); #ifdef HAVE_CHARSET if (view->utf8) tty_print_anychar (ch); else #endif tty_print_char (c); } /* Save the cursor position for mcview_place_cursor() */ if (from == view->hex_cursor && view->hexview_in_text) { view->cursor_row = row; view->cursor_col = text_start + bytes; } } } /* Be polite to the other functions */ tty_setcolor (VIEW_NORMAL_COLOR); mcview_place_cursor (view); view->dpy_end = from; }