Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
150 commits
Select commit Hold shift + click to select a range
ca37d89
Consider width2 chars that are not IsBmp
tznind Jul 15, 2025
a37baf0
Apply same fix in WindowsDriver
tznind Jul 15, 2025
1a91f8f
Explicitly use type of local variable
tznind Jul 15, 2025
788ce46
Revert changes to WindowsDriver
tznind Jul 17, 2025
6a59d03
Assume we are running in a terminal that supports true color by defau…
tznind Jul 17, 2025
4983e0c
Switch to SetAttribute and WriteConsole instead of WriteConsoleOutput…
tznind Jul 21, 2025
ebb3b06
Fix some cursor issues (WIP)
tznind Jul 21, 2025
c74df74
Remove concept of 'dirty rows' from v2 as its never actually used
tznind Jul 22, 2025
b9dd4f5
Remove damageRegion as it does nothing
tznind Jul 22, 2025
5501ada
Make string builder to console writing simpler
tznind Jul 22, 2025
6ce6b6b
Radically simplify Write method
tznind Jul 22, 2025
e25beff
Simplify conditional logic
tznind Jul 22, 2025
77fcdef
Simplify restoring cursor position
tznind Jul 22, 2025
e08b2d6
Reference local variable for console buffer
tznind Jul 22, 2025
711e474
Reduce calls to ConsoleWrite by accumulating till attribute changes
tznind Jul 22, 2025
8e3ec18
Merge branch 'v2_develop' into fix4191
tznind Jul 25, 2025
f6fbfc3
When resizing v2 16 color mode on windows, recreate the back buffer t…
tznind Jul 27, 2025
8d98497
Merge branch 'v2_develop' into fix4191
tznind Jul 27, 2025
ab54393
Merge branch 'v2_develop' into fix4191
tznind Jul 30, 2025
aaee6a0
Fixes for VTS enabled
BDisp Aug 1, 2025
51200cb
Fix _lastSize never being assigned
BDisp Aug 1, 2025
41cfc5f
Fixes VTS for Force16Colors
BDisp Aug 1, 2025
6b4e56a
Fixes force16Colors in VTS
BDisp Aug 1, 2025
0308f92
Fixes escape sequences always echoing in non-VTS
BDisp Aug 1, 2025
e36a43e
Force Force16Colors in non-VTS. It have a bug in adding a newline in …
BDisp Aug 1, 2025
a78e83a
Merge pull request #179 from BDisp/fix4191-vts-fix
tznind Aug 2, 2025
52aea94
Merge branch 'v2_develop' into fix4191
tznind Aug 2, 2025
35a4ecb
WIP Add base class for NetOutput
tznind Aug 2, 2025
db07327
Abstract away how we change attribute
tznind Aug 2, 2025
41323ac
WIP - Make WindowsOutput use base class
tznind Aug 2, 2025
9cf7e4b
WIP working to fix set cursor position
tznind Aug 2, 2025
66eccb7
Remove commented out code
tznind Aug 2, 2025
a4eb3eb
Fixes legacy output mode
BDisp Aug 2, 2025
89079d2
Fixes size with no alt buffer supported on VTS and size restore after…
BDisp Aug 3, 2025
46a419d
Fix set cursor which also fixes the broken surrogate pairs
BDisp Aug 3, 2025
dae2b26
Add force parameter
BDisp Aug 3, 2025
556b1d5
Fixes an issue that only happens with Windows Terminal when paste sur…
BDisp Aug 3, 2025
4117f4a
In Windows escape sequences must be sent during the lifetime of the c…
BDisp Aug 4, 2025
e2d3cc1
Ensure flush the input buffer before reset the console
BDisp Aug 4, 2025
5306017
Flush input buffer before reset console in v2win
BDisp Aug 4, 2025
f32aef7
Fixes issue in v2net not being refreshing the menu bar at start
BDisp Aug 4, 2025
96b3b41
Only force layout and draw on size changed.
BDisp Aug 4, 2025
0a5c6bb
Merge pull request #180 from BDisp/fix4191-fix
tznind Aug 5, 2025
36cb50d
Fix v2net issue not draw first line by forcing set cursor position
BDisp Aug 5, 2025
fd76522
Set _lastCursorPosition nullable and remove bool force from set curso…
BDisp Aug 6, 2025
d602d47
Merge pull request #181 from BDisp/fix4191-fix
tznind Aug 6, 2025
9c682d8
Remove force parameter
BDisp Aug 6, 2025
ef103d8
Merge pull request #182 from BDisp/fix4191-fix
tznind Aug 6, 2025
eaf1f79
Add v2 version of fake driver attribute
tznind Aug 9, 2025
0eec334
Make direct replacement and wire up window resizing events
tznind Aug 9, 2025
21d44c6
Update casts to use V2 fake driver instead
tznind Aug 9, 2025
f872cc5
Adjust interfaces to expose less internals
tznind Aug 9, 2025
cbdd0bd
Fix not raising iteration event in v2
tznind Aug 9, 2025
deaf791
WIP investigate what it takes to do resize and redraw using TextAlign…
tznind Aug 9, 2025
866cc73
Sketch adding component factory
tznind Aug 9, 2025
5493181
Create relevant fake component factories
tznind Aug 9, 2025
391df6f
Add window size monitor into factory
tznind Aug 9, 2025
985ec40
Fake size monitor injecting
tznind Aug 9, 2025
af4fecb
Add helper for faking console resize in AutoInitShutdown tests
tznind Aug 9, 2025
9cbf4fe
Fix size setting in FakeDriverV2
tznind Aug 9, 2025
d1ba176
Switch to new method
tznind Aug 9, 2025
4e2b25a
merge rewrite windows driver
tznind Aug 11, 2025
637d984
Fix IsLegacy becoming false when using blank constructor
tznind Aug 11, 2025
3bed0c4
Fix for Ready not being raised when showing same top twice also fixes…
tznind Aug 11, 2025
82a279a
Fix tests
tznind Aug 11, 2025
f0d5794
Remove auto init
tznind Aug 11, 2025
2a68279
Restore conditional compilation stuff
tznind Aug 11, 2025
295a81f
Restore 'if running unit tests' logic
tznind Aug 14, 2025
382156f
Check only for the output being specific classes for the suppression
tznind Aug 14, 2025
ab9ac77
Fix ShadowView blowing up with index out of bounds error
tznind Aug 14, 2025
dd8d6f5
Fix resize in fluent tests
tznind Aug 14, 2025
33f5a5b
Fix for people using Iteration call directly
tznind Aug 16, 2025
a5538b3
Fix more calls to iteration to use
tznind Aug 16, 2025
aae1592
Add comment
tznind Aug 16, 2025
67c4258
Remove assumption that Run with prior view not disposed should throw
tznind Aug 17, 2025
7b5324c
Fix timings in Dialog_Opened_From_Another_Dialog
tznind Aug 17, 2025
745b3fd
Fix Zero_Buttons_Works
tznind Aug 17, 2025
57af471
Standardize and fix Button_IsDefault_True_Return_His_Index_On_Accepting
tznind Aug 17, 2025
d3f408b
Fix iteration counts on MessageBoxTests
tznind Aug 17, 2025
dfb0fb4
Fix WizartTests and DrawTests_Ruler
tznind Aug 17, 2025
a4ca08b
Implement SendKeys into ConsoleDriverFacade
tznind Aug 17, 2025
5c5e0a6
Fix SendKeys in console driver facade such that FileDialogTests works
tznind Aug 17, 2025
8d48c60
Add missing dispose call to test
tznind Aug 17, 2025
eb10c9b
Fix support for Esc in facade SendKeys
tznind Aug 17, 2025
2718bf2
Fix AutocompleteTests
tznind Aug 17, 2025
30734f3
Fix various tests
tznind Aug 17, 2025
cb367d7
Replace LayoutAndDraw with run iteration
tznind Aug 17, 2025
aa67d9f
Fix draw issues
tznind Aug 17, 2025
feffed5
fix draw order
tznind Aug 17, 2025
6f840e0
Fix run iteration calls
tznind Aug 17, 2025
41f26e5
Fix unit tests
tznind Aug 17, 2025
90eea70
Fix SendKeys in facade.
BDisp Aug 17, 2025
b2ea599
Manipulate upper and lower cases.
BDisp Aug 17, 2025
7b5a52a
Add IsValidInput method to the interface.
BDisp Aug 17, 2025
f0ce70b
Fix SendKeys scenario
BDisp Aug 17, 2025
b8a6d0d
Fixes surrogate pairs in the label
BDisp Aug 18, 2025
10df68a
Merge pull request #183 from BDisp/v2-fake-driver-send-fix
tznind Aug 18, 2025
9ceac36
Make tests more sensible - they are testing draw functionality. Call…
tznind Aug 18, 2025
d83446f
Fix tests and harden cleanup in AutoInitShutdownAttribute v2 lifecycl…
tznind Aug 18, 2025
fc7198f
Delete extra create input call
tznind Aug 18, 2025
7b14fcc
Fix mocks and order of exceptions thrown in Run when things are not i…
tznind Aug 18, 2025
d4badc0
Revert use of `MapConsoleKeyInfoToKeyCode`
tznind Aug 18, 2025
9b5c4f4
Ignore casing as it is not what test is really about
tznind Aug 18, 2025
2fc4cd7
Clear application top and top levels before each auto init shutdown test
tznind Aug 19, 2025
2cc1b00
Fix for unstable tests
tznind Aug 19, 2025
6c07cbb
Restore actually working SendKeys code
tznind Aug 19, 2025
2734748
option to pass logger in fluent ctor
tznind Aug 19, 2025
9e4a3cc
restore ToArray
tznind Aug 19, 2025
d0de7c2
Fix SendKeys method and add extension to unit test
BDisp Aug 19, 2025
823b6e4
Leverage the EscSeqUtils.MapConsoleKeyInfo method to avoid duplicate …
BDisp Aug 19, 2025
6a11f0d
Merge pull request #184 from BDisp/v2-fake-driver-sendkeys-fix
tznind Aug 19, 2025
a554e0e
Remove unnecessary hack
BDisp Aug 19, 2025
f38e8ef
Using only KeyCode for rKeys
BDisp Aug 19, 2025
ec74932
Recover modifier keys in surrogate pairs
BDisp Aug 19, 2025
08ae16d
Reformat
BDisp Aug 19, 2025
fb00c6f
Merge pull request #185 from BDisp/v2-fake-driver-fix
tznind Aug 20, 2025
4234bac
Remove iteration limit for benchmarking in v2
tznind Mar 2, 2025
1ddc17f
remove iteration delay to identify bugs
tznind Aug 21, 2025
0bf2c74
Remove nudge to unique key and make Then run on UI thread
tznind Aug 24, 2025
a5e26ed
fix fluid assertions
tznind Aug 28, 2025
e1491a7
Ensure UI operations all happen on UI thread
tznind Aug 28, 2025
a11ee36
Add explicit error for WaitIteration during an invoke
tznind Aug 29, 2025
8e79ddb
Remove timeout added for debug
tznind Aug 29, 2025
6d18e98
Catch failing asserts better
tznind Aug 29, 2025
b84ce08
Fix screenshot
tznind Aug 29, 2025
5409cf0
Fix null ref
tznind Aug 29, 2025
29b6d7e
Fix race condition in processing input
tznind Aug 30, 2025
893fe74
Test fixing
tznind Aug 30, 2025
0d259c1
Standardize asserts
tznind Aug 30, 2025
f62456a
Remove calls to layout and draw, remove pointless lock and enable rea…
tznind Aug 30, 2025
0ea6dfc
Merge branch 'v2_develop' into v2-fake-driver
tznind Aug 31, 2025
90927a9
Merge branch 'v2-fake-driver' of https://github.com/tznind/gui.cs int…
tznind Aug 31, 2025
08ec7f6
fix bad merge
tznind Aug 31, 2025
c52b1b8
Merge branch 'v2-fake-driver' into iteration-zero
tznind Aug 31, 2025
fb466cc
Make logs access threadsafe
tznind Aug 31, 2025
938356a
add extra wait to remove race between iteration end and assert
tznind Aug 31, 2025
9efc530
Code cleanup
tznind Aug 31, 2025
e8c061d
Remove test for crash on access Cancelled after dispose as this is no…
tznind Sep 1, 2025
cff202d
Change resize console to run on UI thread - fixing race condition wit…
tznind Sep 1, 2025
d47fd50
Restore original frame rate after test
tznind Sep 1, 2025
47ca6fd
Restore nudge to unique key
tznind Sep 1, 2025
d463213
Code Cleanup
tznind Sep 1, 2025
370bd12
Fix for cascading failures when an assert fails in a specific test
tznind Sep 1, 2025
2b8d72d
Merge branch 'v2_develop' into iteration-zero
tznind Sep 1, 2025
a6524e8
fix for bad merge
tznind Sep 1, 2025
14c68e5
Address PR feedback
tznind Sep 10, 2025
7e54cc2
Move classes to seperate files and add xmldoc
tznind Sep 10, 2025
dd8857d
xml doc warnings
tznind Sep 10, 2025
4891b00
More xml comments docs
tznind Sep 10, 2025
73f2d9e
Fix spelling
tznind Sep 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions Examples/UICatalog/Scenarios/SendKeys.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System.Text;

