From b4d3b93da2e23cefb85dd98f1f7f9706aa0402d4 Mon Sep 17 00:00:00 2001 From: mathieui Date: Fri, 17 Aug 2018 02:16:03 +0200 Subject: Add typing information and reformat stuff --- poezio/windows/base_wins.py | 10 ++++++---- poezio/windows/funcs.py | 17 +++++++++-------- poezio/windows/info_bar.py | 9 ++++++--- 3 files changed, 21 insertions(+), 15 deletions(-) (limited to 'poezio/windows') diff --git a/poezio/windows/base_wins.py b/poezio/windows/base_wins.py index eaedd82b..89c4b73c 100644 --- a/poezio/windows/base_wins.py +++ b/poezio/windows/base_wins.py @@ -15,6 +15,8 @@ log = logging.getLogger(__name__) import curses import string +from typing import Optional, Tuple + from poezio.theming import to_curses_attr, read_tuple FORMAT_CHAR = '\x19' @@ -51,7 +53,7 @@ class Win: if self._win is None: self._win = DummyWin() - def resize(self, height, width, y, x): + def resize(self, height: int, width: int, y: int, x: int): """ Override if something has to be done on resize """ @@ -81,13 +83,13 @@ class Win: except: pass - def move(self, y, x): + def move(self, y: int, x: int): try: self._win.move(y, x) except: pass - def addstr_colored(self, text, y=None, x=None): + def addstr_colored(self, text: str, y=None, x=None): """ Write a string on the window, setting the attributes as they are in the string. @@ -146,7 +148,7 @@ class Win: next_attr_char = text.find(FORMAT_CHAR) self.addstr(text) - def finish_line(self, color=None): + def finish_line(self, color: Optional[Tuple] = None): """ Write colored spaces until the end of line """ diff --git a/poezio/windows/funcs.py b/poezio/windows/funcs.py index 3648bac3..d118f353 100644 --- a/poezio/windows/funcs.py +++ b/poezio/windows/funcs.py @@ -3,16 +3,17 @@ Standalone functions used by the modules """ import string -DIGITS = string.digits + '-' - +from typing import Optional, List from poezio.windows.base_wins import FORMAT_CHAR, format_chars +DIGITS = string.digits + '-' + -def find_first_format_char(text, chars=None): - if chars is None: - chars = format_chars +def find_first_format_char(text: str, + chars: Optional[List[str]] = None) -> int: + to_find = chars or format_chars pos = -1 - for char in chars: + for char in to_find: p = text.find(char) if p == -1: continue @@ -21,7 +22,7 @@ def find_first_format_char(text, chars=None): return pos -def truncate_nick(nick, size=10): +def truncate_nick(nick: str, size=10) -> str: if size < 1: size = 1 if nick and len(nick) > size: @@ -29,7 +30,7 @@ def truncate_nick(nick, size=10): return nick -def parse_attrs(text, previous=None): +def parse_attrs(text: str, previous: Optional[List[str]] = None) -> List[str]: next_attr_char = text.find(FORMAT_CHAR) if previous: attrs = previous diff --git a/poezio/windows/info_bar.py b/poezio/windows/info_bar.py index 6e338a78..f4ba1f1f 100644 --- a/poezio/windows/info_bar.py +++ b/poezio/windows/info_bar.py @@ -32,7 +32,8 @@ class GlobalInfoBar(Win): show_inactive = config.get('show_inactive_tabs') for nb, tab in enumerate(self.core.tabs): - if not tab: continue + if not tab: + continue color = tab.color if not show_inactive and color is get_theme().COLOR_TAB_NORMAL: continue @@ -72,8 +73,10 @@ class VerticalGlobalInfoBar(Win): self._win.erase() sorted_tabs = [tab for tab in self.core.tabs if tab] if not config.get('show_inactive_tabs'): - sorted_tabs = [tab for tab in sorted_tabs if\ - tab.vertical_color != get_theme().COLOR_VERTICAL_TAB_NORMAL] + sorted_tabs = [ + tab for tab in sorted_tabs + if tab.vertical_color != get_theme().COLOR_VERTICAL_TAB_NORMAL + ] nb_tabs = len(sorted_tabs) use_nicks = config.get('use_tab_nicks') if nb_tabs >= height: -- cgit v1.2.3