Print tabbed columns from (name, help) ``tuples``. Useful for listing tasks + docstrings, flags + help strings, etc. .. versionadded:: 1.0
(
self, tuples: Sequence[Tuple[str, Optional[str]]]
)
| 942 | print("Default{} task: {}\n".format(specific, default)) |
| 943 | |
| 944 | def print_columns( |
| 945 | self, tuples: Sequence[Tuple[str, Optional[str]]] |
| 946 | ) -> None: |
| 947 | """ |
| 948 | Print tabbed columns from (name, help) ``tuples``. |
| 949 | |
| 950 | Useful for listing tasks + docstrings, flags + help strings, etc. |
| 951 | |
| 952 | .. versionadded:: 1.0 |
| 953 | """ |
| 954 | # Calculate column sizes: don't wrap flag specs, give what's left over |
| 955 | # to the descriptions. |
| 956 | name_width = max(len(x[0]) for x in tuples) |
| 957 | desc_width = ( |
| 958 | pty_size()[0] |
| 959 | - name_width |
| 960 | - self.leading_indent_width |
| 961 | - self.col_padding |
| 962 | - 1 |
| 963 | ) |
| 964 | wrapper = textwrap.TextWrapper(width=desc_width) |
| 965 | for name, help_str in tuples: |
| 966 | if help_str is None: |
| 967 | help_str = "" |
| 968 | # Wrap descriptions/help text |
| 969 | help_chunks = wrapper.wrap(help_str) |
| 970 | # Print flag spec + padding |
| 971 | name_padding = name_width - len(name) |
| 972 | spec = "".join( |
| 973 | ( |
| 974 | self.leading_indent, |
| 975 | name, |
| 976 | name_padding * " ", |
| 977 | self.col_padding * " ", |
| 978 | ) |
| 979 | ) |
| 980 | # Print help text as needed |
| 981 | if help_chunks: |
| 982 | print(spec + help_chunks[0]) |
| 983 | for chunk in help_chunks[1:]: |
| 984 | print((" " * len(spec)) + chunk) |
| 985 | else: |
| 986 | print(spec.rstrip()) |
| 987 | print("") |
no test coverage detected