Пример #1
0
 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
Пример #2
0
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
Пример #3
0
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
Пример #4
0
def test_title(input, expected):
    assert text.title(input) == expected