X-Git-Url: https://git.distorted.org.uk/~mdw/tig/blobdiff_plain/33c4f9ea1de94641094993578a789d12ab2d95e9..3360f4491f10680a0e037c9afeb6b450f5aeea59:/tig.c diff --git a/tig.c b/tig.c index 6518f0d..e78c26c 100644 --- a/tig.c +++ b/tig.c @@ -145,7 +145,7 @@ set_from_int_map(struct int_map *map, size_t map_size, */ static inline void -string_ncopy(char *dst, const char *src, int dstlen) +string_ncopy(char *dst, const char *src, size_t dstlen) { strncpy(dst, src, dstlen - 1); dst[dstlen - 1] = 0; @@ -172,10 +172,10 @@ chomp_string(char *name) } static bool -string_nformat(char *buf, size_t bufsize, int *bufpos, const char *fmt, ...) +string_nformat(char *buf, size_t bufsize, size_t *bufpos, const char *fmt, ...) { va_list args; - int pos = bufpos ? *bufpos : 0; + size_t pos = bufpos ? *bufpos : 0; va_start(args, fmt); pos += vsnprintf(buf + pos, bufsize - pos, fmt, args); @@ -714,7 +714,7 @@ static struct keybinding default_keybindings[] = { { 'z', REQ_STOP_LOADING }, { 'v', REQ_SHOW_VERSION }, { 'r', REQ_SCREEN_REDRAW }, - { 'n', REQ_TOGGLE_LINENO }, + { '.', REQ_TOGGLE_LINENO }, { 'g', REQ_TOGGLE_REV_GRAPH }, { ':', REQ_PROMPT }, @@ -847,7 +847,7 @@ get_key(enum request request) { static char buf[BUFSIZ]; static char key_char[] = "'X'"; - int pos = 0; + size_t pos = 0; char *sep = " "; int i; @@ -1240,10 +1240,17 @@ static struct view views[] = { #define VIEW(req) (&views[(req) - REQ_OFFSET - 1]) +#define foreach_view(view, i) \ + for (i = 0; i < ARRAY_SIZE(views) && (view = &views[i]); i++) + +#define view_is_displayed(view) \ + (view == display[0] || view == display[1]) static bool draw_view_line(struct view *view, unsigned int lineno) { + assert(view_is_displayed(view)); + if (view->offset + lineno >= view->lines) return FALSE; @@ -1275,6 +1282,8 @@ redraw_view(struct view *view) static void update_view_title(struct view *view) { + assert(view_is_displayed(view)); + if (view == display[current_view]) wbkgdset(view->title, get_line_attr(LINE_TITLE_FOCUS)); else @@ -1399,6 +1408,8 @@ update_display_cursor(void) static void do_scroll_view(struct view *view, int lines, bool redraw) { + assert(view_is_displayed(view)); + /* The rendering expects the new offset. */ view->offset += lines; @@ -1586,6 +1597,8 @@ static void search_view(struct view *view, enum request request, const char *sea static bool find_next_line(struct view *view, unsigned long lineno, struct line *line) { + assert(view_is_displayed(view)); + if (!view->ops->grep(view, line)) return FALSE; @@ -1795,6 +1808,7 @@ update_view(struct view *view) if (view->offset + view->height >= view->lines) redraw_from = view->lines - view->offset; + /* FIXME: This is probably not perfect for backgrounded views. */ if (!realloc_lines(view, view->lines + lines)) goto alloc_error; @@ -1841,6 +1855,9 @@ update_view(struct view *view) } } + if (!view_is_displayed(view)) + goto check_pipe; + if (view == VIEW(REQ_VIEW_TREE)) { /* Clear the view and redraw everything since the tree sorting * might have rearranged things. */ @@ -1861,6 +1878,7 @@ update_view(struct view *view) * commit reference in view->ref it'll be available here. */ update_view_title(view); +check_pipe: if (ferror(view->pipe)) { report("Failed to read: %s", strerror(errno)); goto end; @@ -2252,7 +2270,7 @@ pager_draw(struct view *view, struct line *line, unsigned int lineno) } static bool -add_describe_ref(char *buf, int *bufpos, char *commit_id, const char *sep) +add_describe_ref(char *buf, size_t *bufpos, char *commit_id, const char *sep) { char refbuf[SIZEOF_STR]; char *ref = NULL; @@ -2285,7 +2303,7 @@ add_pager_refs(struct view *view, struct line *line) char buf[SIZEOF_STR]; char *commit_id = line->data + STRING_SIZE("commit "); struct ref **refs; - int bufpos = 0, refpos = 0; + size_t bufpos = 0, refpos = 0; const char *sep = "Refs: "; bool is_tag = FALSE; @@ -2525,7 +2543,7 @@ tree_enter(struct view *view, struct line *line) dirsep[0] = 0; } else { - int pathlen = strlen(opt_path); + size_t pathlen = strlen(opt_path); char *basename = data + SIZEOF_TREE_ATTR; string_format_from(opt_path, &pathlen, "%s/", basename); @@ -3125,7 +3143,7 @@ read_prompt(const char *prompt) struct view *view; int i, key; - foreach_displayed_view (view, i) + foreach_view (view, i) update_view(view); report("%s%.*s", prompt, pos, buf); @@ -3420,7 +3438,7 @@ main(int argc, char *argv[]) int key; int i; - foreach_displayed_view (view, i) + foreach_view (view, i) update_view(view); /* Refresh, accept single keystroke of input */