summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2017-10-18 15:26:06 +0100
committerEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2017-10-18 15:26:06 +0100
commitaf73b413eb8d143499c6f6d796aab5aa03efd75a (patch)
tree8e345d5389094874795ac8557b303b89bf47630e
parent9844f288de27dac7095c82832ad51c75ede7a362 (diff)
downloadpoezio-af73b413eb8d143499c6f6d796aab5aa03efd75a.tar.gz
poezio-af73b413eb8d143499c6f6d796aab5aa03efd75a.tar.bz2
poezio-af73b413eb8d143499c6f6d796aab5aa03efd75a.tar.xz
poezio-af73b413eb8d143499c6f6d796aab5aa03efd75a.zip
Check whether curses.A_ITALIC exists, fixes a traceback on <em/> on Python < 3.7.
-rwxr-xr-xpoezio/theming.py2
-rw-r--r--poezio/windows/base_wins.py5
-rw-r--r--poezio/windows/inputs.py3
3 files changed, 6 insertions, 4 deletions
diff --git a/poezio/theming.py b/poezio/theming.py
index 813f8bc0..d007e463 100755
--- a/poezio/theming.py
+++ b/poezio/theming.py
@@ -445,7 +445,7 @@ def to_curses_attr(color_tuple):
curses_pair = curses_pair | curses.A_BOLD
if 'u' in additional_val:
curses_pair = curses_pair | curses.A_UNDERLINE
- if 'i' in additional_val:
+ if 'i' in additional_val and hasattr(curses, 'A_ITALIC'):
curses_pair = curses_pair | curses.A_ITALIC
if 'a' in additional_val:
curses_pair = curses_pair | curses.A_BLINK
diff --git a/poezio/windows/base_wins.py b/poezio/windows/base_wins.py
index a009c763..8813d8f7 100644
--- a/poezio/windows/base_wins.py
+++ b/poezio/windows/base_wins.py
@@ -100,6 +100,7 @@ class Win(object):
if y is not None and x is not None:
self.move(y, x)
next_attr_char = text.find(FORMAT_CHAR)
+ has_italic = hasattr(curses, 'A_ITALIC')
while next_attr_char != -1 and text:
if next_attr_char + 1 < len(text):
attr_char = text[next_attr_char+1].lower()
@@ -113,7 +114,7 @@ class Win(object):
self._win.attron(curses.A_UNDERLINE)
elif attr_char == 'b':
self._win.attron(curses.A_BOLD)
- elif attr_char == 'i':
+ elif attr_char == 'i' and has_italic:
self._win.attron(curses.A_ITALIC)
if (attr_char in string.digits or attr_char == '-') and attr_char != '':
color_str = text[next_attr_char+1:text.find('}', next_attr_char)]
@@ -127,7 +128,7 @@ class Win(object):
self._win.attron(curses.A_UNDERLINE)
elif char == 'b':
self._win.attron(curses.A_BOLD)
- elif char == 'i':
+ elif char == 'i' and has_italic:
self._win.attron(curses.A_ITALIC)
else:
# this will reset previous bold/uderline sequences if any was used
diff --git a/poezio/windows/inputs.py b/poezio/windows/inputs.py
index fca12e9d..faf0125d 100644
--- a/poezio/windows/inputs.py
+++ b/poezio/windows/inputs.py
@@ -467,6 +467,7 @@ class Input(Win):
if y is not None and x is not None:
self.move(y, x)
format_char = find_first_format_char(text, chars)
+ has_italic = hasattr(curses, 'A_ITALIC')
while format_char != -1:
if text[format_char] == '\n':
attr_char = '|'
@@ -482,7 +483,7 @@ class Input(Win):
self._win.attron(curses.A_UNDERLINE)
elif attr_char == 'b':
self._win.attron(curses.A_BOLD)
- elif attr_char == 'i':
+ elif attr_char == 'i' and has_italic:
self._win.attron(curses.A_ITALIC)
elif attr_char in string.digits and attr_char != '':
self._win.attron(to_curses_attr((int(attr_char), -1)))