From 7078ebbf058eda098fc9a427aff3155fb7065023 Mon Sep 17 00:00:00 2001 From: Thomas Koutcher Date: Fri, 17 Jan 2020 23:44:57 +0100 Subject: [PATCH] Add line-graphics = auto Closes #834 --- NEWS.adoc | 1 + doc/tigrc.5.adoc | 5 +++-- src/options.c | 20 +++++++++++++++++--- tigrc | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/NEWS.adoc b/NEWS.adoc index e13e1c199..48039bf97 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -7,6 +7,7 @@ master Improvements: - Jump from blame to commit. (#355) + - Add line-graphics = auto. (#834) Bug fixes: diff --git a/doc/tigrc.5.adoc b/doc/tigrc.5.adoc index 6b40afe37..d99441a7d 100644 --- a/doc/tigrc.5.adoc +++ b/doc/tigrc.5.adoc @@ -191,9 +191,10 @@ The following variables can be set: - replace : A replaced reference. - branch : Any other reference. -'line-graphics' (mixed) [ascii|default|utf-8|]:: +'line-graphics' (mixed) [ascii|default|utf-8|auto|]:: - What type of character graphics for line drawing. + What type of character graphics for line drawing. "auto" means "utf-8" + if the locale is UTF-8, "default" otherwise. 'truncation-delimiter' (mixed) [utf-8|]:: diff --git a/src/options.c b/src/options.c index 8ef8024d8..dcef0a7d0 100644 --- a/src/options.c +++ b/src/options.c @@ -594,10 +594,24 @@ parse_option(struct option_info *option, const char *prefix, const char *arg) return parse_step(option->value, arg); if (!strncmp(option->type, "enum", 4)) { - const char *type = option->type + STRING_SIZE("enum "); - const struct enum_map *map = find_enum_map(type); + if (!strcmp(name, "line-graphics") && !strcasecmp(arg, "auto")) { + const char *locale; + int *value = option->value; - return parse_enum(name, option->value, arg, map); + if ((((locale = getenv("LC_ALL")) && *locale) || + ((locale = getenv("LC_CTYPE")) && *locale) || + ((locale = getenv("LANG")) && *locale)) && + (strstr(locale, "UTF") || strstr(locale, "utf"))) + *value = GRAPHIC_UTF_8; + else + *value = GRAPHIC_DEFAULT; + return SUCCESS; + } else { + const char *type = option->type + STRING_SIZE("enum "); + const struct enum_map *map = find_enum_map(type); + + return parse_enum(name, option->value, arg, map); + } } if (!strcmp(option->type, "int")) { diff --git a/tigrc b/tigrc index a54499095..70e2cc69f 100644 --- a/tigrc +++ b/tigrc @@ -88,7 +88,7 @@ set show-changes = yes # Show changes commits in the main view? set show-untracked = yes # Show also untracked changes? set wrap-lines = no # Wrap long lines in pager views? set tab-size = 8 # Number of spaces to use when expanding tabs -set line-graphics = default # Enum: ascii, default, utf-8 +set line-graphics = default # Enum: ascii, default, utf-8, auto set truncation-delimiter = ~ # Character drawn for truncations, or "utf-8" # Format reference names based on type.