From 285a6aa3ce779544b7b72ce470f98d49b377a4e4 Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 27 Aug 2014 22:24:27 +0400 Subject: [PATCH] Fall back to ASCII-only theme in case of non-unicode locale --- docs/source/configuration/reference.rst | 3 ++- powerline/__init__.py | 13 ++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/source/configuration/reference.rst b/docs/source/configuration/reference.rst index a0edf36f..9277e4f9 100644 --- a/docs/source/configuration/reference.rst +++ b/docs/source/configuration/reference.rst @@ -94,7 +94,8 @@ Common configuration is a subdictionary that is a value of ``common`` key in ``default_top_theme`` String, determines which top-level theme will be used as the default. - Defaults to ``powerline``. See `Themes`_ section for more details. + Defaults to ``powerline`` in unicode locales and ``ascii`` in non-unicode + locales. See `Themes`_ section for more details. Extension-specific configuration -------------------------------- diff --git a/powerline/__init__.py b/powerline/__init__.py index 1bd5a5d3..428e3d46 100644 --- a/powerline/__init__.py +++ b/powerline/__init__.py @@ -5,14 +5,15 @@ import os import sys import logging +from locale import getpreferredencoding +from threading import Lock, Event + from powerline.colorscheme import Colorscheme from powerline.lib.config import ConfigLoader from powerline.lib.unicode import safe_unicode, FailedUnicode from powerline.config import DEFAULT_SYSTEM_CONFIG_DIR from powerline.lib import mergedicts -from threading import Lock, Event - def _config_loader_condition(path): if path and os.path.isfile(path): @@ -234,8 +235,14 @@ def finish_common_config(common_config): Copy of common configuration with all configuration keys and expanded paths. ''' + encoding = getpreferredencoding().lower() + if encoding.startswith('utf') or encoding.startswith('ucs'): + default_top_theme = 'powerline' + else: + default_top_theme = 'ascii' + common_config = common_config.copy() - common_config.setdefault('default_top_theme', 'powerline') + common_config.setdefault('default_top_theme', default_top_theme) common_config.setdefault('paths', []) common_config.setdefault('watcher', 'auto') common_config.setdefault('log_level', 'WARNING')