Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/prompt_toolkit/output/base.py: 75%
150 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-20 06:09 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-20 06:09 +0000
1"""
2Interface for an output.
3"""
4from __future__ import annotations
6from abc import ABCMeta, abstractmethod
7from typing import TextIO
9from prompt_toolkit.cursor_shapes import CursorShape
10from prompt_toolkit.data_structures import Size
11from prompt_toolkit.styles import Attrs
13from .color_depth import ColorDepth
15__all__ = [
16 "Output",
17 "DummyOutput",
18]
21class Output(metaclass=ABCMeta):
22 """
23 Base class defining the output interface for a
24 :class:`~prompt_toolkit.renderer.Renderer`.
26 Actual implementations are
27 :class:`~prompt_toolkit.output.vt100.Vt100_Output` and
28 :class:`~prompt_toolkit.output.win32.Win32Output`.
29 """
31 stdout: TextIO | None = None
33 @abstractmethod
34 def fileno(self) -> int:
35 "Return the file descriptor to which we can write for the output."
37 @abstractmethod
38 def encoding(self) -> str:
39 """
40 Return the encoding for this output, e.g. 'utf-8'.
41 (This is used mainly to know which characters are supported by the
42 output the data, so that the UI can provide alternatives, when
43 required.)
44 """
46 @abstractmethod
47 def write(self, data: str) -> None:
48 "Write text (Terminal escape sequences will be removed/escaped.)"
50 @abstractmethod
51 def write_raw(self, data: str) -> None:
52 "Write text."
54 @abstractmethod
55 def set_title(self, title: str) -> None:
56 "Set terminal title."
58 @abstractmethod
59 def clear_title(self) -> None:
60 "Clear title again. (or restore previous title.)"
62 @abstractmethod
63 def flush(self) -> None:
64 "Write to output stream and flush."
66 @abstractmethod
67 def erase_screen(self) -> None:
68 """
69 Erases the screen with the background color and moves the cursor to
70 home.
71 """
73 @abstractmethod
74 def enter_alternate_screen(self) -> None:
75 "Go to the alternate screen buffer. (For full screen applications)."
77 @abstractmethod
78 def quit_alternate_screen(self) -> None:
79 "Leave the alternate screen buffer."
81 @abstractmethod
82 def enable_mouse_support(self) -> None:
83 "Enable mouse."
85 @abstractmethod
86 def disable_mouse_support(self) -> None:
87 "Disable mouse."
89 @abstractmethod
90 def erase_end_of_line(self) -> None:
91 """
92 Erases from the current cursor position to the end of the current line.
93 """
95 @abstractmethod
96 def erase_down(self) -> None:
97 """
98 Erases the screen from the current line down to the bottom of the
99 screen.
100 """
102 @abstractmethod
103 def reset_attributes(self) -> None:
104 "Reset color and styling attributes."
106 @abstractmethod
107 def set_attributes(self, attrs: Attrs, color_depth: ColorDepth) -> None:
108 "Set new color and styling attributes."
110 @abstractmethod
111 def disable_autowrap(self) -> None:
112 "Disable auto line wrapping."
114 @abstractmethod
115 def enable_autowrap(self) -> None:
116 "Enable auto line wrapping."
118 @abstractmethod
119 def cursor_goto(self, row: int = 0, column: int = 0) -> None:
120 "Move cursor position."
122 @abstractmethod
123 def cursor_up(self, amount: int) -> None:
124 "Move cursor `amount` place up."
126 @abstractmethod
127 def cursor_down(self, amount: int) -> None:
128 "Move cursor `amount` place down."
130 @abstractmethod
131 def cursor_forward(self, amount: int) -> None:
132 "Move cursor `amount` place forward."
134 @abstractmethod
135 def cursor_backward(self, amount: int) -> None:
136 "Move cursor `amount` place backward."
138 @abstractmethod
139 def hide_cursor(self) -> None:
140 "Hide cursor."
142 @abstractmethod
143 def show_cursor(self) -> None:
144 "Show cursor."
146 @abstractmethod
147 def set_cursor_shape(self, cursor_shape: CursorShape) -> None:
148 "Set cursor shape to block, beam or underline."
150 @abstractmethod
151 def reset_cursor_shape(self) -> None:
152 "Reset cursor shape."
154 def ask_for_cpr(self) -> None:
155 """
156 Asks for a cursor position report (CPR).
157 (VT100 only.)
158 """
160 @property
161 def responds_to_cpr(self) -> bool:
162 """
163 `True` if the `Application` can expect to receive a CPR response after
164 calling `ask_for_cpr` (this will come back through the corresponding
165 `Input`).
167 This is used to determine the amount of available rows we have below
168 the cursor position. In the first place, we have this so that the drop
169 down autocompletion menus are sized according to the available space.
171 On Windows, we don't need this, there we have
172 `get_rows_below_cursor_position`.
173 """
174 return False
176 @abstractmethod
177 def get_size(self) -> Size:
178 "Return the size of the output window."
180 def bell(self) -> None:
181 "Sound bell."
183 def enable_bracketed_paste(self) -> None:
184 "For vt100 only."
186 def disable_bracketed_paste(self) -> None:
187 "For vt100 only."
189 def reset_cursor_key_mode(self) -> None:
190 """
191 For vt100 only.
192 Put the terminal in normal cursor mode (instead of application mode).
194 See: https://vt100.net/docs/vt100-ug/chapter3.html
195 """
197 def scroll_buffer_to_prompt(self) -> None:
198 "For Win32 only."
200 def get_rows_below_cursor_position(self) -> int:
201 "For Windows only."
202 raise NotImplementedError
204 @abstractmethod
205 def get_default_color_depth(self) -> ColorDepth:
206 """
207 Get default color depth for this output.
209 This value will be used if no color depth was explicitly passed to the
210 `Application`.
212 .. note::
214 If the `$PROMPT_TOOLKIT_COLOR_DEPTH` environment variable has been
215 set, then `outputs.defaults.create_output` will pass this value to
216 the implementation as the default_color_depth, which is returned
217 here. (This is not used when the output corresponds to a
218 prompt_toolkit SSH/Telnet session.)
219 """
222class DummyOutput(Output):
223 """
224 For testing. An output class that doesn't render anything.
225 """
227 def fileno(self) -> int:
228 "There is no sensible default for fileno()."
229 raise NotImplementedError
231 def encoding(self) -> str:
232 return "utf-8"
234 def write(self, data: str) -> None:
235 pass
237 def write_raw(self, data: str) -> None:
238 pass
240 def set_title(self, title: str) -> None:
241 pass
243 def clear_title(self) -> None:
244 pass
246 def flush(self) -> None:
247 pass
249 def erase_screen(self) -> None:
250 pass
252 def enter_alternate_screen(self) -> None:
253 pass
255 def quit_alternate_screen(self) -> None:
256 pass
258 def enable_mouse_support(self) -> None:
259 pass
261 def disable_mouse_support(self) -> None:
262 pass
264 def erase_end_of_line(self) -> None:
265 pass
267 def erase_down(self) -> None:
268 pass
270 def reset_attributes(self) -> None:
271 pass
273 def set_attributes(self, attrs: Attrs, color_depth: ColorDepth) -> None:
274 pass
276 def disable_autowrap(self) -> None:
277 pass
279 def enable_autowrap(self) -> None:
280 pass
282 def cursor_goto(self, row: int = 0, column: int = 0) -> None:
283 pass
285 def cursor_up(self, amount: int) -> None:
286 pass
288 def cursor_down(self, amount: int) -> None:
289 pass
291 def cursor_forward(self, amount: int) -> None:
292 pass
294 def cursor_backward(self, amount: int) -> None:
295 pass
297 def hide_cursor(self) -> None:
298 pass
300 def show_cursor(self) -> None:
301 pass
303 def set_cursor_shape(self, cursor_shape: CursorShape) -> None:
304 pass
306 def reset_cursor_shape(self) -> None:
307 pass
309 def ask_for_cpr(self) -> None:
310 pass
312 def bell(self) -> None:
313 pass
315 def enable_bracketed_paste(self) -> None:
316 pass
318 def disable_bracketed_paste(self) -> None:
319 pass
321 def scroll_buffer_to_prompt(self) -> None:
322 pass
324 def get_size(self) -> Size:
325 return Size(rows=40, columns=80)
327 def get_rows_below_cursor_position(self) -> int:
328 return 40
330 def get_default_color_depth(self) -> ColorDepth:
331 return ColorDepth.DEPTH_1_BIT