|
|
@@ -1,3 +1,4 @@
|
|
|
+using System.Collections.Concurrent;
|
|
|
|
|
|
namespace Terminal.Gui.Drivers;
|
|
|
|
|
|
@@ -5,92 +6,107 @@ namespace Terminal.Gui.Drivers;
|
|
|
/// <remarks>
|
|
|
/// There are currently four implementations: UnixDriver, WindowsDriver, DotNetDriver, and FakeDriver
|
|
|
/// </remarks>
|
|
|
-public interface IDriver
|
|
|
+public interface IDriver : IDisposable
|
|
|
{
|
|
|
+ #region Driver Lifecycle
|
|
|
+
|
|
|
+ /// <summary>Initializes the driver</summary>
|
|
|
+ void Init ();
|
|
|
+
|
|
|
/// <summary>
|
|
|
- /// Gets the name of the driver implementation.
|
|
|
+ /// INTERNAL: Updates the terminal with the current output buffer. Should not be used by applications. Drawing occurs
|
|
|
+ /// once each Application main loop iteration.
|
|
|
/// </summary>
|
|
|
- string? GetName ();
|
|
|
+ void Refresh ();
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Class responsible for processing native driver input objects
|
|
|
- /// e.g. <see cref="ConsoleKeyInfo"/> into <see cref="Key"/> events
|
|
|
- /// and detecting and processing ansi escape sequences.
|
|
|
+ /// Gets the name of the driver implementation.
|
|
|
/// </summary>
|
|
|
- IInputProcessor InputProcessor { get; }
|
|
|
+ string? GetName ();
|
|
|
+
|
|
|
+ /// <summary>Returns the name of the driver and relevant library version information.</summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ string GetVersionInfo ();
|
|
|
+
|
|
|
+ /// <summary>Suspends the application (e.g. on Linux via SIGTSTP) and upon resume, resets the console driver.</summary>
|
|
|
+ /// <remarks>This is only implemented in UnixDriver.</remarks>
|
|
|
+ void Suspend ();
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Describes the desired screen state. Data source for <see cref="IOutput"/>.
|
|
|
+ /// Gets whether the driver has detected the console requires legacy console API (Windows Console API without ANSI/VT
|
|
|
+ /// support).
|
|
|
+ /// Returns <see langword="true"/> for legacy consoles that don't support modern ANSI escape sequences (e.g. Windows
|
|
|
+ /// conhost);
|
|
|
+ /// <see langword="false"/> for modern terminals with ANSI/VT support.
|
|
|
/// </summary>
|
|
|
- IOutputBuffer OutputBuffer { get; }
|
|
|
+ /// <remarks>
|
|
|
+ /// <para>
|
|
|
+ /// This property indicates whether the terminal supports modern ANSI escape sequences for input/output.
|
|
|
+ /// On Windows, this maps to whether Virtual Terminal processing is enabled.
|
|
|
+ /// On Unix-like systems, this is typically <see langword="false"/> as they support ANSI by default.
|
|
|
+ /// </para>
|
|
|
+ /// <para>
|
|
|
+ /// When <see langword="true"/>, the driver must use legacy Windows Console API functions
|
|
|
+ /// (e.g., WriteConsoleW, SetConsoleTextAttribute) instead of ANSI escape sequences.
|
|
|
+ /// </para>
|
|
|
+ /// </remarks>
|
|
|
+ bool IsLegacyConsole { get; internal set; }
|
|
|
+
|
|
|
+ #endregion Driver Lifecycle
|
|
|
+
|
|
|
+ #region Driver Components
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Interface for classes responsible for reporting the current
|
|
|
- /// size of the terminal window.
|
|
|
+ /// Class responsible for processing native driver input objects
|
|
|
+ /// e.g. <see cref="ConsoleKeyInfo"/> into <see cref="Key"/> events
|
|
|
+ /// and detecting and processing ansi escape sequences.
|
|
|
/// </summary>
|
|
|
- ISizeMonitor SizeMonitor { get; }
|
|
|
+ IInputProcessor InputProcessor { get; }
|
|
|
|
|
|
/// <summary>Get the operating system clipboard.</summary>
|
|
|
- ///
|
|
|
IClipboard? Clipboard { get; }
|
|
|
|
|
|
+ #endregion Driver Components
|
|
|
+
|
|
|
+ #region Screen and Display
|
|
|
+
|
|
|
/// <summary>Gets the location and size of the terminal screen.</summary>
|
|
|
Rectangle Screen { get; }
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Sets the screen size for testing purposes. Only supported by FakeDriver.
|
|
|
- /// <see cref="Screen"/> is the source of truth for screen dimensions.
|
|
|
+ /// Sets the screen size. <see cref="Screen"/> is the source of truth for screen dimensions.
|
|
|
/// </summary>
|
|
|
/// <param name="width">The new width in columns.</param>
|
|
|
/// <param name="height">The new height in rows.</param>
|
|
|
- /// <exception cref="NotSupportedException">Thrown when called on non-FakeDriver instances.</exception>
|
|
|
void SetScreenSize (int width, int height);
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Gets or sets the clip rectangle that <see cref="AddRune(Rune)"/> and <see cref="AddStr(string)"/> are subject
|
|
|
- /// to.
|
|
|
- /// </summary>
|
|
|
- /// <value>The rectangle describing the of <see cref="Clip"/> region.</value>
|
|
|
- Region? Clip { get; set; }
|
|
|
-
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Gets the column last set by <see cref="Move"/>. <see cref="Col"/> and <see cref="Row"/> are used by
|
|
|
- /// <see cref="AddRune(Rune)"/> and <see cref="AddStr"/> to determine where to add content.
|
|
|
+ /// The event fired when the screen changes (size, position, etc.).
|
|
|
+ /// <see cref="Screen"/> is the source of truth for screen dimensions.
|
|
|
/// </summary>
|
|
|
- int Col { get; }
|
|
|
+ event EventHandler<SizeChangedEventArgs>? SizeChanged;
|
|
|
|
|
|
/// <summary>The number of columns visible in the terminal.</summary>
|
|
|
int Cols { get; set; }
|
|
|
|
|
|
- // BUGBUG: This should not be publicly settable.
|
|
|
- /// <summary>
|
|
|
- /// Gets or sets the contents of the application output. The driver outputs this buffer to the terminal.
|
|
|
- /// <remarks>The format of the array is rows, columns. The first index is the row, the second index is the column.</remarks>
|
|
|
- /// </summary>
|
|
|
- Cell [,]? Contents { get; set; }
|
|
|
+ /// <summary>The number of rows visible in the terminal.</summary>
|
|
|
+ int Rows { get; set; }
|
|
|
|
|
|
/// <summary>The leftmost column in the terminal.</summary>
|
|
|
int Left { get; set; }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// Gets the row last set by <see cref="Move"/>. <see cref="Col"/> and <see cref="Row"/> are used by
|
|
|
- /// <see cref="AddRune(Rune)"/> and <see cref="AddStr"/> to determine where to add content.
|
|
|
- /// </summary>
|
|
|
- int Row { get; }
|
|
|
-
|
|
|
- /// <summary>The number of rows visible in the terminal.</summary>
|
|
|
- int Rows { get; set; }
|
|
|
-
|
|
|
/// <summary>The topmost row in the terminal.</summary>
|
|
|
int Top { get; set; }
|
|
|
|
|
|
+ #endregion Screen and Display
|
|
|
+
|
|
|
+ #region Color Support
|
|
|
+
|
|
|
/// <summary>Gets whether the <see cref="IDriver"/> supports TrueColor output.</summary>
|
|
|
bool SupportsTrueColor { get; }
|
|
|
|
|
|
/// <summary>
|
|
|
/// Gets or sets whether the <see cref="IDriver"/> should use 16 colors instead of the default TrueColors.
|
|
|
- /// See <see cref="Application.Force16Colors"/> to change this setting via <see cref="ConfigurationManager"/>.
|
|
|
/// </summary>
|
|
|
/// <remarks>
|
|
|
/// <para>
|
|
|
@@ -98,42 +114,57 @@ public interface IDriver
|
|
|
/// <see langword="false"/>, indicating that the <see cref="IDriver"/> cannot support TrueColor.
|
|
|
/// </para>
|
|
|
/// </remarks>
|
|
|
+ /// <seealso cref="Driver.Force16Colors"/>
|
|
|
bool Force16Colors { get; set; }
|
|
|
|
|
|
+ #endregion Color Support
|
|
|
+
|
|
|
+ #region Content Buffer
|
|
|
+
|
|
|
+ // BUGBUG: This should not be publicly settable.
|
|
|
/// <summary>
|
|
|
- /// The <see cref="System.Attribute"/> that will be used for the next <see cref="AddRune(Rune)"/> or <see cref="AddStr"/>
|
|
|
- /// call.
|
|
|
+ /// Gets or sets the contents of the application output. The driver outputs this buffer to the terminal.
|
|
|
+ /// <remarks>The format of the array is rows, columns. The first index is the row, the second index is the column.</remarks>
|
|
|
/// </summary>
|
|
|
- Attribute CurrentAttribute { get; set; }
|
|
|
+ Cell [,]? Contents { get; set; }
|
|
|
|
|
|
- /// <summary>Returns the name of the driver and relevant library version information.</summary>
|
|
|
- /// <returns></returns>
|
|
|
- string GetVersionInfo ();
|
|
|
+ /// <summary>
|
|
|
+ /// Gets or sets the clip rectangle that <see cref="AddRune(Rune)"/> and <see cref="AddStr(string)"/> are subject
|
|
|
+ /// to.
|
|
|
+ /// </summary>
|
|
|
+ /// <value>The rectangle describing the of <see cref="Clip"/> region.</value>
|
|
|
+ Region? Clip { get; set; }
|
|
|
+
|
|
|
+ /// <summary>Clears the <see cref="IDriver.Contents"/> of the driver.</summary>
|
|
|
+ void ClearContents ();
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Provide proper writing to send escape sequence recognized by the <see cref="IDriver"/>.
|
|
|
+ /// Fills the specified rectangle with the specified rune, using <see cref="IDriver.CurrentAttribute"/>
|
|
|
/// </summary>
|
|
|
- /// <param name="ansi"></param>
|
|
|
- void WriteRaw (string ansi);
|
|
|
+ event EventHandler<EventArgs> ClearedContents;
|
|
|
|
|
|
- /// <summary>Tests if the specified rune is supported by the driver.</summary>
|
|
|
- /// <param name="rune"></param>
|
|
|
- /// <returns>
|
|
|
- /// <see langword="true"/> if the rune can be properly presented; <see langword="false"/> if the driver does not
|
|
|
- /// support displaying this rune.
|
|
|
- /// </returns>
|
|
|
- bool IsRuneSupported (Rune rune);
|
|
|
+ #endregion Content Buffer
|
|
|
|
|
|
- /// <summary>Tests whether the specified coordinate are valid for drawing the specified Text.</summary>
|
|
|
- /// <param name="text">Used to determine if one or two columns are required.</param>
|
|
|
- /// <param name="col">The column.</param>
|
|
|
- /// <param name="row">The row.</param>
|
|
|
- /// <returns>
|
|
|
- /// <see langword="false"/> if the coordinate is outside the screen bounds or outside of
|
|
|
- /// <see cref="IDriver.Clip"/>.
|
|
|
- /// <see langword="true"/> otherwise.
|
|
|
- /// </returns>
|
|
|
- bool IsValidLocation (string text, int col, int row);
|
|
|
+ #region Drawing and Rendering
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Gets the column last set by <see cref="Move"/>. <see cref="Col"/> and <see cref="Row"/> are used by
|
|
|
+ /// <see cref="AddRune(Rune)"/> and <see cref="AddStr"/> to determine where to add content.
|
|
|
+ /// </summary>
|
|
|
+ int Col { get; }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Gets the row last set by <see cref="Move"/>. <see cref="Col"/> and <see cref="Row"/> are used by
|
|
|
+ /// <see cref="AddRune(Rune)"/> and <see cref="AddStr"/> to determine where to add content.
|
|
|
+ /// </summary>
|
|
|
+ int Row { get; }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// The <see cref="System.Attribute"/> that will be used for the next <see cref="AddRune(Rune)"/> or
|
|
|
+ /// <see cref="AddStr"/>
|
|
|
+ /// call.
|
|
|
+ /// </summary>
|
|
|
+ Attribute CurrentAttribute { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
|
/// Updates <see cref="IDriver.Col"/> and <see cref="IDriver.Row"/> to the specified column and row in
|
|
|
@@ -153,6 +184,25 @@ public interface IDriver
|
|
|
/// <param name="row">Row to move to.</param>
|
|
|
void Move (int col, int row);
|
|
|
|
|
|
+ /// <summary>Tests if the specified rune is supported by the driver.</summary>
|
|
|
+ /// <param name="rune"></param>
|
|
|
+ /// <returns>
|
|
|
+ /// <see langword="true"/> if the rune can be properly presented; <see langword="false"/> if the driver does not
|
|
|
+ /// support displaying this rune.
|
|
|
+ /// </returns>
|
|
|
+ bool IsRuneSupported (Rune rune);
|
|
|
+
|
|
|
+ /// <summary>Tests whether the specified coordinate are valid for drawing the specified Text.</summary>
|
|
|
+ /// <param name="text">Used to determine if one or two columns are required.</param>
|
|
|
+ /// <param name="col">The column.</param>
|
|
|
+ /// <param name="row">The row.</param>
|
|
|
+ /// <returns>
|
|
|
+ /// <see langword="false"/> if the coordinate is outside the screen bounds or outside of
|
|
|
+ /// <see cref="IDriver.Clip"/>.
|
|
|
+ /// <see langword="true"/> otherwise.
|
|
|
+ /// </returns>
|
|
|
+ bool IsValidLocation (string text, int col, int row);
|
|
|
+
|
|
|
/// <summary>Adds the specified rune to the display at the current cursor position.</summary>
|
|
|
/// <remarks>
|
|
|
/// <para>
|
|
|
@@ -193,14 +243,6 @@ public interface IDriver
|
|
|
/// <param name="str">String.</param>
|
|
|
void AddStr (string str);
|
|
|
|
|
|
- /// <summary>Clears the <see cref="IDriver.Contents"/> of the driver.</summary>
|
|
|
- void ClearContents ();
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Fills the specified rectangle with the specified rune, using <see cref="IDriver.CurrentAttribute"/>
|
|
|
- /// </summary>
|
|
|
- event EventHandler<EventArgs> ClearedContents;
|
|
|
-
|
|
|
/// <summary>Fills the specified rectangle with the specified rune, using <see cref="IDriver.CurrentAttribute"/></summary>
|
|
|
/// <remarks>
|
|
|
/// The value of <see cref="IDriver.Clip"/> is honored. Any parts of the rectangle not in the clip will not be
|
|
|
@@ -218,29 +260,43 @@ public interface IDriver
|
|
|
/// <param name="c"></param>
|
|
|
void FillRect (Rectangle rect, char c);
|
|
|
|
|
|
+ /// <summary>Selects the specified attribute as the attribute to use for future calls to AddRune and AddString.</summary>
|
|
|
+ /// <remarks>Implementations should call <c>base.SetAttribute(c)</c>.</remarks>
|
|
|
+ /// <param name="c">C.</param>
|
|
|
+ Attribute SetAttribute (Attribute c);
|
|
|
|
|
|
- /// <summary>Gets the terminal cursor visibility.</summary>
|
|
|
- /// <param name="visibility">The current <see cref="CursorVisibility"/></param>
|
|
|
- /// <returns><see langword="true"/> upon success</returns>
|
|
|
- bool GetCursorVisibility (out CursorVisibility visibility);
|
|
|
+ /// <summary>Gets the current <see cref="Attribute"/>.</summary>
|
|
|
+ /// <returns>The current attribute.</returns>
|
|
|
+ Attribute GetAttribute ();
|
|
|
|
|
|
- /// <summary>Updates the screen to reflect all the changes that have been done to the display buffer</summary>
|
|
|
- void Refresh ();
|
|
|
+ /// <summary>
|
|
|
+ /// Provide proper writing to send escape sequence recognized by the <see cref="IDriver"/>.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="ansi"></param>
|
|
|
+ void WriteRaw (string ansi);
|
|
|
|
|
|
- /// <summary>Sets the terminal cursor visibility.</summary>
|
|
|
- /// <param name="visibility">The wished <see cref="CursorVisibility"/></param>
|
|
|
- /// <returns><see langword="true"/> upon success</returns>
|
|
|
- bool SetCursorVisibility (CursorVisibility visibility);
|
|
|
+ /// <summary>
|
|
|
+ /// Gets the queue of sixel images to write out to screen when updating.
|
|
|
+ /// If the terminal does not support Sixel, adding to this queue has no effect.
|
|
|
+ /// </summary>
|
|
|
+ ConcurrentQueue<SixelToRender> GetSixels ();
|
|
|
|
|
|
/// <summary>
|
|
|
- /// The event fired when the screen changes (size, position, etc.).
|
|
|
- /// <see cref="Screen"/> is the source of truth for screen dimensions.
|
|
|
+ /// Gets a string representation of <see cref="Contents"/>.
|
|
|
/// </summary>
|
|
|
- event EventHandler<SizeChangedEventArgs>? SizeChanged;
|
|
|
+ /// <returns></returns>
|
|
|
+ public string ToString ();
|
|
|
|
|
|
- /// <summary>Suspends the application (e.g. on Linux via SIGTSTP) and upon resume, resets the console driver.</summary>
|
|
|
- /// <remarks>This is only implemented in UnixDriver.</remarks>
|
|
|
- void Suspend ();
|
|
|
+ /// <summary>
|
|
|
+ /// Gets an ANSI escape sequence representation of <see cref="Contents"/>. This is the
|
|
|
+ /// same output as would be written to the terminal to recreate the current screen contents.
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ public string ToAnsi ();
|
|
|
+
|
|
|
+ #endregion Drawing and Rendering
|
|
|
+
|
|
|
+ #region Cursor
|
|
|
|
|
|
/// <summary>
|
|
|
/// Sets the position of the terminal cursor to <see cref="IDriver.Col"/> and
|
|
|
@@ -248,20 +304,19 @@ public interface IDriver
|
|
|
/// </summary>
|
|
|
void UpdateCursor ();
|
|
|
|
|
|
- /// <summary>Initializes the driver</summary>
|
|
|
- void Init ();
|
|
|
+ /// <summary>Gets the terminal cursor visibility.</summary>
|
|
|
+ /// <param name="visibility">The current <see cref="CursorVisibility"/></param>
|
|
|
+ /// <returns><see langword="true"/> upon success</returns>
|
|
|
+ bool GetCursorVisibility (out CursorVisibility visibility);
|
|
|
|
|
|
- /// <summary>Ends the execution of the console driver.</summary>
|
|
|
- void End ();
|
|
|
+ /// <summary>Sets the terminal cursor visibility.</summary>
|
|
|
+ /// <param name="visibility">The wished <see cref="CursorVisibility"/></param>
|
|
|
+ /// <returns><see langword="true"/> upon success</returns>
|
|
|
+ bool SetCursorVisibility (CursorVisibility visibility);
|
|
|
|
|
|
- /// <summary>Selects the specified attribute as the attribute to use for future calls to AddRune and AddString.</summary>
|
|
|
- /// <remarks>Implementations should call <c>base.SetAttribute(c)</c>.</remarks>
|
|
|
- /// <param name="c">C.</param>
|
|
|
- Attribute SetAttribute (Attribute c);
|
|
|
+ #endregion Cursor
|
|
|
|
|
|
- /// <summary>Gets the current <see cref="Attribute"/>.</summary>
|
|
|
- /// <returns>The current attribute.</returns>
|
|
|
- Attribute GetAttribute ();
|
|
|
+ #region Input Events
|
|
|
|
|
|
/// <summary>Event fired when a mouse event occurs.</summary>
|
|
|
event EventHandler<MouseEventArgs>? MouseEvent;
|
|
|
@@ -283,29 +338,15 @@ public interface IDriver
|
|
|
/// <param name="key"></param>
|
|
|
void EnqueueKeyEvent (Key key);
|
|
|
|
|
|
+ #endregion Input Events
|
|
|
+
|
|
|
+ #region ANSI Escape Sequences
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Queues the given <paramref name="request"/> for execution
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
public void QueueAnsiRequest (AnsiEscapeSequenceRequest request);
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// Gets the <see cref="AnsiRequestScheduler"/> for the driver
|
|
|
- /// </summary>
|
|
|
- /// <returns></returns>
|
|
|
- public AnsiRequestScheduler GetRequestScheduler ();
|
|
|
-
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Gets a string representation of <see cref="Contents"/>.
|
|
|
- /// </summary>
|
|
|
- /// <returns></returns>
|
|
|
- public string ToString ();
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Gets an ANSI escape sequence representation of <see cref="Contents"/>. This is the
|
|
|
- /// same output as would be written to the terminal to recreate the current screen contents.
|
|
|
- /// </summary>
|
|
|
- /// <returns></returns>
|
|
|
- public string ToAnsi ();
|
|
|
+ #endregion ANSI Escape Sequences
|
|
|
}
|