1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
from __future__ import annotations
from typing import TextIO
from prompt_toolkit.cursor_shapes import CursorShape
from prompt_toolkit.data_structures import Size
from prompt_toolkit.styles import Attrs
from .base import Output
from .color_depth import ColorDepth
from .flush_stdout import flush_stdout
__all__ = ["PlainTextOutput"]
class PlainTextOutput(Output):
"""
Output that won't include any ANSI escape sequences.
Useful when stdout is not a terminal. Maybe stdout is redirected to a file.
In this case, if `print_formatted_text` is used, for instance, we don't
want to include formatting.
(The code is mostly identical to `Vt100_Output`, but without the
formatting.)
"""
def __init__(self, stdout: TextIO) -> None:
assert all(hasattr(stdout, a) for a in ("write", "flush"))
self.stdout: TextIO = stdout
self._buffer: list[str] = []
def fileno(self) -> int:
"There is no sensible default for fileno()."
return self.stdout.fileno()
def encoding(self) -> str:
return "utf-8"
def write(self, data: str) -> None:
self._buffer.append(data)
def write_raw(self, data: str) -> None:
self._buffer.append(data)
def set_title(self, title: str) -> None:
pass
def clear_title(self) -> None:
pass
def flush(self) -> None:
if not self._buffer:
return
data = "".join(self._buffer)
self._buffer = []
flush_stdout(self.stdout, data)
def erase_screen(self) -> None:
pass
def enter_alternate_screen(self) -> None:
pass
def quit_alternate_screen(self) -> None:
pass
def enable_mouse_support(self) -> None:
pass
def disable_mouse_support(self) -> None:
pass
def erase_end_of_line(self) -> None:
pass
def erase_down(self) -> None:
pass
def reset_attributes(self) -> None:
pass
def set_attributes(self, attrs: Attrs, color_depth: ColorDepth) -> None:
pass
def disable_autowrap(self) -> None:
pass
def enable_autowrap(self) -> None:
pass
def cursor_goto(self, row: int = 0, column: int = 0) -> None:
pass
def cursor_up(self, amount: int) -> None:
pass
def cursor_down(self, amount: int) -> None:
self._buffer.append("\n")
def cursor_forward(self, amount: int) -> None:
self._buffer.append(" " * amount)
def cursor_backward(self, amount: int) -> None:
pass
def hide_cursor(self) -> None:
pass
def show_cursor(self) -> None:
pass
def set_cursor_shape(self, cursor_shape: CursorShape) -> None:
pass
def reset_cursor_shape(self) -> None:
pass
def ask_for_cpr(self) -> None:
pass
def bell(self) -> None:
pass
def enable_bracketed_paste(self) -> None:
pass
def disable_bracketed_paste(self) -> None:
pass
def scroll_buffer_to_prompt(self) -> None:
pass
def get_size(self) -> Size:
return Size(rows=40, columns=80)
def get_rows_below_cursor_position(self) -> int:
return 8
def get_default_color_depth(self) -> ColorDepth:
return ColorDepth.DEPTH_1_BIT
|