Skip to content

Commit 7db9356

Browse files
Underline non-breaking space instead of rendering as '&'.
1 parent 05fc17b commit 7db9356

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

prompt_toolkit/layout/screen.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,21 @@ class Char(object):
100100
'\x9e': '<9e>',
101101
'\x9f': '<9f>',
102102

103-
'\xa0': '&', # Non breaking space.
103+
# For the non-breaking space: visualize like Emacs does by default.
104+
# (Print a space, but attach the 'nbsp' class that applies the
105+
# underline style.)
106+
'\xa0': ' ',
104107
}
105108

106109
def __init__(self, char=' ', style=''):
107110
# If this character has to be displayed otherwise, take that one.
108111
if char in self.display_mappings:
112+
if char == '\xa0':
113+
style += ' class:nbsp ' # Will be underlined.
114+
else:
115+
style += ' class:control-character '
116+
109117
char = self.display_mappings[char]
110-
style += 'class:control-character'
111118

112119
self.char = char
113120
self.style = style

prompt_toolkit/styles/defaults.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@
106106
# Control characters, like ^C, ^X.
107107
('control-character', 'ansiblue'),
108108

109+
# Non-breaking space.
110+
('nbsp', 'underline ansiyellow'),
111+
109112
# Default styling of HTML elements.
110113
('i', 'italic'),
111114
('u', 'underline'),

0 commit comments

Comments
 (0)