From d32b798c1190f71923fc9abb8557aff02a5ee312 Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 27 Aug 2014 21:58:57 +0400 Subject: [PATCH] Add `use_non_breaking_spaces` theme option, use it in ascii theme --- docs/source/configuration/reference.rst | 13 +++++++++++++ powerline/config_files/themes/ascii.json | 1 + powerline/lint/__init__.py | 1 + powerline/renderer.py | 10 ++++++---- tests/test_local_overrides.vim | 2 +- tests/test_shells/ipython.ok | 20 ++++++++++---------- 6 files changed, 32 insertions(+), 15 deletions(-) diff --git a/docs/source/configuration/reference.rst b/docs/source/configuration/reference.rst index 12966b45..a0edf36f 100644 --- a/docs/source/configuration/reference.rst +++ b/docs/source/configuration/reference.rst @@ -287,6 +287,19 @@ ascii Theme without any unicode characters at all after it (on the left side). These spaces will not be added if divider is not drawn. +``use_non_breaking_spaces`` + Determines whether non-breaking spaces should be used in place of the + regular ones. This option is needed because regular spaces are not displayed + properly when using powerline with some font configuration. Defaults to + ``True``. + + .. note:: + Unlike all other options this one is only checked once at startup using + whatever theme is :ref:`the default `. If this option + is set in the local themes it will be ignored. This option may also be + ignored in some bindings. + + ``dividers`` Defines the dividers used in all Powerline extensions. This option should usually only be changed if you don't have a patched font, or if diff --git a/powerline/config_files/themes/ascii.json b/powerline/config_files/themes/ascii.json index adacfbfb..c8ff0d71 100644 --- a/powerline/config_files/themes/ascii.json +++ b/powerline/config_files/themes/ascii.json @@ -1,4 +1,5 @@ { + "use_non_breaking_spaces": false, "dividers": { "left": { "hard": " ", diff --git a/powerline/lint/__init__.py b/powerline/lint/__init__.py index aac214ae..61ecca38 100644 --- a/powerline/lint/__init__.py +++ b/powerline/lint/__init__.py @@ -1388,6 +1388,7 @@ common_theme_spec = Spec( top_theme_spec = common_theme_spec().update( dividers=dividers_spec(), spaces=spaces_spec(), + use_non_breaking_spaces=Spec().type(bool).optional(), segment_data=Spec().unknown_spec( Spec().func(check_segment_data_key), segment_data_value_spec(), diff --git a/powerline/renderer.py b/powerline/renderer.py index 4ac0a9db..b129a710 100644 --- a/powerline/renderer.py +++ b/powerline/renderer.py @@ -73,7 +73,7 @@ class Renderer(object): python-2) regular string or ``None``. ''' - character_translations = {ord(' '): NBSP} + character_translations = {} '''Character translations for use in escape() function. See documentation of ``unicode.translate`` for details. @@ -101,6 +101,9 @@ class Renderer(object): self.theme_config = theme_config theme_kwargs['pl'] = pl self.pl = pl + if theme_config.get('use_non_breaking_spaces', True): + self.character_translations = self.character_translations.copy() + self.character_translations[ord(' ')] = NBSP self.theme = Theme(theme_config=theme_config, **theme_kwargs) self.local_themes = local_themes self.theme_kwargs = theme_kwargs @@ -442,11 +445,10 @@ class Renderer(object): segment['_rendered_hl'] = contents_highlighted yield segment - @classmethod - def escape(cls, string): + def escape(self, string): '''Method that escapes segment contents. ''' - return string.translate(cls.character_translations) + return string.translate(self.character_translations) def hlstyle(fg=None, bg=None, attr=None): '''Output highlight style string. diff --git a/tests/test_local_overrides.vim b/tests/test_local_overrides.vim index 5b80d26c..bf2ad8f8 100755 --- a/tests/test_local_overrides.vim +++ b/tests/test_local_overrides.vim @@ -30,7 +30,7 @@ catch cquit endtry -if result isnot# '%#Pl_22_24320_148_11523840_bold# NORMAL %#Pl_148_11523840_236_3158064_NONE# %#Pl_231_16777215_236_3158064_NONE#                                                 %#Pl_247_10395294_236_3158064_NONE#unix%#Pl_240_5789784_236_3158064_NONE# %#Pl_247_10329757_240_5789784_NONE# 100%%%#Pl_252_13684944_240_5789784_NONE# %#Pl_235_2500134_252_13684944_NONE# LN %#Pl_235_2500134_252_13684944_bold#  1%#Pl_22_24576_252_13684944_NONE#:1  ' +if result isnot# '%#Pl_22_24320_148_11523840_bold# NORMAL %#Pl_148_11523840_236_3158064_NONE# %#Pl_231_16777215_236_3158064_NONE# %#Pl_247_10395294_236_3158064_NONE#unix%#Pl_240_5789784_236_3158064_NONE# %#Pl_247_10329757_240_5789784_NONE# 100%%%#Pl_252_13684944_240_5789784_NONE# %#Pl_235_2500134_252_13684944_NONE# LN %#Pl_235_2500134_252_13684944_bold# 1%#Pl_22_24576_252_13684944_NONE#:1 ' call writefile(['Unexpected result', result], 'message.fail') cquit endif diff --git a/tests/test_shells/ipython.ok b/tests/test_shells/ipython.ok index 2ccd6e14..2de654fc 100644 --- a/tests/test_shells/ipython.ok +++ b/tests/test_shells/ipython.ok @@ -1,14 +1,14 @@ - In [2]  bool 42 -     2>  bool(42) - Out[2]  True + In [2]  bool 42 + 2>  bool(42) + Out[2]  True - In [3]  bool 44 -     3>  bool(44) - Out[3]  True + In [3]  bool 44 + 3>  bool(44) + Out[3]  True - In [4]  class Test(object): -          pass -          + In [4]  class Test(object): +   pass +   - In [5]  exit + In [5]  exit