namespace UICatalog.Scenarios;

Expand Down Expand Up @@ -39,7 +39,7 @@ public override void Main ()

txtResult.KeyDown += (s, e) =>
{
rKeys += (char)e.KeyCode;
rKeys += e.ToString ();

if (!IsShift && e.IsShift)
{
Expand Down Expand Up @@ -81,17 +81,15 @@ void ProcessInput ()

foreach (char r in txtInput.Text)
{
ConsoleKey ck = char.IsLetter (r)
? (ConsoleKey)char.ToUpper (r)
: (ConsoleKey)r;
ConsoleKeyInfo consoleKeyInfo = EscSeqUtils.MapConsoleKeyInfo (new (r, ConsoleKey.None, false, false, false));

Application.Driver?.SendKeys (
r,
ck,
ckbShift.CheckedState == CheckState.Checked,
ckbAlt.CheckedState == CheckState.Checked,
ckbControl.CheckedState == CheckState.Checked
);
r,
consoleKeyInfo.Key,
ckbShift.CheckedState == CheckState.Checked || (consoleKeyInfo.Modifiers & ConsoleModifiers.Shift) != 0,
ckbAlt.CheckedState == CheckState.Checked || (consoleKeyInfo.Modifiers & ConsoleModifiers.Alt) != 0,
ckbControl.CheckedState == CheckState.Checked || (consoleKeyInfo.Modifiers & ConsoleModifiers.Control) != 0
);
}

lblShippedKeys.Text = rKeys;
Expand Down
6 changes: 5 additions & 1 deletion Terminal.Gui/App/Application.Run.cs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ internal static void LayoutAndDrawImpl (bool forceDraw = false)
/// <summary>This event is raised on each iteration of the main loop.</summary>
/// <remarks>See also <see cref="Timeout"/></remarks>
public static event EventHandler<IterationEventArgs>? Iteration;

/// <summary>The <see cref="MainLoop"/> driver for the application</summary>
/// <value>The main loop.</value>
internal static MainLoop? MainLoop { get; set; }
Expand Down Expand Up @@ -618,4 +618,8 @@ public static void End (RunState runState)

LayoutAndDraw (true);
}
internal static void RaiseIteration ()
{
Iteration?.Invoke (null, new ());
}
}
14 changes: 14 additions & 0 deletions Terminal.Gui/App/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ public static partial class Application
/// </summary>
public static ITimedEvents? TimedEvents => ApplicationImpl.Instance?.TimedEvents;

