MCPcopy
hub / github.com/pallets/click / write_dl

Method write_dl

src/click/formatting.py:229–271  ·  view source on GitHub ↗

Writes a definition list into the buffer. This is how options and commands are usually formatted. :param rows: a list of two item tuples for the terms and values. :param col_max: the maximum width of the first column. :param col_spacing: the number of spaces between

(
        self,
        rows: cabc.Iterable[tuple[str, str]],
        col_max: int = 30,
        col_spacing: int = 2,
    )

Source from the content-addressed store, hash-verified

227 self.write("\n")
228
229 def write_dl(
230 self,
231 rows: cabc.Iterable[tuple[str, str]],
232 col_max: int = 30,
233 col_spacing: int = 2,
234 ) -> None:
235 """Writes a definition list into the buffer. This is how options
236 and commands are usually formatted.
237
238 :param rows: a list of two item tuples for the terms and values.
239 :param col_max: the maximum width of the first column.
240 :param col_spacing: the number of spaces between the first and
241 second column.
242 """
243 rows = list(rows)
244 widths = measure_table(rows)
245 if len(widths) != 2:
246 raise TypeError("Expected two columns for definition list")
247
248 first_col = min(widths[0], col_max) + col_spacing
249
250 for first, second in iter_rows(rows, len(widths)):
251 self.write(f"{'':>{self.current_indent}}{first}")
252 if not second:
253 self.write("\n")
254 continue
255 if term_len(first) <= first_col - col_spacing:
256 self.write(" " * (first_col - term_len(first)))
257 else:
258 self.write("\n")
259 self.write(" " * (first_col + self.current_indent))
260
261 text_width = max(self.width - first_col - 2, 10)
262 wrapped_text = wrap_text(second, text_width, preserve_paragraphs=True)
263 lines = wrapped_text.splitlines()
264
265 if lines:
266 self.write(f"{lines[0]}\n")
267
268 for line in lines[1:]:
269 self.write(f"{'':>{first_col + self.current_indent}}{line}\n")
270 else:
271 self.write("\n")
272
273 @contextmanager
274 def section(self, name: str) -> cabc.Generator[None]:

Callers 2

format_optionsMethod · 0.80
format_commandsMethod · 0.80

Calls 5

writeMethod · 0.95
measure_tableFunction · 0.85
iter_rowsFunction · 0.85
term_lenFunction · 0.85
wrap_textFunction · 0.85

Tested by

no test coverage detected