Skip to content

Commit

Permalink
ArrayMultilineFormatter._indent_element -> _left_pad_element
Browse files Browse the repository at this point in the history
  • Loading branch information
derek-globus committed Feb 5, 2025
1 parent 9e8e3dc commit 799ea26
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/globus_cli/termio/formatters/compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,32 @@ def render(self, value: list[str]) -> str:
def parse_element(self, element: t.Any) -> str:
with TERM_INFO.indented(4):
formatted = self.element_formatter.format(element)
return self._indent_element(formatted)
return self._left_pad_element(formatted)

@classmethod
def _indent_element(cls, value: str) -> str:
"""Indent a multi-line formatted element string."""
first_ = " - "
def _left_pad_element(cls, value: str) -> str:
"""
Insert a rectangle of characters to the left of a multiline string.
Inserted rectangle:
" - "
" "
" "
...
Example
" ABC" -> " - ABC"
"DEF" -> " DEF"
" GHI" -> " GHI"
"""
if not value:
return first_
indent = " "
indented = textwrap.indent(value, indent, lambda _: True)
return first_ + indented[len(indent) :]
return " - "

# Empty strings are default not indented by textwrap so a predicate is needed.
indented = textwrap.indent(value, " ", predicate=lambda line: True)

return " - " + indented[4:]


Record = t.Union[JsonDict, globus_sdk.GlobusHTTPResponse]
Expand Down

0 comments on commit 799ea26

Please sign in to comment.