1""" 2Interface for an output. 3""" 4from __future__ import unicode_literals 5from abc import ABCMeta, abstractmethod 6from six import with_metaclass 7from prompt_toolkit.layout.screen import Size 8 9__all__ = ( 10 'Output', 11) 12 13 14class Output(with_metaclass(ABCMeta, object)): 15 """ 16 Base class defining the output interface for a 17 :class:`~prompt_toolkit.renderer.Renderer`. 18 19 Actual implementations are 20 :class:`~prompt_toolkit.terminal.vt100_output.Vt100_Output` and 21 :class:`~prompt_toolkit.terminal.win32_output.Win32Output`. 22 """ 23 @abstractmethod 24 def fileno(self): 25 " Return the file descriptor to which we can write for the output. " 26 27 @abstractmethod 28 def encoding(self): 29 """ 30 Return the encoding for this output, e.g. 'utf-8'. 31 (This is used mainly to know which characters are supported by the 32 output the data, so that the UI can provide alternatives, when 33 required.) 34 """ 35 36 @abstractmethod 37 def write(self, data): 38 " Write text (Terminal escape sequences will be removed/escaped.) " 39 40 @abstractmethod 41 def write_raw(self, data): 42 " Write text. " 43 44 @abstractmethod 45 def set_title(self, title): 46 " Set terminal title. " 47 48 @abstractmethod 49 def clear_title(self): 50 " Clear title again. (or restore previous title.) " 51 52 @abstractmethod 53 def flush(self): 54 " Write to output stream and flush. " 55 56 @abstractmethod 57 def erase_screen(self): 58 """ 59 Erases the screen with the background colour and moves the cursor to 60 home. 61 """ 62 63 @abstractmethod 64 def enter_alternate_screen(self): 65 " Go to the alternate screen buffer. (For full screen applications). " 66 67 @abstractmethod 68 def quit_alternate_screen(self): 69 " Leave the alternate screen buffer. " 70 71 @abstractmethod 72 def enable_mouse_support(self): 73 " Enable mouse. " 74 75 @abstractmethod 76 def disable_mouse_support(self): 77 " Disable mouse. " 78 79 @abstractmethod 80 def erase_end_of_line(self): 81 """ 82 Erases from the current cursor position to the end of the current line. 83 """ 84 85 @abstractmethod 86 def erase_down(self): 87 """ 88 Erases the screen from the current line down to the bottom of the 89 screen. 90 """ 91 92 @abstractmethod 93 def reset_attributes(self): 94 " Reset color and styling attributes. " 95 96 @abstractmethod 97 def set_attributes(self, attrs): 98 " Set new color and styling attributes. " 99 100 @abstractmethod 101 def disable_autowrap(self): 102 " Disable auto line wrapping. " 103 104 @abstractmethod 105 def enable_autowrap(self): 106 " Enable auto line wrapping. " 107 108 @abstractmethod 109 def cursor_goto(self, row=0, column=0): 110 " Move cursor position. " 111 112 @abstractmethod 113 def cursor_up(self, amount): 114 " Move cursor `amount` place up. " 115 116 @abstractmethod 117 def cursor_down(self, amount): 118 " Move cursor `amount` place down. " 119 120 @abstractmethod 121 def cursor_forward(self, amount): 122 " Move cursor `amount` place forward. " 123 124 @abstractmethod 125 def cursor_backward(self, amount): 126 " Move cursor `amount` place backward. " 127 128 @abstractmethod 129 def hide_cursor(self): 130 " Hide cursor. " 131 132 @abstractmethod 133 def show_cursor(self): 134 " Show cursor. " 135 136 def ask_for_cpr(self): 137 """ 138 Asks for a cursor position report (CPR). 139 (VT100 only.) 140 """ 141 142 def bell(self): 143 " Sound bell. " 144 145 def enable_bracketed_paste(self): 146 " For vt100 only. " 147 148 def disable_bracketed_paste(self): 149 " For vt100 only. " 150 151 152class DummyOutput(Output): 153 """ 154 For testing. An output class that doesn't render anything. 155 """ 156 def fileno(self): 157 " There is no sensible default for fileno(). " 158 raise NotImplementedError 159 160 def encoding(self): 161 return 'utf-8' 162 163 def write(self, data): pass 164 def write_raw(self, data): pass 165 def set_title(self, title): pass 166 def clear_title(self): pass 167 def flush(self): pass 168 def erase_screen(self): pass 169 def enter_alternate_screen(self): pass 170 def quit_alternate_screen(self): pass 171 def enable_mouse_support(self): pass 172 def disable_mouse_support(self): pass 173 def erase_end_of_line(self): pass 174 def erase_down(self): pass 175 def reset_attributes(self): pass 176 def set_attributes(self, attrs): pass 177 def disable_autowrap(self): pass 178 def enable_autowrap(self): pass 179 def cursor_goto(self, row=0, column=0): pass 180 def cursor_up(self, amount): pass 181 def cursor_down(self, amount): pass 182 def cursor_forward(self, amount): pass 183 def cursor_backward(self, amount): pass 184 def hide_cursor(self): pass 185 def show_cursor(self): pass 186 def ask_for_cpr(self): pass 187 def bell(self): pass 188 def enable_bracketed_paste(self): pass 189 def disable_bracketed_paste(self): pass 190 191 def get_size(self): 192 return Size(rows=40, columns=80) 193