From 71d1c7db12d1d0ad63ecfbefa8f14289e0501cc3 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sat, 16 Sep 2006 02:37:49 +0200 Subject: [PATCH] Abbreviate the view reference in the view title for small widths --- tig.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tig.c b/tig.c index 8a796fd..de85ca1 100644 --- a/tig.c +++ b/tig.c @@ -1316,21 +1316,18 @@ 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, @@ -1341,10 +1338,24 @@ update_view_title(struct view *view) /* Three git seconds are a long time ... */ if (secs > 2) - string_format_from(buf, &bufpos, " %lds", secs); + string_format_from(state, &statelen, " %lds", secs); } } + 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); + } + + if (statelen && bufpos < view->width) { + string_format_from(buf, &bufpos, " %s", state); + } + if (view == display[current_view]) wbkgdset(view->title, get_line_attr(LINE_TITLE_FOCUS)); else -- 2.11.0