From f902cc21563a2ae22ffdd81a293f070571786ddb Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Mon, 14 Dec 2009 22:01:59 -0500 Subject: [PATCH] Abbreviation of author names is now configurable and toggleable --- NEWS | 1 + manual.txt | 4 +-- tig.c | 70 +++++++++++++++++++++++++++++++++++++---------------- tigrc.5.txt | 15 +++++++----- 4 files changed, 61 insertions(+), 29 deletions(-) diff --git a/NEWS b/NEWS index e80e847..17d3925 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,7 @@ Improvements: %(file) works as expected. - Branch view: add entry to browse all branches (uses git-log's --all flag). + - Abbreviation of author names can now be configured and toggled. Bug fixes: diff --git a/manual.txt b/manual.txt index cc8cb79..475cf5a 100644 --- a/manual.txt +++ b/manual.txt @@ -433,8 +433,8 @@ Misc |v |Show version. |o |Open option menu |. |Toggle line numbers on/off. -|D |Toggle date display on/off. -|A |Toggle author display on/off. +|D |Toggle date display on/off/relative. +|A |Toggle author display on/off/abbreviated. |g |Toggle revision graph visualization on/off. |F |Toggle reference display on/off (tag and branch names). |: |Open prompt. This allows you to specify what git command diff --git a/tig.c b/tig.c index d2dff15..b668cf0 100644 --- a/tig.c +++ b/tig.c @@ -442,6 +442,45 @@ string_date(const time_t *time, enum date date) } +#define AUTHOR_VALUES \ + AUTHOR_(NO), \ + AUTHOR_(FULL), \ + AUTHOR_(ABBREVIATED) + +enum author { +#define AUTHOR_(name) AUTHOR_##name + AUTHOR_VALUES, +#undef AUTHOR_ + AUTHOR_DEFAULT = AUTHOR_FULL +}; + +static const struct enum_map author_map[] = { +#define AUTHOR_(name) ENUM_MAP(#name, AUTHOR_##name) + AUTHOR_VALUES +#undef AUTHOR_ +}; + +static const char * +get_author_initials(const char *author, size_t max_columns) +{ + 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 < max_columns - 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++; + } + + return initials; +} + + static bool argv_from_string(const char *argv[SIZEOF_ARG], int *argc, char *cmd) { @@ -1007,7 +1046,7 @@ get_request(const char *name) /* Option and state variables. */ static enum date opt_date = DATE_DEFAULT; -static bool opt_author = TRUE; +static enum author opt_author = AUTHOR_DEFAULT; static bool opt_line_number = FALSE; static bool opt_line_graphics = TRUE; static bool opt_rev_graph = FALSE; @@ -1741,7 +1780,7 @@ option_set_command(int argc, const char *argv[]) } if (!strcmp(argv[0], "show-author")) - return parse_bool(&opt_author, argv[2]); + return parse_enum(&opt_author, argv[2], author_map); if (!strcmp(argv[0], "show-date")) return parse_enum(&opt_date, argv[2], date_map); @@ -2214,25 +2253,11 @@ draw_date(struct view *view, time_t *time) static bool draw_author(struct view *view, const char *author) { - bool trim = opt_author_cols == 0 || opt_author_cols > 5 || !author; - - if (!trim) { - static char initials[10]; - size_t pos; + bool trim = opt_author_cols == 0 || opt_author_cols > 5; + bool abbreviate = opt_author == AUTHOR_ABBREVIATED || !trim; -#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; - } + if (abbreviate && author) + author = get_author_initials(author, opt_author_cols); return draw_field(view, LINE_AUTHOR, author, opt_author_cols, trim); } @@ -2498,6 +2523,7 @@ toggle_enum_option_do(unsigned int *opt, const char *help, toggle_enum_option_do(opt, help, map, ARRAY_SIZE(map)) #define toggle_date() toggle_enum_option(&opt_date, "dates", date_map) +#define toggle_author() toggle_enum_option(&opt_author, "author names", author_map) static void toggle_view_option(bool *option, const char *help) @@ -2523,6 +2549,8 @@ open_option_menu(void) if (prompt_menu("Toggle option", menu, &selected)) { if (menu[selected].data == &opt_date) toggle_date(); + else if (menu[selected].data == &opt_author) + toggle_author(); else toggle_view_option(menu[selected].data, menu[selected].text); } @@ -3535,7 +3563,7 @@ view_driver(struct view *view, enum request request) break; case REQ_TOGGLE_AUTHOR: - toggle_view_option(&opt_author, "author display"); + toggle_author(); break; case REQ_TOGGLE_REV_GRAPH: diff --git a/tigrc.5.txt b/tigrc.5.txt index be9bf8d..e3276ca 100644 --- a/tigrc.5.txt +++ b/tigrc.5.txt @@ -41,7 +41,7 @@ is: Examples: -------------------------------------------------------------------------- -set show-author = yes # Show author? +set show-author = abbreviated # Show abbreviated author names. set show-date = relative # Show relative commit date. set show-rev-graph = yes # Show revision graph? set show-refs = yes # Show references? @@ -86,15 +86,18 @@ Variables The following variables can be set: -'show-author' (bool):: 'show-rev-graph' (bool):: 'show-refs' (bool):: - Whether to show author, revision graph, and references - (branches, tags, and remotes) in the main view on start-up. Can all be - toggled. + Whether to show revision graph, and references (branches, tags, and + remotes) in the main view on start-up. Can all be toggled. -'show-date' (bool or "relative" or "short"):: +'show-author' (mixed) ["abbreviated" | "default" | bool]:: + + How to display author names. If set to "abbreviated" author initials + will be shown. Can be toggled. + +'show-date' (mixed) ["relative" | "short" | "default" | bool]:: Whether and how to show date. If set to "relative" a relative date will be used, e.g. "2 minutes ago". If set to "short" no time information is -- 2.30.2