Code

Abbreviate author names to initials when author-width < 6
authorJonas Fonseca <fonseca@diku.dk>
Fri, 30 Jan 2009 23:49:25 +0000 (00:49 +0100)
committerJonas Fonseca <fonseca@diku.dk>
Mon, 2 Feb 2009 08:17:58 +0000 (09:17 +0100)
NEWS
TODO
tig.c
tigrc.5.txt

diff --git a/NEWS b/NEWS
index c8d080b05f703ff46185ec5323a2c576d07eebd5..de00136e74e331ab7e580fbd3bd50b8d94f4913a 100644 (file)
--- 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 651b92cecfb803c56f7d9bd5198e861014dbf227..374b173a21fea3235a35e0a98f7498816cfaf836 100644 (file)
--- 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 b9543707cbea8f546b793060393048db231429f1..90e03735ef9a1be09901bd85d6f0b71c0ce81d9b 100644 (file)
--- 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
index 0090ca770d7ae25758368be225fa8643652b38f7..1120a8642b6c817f833db9ef91f258729fdb5b8a 100644 (file)
@@ -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)::