diff --git a/NativeAot/Program.cs b/NativeAot/Program.cs index bb0f38bc0..e9c8cf77f 100644 --- a/NativeAot/Program.cs +++ b/NativeAot/Program.cs @@ -9,8 +9,8 @@ namespace NativeAot; public static class Program { - [RequiresUnreferencedCode ("Calls Terminal.Gui.Application.Init(ConsoleDriver, String)")] - [RequiresDynamicCode ("Calls Terminal.Gui.Application.Init(ConsoleDriver, String)")] + [RequiresUnreferencedCode ("Calls Terminal.Gui.Application.Init(IConsoleDriver, String)")] + [RequiresDynamicCode ("Calls Terminal.Gui.Application.Init(IConsoleDriver, String)")] private static void Main (string [] args) { Application.Init (); diff --git a/SelfContained/Program.cs b/SelfContained/Program.cs index 29b7f5cd9..c57f39e58 100644 --- a/SelfContained/Program.cs +++ b/SelfContained/Program.cs @@ -9,7 +9,7 @@ namespace SelfContained; public static class Program { - [RequiresUnreferencedCode ("Calls Terminal.Gui.Application.Run(Func, ConsoleDriver)")] + [RequiresUnreferencedCode ("Calls Terminal.Gui.Application.Run(Func, IConsoleDriver)")] private static void Main (string [] args) { Application.Init (); diff --git a/Terminal.Gui/Application/Application.Driver.cs b/Terminal.Gui/Application/Application.Driver.cs index c2f6431db..7b3340cbd 100644 --- a/Terminal.Gui/Application/Application.Driver.cs +++ b/Terminal.Gui/Application/Application.Driver.cs @@ -5,13 +5,13 @@ public static partial class Application // Driver abstractions { internal static bool _forceFakeConsole; - /// Gets the that has been selected. See also . - public static ConsoleDriver? Driver { get; internal set; } + /// Gets the that has been selected. See also . + public static IConsoleDriver? Driver { get; internal set; } /// /// Gets or sets whether will be forced to output only the 16 colors defined in /// . The default is , meaning 24-bit (TrueColor) colors will be output - /// as long as the selected supports TrueColor. + /// as long as the selected supports TrueColor. /// [SerializableConfigurationProperty (Scope = typeof (SettingsScope))] public static bool Force16Colors { get; set; } @@ -21,7 +21,7 @@ public static partial class Application // Driver abstractions /// specified, the driver is selected based on the platform. /// /// - /// Note, will override this configuration setting if called + /// Note, will override this configuration setting if called /// with either `driver` or `driverName` specified. /// [SerializableConfigurationProperty (Scope = typeof (SettingsScope))] diff --git a/Terminal.Gui/Application/Application.Initialization.cs b/Terminal.Gui/Application/Application.Initialization.cs index 47c07a19f..31cfa09df 100644 --- a/Terminal.Gui/Application/Application.Initialization.cs +++ b/Terminal.Gui/Application/Application.Initialization.cs @@ -10,7 +10,7 @@ public static partial class Application // Initialization (Init/Shutdown) /// Initializes a new instance of Application. /// Call this method once per instance (or after has been called). /// - /// This function loads the right for the platform, Creates a . and + /// This function loads the right for the platform, Creates a . and /// assigns it to /// /// @@ -21,23 +21,23 @@ public static partial class Application // Initialization (Init/Shutdown) /// /// /// The function combines - /// and + /// and /// into a single /// call. An application cam use without explicitly calling - /// . + /// . /// /// - /// The to use. If neither or + /// The to use. If neither or /// are specified the default driver for the platform will be used. /// /// /// The short name (e.g. "net", "windows", "ansi", "fake", or "curses") of the - /// to use. If neither or are + /// to use. If neither or are /// specified the default driver for the platform will be used. /// [RequiresUnreferencedCode ("AOT")] [RequiresDynamicCode ("AOT")] - public static void Init (ConsoleDriver? driver = null, string? driverName = null) { InternalInit (driver, driverName); } + public static void Init (IConsoleDriver? driver = null, string? driverName = null) { InternalInit (driver, driverName); } internal static int MainThreadId { get; set; } = -1; @@ -53,7 +53,7 @@ public static partial class Application // Initialization (Init/Shutdown) [RequiresUnreferencedCode ("AOT")] [RequiresDynamicCode ("AOT")] internal static void InternalInit ( - ConsoleDriver? driver = null, + IConsoleDriver? driver = null, string? driverName = null, bool calledViaRunT = false ) @@ -136,7 +136,7 @@ public static partial class Application // Initialization (Init/Shutdown) if (driverType is { }) { - Driver = (ConsoleDriver)Activator.CreateInstance (driverType)!; + Driver = (IConsoleDriver)Activator.CreateInstance (driverType)!; } else { @@ -181,7 +181,7 @@ public static partial class Application // Initialization (Init/Shutdown) private static void Driver_KeyUp (object? sender, Key e) { RaiseKeyUpEvent (e); } private static void Driver_MouseEvent (object? sender, MouseEventArgs e) { RaiseMouseEvent (e); } - /// Gets of list of types that are available. + /// Gets of list of types that are available. /// [RequiresUnreferencedCode ("AOT")] public static List GetDriverTypes () @@ -193,7 +193,7 @@ public static partial class Application // Initialization (Init/Shutdown) { foreach (Type? type in asm.GetTypes ()) { - if (type.IsSubclassOf (typeof (ConsoleDriver)) && !type.IsAbstract) + if (type.IsSubclassOf (typeof (IConsoleDriver)) && !type.IsAbstract) { driverTypes.Add (type); } diff --git a/Terminal.Gui/Application/Application.Keyboard.cs b/Terminal.Gui/Application/Application.Keyboard.cs index 18881d6c5..16ddcf66c 100644 --- a/Terminal.Gui/Application/Application.Keyboard.cs +++ b/Terminal.Gui/Application/Application.Keyboard.cs @@ -4,7 +4,7 @@ namespace Terminal.Gui; public static partial class Application // Keyboard handling { /// - /// Called when the user presses a key (by the ). Raises the cancelable + /// Called when the user presses a key (by the ). Raises the cancelable /// event, then calls on all top level views, and finally /// if the key was not handled, invokes any Application-scoped . /// @@ -111,7 +111,7 @@ public static partial class Application // Keyboard handling public static event EventHandler? KeyDown; /// - /// Called when the user releases a key (by the ). Raises the cancelable + /// Called when the user releases a key (by the ). Raises the cancelable /// event /// then calls on all top level views. Called after . /// diff --git a/Terminal.Gui/Application/Application.Run.cs b/Terminal.Gui/Application/Application.Run.cs index 7511f8216..cf70ff5e3 100644 --- a/Terminal.Gui/Application/Application.Run.cs +++ b/Terminal.Gui/Application/Application.Run.cs @@ -305,7 +305,7 @@ public static partial class Application // Run (Begin, Run, End, Stop) /// The created object. The caller is responsible for disposing this object. [RequiresUnreferencedCode ("AOT")] [RequiresDynamicCode ("AOT")] - public static Toplevel Run (Func? errorHandler = null, ConsoleDriver? driver = null) { return Run (errorHandler, driver); } + public static Toplevel Run (Func? errorHandler = null, IConsoleDriver? driver = null) { return Run (errorHandler, driver); } /// /// Runs the application by creating a -derived object of type T and calling @@ -323,14 +323,14 @@ public static partial class Application // Run (Begin, Run, End, Stop) /// /// /// - /// The to use. If not specified the default driver for the platform will + /// The to use. If not specified the default driver for the platform will /// be used ( , , or ). Must be /// if has already been called. /// /// The created T object. The caller is responsible for disposing this object. [RequiresUnreferencedCode ("AOT")] [RequiresDynamicCode ("AOT")] - public static T Run (Func? errorHandler = null, ConsoleDriver? driver = null) + public static T Run (Func? errorHandler = null, IConsoleDriver? driver = null) where T : Toplevel, new() { if (!Initialized) @@ -369,7 +369,7 @@ public static partial class Application // Run (Begin, Run, End, Stop) /// return control immediately. /// /// When using or - /// + /// /// will be called automatically. /// /// diff --git a/Terminal.Gui/Application/Application.Screen.cs b/Terminal.Gui/Application/Application.Screen.cs index c5bf6d6fd..a322aa31f 100644 --- a/Terminal.Gui/Application/Application.Screen.cs +++ b/Terminal.Gui/Application/Application.Screen.cs @@ -6,11 +6,11 @@ public static partial class Application // Screen related stuff private static Rectangle? _screen; /// - /// Gets or sets the size of the screen. By default, this is the size of the screen as reported by the . + /// Gets or sets the size of the screen. By default, this is the size of the screen as reported by the . /// /// /// - /// If the has not been initialized, this will return a default size of 2048x2048; useful for unit tests. + /// If the has not been initialized, this will return a default size of 2048x2048; useful for unit tests. /// /// public static Rectangle Screen diff --git a/Terminal.Gui/Application/Application.cs b/Terminal.Gui/Application/Application.cs index d9e6c68d9..216f8a90d 100644 --- a/Terminal.Gui/Application/Application.cs +++ b/Terminal.Gui/Application/Application.cs @@ -32,7 +32,7 @@ public static partial class Application /// A string representation of the Application public new static string ToString () { - ConsoleDriver? driver = Driver; + IConsoleDriver? driver = Driver; if (driver is null) { @@ -43,11 +43,11 @@ public static partial class Application } /// - /// Gets a string representation of the Application rendered by the provided . + /// Gets a string representation of the Application rendered by the provided . /// /// The driver to use to render the contents. /// A string representation of the Application - public static string ToString (ConsoleDriver? driver) + public static string ToString (IConsoleDriver? driver) { if (driver is null) { diff --git a/Terminal.Gui/Application/MainLoop.cs b/Terminal.Gui/Application/MainLoop.cs index 9d8c08d37..2d463ab70 100644 --- a/Terminal.Gui/Application/MainLoop.cs +++ b/Terminal.Gui/Application/MainLoop.cs @@ -37,7 +37,7 @@ internal interface IMainLoopDriver /// Monitoring of file descriptors is only available on Unix, there does not seem to be a way of supporting this /// on Windows. /// -internal class MainLoop : IDisposable +public class MainLoop : IDisposable { internal List> _idleHandlers = new (); internal SortedList _timeouts = new (); @@ -50,7 +50,7 @@ internal class MainLoop : IDisposable /// Creates a new MainLoop. /// Use to release resources. /// - /// The instance (one of the implementations FakeMainLoop, UnixMainLoop, + /// The instance (one of the implementations FakeMainLoop, UnixMainLoop, /// NetMainLoop or WindowsMainLoop). /// internal MainLoop (IMainLoopDriver driver) diff --git a/Terminal.Gui/Clipboard/Clipboard.cs b/Terminal.Gui/Clipboard/Clipboard.cs index f8bf907c7..ecb59205f 100644 --- a/Terminal.Gui/Clipboard/Clipboard.cs +++ b/Terminal.Gui/Clipboard/Clipboard.cs @@ -111,7 +111,7 @@ public static class Clipboard /// /// Helper class for console drivers to invoke shell commands to interact with the clipboard. Used primarily by -/// CursesDriver, but also used in Unit tests which is why it is in ConsoleDriver.cs. +/// CursesDriver, but also used in Unit tests which is why it is in IConsoleDriver.cs. /// internal static class ClipboardProcessRunner { diff --git a/Terminal.Gui/Clipboard/ClipboardBase.cs b/Terminal.Gui/Clipboard/ClipboardBase.cs index 8c01e9c43..8c1c0a93a 100644 --- a/Terminal.Gui/Clipboard/ClipboardBase.cs +++ b/Terminal.Gui/Clipboard/ClipboardBase.cs @@ -103,7 +103,7 @@ public abstract class ClipboardBase : IClipboard } /// - /// Returns the contents of the OS clipboard if possible. Implemented by -specific + /// Returns the contents of the OS clipboard if possible. Implemented by -specific /// subclasses. /// /// The contents of the OS clipboard if successful. @@ -111,7 +111,7 @@ public abstract class ClipboardBase : IClipboard protected abstract string GetClipboardDataImpl (); /// - /// Pastes the to the OS clipboard if possible. Implemented by + /// Pastes the to the OS clipboard if possible. Implemented by /// -specific subclasses. /// /// The text to paste to the OS clipboard. diff --git a/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs b/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs index 9b57f20db..c4e0e385c 100644 --- a/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs @@ -4,13 +4,300 @@ using System.Diagnostics; namespace Terminal.Gui; +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); +} + /// Base class for Terminal.Gui ConsoleDriver implementations. /// /// There are currently four implementations: - (for Unix and Mac) - /// - that uses the .NET Console API - /// for unit testing. /// -public abstract class ConsoleDriver +public abstract class ConsoleDriver : IConsoleDriver { /// /// Set this to true in any unit tests that attempt to test drivers other than FakeDriver. @@ -38,7 +325,7 @@ public abstract class ConsoleDriver /// Provide proper writing to send escape sequence recognized by the . /// /// - internal abstract void WriteRaw (string ansi); + public abstract void WriteRaw (string ansi); #endregion ANSI Esc Sequence Handling @@ -50,7 +337,7 @@ public abstract class ConsoleDriver // QUESTION: When non-full screen apps are supported, will this represent the app size, or will that be in Application? /// Gets the location and size of the terminal screen. - internal Rectangle Screen => new (0, 0, Cols, Rows); + public Rectangle Screen => new (0, 0, Cols, Rows); private Region? _clip; @@ -59,7 +346,7 @@ public abstract class ConsoleDriver /// to. /// /// The rectangle describing the of region. - internal Region? Clip + public Region? Clip { get => _clip; set @@ -83,10 +370,10 @@ public abstract class ConsoleDriver /// Gets the column last set by . and are used by /// and to determine where to add content. /// - internal int Col { get; private set; } + public int Col { get; private set; } /// The number of columns visible in the terminal. - internal virtual int Cols + public virtual int Cols { get => _cols; set @@ -101,10 +388,10 @@ public abstract class ConsoleDriver /// is called. /// The format of the array is rows, columns. The first index is the row, the second index is the column. /// - internal Cell [,]? Contents { get; set; } + public Cell [,]? Contents { get; set; } /// The leftmost column in the terminal. - internal virtual int Left { get; set; } = 0; + public virtual int Left { get; set; } = 0; /// Tests if the specified rune is supported by the driver. /// @@ -147,10 +434,10 @@ public abstract class ConsoleDriver /// Gets the row last set by . and are used by /// and to determine where to add content. /// - internal int Row { get; private set; } + public int Row { get; private set; } /// The number of rows visible in the terminal. - internal virtual int Rows + public virtual int Rows { get => _rows; set @@ -161,7 +448,7 @@ public abstract class ConsoleDriver } /// The topmost row in the terminal. - internal virtual int Top { get; set; } = 0; + public virtual int Top { get; set; } = 0; /// Adds the specified rune to the display at the current cursor position. /// @@ -177,7 +464,7 @@ public abstract class ConsoleDriver /// /// /// Rune to add. - internal void AddRune (Rune rune) + public void AddRune (Rune rune) { int runeWidth = -1; bool validLocation = IsValidLocation (rune, Col, Row); @@ -352,7 +639,7 @@ public abstract class ConsoleDriver /// convenience method that calls with the constructor. /// /// Character to add. - internal void AddRune (char c) { AddRune (new Rune (c)); } + public void AddRune (char c) { AddRune (new Rune (c)); } /// Adds the to the display at the cursor position. /// @@ -364,7 +651,7 @@ public abstract class ConsoleDriver /// If requires more columns than are available, the output will be clipped. /// /// String. - internal void AddStr (string str) + public void AddStr (string str) { List runes = str.EnumerateRunes ().ToList (); @@ -380,7 +667,7 @@ public abstract class ConsoleDriver /// /// The Screen-relative rectangle. /// The Rune used to fill the rectangle - internal void FillRect (Rectangle rect, Rune rune = default) + public void FillRect (Rectangle rect, Rune rune = default) { // BUGBUG: This should be a method on Region rect = Rectangle.Intersect (rect, Clip?.GetBounds () ?? Screen); @@ -406,7 +693,7 @@ public abstract class ConsoleDriver } /// Clears the of the driver. - internal void ClearContents () + public void ClearContents () { Contents = new Cell [Rows, Cols]; @@ -446,7 +733,7 @@ public abstract class ConsoleDriver /// Sets as dirty for situations where views /// don't need layout and redrawing, but just refresh the screen. /// - internal void SetContentsAsDirty () + public void SetContentsAsDirty () { lock (Contents!) { @@ -468,7 +755,7 @@ public abstract class ConsoleDriver /// /// /// - internal void FillRect (Rectangle rect, char c) { FillRect (rect, new Rune (c)); } + public void FillRect (Rectangle rect, char c) { FillRect (rect, new Rune (c)); } #endregion Screen and Contents @@ -491,7 +778,7 @@ public abstract class ConsoleDriver /// if the coordinate is outside the screen bounds or outside of . /// otherwise. /// - internal bool IsValidLocation (Rune rune, int col, int row) + public bool IsValidLocation (Rune rune, int col, int row) { if (rune.GetColumns () < 2) { @@ -506,10 +793,10 @@ public abstract class ConsoleDriver /// Called when the terminal size changes. Fires the event. /// - internal void OnSizeChanged (SizeChangedEventArgs args) { SizeChanged?.Invoke (this, args); } + public void OnSizeChanged (SizeChangedEventArgs args) { SizeChanged?.Invoke (this, args); } /// Updates the screen to reflect all the changes that have been done to the display buffer - internal void Refresh () + public void Refresh () { bool updated = UpdateScreen (); UpdateCursor (); @@ -547,10 +834,10 @@ public abstract class ConsoleDriver /// Initializes the driver /// Returns an instance of using the for the driver. - internal abstract MainLoop Init (); + public abstract MainLoop Init (); /// Ends the execution of the console driver. - internal abstract void End (); + public abstract void End (); #endregion @@ -571,7 +858,7 @@ public abstract class ConsoleDriver /// , indicating that the cannot support TrueColor. /// /// - internal virtual bool Force16Colors + public virtual bool Force16Colors { get => Application.Force16Colors || !SupportsTrueColor; set => Application.Force16Colors = value || !SupportsTrueColor; @@ -605,7 +892,7 @@ public abstract class ConsoleDriver /// Selects the specified attribute as the attribute to use for future calls to AddRune and AddString. /// Implementations should call base.SetAttribute(c). /// C. - internal Attribute SetAttribute (Attribute c) + public Attribute SetAttribute (Attribute c) { Attribute prevAttribute = CurrentAttribute; CurrentAttribute = c; @@ -615,7 +902,7 @@ public abstract class ConsoleDriver /// Gets the current . /// The current attribute. - internal Attribute GetAttribute () { return CurrentAttribute; } + public Attribute GetAttribute () { return CurrentAttribute; } // TODO: This is only overridden by CursesDriver. Once CursesDriver supports 24-bit color, this virtual method can be // removed (and Attribute can lose the platformColor property). diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs index d40652dd3..43330eab3 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs @@ -14,7 +14,7 @@ internal class CursesDriver : ConsoleDriver { public override string GetVersionInfo () { return $"{Curses.curses_version ()}"; } - internal override int Cols + public override int Cols { get => Curses.Cols; set @@ -24,7 +24,7 @@ internal class CursesDriver : ConsoleDriver } } - internal override int Rows + public override int Rows { get => Curses.Lines; set @@ -582,7 +582,7 @@ internal class CursesDriver : ConsoleDriver private UnixMainLoop? _mainLoopDriver; private object _processInputToken; - internal override MainLoop Init () + public override MainLoop Init () { _mainLoopDriver = new (this); @@ -1084,7 +1084,7 @@ internal class CursesDriver : ConsoleDriver } } - internal override void End () + public override void End () { EscSeqUtils.ContinuousButtonPressed -= EscSeqUtils_ContinuousButtonPressed; @@ -1128,7 +1128,7 @@ internal class CursesDriver : ConsoleDriver } /// - internal override void WriteRaw (string ansi) { _mainLoopDriver?.WriteRaw (ansi); } + public override void WriteRaw (string ansi) { _mainLoopDriver?.WriteRaw (ansi); } } // TODO: One type per file - move to another file diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs index c6414a2b9..28df408ea 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs +++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs @@ -48,11 +48,11 @@ internal class UnixMainLoop : IMainLoopDriver private Pollfd []? _pollMap; private bool _winChanged; - public UnixMainLoop (ConsoleDriver consoleDriver) + public UnixMainLoop (IConsoleDriver IConsoleDriver) { - ArgumentNullException.ThrowIfNull (consoleDriver); + ArgumentNullException.ThrowIfNull (IConsoleDriver); - _cursesDriver = (CursesDriver)consoleDriver; + _cursesDriver = (CursesDriver)IConsoleDriver; } void IMainLoopDriver.Wakeup () diff --git a/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs b/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs index 7d82737cc..a9117cee4 100644 --- a/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs @@ -76,7 +76,7 @@ public class FakeDriver : ConsoleDriver } } - internal override void End () + public override void End () { FakeConsole.ResetColor (); FakeConsole.Clear (); @@ -84,7 +84,7 @@ public class FakeDriver : ConsoleDriver private FakeMainLoop _mainLoopDriver; - internal override MainLoop Init () + public override MainLoop Init () { FakeConsole.MockKeyPresses.Clear (); @@ -393,7 +393,7 @@ public class FakeDriver : ConsoleDriver } /// - internal override void WriteRaw (string ansi) { throw new NotImplementedException (); } + public override void WriteRaw (string ansi) { throw new NotImplementedException (); } public void SetBufferSize (int width, int height) { diff --git a/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeMainLoop.cs b/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeMainLoop.cs index d90caace7..ebc3ae684 100644 --- a/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeMainLoop.cs +++ b/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeMainLoop.cs @@ -4,7 +4,7 @@ internal class FakeMainLoop : IMainLoopDriver { public Action MockKeyPressed; - public FakeMainLoop (ConsoleDriver consoleDriver = null) + public FakeMainLoop (IConsoleDriver IConsoleDriver = null) { // No implementation needed for FakeMainLoop } diff --git a/Terminal.Gui/ConsoleDrivers/KeyCode.cs b/Terminal.Gui/ConsoleDrivers/KeyCode.cs index 183322ec8..2a89667ea 100644 --- a/Terminal.Gui/ConsoleDrivers/KeyCode.cs +++ b/Terminal.Gui/ConsoleDrivers/KeyCode.cs @@ -2,7 +2,7 @@ namespace Terminal.Gui; /// -/// The enumeration encodes key information from s and provides a +/// The enumeration encodes key information from s and provides a /// consistent way for application code to specify keys and receive key events. /// /// The class provides a higher-level abstraction, with helper methods and properties for diff --git a/Terminal.Gui/ConsoleDrivers/NetDriver/NetDriver.cs b/Terminal.Gui/ConsoleDrivers/NetDriver/NetDriver.cs index c477f27e6..62c6db94b 100644 --- a/Terminal.Gui/ConsoleDrivers/NetDriver/NetDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/NetDriver/NetDriver.cs @@ -226,7 +226,7 @@ internal class NetDriver : ConsoleDriver internal NetMainLoop? _mainLoopDriver; - internal override MainLoop Init () + public override MainLoop Init () { PlatformID p = Environment.OSVersion.Platform; @@ -350,7 +350,7 @@ internal class NetDriver : ConsoleDriver } } - internal override void End () + public override void End () { if (IsWinPlatform) { @@ -717,7 +717,7 @@ internal class NetDriver : ConsoleDriver #region Low-Level DotNet tuff /// - internal override void WriteRaw (string ansi) + public override void WriteRaw (string ansi) { Console.Out.Write (ansi); Console.Out.Flush (); diff --git a/Terminal.Gui/ConsoleDrivers/NetDriver/NetEvents.cs b/Terminal.Gui/ConsoleDrivers/NetDriver/NetEvents.cs index d03a1fd9d..c0dcaffb4 100644 --- a/Terminal.Gui/ConsoleDrivers/NetDriver/NetEvents.cs +++ b/Terminal.Gui/ConsoleDrivers/NetDriver/NetEvents.cs @@ -8,15 +8,15 @@ internal class NetEvents : IDisposable private readonly ManualResetEventSlim _inputReady = new (false); private CancellationTokenSource? _inputReadyCancellationTokenSource; private readonly Queue _inputQueue = new (); - private readonly ConsoleDriver _consoleDriver; + private readonly IConsoleDriver _consoleDriver; private ConsoleKeyInfo []? _cki; private bool _isEscSeq; #if PROCESS_REQUEST bool _neededProcessRequest; #endif - public NetEvents (ConsoleDriver consoleDriver) + public NetEvents (IConsoleDriver IConsoleDriver) { - _consoleDriver = consoleDriver ?? throw new ArgumentNullException (nameof (consoleDriver)); + _consoleDriver = IConsoleDriver ?? throw new ArgumentNullException (nameof (IConsoleDriver)); _inputReadyCancellationTokenSource = new (); Task.Run (ProcessInputQueue, _inputReadyCancellationTokenSource.Token); diff --git a/Terminal.Gui/ConsoleDrivers/NetDriver/NetMainLoop.cs b/Terminal.Gui/ConsoleDrivers/NetDriver/NetMainLoop.cs index 08efe66d5..7632c49fb 100644 --- a/Terminal.Gui/ConsoleDrivers/NetDriver/NetMainLoop.cs +++ b/Terminal.Gui/ConsoleDrivers/NetDriver/NetMainLoop.cs @@ -24,16 +24,16 @@ internal class NetMainLoop : IMainLoopDriver private MainLoop? _mainLoop; /// Initializes the class with the console driver. - /// Passing a consoleDriver is provided to capture windows resizing. - /// The console driver used by this Net main loop. + /// Passing a IConsoleDriver is provided to capture windows resizing. + /// The console driver used by this Net main loop. /// - public NetMainLoop (ConsoleDriver consoleDriver) + public NetMainLoop (IConsoleDriver IConsoleDriver) { - ArgumentNullException.ThrowIfNull (consoleDriver); + ArgumentNullException.ThrowIfNull (IConsoleDriver); if (!ConsoleDriver.RunningUnitTests) { - _netEvents = new (consoleDriver); + _netEvents = new (IConsoleDriver); } } diff --git a/Terminal.Gui/ConsoleDrivers/WindowsDriver/WindowsDriver.cs b/Terminal.Gui/ConsoleDrivers/WindowsDriver/WindowsDriver.cs index f18616fd2..251ad4dad 100644 --- a/Terminal.Gui/ConsoleDrivers/WindowsDriver/WindowsDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/WindowsDriver/WindowsDriver.cs @@ -187,7 +187,7 @@ internal class WindowsDriver : ConsoleDriver } } - internal override void WriteRaw (string ansi) { WinConsole?.WriteANSI (ansi); } + public override void WriteRaw (string ansi) { WinConsole?.WriteANSI (ansi); } #region Not Implemented @@ -402,7 +402,7 @@ internal class WindowsDriver : ConsoleDriver return updated; } - internal override void End () + public override void End () { if (_mainLoopDriver is { }) { @@ -424,7 +424,7 @@ internal class WindowsDriver : ConsoleDriver } } - internal override MainLoop Init () + public override MainLoop Init () { _mainLoopDriver = new WindowsMainLoop (this); @@ -867,7 +867,7 @@ internal class WindowsDriver : ConsoleDriver int delay = START_DELAY; while (_isButtonPressed) { - // TODO: This makes ConsoleDriver dependent on Application, which is not ideal. This should be moved to Application. + // TODO: This makes IConsoleDriver dependent on Application, which is not ideal. This should be moved to Application. View? view = Application.WantContinuousButtonPressedView; if (view is null) @@ -890,7 +890,7 @@ internal class WindowsDriver : ConsoleDriver //Debug.WriteLine($"ProcessContinuousButtonPressedAsync: {view}"); if (_isButtonPressed && (mouseFlag & MouseFlags.ReportMousePosition) == 0) { - // TODO: This makes ConsoleDriver dependent on Application, which is not ideal. This should be moved to Application. + // TODO: This makes IConsoleDriver dependent on Application, which is not ideal. This should be moved to Application. Application.Invoke (() => OnMouseEvent (me)); } } @@ -945,7 +945,7 @@ internal class WindowsDriver : ConsoleDriver if (_isButtonDoubleClicked || _isOneFingerDoubleClicked) { - // TODO: This makes ConsoleDriver dependent on Application, which is not ideal. This should be moved to Application. + // TODO: This makes IConsoleDriver dependent on Application, which is not ideal. This should be moved to Application. Application.MainLoop!.AddIdle ( () => { @@ -1017,7 +1017,7 @@ internal class WindowsDriver : ConsoleDriver if ((mouseFlag & MouseFlags.ReportMousePosition) == 0) { - // TODO: This makes ConsoleDriver dependent on Application, which is not ideal. This should be moved to Application. + // TODO: This makes IConsoleDriver dependent on Application, which is not ideal. This should be moved to Application. Application.MainLoop!.AddIdle ( () => { diff --git a/Terminal.Gui/ConsoleDrivers/WindowsDriver/WindowsMainLoop.cs b/Terminal.Gui/ConsoleDrivers/WindowsDriver/WindowsMainLoop.cs index 1cbe88211..12944b298 100644 --- a/Terminal.Gui/ConsoleDrivers/WindowsDriver/WindowsMainLoop.cs +++ b/Terminal.Gui/ConsoleDrivers/WindowsDriver/WindowsMainLoop.cs @@ -18,7 +18,7 @@ internal class WindowsMainLoop : IMainLoopDriver /// public EventHandler? WinChanged; - private readonly ConsoleDriver _consoleDriver; + private readonly IConsoleDriver _consoleDriver; private readonly ManualResetEventSlim _eventReady = new (false); // The records that we keep fetching @@ -29,13 +29,13 @@ internal class WindowsMainLoop : IMainLoopDriver private readonly CancellationTokenSource _inputHandlerTokenSource = new (); private MainLoop? _mainLoop; - public WindowsMainLoop (ConsoleDriver consoleDriver) + public WindowsMainLoop (IConsoleDriver IConsoleDriver) { - _consoleDriver = consoleDriver ?? throw new ArgumentNullException (nameof (consoleDriver)); + _consoleDriver = IConsoleDriver ?? throw new ArgumentNullException (nameof (IConsoleDriver)); if (!ConsoleDriver.RunningUnitTests) { - _winConsole = ((WindowsDriver)consoleDriver).WinConsole; + _winConsole = ((WindowsDriver)IConsoleDriver).WinConsole; _winConsole!._mainLoop = this; } } diff --git a/Terminal.Gui/Drawing/Attribute.cs b/Terminal.Gui/Drawing/Attribute.cs index 32c948d2e..a36601ba1 100644 --- a/Terminal.Gui/Drawing/Attribute.cs +++ b/Terminal.Gui/Drawing/Attribute.cs @@ -17,7 +17,7 @@ public readonly record struct Attribute : IEqualityOperators new (Color.White, Color.Black); - /// The -specific color value. + /// The -specific color value. [JsonIgnore (Condition = JsonIgnoreCondition.Always)] internal int PlatformColor { get; init; } diff --git a/Terminal.Gui/Drawing/Cell.cs b/Terminal.Gui/Drawing/Cell.cs index 16af046a7..5ce4e21df 100644 --- a/Terminal.Gui/Drawing/Cell.cs +++ b/Terminal.Gui/Drawing/Cell.cs @@ -2,7 +2,7 @@ /// /// Represents a single row/column in a Terminal.Gui rendering surface (e.g. and -/// ). +/// ). /// public record struct Cell (Attribute? Attribute = null, bool IsDirty = false, Rune Rune = default) { diff --git a/Terminal.Gui/Drawing/LineCanvas.cs b/Terminal.Gui/Drawing/LineCanvas.cs index 8261b156a..4a69a96b7 100644 --- a/Terminal.Gui/Drawing/LineCanvas.cs +++ b/Terminal.Gui/Drawing/LineCanvas.cs @@ -384,7 +384,7 @@ public class LineCanvas : IDisposable // TODO: Add other resolvers }; - private Cell? GetCellForIntersects (ConsoleDriver? driver, IntersectionDefinition? [] intersects) + private Cell? GetCellForIntersects (IConsoleDriver? driver, IntersectionDefinition? [] intersects) { if (!intersects.Any ()) { @@ -404,7 +404,7 @@ public class LineCanvas : IDisposable return cell; } - private Rune? GetRuneForIntersects (ConsoleDriver? driver, IntersectionDefinition? [] intersects) + private Rune? GetRuneForIntersects (IConsoleDriver? driver, IntersectionDefinition? [] intersects) { if (!intersects.Any ()) { @@ -727,7 +727,7 @@ public class LineCanvas : IDisposable internal Rune _thickV; protected IntersectionRuneResolver () { SetGlyphs (); } - public Rune? GetRuneForIntersects (ConsoleDriver? driver, IntersectionDefinition? [] intersects) + public Rune? GetRuneForIntersects (IConsoleDriver? driver, IntersectionDefinition? [] intersects) { bool useRounded = intersects.Any ( i => i?.Line.Length != 0 diff --git a/Terminal.Gui/Drawing/SixelToRender.cs b/Terminal.Gui/Drawing/SixelToRender.cs index dedd399ef..f9981f19f 100644 --- a/Terminal.Gui/Drawing/SixelToRender.cs +++ b/Terminal.Gui/Drawing/SixelToRender.cs @@ -2,7 +2,7 @@ /// /// Describes a request to render a given at a given . -/// Requires that the terminal and both support sixel. +/// Requires that the terminal and both support sixel. /// public class SixelToRender { diff --git a/Terminal.Gui/README.md b/Terminal.Gui/README.md index 5c22df0ac..a9ec75460 100644 --- a/Terminal.Gui/README.md +++ b/Terminal.Gui/README.md @@ -9,8 +9,8 @@ All files required to build the **Terminal.Gui** library (and NuGet package). - `Application\` - The core `Application` logic, including `Application.cs`, which is is a `static` class that provides the base 'application engine', `RunState`, and `MainLoop`. - `ConsoleDrivers\` - - `ConsoleDriver.cs` - Definition for the Console Driver API. - - Source files for the three `ConsoleDriver`-based drivers: .NET: `NetDriver`, Unix & Mac: `UnixDriver`, and Windows: `WindowsDriver`. + - `IConsoleDriver.cs` - Definition for the Console Driver API. + - Source files for the three `IConsoleDriver`-based drivers: .NET: `NetDriver`, Unix & Mac: `UnixDriver`, and Windows: `WindowsDriver`. - `Configuration\` - Classes related the `ConfigurationManager`. diff --git a/Terminal.Gui/Text/TextFormatter.cs b/Terminal.Gui/Text/TextFormatter.cs index 2938b69bc..90152452f 100644 --- a/Terminal.Gui/Text/TextFormatter.cs +++ b/Terminal.Gui/Text/TextFormatter.cs @@ -43,7 +43,7 @@ public class TextFormatter set => _textDirection = EnableNeedsFormat (value); } - /// Draws the text held by to using the colors specified. + /// Draws the text held by to using the colors specified. /// /// Causes the text to be formatted (references ). Sets to /// false. @@ -59,7 +59,7 @@ public class TextFormatter Attribute normalColor, Attribute hotColor, Rectangle maximum = default, - ConsoleDriver? driver = null + IConsoleDriver? driver = null ) { // With this check, we protect against subclasses with overrides of Text (like Button) diff --git a/Terminal.Gui/View/View.cs b/Terminal.Gui/View/View.cs index 27fcb065a..433822b4b 100644 --- a/Terminal.Gui/View/View.cs +++ b/Terminal.Gui/View/View.cs @@ -126,7 +126,7 @@ public partial class View : IDisposable, ISupportInitializeNotification /// Points to the current driver in use by the view, it is a convenience property for simplifying the development /// of new views. /// - public static ConsoleDriver? Driver => Application.Driver; + public static IConsoleDriver? Driver => Application.Driver; /// Initializes a new instance of . /// diff --git a/Terminal.Gui/Views/ColorPicker.Prompt.cs b/Terminal.Gui/Views/ColorPicker.Prompt.cs index 3f2372db9..0b79d3e9f 100644 --- a/Terminal.Gui/Views/ColorPicker.Prompt.cs +++ b/Terminal.Gui/Views/ColorPicker.Prompt.cs @@ -4,7 +4,7 @@ public partial class ColorPicker { /// /// Open a with two or , based on the - /// is false or true, respectively, for + /// is false or true, respectively, for /// and colors. /// /// The title to show in the dialog. diff --git a/Terminal.Gui/Views/GraphView/Axis.cs b/Terminal.Gui/Views/GraphView/Axis.cs index c46938890..01d78ee03 100644 --- a/Terminal.Gui/Views/GraphView/Axis.cs +++ b/Terminal.Gui/Views/GraphView/Axis.cs @@ -97,7 +97,7 @@ public class HorizontalAxis : Axis /// Text to render under the axis tick public override void DrawAxisLabel (GraphView graph, int screenPosition, string text) { - ConsoleDriver driver = Application.Driver; + IConsoleDriver driver = Application.Driver; int y = GetAxisYPosition (graph); graph.Move (screenPosition, y); diff --git a/Terminal.Gui/Views/Menu/MenuBar.cs b/Terminal.Gui/Views/Menu/MenuBar.cs index 7bba8b714..6da4f2125 100644 --- a/Terminal.Gui/Views/Menu/MenuBar.cs +++ b/Terminal.Gui/Views/Menu/MenuBar.cs @@ -667,7 +667,7 @@ public class MenuBar : View, IDesignable return true; } - /// Gets the superview location offset relative to the location. + /// Gets the superview location offset relative to the location. /// The location offset. internal Point GetScreenOffset () { diff --git a/Terminal.Gui/Views/TableView/TableStyle.cs b/Terminal.Gui/Views/TableView/TableStyle.cs index 4dd947734..ffc806880 100644 --- a/Terminal.Gui/Views/TableView/TableStyle.cs +++ b/Terminal.Gui/Views/TableView/TableStyle.cs @@ -29,7 +29,7 @@ public class TableStyle /// /// True to invert the colors of the first symbol of the selected cell in the . This gives - /// the appearance of a cursor for when the doesn't otherwise show this + /// the appearance of a cursor for when the doesn't otherwise show this /// public bool InvertSelectedCellFirstCharacter { get; set; } = false; diff --git a/Terminal.Gui/Views/TableView/TableView.cs b/Terminal.Gui/Views/TableView/TableView.cs index 468b851f6..68c5a037e 100644 --- a/Terminal.Gui/Views/TableView/TableView.cs +++ b/Terminal.Gui/Views/TableView/TableView.cs @@ -1277,7 +1277,7 @@ public class TableView : View, IDesignable /// /// Override to provide custom multi colouring to cells. Use to with - /// . The driver will already be in the correct place when rendering and you + /// . The driver will already be in the correct place when rendering and you /// must render the full or the view will not look right. For simpler provision of color use /// For changing the content that is rendered use /// @@ -1335,7 +1335,7 @@ public class TableView : View, IDesignable /// internal int GetHeaderHeightIfAny () { return ShouldRenderHeaders () ? GetHeaderHeight () : 0; } - private void AddRuneAt (ConsoleDriver d, int col, int row, Rune ch) + private void AddRuneAt (IConsoleDriver d, int col, int row, Rune ch) { Move (col, row); d?.AddRune (ch); diff --git a/Terminal.Gui/Views/TreeView/Branch.cs b/Terminal.Gui/Views/TreeView/Branch.cs index e2d220ace..e7a5eb4ca 100644 --- a/Terminal.Gui/Views/TreeView/Branch.cs +++ b/Terminal.Gui/Views/TreeView/Branch.cs @@ -73,7 +73,7 @@ internal class Branch where T : class /// /// /// - public virtual void Draw (ConsoleDriver driver, ColorScheme colorScheme, int y, int availableWidth) + public virtual void Draw (IConsoleDriver driver, ColorScheme colorScheme, int y, int availableWidth) { List cells = new (); int? indexOfExpandCollapseSymbol = null; @@ -291,7 +291,7 @@ internal class Branch where T : class /// /// /// - public Rune GetExpandableSymbol (ConsoleDriver driver) + public Rune GetExpandableSymbol (IConsoleDriver driver) { Rune leafSymbol = tree.Style.ShowBranchLines ? Glyphs.HLine : (Rune)' '; @@ -313,7 +313,7 @@ internal class Branch where T : class /// line body). /// /// - public virtual int GetWidth (ConsoleDriver driver) + public virtual int GetWidth (IConsoleDriver driver) { return GetLinePrefix (driver).Sum (r => r.GetColumns ()) + GetExpandableSymbol (driver).GetColumns () + (tree.AspectGetter (Model) ?? "").Length; @@ -408,7 +408,7 @@ internal class Branch where T : class /// /// /// - internal IEnumerable GetLinePrefix (ConsoleDriver driver) + internal IEnumerable GetLinePrefix (IConsoleDriver driver) { // If not showing line branches or this is a root object. if (!tree.Style.ShowBranchLines) @@ -453,7 +453,7 @@ internal class Branch where T : class /// /// /// - internal bool IsHitOnExpandableSymbol (ConsoleDriver driver, int x) + internal bool IsHitOnExpandableSymbol (IConsoleDriver driver, int x) { // if leaf node then we cannot expand if (!CanExpand ()) diff --git a/UICatalog/Scenarios/GraphViewExample.cs b/UICatalog/Scenarios/GraphViewExample.cs index 056086c64..f66463664 100644 --- a/UICatalog/Scenarios/GraphViewExample.cs +++ b/UICatalog/Scenarios/GraphViewExample.cs @@ -1000,7 +1000,7 @@ public class GraphViewExample : Scenario protected override void DrawBarLine (GraphView graph, Point start, Point end, BarSeriesBar beingDrawn) { - ConsoleDriver driver = Application.Driver; + IConsoleDriver driver = Application.Driver; int x = start.X; diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs index ba7e3f26d..fffa989f2 100644 --- a/UICatalog/UICatalog.cs +++ b/UICatalog/UICatalog.cs @@ -136,7 +136,7 @@ public class UICatalogApp // Process command line args // "UICatalog [--driver ] [--benchmark] [scenario name]" // If no driver is provided, the default driver is used. - Option driverOption = new Option ("--driver", "The ConsoleDriver to use.").FromAmong ( + Option driverOption = new Option ("--driver", "The IConsoleDriver to use.").FromAmong ( Application.GetDriverTypes () .Select (d => d!.Name) .ToArray () diff --git a/UnitTests/Application/ApplicationTests.cs b/UnitTests/Application/ApplicationTests.cs index 5e3bf43a2..ab44e66ef 100644 --- a/UnitTests/Application/ApplicationTests.cs +++ b/UnitTests/Application/ApplicationTests.cs @@ -248,7 +248,7 @@ public class ApplicationTests [InlineData (typeof (CursesDriver))] public void Init_DriverName_Should_Pick_Correct_Driver (Type driverType) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); Application.Init (driverName: driverType.Name); Assert.NotNull (Application.Driver); Assert.NotEqual (driver, Application.Driver); @@ -630,7 +630,7 @@ public class ApplicationTests driver.Cols = 100; driver.Rows = 30; - // ConsoleDriver.Screen isn't assignable + // IConsoleDriver.Screen isn't assignable //driver.Screen = new (0, 0, driver.Cols, Rows); Assert.Equal (new (0, 0, 100, 30), driver.Screen); Assert.NotEqual (new (0, 0, 100, 30), Application.Screen); diff --git a/UnitTests/ConsoleDrivers/AddRuneTests.cs b/UnitTests/ConsoleDrivers/AddRuneTests.cs index 6769db830..5c753386e 100644 --- a/UnitTests/ConsoleDrivers/AddRuneTests.cs +++ b/UnitTests/ConsoleDrivers/AddRuneTests.cs @@ -25,7 +25,7 @@ public class AddRuneTests [InlineData (typeof (CursesDriver))] public void AddRune (Type driverType) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); driver.Init (); driver.Rows = 25; diff --git a/UnitTests/ConsoleDrivers/ClipRegionTests.cs b/UnitTests/ConsoleDrivers/ClipRegionTests.cs index c85f7fec8..9e01f83ee 100644 --- a/UnitTests/ConsoleDrivers/ClipRegionTests.cs +++ b/UnitTests/ConsoleDrivers/ClipRegionTests.cs @@ -24,7 +24,7 @@ public class ClipRegionTests [InlineData (typeof (CursesDriver))] public void AddRune_Is_Clipped (Type driverType) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); Application.Init (driver); Application.Driver!.Rows = 25; Application.Driver!.Cols = 80; @@ -62,7 +62,7 @@ public class ClipRegionTests [InlineData (typeof (CursesDriver))] public void Clip_Set_To_Empty_AllInvalid (Type driverType) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); Application.Init (driver); // Define a clip rectangle @@ -92,7 +92,7 @@ public class ClipRegionTests [InlineData (typeof (CursesDriver))] public void IsValidLocation (Type driverType) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); Application.Init (driver); Application.Driver!.Rows = 10; Application.Driver!.Cols = 10; diff --git a/UnitTests/ConsoleDrivers/ConsoleDriverTests.cs b/UnitTests/ConsoleDrivers/ConsoleDriverTests.cs index 8ecc97807..d75a56639 100644 --- a/UnitTests/ConsoleDrivers/ConsoleDriverTests.cs +++ b/UnitTests/ConsoleDrivers/ConsoleDriverTests.cs @@ -25,7 +25,7 @@ public class ConsoleDriverTests [InlineData (typeof (CursesDriver))] public void End_Cleans_Up (Type driverType) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); driver.Init (); driver.End (); } @@ -34,7 +34,7 @@ public class ConsoleDriverTests [InlineData (typeof (FakeDriver))] public void FakeDriver_MockKeyPresses (Type driverType) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); Application.Init (driver); var text = "MockKeyPresses"; @@ -85,7 +85,7 @@ public class ConsoleDriverTests [InlineData (typeof (FakeDriver))] public void FakeDriver_Only_Sends_Keystrokes_Through_MockKeyPresses (Type driverType) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); Application.Init (driver); Toplevel top = new (); @@ -124,7 +124,7 @@ public class ConsoleDriverTests [InlineData (typeof (CursesDriver))] public void Init_Inits (Type driverType) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); MainLoop ml = driver.Init (); Assert.NotNull (ml); Assert.NotNull (driver.Clipboard); @@ -140,7 +140,7 @@ public class ConsoleDriverTests //[InlineData (typeof (FakeDriver))] //public void FakeDriver_MockKeyPresses_Press_AfterTimeOut (Type driverType) //{ - // var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + // var driver = (IConsoleDriver)Activator.CreateInstance (driverType); // Application.Init (driver); // // Simulating pressing of QuitKey after a short period of time @@ -201,7 +201,7 @@ public class ConsoleDriverTests [InlineData (typeof (CursesDriver))] public void TerminalResized_Simulation (Type driverType) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); driver?.Init (); driver.Cols = 80; driver.Rows = 25; diff --git a/UnitTests/ConsoleDrivers/ContentsTests.cs b/UnitTests/ConsoleDrivers/ContentsTests.cs index 0dd4be3bf..d0f2d83ff 100644 --- a/UnitTests/ConsoleDrivers/ContentsTests.cs +++ b/UnitTests/ConsoleDrivers/ContentsTests.cs @@ -24,7 +24,7 @@ public class ContentsTests //[InlineData (typeof (WindowsDriver))] // TODO: Uncomment when #2610 is fixed public void AddStr_Combining_Character_1st_Column (Type driverType) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); driver.Init (); var expected = "\u0301!"; driver.AddStr ("\u0301!"); // acute accent + exclamation mark @@ -42,7 +42,7 @@ public class ContentsTests //[InlineData (typeof (WindowsDriver))] // TODO: Uncomment when #2610 is fixed public void AddStr_With_Combining_Characters (Type driverType) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); driver.Init (); var acuteaccent = new Rune (0x0301); // Combining acute accent (é) @@ -98,7 +98,7 @@ public class ContentsTests [InlineData (typeof (CursesDriver))] public void Move_Bad_Coordinates (Type driverType) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); driver.Init (); Assert.Equal (0, driver.Col); diff --git a/UnitTests/ConsoleDrivers/DriverColorTests.cs b/UnitTests/ConsoleDrivers/DriverColorTests.cs index 8bebace1e..856e0481a 100644 --- a/UnitTests/ConsoleDrivers/DriverColorTests.cs +++ b/UnitTests/ConsoleDrivers/DriverColorTests.cs @@ -17,7 +17,7 @@ public class DriverColorTests [InlineData (typeof (CursesDriver))] public void Force16Colors_Sets (Type driverType) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); driver.Init (); driver.Force16Colors = true; @@ -35,7 +35,7 @@ public class DriverColorTests [InlineData (typeof (CursesDriver))] public void SetColors_Changes_Colors (Type driverType) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); driver.Init (); Assert.Equal (ConsoleColor.Gray, Console.ForegroundColor); @@ -63,7 +63,7 @@ public class DriverColorTests [InlineData (typeof (CursesDriver), true)] public void SupportsTrueColor_Defaults (Type driverType, bool expectedSetting) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); driver.Init (); Assert.Equal (expectedSetting, driver.SupportsTrueColor); diff --git a/UnitTests/ConsoleDrivers/MainLoopDriverTests.cs b/UnitTests/ConsoleDrivers/MainLoopDriverTests.cs index 2380ed83e..9720d51b5 100644 --- a/UnitTests/ConsoleDrivers/MainLoopDriverTests.cs +++ b/UnitTests/ConsoleDrivers/MainLoopDriverTests.cs @@ -17,7 +17,7 @@ public class MainLoopDriverTests //[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))] public void MainLoop_AddIdle_ValidIdleHandler_ReturnsToken (Type driverType, Type mainLoopDriverType) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver); var mainLoop = new MainLoop (mainLoopDriver); var idleHandlerInvoked = false; @@ -47,7 +47,7 @@ public class MainLoopDriverTests //[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))] public void MainLoop_AddTimeout_ValidParameters_ReturnsToken (Type driverType, Type mainLoopDriverType) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver); var mainLoop = new MainLoop (mainLoopDriver); var callbackInvoked = false; @@ -83,7 +83,7 @@ public class MainLoopDriverTests Type mainLoopDriverType ) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver); var mainLoop = new MainLoop (mainLoopDriver); @@ -107,7 +107,7 @@ public class MainLoopDriverTests Type mainLoopDriverType ) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver); var mainLoop = new MainLoop (mainLoopDriver); @@ -130,7 +130,7 @@ public class MainLoopDriverTests Type mainLoopDriverType ) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver); var mainLoop = new MainLoop (mainLoopDriver); @@ -151,7 +151,7 @@ public class MainLoopDriverTests //[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))] public void MainLoop_Constructs_Disposes (Type driverType, Type mainLoopDriverType) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver); var mainLoop = new MainLoop (mainLoopDriver); @@ -182,7 +182,7 @@ public class MainLoopDriverTests //[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))] public void MainLoop_RemoveIdle_InvalidToken_ReturnsFalse (Type driverType, Type mainLoopDriverType) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver); var mainLoop = new MainLoop (mainLoopDriver); @@ -201,7 +201,7 @@ public class MainLoopDriverTests //[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))] public void MainLoop_RemoveIdle_ValidToken_ReturnsTrue (Type driverType, Type mainLoopDriverType) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver); var mainLoop = new MainLoop (mainLoopDriver); @@ -223,7 +223,7 @@ public class MainLoopDriverTests //[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))] public void MainLoop_RemoveTimeout_InvalidToken_ReturnsFalse (Type driverType, Type mainLoopDriverType) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver); var mainLoop = new MainLoop (mainLoopDriver); @@ -241,7 +241,7 @@ public class MainLoopDriverTests //[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))] public void MainLoop_RemoveTimeout_ValidToken_ReturnsTrue (Type driverType, Type mainLoopDriverType) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver); var mainLoop = new MainLoop (mainLoopDriver); @@ -261,7 +261,7 @@ public class MainLoopDriverTests //[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))] public void MainLoop_RunIteration_ValidIdleHandler_CallsIdleHandler (Type driverType, Type mainLoopDriverType) { - var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + var driver = (IConsoleDriver)Activator.CreateInstance (driverType); var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver); var mainLoop = new MainLoop (mainLoopDriver); var idleHandlerInvoked = false; @@ -287,7 +287,7 @@ public class MainLoopDriverTests //[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))] //public void MainLoop_Invoke_ValidAction_RunsAction (Type driverType, Type mainLoopDriverType) //{ - // var driver = (ConsoleDriver)Activator.CreateInstance (driverType); + // var driver = (IConsoleDriver)Activator.CreateInstance (driverType); // var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, new object [] { driver }); // var mainLoop = new MainLoop (mainLoopDriver); // var actionInvoked = false; diff --git a/UnitTests/TestHelpers.cs b/UnitTests/TestHelpers.cs index 19a532ad4..3f32e35b5 100644 --- a/UnitTests/TestHelpers.cs +++ b/UnitTests/TestHelpers.cs @@ -25,21 +25,21 @@ public class AutoInitShutdownAttribute : BeforeAfterTestAttribute /// /// If true, Application.Init will be called Before the test runs. /// - /// Determines which ConsoleDriver (FakeDriver, WindowsDriver, CursesDriver, NetDriver) + /// Determines which IConsoleDriver (FakeDriver, WindowsDriver, CursesDriver, NetDriver) /// will be used when Application.Init is called. If null FakeDriver will be used. Only valid if /// is true. /// /// /// If true, will force the use of . Only valid if - /// == and is true. + /// == and is true. /// /// /// Only valid if is true. Only - /// valid if == and is true. + /// valid if == and is true. /// /// /// Only valid if is true. Only valid if - /// == and is true. + /// == and is true. /// /// Determines what config file locations will load from. /// If true and is true, the test will fail. @@ -135,7 +135,7 @@ public class AutoInitShutdownAttribute : BeforeAfterTestAttribute View.Instances.Clear (); } #endif - Application.Init ((ConsoleDriver)Activator.CreateInstance (_driverType)); + Application.Init ((IConsoleDriver)Activator.CreateInstance (_driverType)); } } @@ -251,12 +251,12 @@ internal partial class TestHelpers /// . /// /// - /// The ConsoleDriver to use. If null will be used. + /// The IConsoleDriver to use. If null will be used. /// public static void AssertDriverAttributesAre ( string expectedLook, ITestOutputHelper output, - ConsoleDriver driver = null, + IConsoleDriver driver = null, params Attribute [] expectedAttributes ) { @@ -321,12 +321,12 @@ internal partial class TestHelpers /// Asserts that the driver contents match the expected contents, optionally ignoring any trailing whitespace. /// /// - /// The ConsoleDriver to use. If null will be used. + /// The IConsoleDriver to use. If null will be used. /// public static void AssertDriverContentsAre ( string expectedLook, ITestOutputHelper output, - ConsoleDriver driver = null, + IConsoleDriver driver = null, bool ignoreLeadingWhitespace = false ) { @@ -367,12 +367,12 @@ internal partial class TestHelpers /// /// /// - /// The ConsoleDriver to use. If null will be used. + /// The IConsoleDriver to use. If null will be used. /// public static Rectangle AssertDriverContentsWithFrameAre ( string expectedLook, ITestOutputHelper output, - ConsoleDriver driver = null + IConsoleDriver driver = null ) { List> lines = new (); @@ -625,7 +625,7 @@ internal partial class TestHelpers /// /// if null uses /// - internal static void AssertDriverUsedColors (ConsoleDriver driver = null, params Attribute [] expectedColors) + internal static void AssertDriverUsedColors (IConsoleDriver driver = null, params Attribute [] expectedColors) { driver ??= Application.Driver; Cell [,] contents = driver.Contents;