From: Jonas Fonseca Date: Fri, 30 Jan 2009 23:49:25 +0000 (+0100) Subject: Abbreviate author names to initials when author-width < 6 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=73771ecdbc1472b5506c90b4cb30fe464fd88403;p=tig.git Abbreviate author names to initials when author-width < 6 --- diff --git a/NEWS b/NEWS index c8d080b..de00136 100644 --- a/NEWS +++ b/NEWS @@ -19,6 +19,8 @@ Improvements: - Stage & main view: restore view position when reloading. - Blame view: load blame for parent commit. For merge commits the parent is queried. Bound to ',' by default via the existing "parent" action. + - Abbreviate author names to initials when the width of the author column + is below 6 characters. Bug fixes: diff --git a/TODO b/TODO index 651b92c..374b173 100644 --- a/TODO +++ b/TODO @@ -26,9 +26,6 @@ Features that should be explored. - Color the revgraph to make it easier to follow branches. Idea by Dominik Vogt. - - Blame view: Allow names in the author column to be abbreviated to - initials. Will optimize screen usage for the blame view. - - Commit cache: Many views use commit information and load it into their own custom data structure. Having the information shared would make it easier to do various interesting stuff across the views. diff --git a/tig.c b/tig.c index b954370..90e0373 100644 --- a/tig.c +++ b/tig.c @@ -2010,7 +2010,27 @@ draw_date(struct view *view, struct tm *time) static bool draw_author(struct view *view, const char *author) { - return draw_field(view, LINE_MAIN_AUTHOR, author, opt_author_cols, TRUE); + bool trim = opt_author_cols == 0 || opt_author_cols > 5 || !author; + + if (!trim) { + static char initials[10]; + size_t pos; + +#define is_initial_sep(c) (isspace(c) || ispunct(c) || (c) == '@') + + memset(initials, 0, sizeof(initials)); + for (pos = 0; *author && pos < opt_author_cols - 1; author++, pos++) { + while (is_initial_sep(*author)) + author++; + strncpy(&initials[pos], author, sizeof(initials) - 1 - pos); + while (*author && !is_initial_sep(author[1])) + author++; + } + + author = initials; + } + + return draw_field(view, LINE_MAIN_AUTHOR, author, opt_author_cols, trim); } static bool diff --git a/tigrc.5.txt b/tigrc.5.txt index 0090ca7..1120a86 100644 --- a/tigrc.5.txt +++ b/tigrc.5.txt @@ -85,7 +85,8 @@ The following variables can be set: 'author-width' (int):: - Width of the author column. + Width of the author column. When set to 5 or below, the author name + will be abbreviated to the author's initials. 'line-graphics' (bool)::