Add `use_non_breaking_spaces` theme option, use it in ascii theme

This commit is contained in:
ZyX 2014-08-27 21:58:57 +04:00
parent 7e7803f680
commit d32b798c11
6 changed files with 32 additions and 15 deletions

View File

@ -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 <config-ext-theme>`. 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

View File

@ -1,4 +1,5 @@
{
"use_non_breaking_spaces": false,
"dividers": {
"left": {
"hard": " ",

View File

@ -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(),

View File

@ -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.

View File

@ -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

View File

@ -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