#nullable enable
namespace Terminal.Gui;
/// Base interface for Terminal.Gui ConsoleDriver implementations.
///
/// There are currently four implementations: - (for Unix and Mac) -
/// - that uses the .NET Console API -
/// for unit testing.
///
public interface IConsoleDriver
{
/// Get the operating system clipboard.
IClipboard? Clipboard { get; }
/// Gets the location and size of the terminal screen.
Rectangle Screen { get; }
///
/// Gets or sets the clip rectangle that and are subject
/// to.
///
/// The rectangle describing the of region.
Region? Clip { get; set; }
///
/// Gets the column last set by . and are used by
/// and to determine where to add content.
///
int Col { get; }
/// The number of columns visible in the terminal.
int Cols { get; set; }
///
/// The contents of the application output. The driver outputs this buffer to the terminal when
/// is called.
/// The format of the array is rows, columns. The first index is the row, the second index is the column.
///
Cell [,]? Contents { get; set; }
/// The leftmost column in the terminal.
int Left { get; set; }
///
/// Gets the row last set by . and are used by
/// and to determine where to add content.
///
int Row { get; }
/// The number of rows visible in the terminal.
int Rows { get; set; }
/// The topmost row in the terminal.
int Top { get; set; }
/// Gets whether the supports TrueColor output.
bool SupportsTrueColor { get; }
///
/// Gets or sets whether the should use 16 colors instead of the default TrueColors.
/// See to change this setting via .
///
///
///
/// Will be forced to if is
/// , indicating that the cannot support TrueColor.
///
///
bool Force16Colors { get; set; }
///
/// The that will be used for the next or
/// call.
///
Attribute CurrentAttribute { get; set; }
/// Returns the name of the driver and relevant library version information.
///
string GetVersionInfo ();
///
/// Provide proper writing to send escape sequence recognized by the .
///
///
void WriteRaw (string ansi);
/// 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 column.
/// The row.
///
/// if the coordinate is outside the screen bounds or outside of .
/// otherwise.
///
bool IsValidLocation (int col, int row);
/// Tests whether the specified coordinate are valid for drawing the specified Rune.
/// 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 (Rune rune, int col, int row);
///
/// 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);
/// 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);
///
/// Fills the specified rectangle with the specified . This method is a convenience method
/// that calls .
///
///
///
void FillRect (Rectangle rect, char c);
/// Clears the of the driver.
void ClearContents ();
///
/// Raised each time is called. For benchmarking.
///
event EventHandler? ClearedContents;
///
/// Sets as dirty for situations where views
/// don't need layout and redrawing, but just refresh the screen.
///
void SetContentsAsDirty ();
/// Determines if the terminal cursor should be visible or not and sets it accordingly.
/// upon success
bool EnsureCursorVisibility ();
/// Gets the terminal cursor visibility.
/// The current
/// upon success
bool GetCursorVisibility (out CursorVisibility visibility);
/// Called when the terminal size changes. Fires the event.
///
void OnSizeChanged (SizeChangedEventArgs args);
/// Updates the screen to reflect all the changes that have been done to the display buffer
void Refresh ();
///
/// Raised each time is called. For benchmarking.
///
event EventHandler>? Refreshed;
/// Sets the terminal cursor visibility.
/// The wished
/// upon success
bool SetCursorVisibility (CursorVisibility visibility);
/// The event fired when the terminal is resized.
event EventHandler? SizeChanged;
/// Suspends the application (e.g. on Linux via SIGTSTP) and upon resume, resets the console driver.
/// This is only implemented in .
void Suspend ();
/// Sets the position of the terminal cursor to and .
void UpdateCursor ();
/// Redraws the physical screen with the contents that have been queued up via any of the printing commands.
/// if any updates to the screen were made.
bool UpdateScreen ();
/// Initializes the driver
/// Returns an instance of using the for the driver.
MainLoop Init ();
/// Ends the execution of the console driver.
void End ();
/// 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 ();
/// Makes an .
/// The foreground color.
/// The background color.
/// The attribute for the foreground and background colors.
Attribute MakeColor (in Color foreground, in Color background);
/// Event fired when a mouse event occurs.
event EventHandler? MouseEvent;
/// Called when a mouse event occurs. Fires the event.
///
void OnMouseEvent (MouseEventArgs a);
/// Event fired when a key is pressed down. This is a precursor to .
event EventHandler? KeyDown;
///
/// Called when a key is pressed down. Fires the event. This is a precursor to
/// .
///
///
void OnKeyDown (Key a);
/// 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;
/// Called when a key is released. Fires the event.
///
/// Drivers that do not support key release events will call this method after processing
/// is complete.
///
///
void OnKeyUp (Key a);
/// Simulates a key press.
/// The key character.
/// The key.
/// If simulates the Shift key being pressed.
/// If simulates the Alt key being pressed.
/// If simulates the Ctrl key being pressed.
void SendKeys (char keyChar, ConsoleKey key, bool shift, bool alt, bool ctrl);
}