static bool cmd_select(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) { Filerange sel = text_range_empty(); if (!win) return sam_execute(vis, NULL, cmd->cmd, NULL, &sel); bool ret = true; View *view = win->view; Text *txt = win->file->text; bool multiple_cursors = view_cursors_multiple(view); Cursor *primary = view_cursors_primary_get(view); for (Cursor *c = view_cursors(view), *next; c && ret; c = next) { next = view_cursors_next(c); size_t pos = view_cursors_pos(c); if (vis->mode->visual) { sel = view_cursors_selection_get(c); } else if (cmd->cmd->address) { /* convert a single line range to a goto line motion */ if (!multiple_cursors && cmd->cmd->cmddef->func == cmd_print) { Address *addr = cmd->cmd->address; switch (addr->type) { case '+': case '-': addr = addr->right; /* fall through */ case 'l': if (addr && addr->type == 'l' && !addr->right) addr->type = 'g'; break; } } sel = text_range_new(pos, pos); } else if (cmd->cmd->cmddef->flags & CMD_ADDRESS_POS) { sel = text_range_new(pos, pos); } else if (cmd->cmd->cmddef->flags & CMD_ADDRESS_LINE) { sel = text_object_line(txt, pos); } else if (cmd->cmd->cmddef->flags & CMD_ADDRESS_AFTER) { size_t next_line = text_line_next(txt, pos); sel = text_range_new(next_line, next_line); } else if (multiple_cursors) { sel = text_object_line(txt, pos); } else { sel = text_range_new(0, text_size(txt)); } if (text_range_valid(&sel)) ret &= sam_execute(vis, win, cmd->cmd, c, &sel); if (cmd->cmd->cmddef->flags & CMD_ONCE) break; } if (vis->win && vis->win->view == view && primary != view_cursors_primary_get(view)) view_cursors_primary_set(view_cursors(view)); return ret; }
static void ui_window_draw_status(UiWin *w) { UiCursesWin *win = (UiCursesWin*)w; if (!win->winstatus) return; UiCurses *uic = win->ui; Vis *vis = uic->vis; bool focused = uic->selwin == win; const char *filename = vis_file_name(win->file); const char *status = vis_mode_status(vis); wattrset(win->winstatus, focused ? A_REVERSE|A_BOLD : A_REVERSE); mvwhline(win->winstatus, 0, 0, ' ', win->width); mvwprintw(win->winstatus, 0, 0, "%s %s %s %s", focused && status ? status : "", filename ? filename : "[No Name]", text_modified(vis_file_text(win->file)) ? "[+]" : "", vis_macro_recording(vis) ? "recording": ""); char buf[4*32] = "", *msg = buf; int cursor_count = view_cursors_count(win->view); if (cursor_count > 1) { Cursor *c = view_cursors_primary_get(win->view); int cursor_number = view_cursors_number(c) + 1; msg += sprintf(msg, "[%d/%d] ", cursor_number, cursor_count); } if (!(win->options & UI_OPTION_LARGE_FILE)) { CursorPos pos = view_cursor_getpos(win->view); msg += sprintf(msg, "%zd, %zd", pos.line, pos.col); } if (buf[0]) mvwaddstr(win->winstatus, 0, win->width - (msg - buf) - 1, buf); }
void vis_prompt_show(Vis *vis, const char *title) { Win *active = vis->win; Win *prompt = window_new_file(vis, title[0] == ':' ? vis->command_file : vis->search_file, UI_OPTION_ONELINE); if (!prompt) return; if (vis->mode->visual) window_selection_save(active); Text *txt = prompt->file->text; text_insert(txt, text_size(txt), title, strlen(title)); Cursor *cursor = view_cursors_primary_get(prompt->view); view_cursors_scroll_to(cursor, text_size(txt)); prompt->parent = active; prompt->parent_mode = vis->mode; vis_window_mode_map(prompt, VIS_MODE_NORMAL, true, "<Enter>", &prompt_enter_binding); vis_window_mode_map(prompt, VIS_MODE_INSERT, true, "<Enter>", &prompt_enter_binding); vis_window_mode_map(prompt, VIS_MODE_VISUAL, true, "<Enter>", &prompt_enter_binding); vis_window_mode_map(prompt, VIS_MODE_NORMAL, true, "<Escape>", &prompt_esc_binding); vis_window_mode_map(prompt, VIS_MODE_INSERT, true, "<Up>", &prompt_up_binding); vis_window_mode_map(prompt, VIS_MODE_INSERT, true, "<Backspace>", &prompt_backspace_binding); vis_mode_switch(vis, VIS_MODE_INSERT); }