rendering: add typings

This commit is contained in:
dece 2021-03-14 00:08:16 +01:00
parent a37ed6f64d
commit 5d1e13ea6a

View file

@ -8,6 +8,7 @@ displayed, along with associated meta-data such as its type or a link's URL.
import curses import curses
import string import string
from enum import IntEnum from enum import IntEnum
from typing import List
from bebop.colors import ColorPair from bebop.colors import ColorPair
from bebop.gemtext import (Blockquote, Link, ListItem, Paragraph, Preformatted, from bebop.gemtext import (Blockquote, Link, ListItem, Paragraph, Preformatted,
@ -160,7 +161,7 @@ def format_list_item(item: ListItem, context: dict):
return [({"type": LineType.LIST_ITEM}, line) for line in lines] return [({"type": LineType.LIST_ITEM}, line) for line in lines]
def wrap_words(text, width, indent=0): def wrap_words(text: str, width: int, indent: int =0) -> List[str]:
"""Wrap a text in several lines according to the renderer's width.""" """Wrap a text in several lines according to the renderer's width."""
lines = [] lines = []
line = " " * indent line = " " * indent
@ -187,7 +188,8 @@ def wrap_words(text, width, indent=0):
return lines return lines
def _explode_words(text): def _explode_words(text: str) -> List[str]:
"""Split a string into a list of words."""
words = [] words = []
pos = 0 pos = 0
while True: while True:
@ -205,7 +207,8 @@ def _explode_words(text):
pos += sep_index + 1 pos += sep_index + 1
def _find_next_sep(text): def _find_next_sep(text: str):
"""Find the next separator index and return both the separator and index."""
indices = [] indices = []
for sep in SPLIT_CHARS: for sep in SPLIT_CHARS:
try: try: