/* Scroll in 'direction' to the next line containing 're' in 'v', * starting from the current line. Returns 0 if no occurrence is * found. * * If consider_current is true then stay on the current line * if it matches. */ int owl_viewwin_search(owl_viewwin *v, const owl_regex *re, int consider_current, int direction) { int start, end, offset; int lineend, linestart; const char *buf, *linestartp; owl_fmtext_line_extents(&v->fmtext, v->topline, &start, &end); if (direction == OWL_DIRECTION_DOWNWARDS) { offset = owl_fmtext_search(&v->fmtext, re, consider_current ? start : end); if (offset < 0) return 0; v->topline = owl_fmtext_line_number(&v->fmtext, offset); owl_viewwin_dirty(v); return 1; } else { /* TODO: This is a hack. Really, we should have an owl_fmlines or * something containing an array of owl_fmtext split into * lines. Also, it cannot handle multi-line regex, if we ever care about * them. */ buf = owl_fmtext_get_text(&v->fmtext); lineend = consider_current ? end : start; while (lineend > 0) { linestartp = memrchr(buf, '\n', lineend - 1); linestart = linestartp ? linestartp - buf + 1 : 0; if (_re_memcompare(re, buf, linestart, lineend)) { v->topline = owl_fmtext_line_number(&v->fmtext, linestart); owl_viewwin_dirty(v); return 1; } lineend = linestart; } return 0; } }
void owl_viewwin_bottom(owl_viewwin *v) { int winlines; owl_window_get_position(v->content, &winlines, 0, 0, 0); v->topline = v->textlines - winlines; owl_viewwin_dirty(v); }
void owl_viewwin_down(owl_viewwin *v, int amount) { int winlines; owl_window_get_position(v->content, &winlines, 0, 0, 0); /* Don't scroll past the bottom. */ amount = MIN(amount, v->textlines - (v->topline + winlines)); /* But if we're already past the bottom, don't back up either. */ if (amount > 0) { v->topline += amount; owl_viewwin_dirty(v); } }
void owl_global_set_search_re(owl_global *g, const owl_regex *re) { if (owl_regex_is_set(&g->search_re)) { owl_regex_cleanup(&g->search_re); owl_regex_init(&g->search_re); } if (re != NULL) owl_regex_copy(re, &g->search_re); /* TODO: Emit a signal so we don't depend on the viewwin and mainwin */ if (owl_global_get_viewwin(g)) owl_viewwin_dirty(owl_global_get_viewwin(g)); owl_mainwin_redisplay(owl_global_get_mainwin(g)); }
void owl_viewwin_top(owl_viewwin *v) { v->topline=0; v->rightshift=0; owl_viewwin_dirty(v); }
void owl_viewwin_left(owl_viewwin *v, int n) { v->rightshift-=n; if (v->rightshift<0) v->rightshift=0; owl_viewwin_dirty(v); }
void owl_viewwin_right(owl_viewwin *v, int n) { v->rightshift+=n; owl_viewwin_dirty(v); }
void owl_viewwin_up(owl_viewwin *v, int amount) { v->topline -= amount; if (v->topline<0) v->topline=0; owl_viewwin_dirty(v); }
void owl_viewwin_append_text(owl_viewwin *v, const char *text) { owl_fmtext_append_normal(&(v->fmtext), text); v->textlines=owl_fmtext_num_lines(&(v->fmtext)); owl_viewwin_dirty(v); }