|
4 | 4 |
|
5 | 5 | namespace Terminal.Gui;
|
6 | 6 |
|
7 |
| -public interface IConsoleDriver |
8 |
| -{ |
9 |
| - /// <summary>Get the operating system clipboard.</summary> |
10 |
| - IClipboard? Clipboard { get; } |
11 |
| - |
12 |
| - /// <summary>Gets the location and size of the terminal screen.</summary> |
13 |
| - Rectangle Screen { get; } |
14 |
| - |
15 |
| - /// <summary> |
16 |
| - /// Gets or sets the clip rectangle that <see cref="AddRune(Rune)"/> and <see cref="AddStr(string)"/> are subject |
17 |
| - /// to. |
18 |
| - /// </summary> |
19 |
| - /// <value>The rectangle describing the of <see cref="Clip"/> region.</value> |
20 |
| - Region? Clip { get; set; } |
21 |
| - |
22 |
| - /// <summary> |
23 |
| - /// Gets the column last set by <see cref="Move"/>. <see cref="Col"/> and <see cref="Row"/> are used by |
24 |
| - /// <see cref="AddRune(Rune)"/> and <see cref="AddStr"/> to determine where to add content. |
25 |
| - /// </summary> |
26 |
| - int Col { get; } |
27 |
| - |
28 |
| - /// <summary>The number of columns visible in the terminal.</summary> |
29 |
| - int Cols { get; set; } |
30 |
| - |
31 |
| - /// <summary> |
32 |
| - /// The contents of the application output. The driver outputs this buffer to the terminal when |
33 |
| - /// <see cref="UpdateScreen"/> is called. |
34 |
| - /// <remarks>The format of the array is rows, columns. The first index is the row, the second index is the column.</remarks> |
35 |
| - /// </summary> |
36 |
| - Cell [,]? Contents { get; set; } |
37 |
| - |
38 |
| - /// <summary>The leftmost column in the terminal.</summary> |
39 |
| - int Left { get; set; } |
40 |
| - |
41 |
| - /// <summary> |
42 |
| - /// Gets the row last set by <see cref="Move"/>. <see cref="Col"/> and <see cref="Row"/> are used by |
43 |
| - /// <see cref="AddRune(Rune)"/> and <see cref="AddStr"/> to determine where to add content. |
44 |
| - /// </summary> |
45 |
| - int Row { get; } |
46 |
| - |
47 |
| - /// <summary>The number of rows visible in the terminal.</summary> |
48 |
| - int Rows { get; set; } |
49 |
| - |
50 |
| - /// <summary>The topmost row in the terminal.</summary> |
51 |
| - int Top { get; set; } |
52 |
| - |
53 |
| - /// <summary>Gets whether the <see cref="ConsoleDriver"/> supports TrueColor output.</summary> |
54 |
| - bool SupportsTrueColor { get; } |
55 |
| - |
56 |
| - /// <summary> |
57 |
| - /// Gets or sets whether the <see cref="ConsoleDriver"/> should use 16 colors instead of the default TrueColors. |
58 |
| - /// See <see cref="Application.Force16Colors"/> to change this setting via <see cref="ConfigurationManager"/>. |
59 |
| - /// </summary> |
60 |
| - /// <remarks> |
61 |
| - /// <para> |
62 |
| - /// Will be forced to <see langword="true"/> if <see cref="ConsoleDriver.SupportsTrueColor"/> is |
63 |
| - /// <see langword="false"/>, indicating that the <see cref="ConsoleDriver"/> cannot support TrueColor. |
64 |
| - /// </para> |
65 |
| - /// </remarks> |
66 |
| - bool Force16Colors { get; set; } |
67 |
| - |
68 |
| - /// <summary> |
69 |
| - /// The <see cref="Attribute"/> that will be used for the next <see cref="AddRune(Rune)"/> or <see cref="AddStr"/> |
70 |
| - /// call. |
71 |
| - /// </summary> |
72 |
| - Attribute CurrentAttribute { get; set; } |
73 |
| - |
74 |
| - /// <summary>Returns the name of the driver and relevant library version information.</summary> |
75 |
| - /// <returns></returns> |
76 |
| - string GetVersionInfo (); |
77 |
| - |
78 |
| - /// <summary> |
79 |
| - /// Provide proper writing to send escape sequence recognized by the <see cref="ConsoleDriver"/>. |
80 |
| - /// </summary> |
81 |
| - /// <param name="ansi"></param> |
82 |
| - void WriteRaw (string ansi); |
83 |
| - |
84 |
| - /// <summary>Tests if the specified rune is supported by the driver.</summary> |
85 |
| - /// <param name="rune"></param> |
86 |
| - /// <returns> |
87 |
| - /// <see langword="true"/> if the rune can be properly presented; <see langword="false"/> if the driver does not |
88 |
| - /// support displaying this rune. |
89 |
| - /// </returns> |
90 |
| - bool IsRuneSupported (Rune rune); |
91 |
| - |
92 |
| - /// <summary>Tests whether the specified coordinate are valid for drawing.</summary> |
93 |
| - /// <param name="col">The column.</param> |
94 |
| - /// <param name="row">The row.</param> |
95 |
| - /// <returns> |
96 |
| - /// <see langword="false"/> if the coordinate is outside the screen bounds or outside of <see cref="ConsoleDriver.Clip"/>. |
97 |
| - /// <see langword="true"/> otherwise. |
98 |
| - /// </returns> |
99 |
| - bool IsValidLocation (int col, int row); |
100 |
| - |
101 |
| - /// <summary>Tests whether the specified coordinate are valid for drawing the specified Rune.</summary> |
102 |
| - /// <param name="rune">Used to determine if one or two columns are required.</param> |
103 |
| - /// <param name="col">The column.</param> |
104 |
| - /// <param name="row">The row.</param> |
105 |
| - /// <returns> |
106 |
| - /// <see langword="false"/> if the coordinate is outside the screen bounds or outside of <see cref="ConsoleDriver.Clip"/>. |
107 |
| - /// <see langword="true"/> otherwise. |
108 |
| - /// </returns> |
109 |
| - bool IsValidLocation (Rune rune, int col, int row); |
110 |
| - |
111 |
| - /// <summary> |
112 |
| - /// Updates <see cref="ConsoleDriver.Col"/> and <see cref="ConsoleDriver.Row"/> to the specified column and row in <see cref="ConsoleDriver.Contents"/>. |
113 |
| - /// Used by <see cref="ConsoleDriver.AddRune(System.Text.Rune)"/> and <see cref="ConsoleDriver.AddStr"/> to determine where to add content. |
114 |
| - /// </summary> |
115 |
| - /// <remarks> |
116 |
| - /// <para>This does not move the cursor on the screen, it only updates the internal state of the driver.</para> |
117 |
| - /// <para> |
118 |
| - /// If <paramref name="col"/> or <paramref name="row"/> are negative or beyond <see cref="ConsoleDriver.Cols"/> and |
119 |
| - /// <see cref="ConsoleDriver.Rows"/>, the method still sets those properties. |
120 |
| - /// </para> |
121 |
| - /// </remarks> |
122 |
| - /// <param name="col">Column to move to.</param> |
123 |
| - /// <param name="row">Row to move to.</param> |
124 |
| - void Move (int col, int row); |
125 |
| - |
126 |
| - /// <summary>Adds the specified rune to the display at the current cursor position.</summary> |
127 |
| - /// <remarks> |
128 |
| - /// <para> |
129 |
| - /// When the method returns, <see cref="ConsoleDriver.Col"/> will be incremented by the number of columns |
130 |
| - /// <paramref name="rune"/> required, even if the new column value is outside of the <see cref="ConsoleDriver.Clip"/> or screen |
131 |
| - /// dimensions defined by <see cref="ConsoleDriver.Cols"/>. |
132 |
| - /// </para> |
133 |
| - /// <para> |
134 |
| - /// If <paramref name="rune"/> requires more than one column, and <see cref="ConsoleDriver.Col"/> plus the number of columns |
135 |
| - /// needed exceeds the <see cref="ConsoleDriver.Clip"/> or screen dimensions, the default Unicode replacement character (U+FFFD) |
136 |
| - /// will be added instead. |
137 |
| - /// </para> |
138 |
| - /// </remarks> |
139 |
| - /// <param name="rune">Rune to add.</param> |
140 |
| - void AddRune (Rune rune); |
141 |
| - |
142 |
| - /// <summary> |
143 |
| - /// Adds the specified <see langword="char"/> to the display at the current cursor position. This method is a |
144 |
| - /// convenience method that calls <see cref="ConsoleDriver.AddRune(System.Text.Rune)"/> with the <see cref="Rune"/> constructor. |
145 |
| - /// </summary> |
146 |
| - /// <param name="c">Character to add.</param> |
147 |
| - void AddRune (char c); |
148 |
| - |
149 |
| - /// <summary>Adds the <paramref name="str"/> to the display at the cursor position.</summary> |
150 |
| - /// <remarks> |
151 |
| - /// <para> |
152 |
| - /// When the method returns, <see cref="ConsoleDriver.Col"/> will be incremented by the number of columns |
153 |
| - /// <paramref name="str"/> required, unless the new column value is outside of the <see cref="ConsoleDriver.Clip"/> or screen |
154 |
| - /// dimensions defined by <see cref="ConsoleDriver.Cols"/>. |
155 |
| - /// </para> |
156 |
| - /// <para>If <paramref name="str"/> requires more columns than are available, the output will be clipped.</para> |
157 |
| - /// </remarks> |
158 |
| - /// <param name="str">String.</param> |
159 |
| - void AddStr (string str); |
160 |
| - |
161 |
| - /// <summary>Fills the specified rectangle with the specified rune, using <see cref="ConsoleDriver.CurrentAttribute"/></summary> |
162 |
| - /// <remarks> |
163 |
| - /// The value of <see cref="ConsoleDriver.Clip"/> is honored. Any parts of the rectangle not in the clip will not be drawn. |
164 |
| - /// </remarks> |
165 |
| - /// <param name="rect">The Screen-relative rectangle.</param> |
166 |
| - /// <param name="rune">The Rune used to fill the rectangle</param> |
167 |
| - void FillRect (Rectangle rect, Rune rune = default); |
168 |
| - |
169 |
| - /// <summary> |
170 |
| - /// Fills the specified rectangle with the specified <see langword="char"/>. This method is a convenience method |
171 |
| - /// that calls <see cref="ConsoleDriver.FillRect(System.Drawing.Rectangle,System.Text.Rune)"/>. |
172 |
| - /// </summary> |
173 |
| - /// <param name="rect"></param> |
174 |
| - /// <param name="c"></param> |
175 |
| - void FillRect (Rectangle rect, char c); |
176 |
| - |
177 |
| - /// <summary>Clears the <see cref="ConsoleDriver.Contents"/> of the driver.</summary> |
178 |
| - void ClearContents (); |
179 |
| - |
180 |
| - /// <summary> |
181 |
| - /// Raised each time <see cref="ConsoleDriver.ClearContents"/> is called. For benchmarking. |
182 |
| - /// </summary> |
183 |
| - event EventHandler<EventArgs>? ClearedContents; |
184 |
| - |
185 |
| - /// <summary> |
186 |
| - /// Sets <see cref="ConsoleDriver.Contents"/> as dirty for situations where views |
187 |
| - /// don't need layout and redrawing, but just refresh the screen. |
188 |
| - /// </summary> |
189 |
| - void SetContentsAsDirty (); |
190 |
| - |
191 |
| - /// <summary>Determines if the terminal cursor should be visible or not and sets it accordingly.</summary> |
192 |
| - /// <returns><see langword="true"/> upon success</returns> |
193 |
| - bool EnsureCursorVisibility (); |
194 |
| - |
195 |
| - /// <summary>Gets the terminal cursor visibility.</summary> |
196 |
| - /// <param name="visibility">The current <see cref="CursorVisibility"/></param> |
197 |
| - /// <returns><see langword="true"/> upon success</returns> |
198 |
| - bool GetCursorVisibility (out CursorVisibility visibility); |
199 |
| - |
200 |
| - /// <summary>Called when the terminal size changes. Fires the <see cref="ConsoleDriver.SizeChanged"/> event.</summary> |
201 |
| - /// <param name="args"></param> |
202 |
| - void OnSizeChanged (SizeChangedEventArgs args); |
203 |
| - |
204 |
| - /// <summary>Updates the screen to reflect all the changes that have been done to the display buffer</summary> |
205 |
| - void Refresh (); |
206 |
| - |
207 |
| - /// <summary> |
208 |
| - /// Raised each time <see cref="ConsoleDriver.Refresh"/> is called. For benchmarking. |
209 |
| - /// </summary> |
210 |
| - event EventHandler<EventArgs<bool>>? Refreshed; |
211 |
| - |
212 |
| - /// <summary>Sets the terminal cursor visibility.</summary> |
213 |
| - /// <param name="visibility">The wished <see cref="CursorVisibility"/></param> |
214 |
| - /// <returns><see langword="true"/> upon success</returns> |
215 |
| - bool SetCursorVisibility (CursorVisibility visibility); |
216 |
| - |
217 |
| - /// <summary>The event fired when the terminal is resized.</summary> |
218 |
| - event EventHandler<SizeChangedEventArgs>? SizeChanged; |
219 |
| - |
220 |
| - /// <summary>Suspends the application (e.g. on Linux via SIGTSTP) and upon resume, resets the console driver.</summary> |
221 |
| - /// <remarks>This is only implemented in <see cref="CursesDriver"/>.</remarks> |
222 |
| - void Suspend (); |
223 |
| - |
224 |
| - /// <summary>Sets the position of the terminal cursor to <see cref="ConsoleDriver.Col"/> and <see cref="ConsoleDriver.Row"/>.</summary> |
225 |
| - void UpdateCursor (); |
226 |
| - |
227 |
| - /// <summary>Redraws the physical screen with the contents that have been queued up via any of the printing commands.</summary> |
228 |
| - /// <returns><see langword="true"/> if any updates to the screen were made.</returns> |
229 |
| - bool UpdateScreen (); |
230 |
| - |
231 |
| - /// <summary>Initializes the driver</summary> |
232 |
| - /// <returns>Returns an instance of <see cref="MainLoop"/> using the <see cref="IMainLoopDriver"/> for the driver.</returns> |
233 |
| - MainLoop Init (); |
234 |
| - |
235 |
| - /// <summary>Ends the execution of the console driver.</summary> |
236 |
| - void End (); |
237 |
| - |
238 |
| - /// <summary>Selects the specified attribute as the attribute to use for future calls to AddRune and AddString.</summary> |
239 |
| - /// <remarks>Implementations should call <c>base.SetAttribute(c)</c>.</remarks> |
240 |
| - /// <param name="c">C.</param> |
241 |
| - Attribute SetAttribute (Attribute c); |
242 |
| - |
243 |
| - /// <summary>Gets the current <see cref="Attribute"/>.</summary> |
244 |
| - /// <returns>The current attribute.</returns> |
245 |
| - Attribute GetAttribute (); |
246 |
| - |
247 |
| - /// <summary>Makes an <see cref="Attribute"/>.</summary> |
248 |
| - /// <param name="foreground">The foreground color.</param> |
249 |
| - /// <param name="background">The background color.</param> |
250 |
| - /// <returns>The attribute for the foreground and background colors.</returns> |
251 |
| - Attribute MakeColor (in Color foreground, in Color background); |
252 |
| - |
253 |
| - /// <summary>Event fired when a mouse event occurs.</summary> |
254 |
| - event EventHandler<MouseEventArgs>? MouseEvent; |
255 |
| - |
256 |
| - /// <summary>Called when a mouse event occurs. Fires the <see cref="ConsoleDriver.MouseEvent"/> event.</summary> |
257 |
| - /// <param name="a"></param> |
258 |
| - void OnMouseEvent (MouseEventArgs a); |
259 |
| - |
260 |
| - /// <summary>Event fired when a key is pressed down. This is a precursor to <see cref="ConsoleDriver.KeyUp"/>.</summary> |
261 |
| - event EventHandler<Key>? KeyDown; |
262 |
| - |
263 |
| - /// <summary> |
264 |
| - /// Called when a key is pressed down. Fires the <see cref="ConsoleDriver.KeyDown"/> event. This is a precursor to |
265 |
| - /// <see cref="ConsoleDriver.OnKeyUp"/>. |
266 |
| - /// </summary> |
267 |
| - /// <param name="a"></param> |
268 |
| - void OnKeyDown (Key a); |
269 |
| - |
270 |
| - /// <summary>Event fired when a key is released.</summary> |
271 |
| - /// <remarks> |
272 |
| - /// Drivers that do not support key release events will fire this event after <see cref="ConsoleDriver.KeyDown"/> processing is |
273 |
| - /// complete. |
274 |
| - /// </remarks> |
275 |
| - event EventHandler<Key>? KeyUp; |
276 |
| - |
277 |
| - /// <summary>Called when a key is released. Fires the <see cref="ConsoleDriver.KeyUp"/> event.</summary> |
278 |
| - /// <remarks> |
279 |
| - /// Drivers that do not support key release events will call this method after <see cref="ConsoleDriver.OnKeyDown"/> processing |
280 |
| - /// is complete. |
281 |
| - /// </remarks> |
282 |
| - /// <param name="a"></param> |
283 |
| - void OnKeyUp (Key a); |
284 |
| - |
285 |
| - /// <summary>Simulates a key press.</summary> |
286 |
| - /// <param name="keyChar">The key character.</param> |
287 |
| - /// <param name="key">The key.</param> |
288 |
| - /// <param name="shift">If <see langword="true"/> simulates the Shift key being pressed.</param> |
289 |
| - /// <param name="alt">If <see langword="true"/> simulates the Alt key being pressed.</param> |
290 |
| - /// <param name="ctrl">If <see langword="true"/> simulates the Ctrl key being pressed.</param> |
291 |
| - void SendKeys (char keyChar, ConsoleKey key, bool shift, bool alt, bool ctrl); |
292 |
| -} |
293 |
| - |
294 | 7 | /// <summary>Base class for Terminal.Gui ConsoleDriver implementations.</summary>
|
295 | 8 | /// <remarks>
|
296 | 9 | /// There are currently four implementations: - <see cref="CursesDriver"/> (for Unix and Mac) -
|
|
0 commit comments