/// <summary>
/// Maximum number of iterations of the main loop (and hence draws)
/// to allow to occur per second. Defaults to <see cref="DefaultMaximumIterationsPerSecond"/>> which is a 40ms sleep
/// after iteration (factoring in how long iteration took to run).
/// <remarks>Note that not every iteration draws (see <see cref="View.NeedsDraw"/>).
/// Only affects v2 drivers.</remarks>
/// </summary>
public static ushort MaximumIterationsPerSecond = DefaultMaximumIterationsPerSecond;

/// <summary>
/// Default value for <see cref="MaximumIterationsPerSecond"/>
/// </summary>
public const ushort DefaultMaximumIterationsPerSecond = 25;

/// <summary>
/// Gets a string representation of the Application as rendered by <see cref="Driver"/>.
/// </summary>
Expand Down
82 changes: 47 additions & 35 deletions Terminal.Gui/Drivers/V2/ApplicationV2.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#nullable enable
using System.Collections.Concurrent;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.Logging;
Expand All @@ -12,10 +13,7 @@ namespace Terminal.Gui.Drivers;
/// </summary>
public class ApplicationV2 : ApplicationImpl
{
private readonly Func<INetInput> _netInputFactory;
private readonly Func<IConsoleOutput> _netOutputFactory;
private readonly Func<IWindowsInput> _winInputFactory;
private readonly Func<IConsoleOutput> _winOutputFactory;
private readonly IComponentFactory? _componentFactory;
private IMainLoopCoordinator? _coordinator;
private string? _driverName;

Expand All @@ -24,29 +22,20 @@ public class ApplicationV2 : ApplicationImpl
/// <inheritdoc/>
public override ITimedEvents TimedEvents => _timedEvents;

internal IMainLoopCoordinator? Coordinator => _coordinator;

/// <summary>
/// Creates anew instance of the Application backend. The provided
/// factory methods will be used on Init calls to get things booted.
/// </summary>
public ApplicationV2 () : this (
() => new NetInput (),
() => new NetOutput (),
() => new WindowsInput (),
() => new WindowsOutput ()
)
{ }

internal ApplicationV2 (
Func<INetInput> netInputFactory,
Func<IConsoleOutput> netOutputFactory,
Func<IWindowsInput> winInputFactory,
Func<IConsoleOutput> winOutputFactory
)
public ApplicationV2 ()
{
IsLegacy = false;
}

internal ApplicationV2 (IComponentFactory componentFactory)
{
_netInputFactory = netInputFactory;
_netOutputFactory = netOutputFactory;
_winInputFactory = winInputFactory;
_winOutputFactory = winOutputFactory;
_componentFactory = componentFactory;
IsLegacy = false;
}

Expand Down Expand Up @@ -92,8 +81,8 @@ private void CreateDriver (string? driverName)
{
PlatformID p = Environment.OSVersion.Platform;

bool definetlyWin = driverName?.Contains ("win") ?? false;
bool definetlyNet = driverName?.Contains ("net") ?? false;
bool definetlyWin = (driverName?.Contains ("win") ?? false )|| _componentFactory is IComponentFactory<WindowsConsole.InputRecord>;
bool definetlyNet = (driverName?.Contains ("net") ?? false ) || _componentFactory is IComponentFactory<ConsoleKeyInfo>;

if (definetlyWin)
{
Expand Down Expand Up @@ -125,27 +114,44 @@ private IMainLoopCoordinator CreateWindowsSubcomponents ()
ConcurrentQueue<WindowsConsole.InputRecord> inputBuffer = new ();
MainLoop<WindowsConsole.InputRecord> loop = new ();

return new MainLoopCoordinator<WindowsConsole.InputRecord> (
_timedEvents,
_winInputFactory,
IComponentFactory<WindowsConsole.InputRecord> cf;

if (_componentFactory != null)
{
cf = (IComponentFactory<WindowsConsole.InputRecord>)_componentFactory;
}
else
{
cf = new WindowsComponentFactory ();
}

return new MainLoopCoordinator<WindowsConsole.InputRecord> (_timedEvents,
inputBuffer,
new WindowsInputProcessor (inputBuffer),
_winOutputFactory,
loop);
loop,
cf);
}

private IMainLoopCoordinator CreateNetSubcomponents ()
{
ConcurrentQueue<ConsoleKeyInfo> inputBuffer = new ();
MainLoop<ConsoleKeyInfo> loop = new ();

IComponentFactory<ConsoleKeyInfo> cf;

if (_componentFactory != null)
{
cf = (IComponentFactory<ConsoleKeyInfo>)_componentFactory;
}
else
{
cf = new NetComponentFactory ();
}

return new MainLoopCoordinator<ConsoleKeyInfo> (
_timedEvents,
_netInputFactory,
inputBuffer,
new NetInputProcessor (inputBuffer),
_netOutputFactory,
loop);
loop,
cf);
}

/// <inheritdoc/>
Expand All @@ -171,6 +177,12 @@ public override void Run (Toplevel view, Func<Exception, bool>? errorHandler = n
throw new NotInitializedException (nameof (Run));
}

if (Application.Driver == null)
{
// See Run_T_Init_Driver_Cleared_with_TestTopLevel_Throws
throw new InvalidOperationException ("Driver was inexplicably null when trying to Run view");
}

Application.Top = view;

RunState rs = Application.Begin (view);
Expand Down Expand Up @@ -258,4 +270,4 @@ public override void LayoutAndDraw (bool forceDraw)
Application.Top?.SetNeedsDraw();
Application.Top?.SetNeedsLayout ();
}
}
}
26 changes: 26 additions & 0 deletions Terminal.Gui/Drivers/V2/ComponentFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#nullable enable
using System.Collections.Concurrent;

namespace Terminal.Gui.Drivers;

/// <summary>
/// Abstract base class implementation of <see cref="IComponentFactory{T}"/>
/// </summary>
/// <typeparam name="T"></typeparam>
public abstract class ComponentFactory<T> : IComponentFactory<T>
{
/// <inheritdoc />
public abstract IConsoleInput<T> CreateInput ();

/// <inheritdoc />
public abstract IInputProcessor CreateInputProcessor (ConcurrentQueue<T> inputBuffer);

/// <inheritdoc />
public virtual IWindowSizeMonitor CreateWindowSizeMonitor (IConsoleOutput consoleOutput, IOutputBuffer outputBuffer)
{
return new WindowSizeMonitor (consoleOutput, outputBuffer);
}

/// <inheritdoc />
public abstract IConsoleOutput CreateOutput ();
}
19 changes: 16 additions & 3 deletions Terminal.Gui/Drivers/V2/ConsoleDriverFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ internal class ConsoleDriverFacade<T> : IConsoleDriver, IConsoleDriverFacade
public event EventHandler<SizeChangedEventArgs> SizeChanged;

public IInputProcessor InputProcessor { get; }
public IOutputBuffer OutputBuffer => _outputBuffer;

public IWindowSizeMonitor WindowSizeMonitor { get; }


public ConsoleDriverFacade (
IInputProcessor inputProcessor,
Expand All @@ -36,7 +40,8 @@ IWindowSizeMonitor windowSizeMonitor
MouseEvent?.Invoke (s, e);
};

windowSizeMonitor.SizeChanging += (_, e) => SizeChanged?.Invoke (this, e);
WindowSizeMonitor = windowSizeMonitor;
windowSizeMonitor.SizeChanging += (_,e) => SizeChanged?.Invoke (this, e);

CreateClipboard ();
}
Expand Down Expand Up @@ -68,7 +73,7 @@ public Rectangle Screen
{
get
{
if (ConsoleDriver.RunningUnitTests)
if (ConsoleDriver.RunningUnitTests && _output is WindowsOutput or NetOutput)
{
// In unit tests, we don't have a real output, so we return an empty rectangle.
return Rectangle.Empty;
Expand Down Expand Up @@ -384,7 +389,15 @@ public Attribute MakeColor (in Color foreground, in Color background)
/// <param name="ctrl">If <see langword="true"/> simulates the Ctrl key being pressed.</param>
public void SendKeys (char keyChar, ConsoleKey key, bool shift, bool alt, bool ctrl)
{
// TODO: implement
ConsoleKeyInfo consoleKeyInfo = new (keyChar, key, shift, alt, ctrl);

Key k = EscSeqUtils.MapKey (consoleKeyInfo);

if (InputProcessor.IsValidInput (k, out k))
{
InputProcessor.OnKeyDown (k);
InputProcessor.OnKeyUp (k);
}
}

/// <summary>
Expand Down
50 changes: 50 additions & 0 deletions Terminal.Gui/Drivers/V2/IComponentFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#nullable enable
using System.Collections.Concurrent;

namespace Terminal.Gui.Drivers;

/// <summary>
/// Base untyped interface for <see cref="IComponentFactory{T}"/> for methods that are not templated on low level
/// console input type.
/// </summary>
public interface IComponentFactory
{
/// <summary>
/// Create the <see cref="IConsoleOutput"/> class for the current driver implementation i.e. the class responsible for
/// rendering <see cref="IOutputBuffer"/> into the console.
/// </summary>
/// <returns></returns>
IConsoleOutput CreateOutput ();
}

/// <summary>
/// Creates driver specific subcomponent classes (<see cref="IConsoleInput{T}"/>, <see cref="IInputProcessor"/> etc) for a
/// <see cref="IMainLoopCoordinator"/>.
/// </summary>
/// <typeparam name="T"></typeparam>
public interface IComponentFactory<T> : IComponentFactory
{
/// <summary>
/// Create <see cref="IConsoleInput{T}"/> class for the current driver implementation i.e. the class responsible for reading
/// user input from the console.
/// </summary>
/// <returns></returns>
IConsoleInput<T> CreateInput ();

/// <summary>
/// Creates the <see cref="InputProcessor{T}"/> class for the current driver implementation i.e. the class responsible for
/// translating raw console input into Terminal.Gui common event <see cref="Key"/> and <see cref="MouseEventArgs"/>.
/// </summary>
/// <param name="inputBuffer"></param>
/// <returns></returns>
IInputProcessor CreateInputProcessor (ConcurrentQueue<T> inputBuffer);

/// <summary>
/// Creates <see cref="IWindowSizeMonitor"/> class for the current driver implementation i.e. the class responsible for
/// reporting the current size of the terminal window.
/// </summary>
/// <param name="consoleOutput"></param>
/// <param name="outputBuffer"></param>
/// <returns></returns>
IWindowSizeMonitor CreateWindowSizeMonitor (IConsoleOutput consoleOutput, IOutputBuffer outputBuffer);
}
13 changes: 12 additions & 1 deletion Terminal.Gui/Drivers/V2/IConsoleDriverFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,16 @@ public interface IConsoleDriverFacade
/// e.g. <see cref="ConsoleKeyInfo"/> into <see cref="Key"/> events
/// and detecting and processing ansi escape sequences.
/// </summary>
public IInputProcessor InputProcessor { get; }
IInputProcessor InputProcessor { get; }

/// <summary>
/// Describes the desired screen state. Data source for <see cref="IConsoleOutput"/>.
/// </summary>
IOutputBuffer OutputBuffer { get; }

/// <summary>
/// Interface for classes responsible for reporting the current
/// size of the terminal window.
/// </summary>
IWindowSizeMonitor WindowSizeMonitor { get; }
}
11 changes: 11 additions & 0 deletions Terminal.Gui/Drivers/V2/IInputProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,15 @@ public interface IInputProcessor
/// </summary>
/// <returns></returns>
public IAnsiResponseParser GetParser ();

/// <summary>
/// Handles surrogate pairs in the input stream.
/// </summary>
/// <param name="key">The key from input.</param>
/// <param name="result">Get the surrogate pair or the key.</param>
/// <returns>
/// <see langword="true"/> if the result is a valid surrogate pair or a valid key, otherwise
/// <see langword="false"/>.
/// </returns>
bool IsValidInput (Key key, out Key result);
}
9 changes: 8 additions & 1 deletion Terminal.Gui/Drivers/V2/IMainLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ public interface IMainLoop<T> : IDisposable
/// <param name="inputBuffer"></param>
/// <param name="inputProcessor"></param>
/// <param name="consoleOutput"></param>
void Initialize (ITimedEvents timedEvents, ConcurrentQueue<T> inputBuffer, IInputProcessor inputProcessor, IConsoleOutput consoleOutput);
/// <param name="componentFactory"></param>
void Initialize (
ITimedEvents timedEvents,
ConcurrentQueue<T> inputBuffer,
IInputProcessor inputProcessor,
IConsoleOutput consoleOutput,
IComponentFactory<T> componentFactory
);

/// <summary>
/// Perform a single iteration of the main loop then blocks for a fixed length
Expand Down
Loading
Loading