int swap_dirs(void) { stack_entry_t item; if(stack_top == 0) return -1; item = stack[--stack_top]; if(pushd() != 0) { free_entry(&item); return -1; } if(change_directory(&lwin, item.lpane_dir) >= 0) load_dir_list(&lwin, 0); if(change_directory(&rwin, item.rpane_dir) >= 0) load_dir_list(&rwin, 0); fview_cursor_redraw(curr_view); refresh_view_win(other_view); free_entry(&item); return 0; }
static void draw(void) { int l, vl; const int height = vi->view->window_rows - 1; const int width = vi->view->window_width - 1; const int max_l = MIN(vi->line + height, vi->nlines); const int searched = (vi->last_search_backward != -1); esc_state state; esc_state_init(&state, &vi->view->cs.color[WIN_COLOR]); werase(vi->view->win); for(vl = 0, l = vi->line; l < max_l && vl < height; l++) { int offset = 0; int t = 0; char *const line = vi->lines[l]; char *p = searched ? esc_highlight_pattern(line, &vi->re) : line; do { int printed; int vis = l != vi->line || vl + t >= vi->linev - vi->widths[vi->line][0]; offset += esc_print_line(p + offset, vi->view->win, COL, 1 + vl, width, !vis, &state, &printed); vl += vis; t++; } while(vi->wrap && p[offset] != '\0' && vl < height); if(searched) { free(p); } } refresh_view_win(vi->view); }
static void draw(void) { int l, vl; const col_scheme_t *cs = ui_view_get_cs(vi->view); const int height = vi->view->window_rows - 1; const int width = vi->view->window_width - 1; const int max_l = MIN(vi->line + height, vi->nlines); const int searched = (vi->last_search_backward != -1); esc_state state; if(vi->graphics) { const char *cmd = gv_get_viewer(vi->filename); cmd = (cmd != NULL) ? ma_get_clean_cmd(cmd) : NULL; qv_cleanup(vi->view, cmd); free_string_array(vi->lines, vi->nlines); (void)get_view_data(vi, vi->filename); return; } esc_state_init(&state, &cs->color[WIN_COLOR]); ui_view_erase(vi->view); for(vl = 0, l = vi->line; l < max_l && vl < height; ++l) { int offset = 0; int t = 0; char *const line = vi->lines[l]; char *p = searched ? esc_highlight_pattern(line, &vi->re) : line; do { int printed; int vis = l != vi->line || vl + t >= vi->linev - vi->widths[vi->line][0]; offset += esc_print_line(p + offset, vi->view->win, COL, 1 + vl, width, !vis, &state, &printed); vl += vis; t++; } while(vi->wrap && p[offset] != '\0' && vl < height); if(searched) { free(p); } } refresh_view_win(vi->view); }
void toggle_quick_view(void) { if(curr_stats.view) { curr_stats.view = 0; draw_dir_list(other_view); refresh_view_win(other_view); } else { curr_stats.view = 1; quick_view_file(curr_view); } }
int popd(void) { if(stack_top == 0) return -1; stack_top--; if(change_directory(&lwin, stack[stack_top].lpane_dir) >= 0) load_dir_list(&lwin, 0); if(change_directory(&rwin, stack[stack_top].rpane_dir) >= 0) load_dir_list(&rwin, 0); fview_cursor_redraw(curr_view); refresh_view_win(other_view); free_entry(&stack[stack_top]); return 0; }
void quick_view_file(FileView *view) { char path[PATH_MAX]; const dir_entry_t *entry; if(curr_stats.load_stage < 2) { return; } if(vle_mode_is(VIEW_MODE)) { return; } if(curr_stats.number_of_windows == 1) { return; } if(draw_abandoned_view_mode()) { return; } ui_view_erase(other_view); entry = &view->dir_entry[view->list_pos]; get_full_path_of(entry, sizeof(path), path); switch(view->dir_entry[view->list_pos].type) { case FT_CHAR_DEV: mvwaddstr(other_view->win, LINE, COL, "File is a Character Device"); break; case FT_BLOCK_DEV: mvwaddstr(other_view->win, LINE, COL, "File is a Block Device"); break; #ifndef _WIN32 case FT_SOCK: mvwaddstr(other_view->win, LINE, COL, "File is a Socket"); break; #endif case FT_FIFO: mvwaddstr(other_view->win, LINE, COL, "File is a Named Pipe"); break; case FT_LINK: if(get_link_target_abs(path, entry->origin, path, sizeof(path)) != 0) { mvwaddstr(other_view->win, LINE, COL, "Cannot resolve Link"); break; } if(!ends_with_slash(path) && is_dir(path)) { strncat(path, "/", sizeof(path) - strlen(path) - 1); } /* break intensionally omitted */ case FT_UNK: default: { const char *viewer; FILE *fp; char *const typed_fname = get_typed_fname(path); viewer = ft_get_viewer(typed_fname); free(typed_fname); if(viewer == NULL && is_dir(path)) { mvwaddstr(other_view->win, LINE, COL, "File is a Directory"); break; } if(is_null_or_empty(viewer)) { fp = os_fopen(path, "rb"); } else { fp = use_info_prog(viewer); } if(fp == NULL) { mvwaddstr(other_view->win, LINE, COL, "Cannot open file"); break; } ui_view_clear(other_view); wattrset(other_view->win, 0); view_file(fp, cfg.wrap_quick_view); fclose(fp); break; } } refresh_view_win(other_view); ui_view_title_update(other_view); }
void quick_view_file(FileView *view) { char buf[PATH_MAX]; if(curr_stats.load_stage < 2) return; if(get_mode() == VIEW_MODE) return; if(curr_stats.number_of_windows == 1) return; werase(other_view->win); werase(other_view->title); mvwaddstr(other_view->title, 0, 0, "File: "); wprint(other_view->title, view->dir_entry[view->list_pos].name); snprintf(buf, sizeof(buf), "%s/%s", view->curr_dir, view->dir_entry[view->list_pos].name); switch(view->dir_entry[view->list_pos].type) { case CHARACTER_DEVICE: mvwaddstr(other_view->win, LINE, COL, "File is a Character Device"); break; case BLOCK_DEVICE: mvwaddstr(other_view->win, LINE, COL, "File is a Block Device"); break; #ifndef _WIN32 case SOCKET: mvwaddstr(other_view->win, LINE, COL, "File is a Socket"); break; #endif case FIFO: mvwaddstr(other_view->win, LINE, COL, "File is a Named Pipe"); break; case LINK: if(get_link_target_abs(buf, view->curr_dir, buf, sizeof(buf)) != 0) { mvwaddstr(other_view->win, LINE, COL, "Cannot resolve Link"); break; } if(!ends_with_slash(buf) && is_dir(buf)) { strncat(buf, "/", sizeof(buf) - strlen(buf) - 1); } /* break intensionally omitted */ case UNKNOWN: default: { const char *viewer; FILE *fp; viewer = get_viewer_for_file(buf); if(viewer == NULL && is_dir(buf)) { mvwaddstr(other_view->win, LINE, COL, "File is a Directory"); break; } if(is_null_or_empty(viewer)) fp = fopen(buf, "r"); else fp = use_info_prog(viewer); if(fp == NULL) { mvwaddstr(other_view->win, LINE, COL, "Cannot open file"); break; } colmgr_reset(); wattrset(other_view->win, 0); view_file(fp, cfg.wrap_quick_view); fclose(fp); } break; } refresh_view_win(other_view); wrefresh(other_view->title); }