diff options
author | mathieui <mathieui@mathieui.net> | 2014-05-03 02:12:05 +0200 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2014-05-03 02:12:05 +0200 |
commit | ea935ded091571ffec14fc020176c6a03f269efc (patch) | |
tree | c6d928e8f6fc451ee81c8b37d435a9e6542c5a60 | |
parent | db7fc6abb22884ee79d0de9df222046c9a7b4f2c (diff) | |
download | poezio-ea935ded091571ffec14fc020176c6a03f269efc.tar.gz poezio-ea935ded091571ffec14fc020176c6a03f269efc.tar.bz2 poezio-ea935ded091571ffec14fc020176c6a03f269efc.tar.xz poezio-ea935ded091571ffec14fc020176c6a03f269efc.zip |
Highlight the newlines characters in the input instead of plain "|"s
-rw-r--r-- | src/windows.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/windows.py b/src/windows.py index 5500059a..dd1e167d 100644 --- a/src/windows.py +++ b/src/windows.py @@ -62,9 +62,11 @@ class DummyWin(object): def __bool__(self): return False -def find_first_format_char(text): +def find_first_format_char(text, chars=None): + if chars is None: + chars = format_chars pos = -1 - for char in format_chars: + for char in chars: p = text.find(char) if p == -1: continue @@ -1645,11 +1647,17 @@ class Input(Win): (\x0E to \x19 instead of \x19 + attr). We do not use any } char in this version """ + chars = format_chars[:] + chars.append('\n') if y is not None and x is not None: self.move(y, x) - format_char = find_first_format_char(text) + format_char = find_first_format_char(text, chars) while format_char != -1: - attr_char = self.text_attributes[format_chars.index(text[format_char])] + if text[format_char] == '\n': + attr_char = '|' + else: + attr_char = self.text_attributes[ + format_chars.index(text[format_char])] self.addstr(text[:format_char]) self.addstr(attr_char, curses.A_REVERSE) text = text[format_char+1:] @@ -1661,7 +1669,7 @@ class Input(Win): self._win.attron(curses.A_BOLD) elif attr_char in string.digits and attr_char != '': self._win.attron(to_curses_attr((int(attr_char), -1))) - format_char = find_first_format_char(text) + format_char = find_first_format_char(text, chars) self.addstr(text) def rewrite_text(self): @@ -1674,7 +1682,7 @@ class Input(Win): """ self.adjust_view_pos() with g_lock: - text = self.text.replace('\n', '|') + text = self.text self._win.erase() if self.color: self._win.attron(to_curses_attr(self.color)) |