MCPcopy Index your code
hub / github.com/prompt-toolkit/ptpython / OutputPrinter

Class OutputPrinter

src/ptpython/printer.py:35–360  ·  view source on GitHub ↗

Result printer. Usage:: printer = OutputPrinter(...) printer.display_result(...) printer.display_exception(...)

Source from the content-addressed store, hash-verified

33
34@dataclass
35class OutputPrinter:
36 """
37 Result printer.
38
39 Usage::
40
41 printer = OutputPrinter(...)
42 printer.display_result(...)
43 printer.display_exception(...)
44 """
45
46 output: Output
47 input: Input
48 style: BaseStyle
49 title: AnyFormattedText
50 style_transformation: StyleTransformation
51
52 def display_result(
53 self,
54 result: object,
55 *,
56 out_prompt: AnyFormattedText,
57 reformat: bool,
58 highlight: bool,
59 paginate: bool,
60 ) -> None:
61 """
62 Show __repr__ (or `__pt_repr__`) for an `eval` result and print to output.
63
64 :param reformat: Reformat result using 'black' before printing if the
65 result is parsable as Python code.
66 :param highlight: Syntax highlight the result.
67 :param paginate: Show paginator when the result does not fit on the
68 screen.
69 """
70 out_prompt = to_formatted_text(out_prompt)
71 out_prompt_width = fragment_list_width(out_prompt)
72
73 result = self._insert_out_prompt_and_split_lines(
74 self._format_result_output(
75 result,
76 reformat=reformat,
77 highlight=highlight,
78 line_length=self.output.get_size().columns - out_prompt_width,
79 paginate=paginate,
80 ),
81 out_prompt=out_prompt,
82 )
83 self._display_result(result, paginate=paginate)
84
85 def display_exception(
86 self, e: BaseException, *, highlight: bool, paginate: bool
87 ) -> None:
88 """
89 Render an exception.
90 """
91 result = self._insert_out_prompt_and_split_lines(
92 self._format_exception_output(e, highlight=highlight),

Callers 1

_get_output_printerMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected