def as_ansitable(self, *, key: str = 'Key', value: str = 'Value', sort: bool = False, sortkey: Callable[[Any], Any] = itemgetter(0), target: IO = sys.stdout, title: str = '{table.name}') -> str: header = [text.title(key), text.title(value)] data = cast(Iterable[List[str]], dict(self).items()) data = list(sorted(data, key=sortkey)) if sort else list(data) if sort: data = list(sorted(data, key=sortkey)) return terminal.table( [header] + list(data), title=text.title(title.format(table=self)), ).table
def dict_as_ansitable(d: Mapping, *, key: str = 'Key', value: str = 'Value', sort: bool = False, sortkey: Callable[[Any], Any] = itemgetter(0), target: IO = sys.stdout, title: str = None) -> str: header = [text.title(key), text.title(value)] data = cast(Iterable[List[str]], d.items()) data = sorted(data, key=sortkey) if sort else list(data) if sort: data = sorted(data, key=sortkey) return table( [header] + list(data), title=text.title(title) if title is not None else '', target=target, ).table
def dict_as_ansitable(d: Mapping, *, key: str = "Key", value: str = "Value", sort: bool = False, sortkey: Callable[[Any], Any] = DEFAULT_SORT_KEY, target: IO = sys.stdout, title: Optional[str] = None) -> str: header = [text.title(key), text.title(value)] data = cast(Iterable[List[str]], d.items()) data = sorted(data, key=sortkey) if sort else list(data) if sort: data = sorted(data, key=sortkey) return table( [header] + list(data), title=text.title(title) if title is not None else "", target=target, ).table
def test_title(input, expected): assert text.title(input) == expected