using System.Collections.Concurrent;
namespace Terminal.Gui.Drivers;
/// Base interface for Terminal.Gui Driver implementations.
///
/// There are currently four implementations: UnixDriver, WindowsDriver, DotNetDriver, and FakeDriver
///
public interface IDriver : IDisposable
{
#region Driver Lifecycle
/// Initializes the driver
void Init ();
///
/// INTERNAL: Updates the terminal with the current output buffer. Should not be used by applications. Drawing occurs
/// once each Application main loop iteration.
///
void Refresh ();
///
/// Gets the name of the driver implementation.
///
string? GetName ();
/// Returns the name of the driver and relevant library version information.
///
string GetVersionInfo ();
/// Suspends the application (e.g. on Linux via SIGTSTP) and upon resume, resets the console driver.
/// This is only implemented in UnixDriver.
void Suspend ();
///
/// Gets whether the driver has detected the console requires legacy console API (Windows Console API without ANSI/VT
/// support).
/// Returns for legacy consoles that don't support modern ANSI escape sequences (e.g. Windows
/// conhost);
/// for modern terminals with ANSI/VT support.
///
///
///
/// 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 as they support ANSI by default.
///
///
/// When , the driver must use legacy Windows Console API functions
/// (e.g., WriteConsoleW, SetConsoleTextAttribute) instead of ANSI escape sequences.
///
///
bool IsLegacyConsole { get; internal set; }
#endregion Driver Lifecycle
#region Driver Components
///
/// Class responsible for processing native driver input objects
/// e.g. into events
/// and detecting and processing ansi escape sequences.
///
IInputProcessor GetInputProcessor ();
///
/// Gets the output handler responsible for writing to the terminal.
///
IOutput GetOutput ();
/// Get the operating system clipboard.
IClipboard? Clipboard { get; }
#endregion Driver Components
#region Screen and Display
/// Gets the location and size of the terminal screen.
Rectangle Screen { get; }
///
/// Sets the screen size. is the source of truth for screen dimensions.
///
/// The new width in columns.
/// The new height in rows.
void SetScreenSize (int width, int height);
///
/// The event fired when the screen changes (size, position, etc.).
/// is the source of truth for screen dimensions.
///
event EventHandler? SizeChanged;
/// The number of columns visible in the terminal.
int Cols { get; set; }
/// The number of rows visible in the terminal.
int Rows { get; set; }
/// The leftmost column in the terminal.
int Left { get; set; }
/// The topmost row in the terminal.
int Top { get; set; }
#endregion Screen and Display
#region Color Support
/// Gets whether the supports TrueColor output.
bool SupportsTrueColor { get; }
///
/// Gets or sets whether the should use 16 colors instead of the default TrueColors.
///
///
///
/// Will be forced to if is
/// , indicating that the cannot support TrueColor.
///
///
///
bool Force16Colors { get; set; }
#endregion Color Support
#region Content Buffer
// BUGBUG: This should not be publicly settable.
///
/// Gets or sets the contents of the application output. The driver outputs this buffer to the terminal.
/// The format of the array is rows, columns. The first index is the row, the second index is the column.
///
Cell [,]? Contents { get; set; }
///
/// Gets or sets the clip rectangle that and are subject
/// to.
///
/// The rectangle describing the of region.
Region? Clip { get; set; }
/// Clears the of the driver.
void ClearContents ();
///
/// Fills the specified rectangle with the specified rune, using
///
event EventHandler ClearedContents;
#endregion Content Buffer
#region Drawing and Rendering
///
/// Gets the column last set by . and are used by
/// and to determine where to add content.
///
int Col { get; }
///
/// Gets the row last set by . and are used by
/// and to determine where to add content.
///
int Row { get; }
///
/// The that will be used for the next or
///
/// call.
///
Attribute CurrentAttribute { get; set; }
///
/// Updates and to the specified column and row in
/// .
/// Used by and to determine
/// where to add content.
///
///
/// This does not move the cursor on the screen, it only updates the internal state of the driver.
///
/// If or are negative or beyond
/// and
/// , the method still sets those properties.
///
///
/// Column to move to.
/// Row to move to.
void Move (int col, int row);
/// Tests if the specified rune is supported by the driver.
///
///
/// if the rune can be properly presented; if the driver does not
/// support displaying this rune.
///
bool IsRuneSupported (Rune rune);
/// Tests whether the specified coordinate are valid for drawing the specified Text.
/// Used to determine if one or two columns are required.
/// The column.
/// The row.
///
/// if the coordinate is outside the screen bounds or outside of
/// .
/// otherwise.
///
bool IsValidLocation (string text, int col, int row);
/// Adds the specified rune to the display at the current cursor position.
///
///
/// When the method returns, will be incremented by the number of columns
/// required, even if the new column value is outside of the
/// or screen
/// dimensions defined by .
///
///
/// If requires more than one column, and plus the number
/// of columns
/// needed exceeds the or screen dimensions, the default Unicode replacement
/// character (U+FFFD)
/// will be added instead.
///
///
/// Rune to add.
void AddRune (Rune rune);
///
/// Adds the specified to the display at the current cursor position. This method is a
/// convenience method that calls with the
/// constructor.
///
/// Character to add.
void AddRune (char c);
/// Adds the to the display at the cursor position.
///
///
/// When the method returns, will be incremented by the number of columns
/// required, unless the new column value is outside of the
/// or screen
/// dimensions defined by .
///
/// If requires more columns than are available, the output will be clipped.
///
/// String.
void AddStr (string str);
/// Fills the specified rectangle with the specified rune, using
///
/// The value of is honored. Any parts of the rectangle not in the clip will not be
/// drawn.
///
/// The Screen-relative rectangle.
/// The Rune used to fill the rectangle
void FillRect (Rectangle rect, Rune rune = default);
/// Selects the specified attribute as the attribute to use for future calls to AddRune and AddString.
/// Implementations should call base.SetAttribute(c).
/// C.
Attribute SetAttribute (Attribute c);
/// Gets the current .
/// The current attribute.
Attribute GetAttribute ();
///
/// Provide proper writing to send escape sequence recognized by the .
///
///
void WriteRaw (string ansi);
///
/// 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.
///
ConcurrentQueue GetSixels ();
///
/// Gets a string representation of .
///
///
public string ToString ();
///
/// Gets an ANSI escape sequence representation of . This is the
/// same output as would be written to the terminal to recreate the current screen contents.
///
///
public string ToAnsi ();
#endregion Drawing and Rendering
#region Cursor
///
/// Sets the position of the terminal cursor to and
/// .
///
void UpdateCursor ();
/// Gets the terminal cursor visibility.
/// The current
/// upon success
bool GetCursorVisibility (out CursorVisibility visibility);
/// Sets the terminal cursor visibility.
/// The wished
/// upon success
bool SetCursorVisibility (CursorVisibility visibility);
#endregion Cursor
#region Input Events
/// Event fired when a mouse event occurs.
event EventHandler? MouseEvent;
/// Event fired when a key is pressed down. This is a precursor to .
event EventHandler? KeyDown;
/// Event fired when a key is released.
///
/// Drivers that do not support key release events will fire this event after
/// processing is
/// complete.
///
event EventHandler? KeyUp;
///
/// Enqueues a key input event to the driver. For unit tests.
///
///
void EnqueueKeyEvent (Key key);
#endregion Input Events
#region ANSI Escape Sequences
///
/// Queues the given for execution
///
///
public void QueueAnsiRequest (AnsiEscapeSequenceRequest request);
#endregion ANSI Escape Sequences
}