X-Git-Url: https://git.distorted.org.uk/~mdw/tig/blobdiff_plain/3c112a880cfbee37741d7e00bc994390399c9527..9d6976b987b08e6b4c4077352ef72bbfd4eccce6:/tig.c diff --git a/tig.c b/tig.c index ef3fe0d..de85ca1 100644 --- a/tig.c +++ b/tig.c @@ -1316,33 +1316,44 @@ static void update_view_title(struct view *view) { char buf[SIZEOF_STR]; - size_t bufpos = 0; + char state[SIZEOF_STR]; + size_t bufpos = 0, statelen = 0; assert(view_is_displayed(view)); - string_format_from(buf, &bufpos, "[%s]", view->name); - if (*view->ref) - string_format_from(buf, &bufpos, " %s", view->ref); - if (view->lines || view->pipe) { unsigned int view_lines = view->offset + view->height; unsigned int lines = view->lines ? MIN(view_lines, view->lines) * 100 / view->lines : 0; - string_format_from(buf, &bufpos, " - %s %d of %d (%d%%)", + string_format_from(state, &statelen, "- %s %d of %d (%d%%)", view->ops->type, view->lineno + 1, view->lines, lines); + + if (view->pipe) { + time_t secs = time(NULL) - view->start_time; + + /* Three git seconds are a long time ... */ + if (secs > 2) + string_format_from(state, &statelen, " %lds", secs); + } } - if (view->pipe) { - time_t secs = time(NULL) - view->start_time; + string_format_from(buf, &bufpos, "[%s]", view->name); + if (*view->ref && bufpos < view->width) { + size_t refsize = strlen(view->ref); + size_t minsize = bufpos + 1 + /* abbrev= */ 7 + 1 + statelen; + + if (minsize < view->width) + refsize = view->width - minsize + 7; + string_format_from(buf, &bufpos, " %.*s", refsize, view->ref); + } - /* Three git seconds are a long time ... */ - if (secs > 2) - string_format_from(buf, &bufpos, " %lds", secs); + if (statelen && bufpos < view->width) { + string_format_from(buf, &bufpos, " %s", state); } if (view == display[current_view])