mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 00:46:39 +01:00
WIP: Scenario
This commit is contained in:
@@ -10,7 +10,12 @@ namespace Terminal.Gui;
|
||||
InResponse
|
||||
}
|
||||
|
||||
internal abstract class AnsiResponseParserBase
|
||||
public interface IAnsiResponseParser
|
||||
{
|
||||
void ExpectResponse (string terminator, Action<string> response);
|
||||
}
|
||||
|
||||
internal abstract class AnsiResponseParserBase : IAnsiResponseParser
|
||||
{
|
||||
protected readonly List<(string terminator, Action<string> response)> expectedResponses = new ();
|
||||
private ParserState _state = ParserState.Normal;
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Terminal.Gui;
|
||||
/// <see cref="WindowsDriver"/> - <see cref="NetDriver"/> that uses the .NET Console API - <see cref="FakeConsole"/>
|
||||
/// for unit testing.
|
||||
/// </remarks>
|
||||
public abstract class ConsoleDriver
|
||||
public abstract class ConsoleDriver : IConsoleDriver
|
||||
{
|
||||
// As performance is a concern, we keep track of the dirty lines and only refresh those.
|
||||
// This is in addition to the dirty flag on each cell.
|
||||
@@ -609,6 +609,20 @@ public abstract class ConsoleDriver
|
||||
public abstract void SendKeys (char keyChar, ConsoleKey key, bool shift, bool alt, bool ctrl);
|
||||
|
||||
#endregion
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual IAnsiResponseParser GetParser ()
|
||||
{
|
||||
// TODO: implement in other drivers
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void RawWrite (string str)
|
||||
{
|
||||
// TODO: implement in other drivers
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
8
Terminal.Gui/ConsoleDrivers/IConsoleDriver.cs
Normal file
8
Terminal.Gui/ConsoleDrivers/IConsoleDriver.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
#nullable enable
|
||||
namespace Terminal.Gui;
|
||||
|
||||
public interface IConsoleDriver
|
||||
{
|
||||
IAnsiResponseParser GetParser ();
|
||||
void RawWrite (string str);
|
||||
}
|
||||
@@ -1164,6 +1164,11 @@ internal class WindowsDriver : ConsoleDriver
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override IAnsiResponseParser GetParser () => Parser;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void RawWrite (string str) => WinConsole?.WriteANSI (str);
|
||||
|
||||
#region Not Implemented
|
||||
|
||||
@@ -1446,19 +1451,9 @@ internal class WindowsDriver : ConsoleDriver
|
||||
|
||||
WinConsole?.SetInitialCursorVisibility ();
|
||||
|
||||
|
||||
// Send DAR
|
||||
Parser.ExpectResponse (EscSeqUtils.CSI_ReportDeviceAttributes_Terminator,
|
||||
(e) =>
|
||||
{
|
||||
// TODO: do something with this
|
||||
});
|
||||
|
||||
return new MainLoop (_mainLoopDriver);
|
||||
}
|
||||
|
||||
private bool firstTime = true;
|
||||
|
||||
/// <summary>
|
||||
/// How long after Esc has been pressed before we give up on getting an Ansi escape sequence
|
||||
/// </summary>
|
||||
@@ -1467,12 +1462,6 @@ internal class WindowsDriver : ConsoleDriver
|
||||
|
||||
internal void ProcessInput (WindowsConsole.InputRecord inputEvent)
|
||||
{
|
||||
if (firstTime)
|
||||
{
|
||||
WinConsole?.WriteANSI (EscSeqUtils.CSI_SendDeviceAttributes);
|
||||
firstTime = false;
|
||||
}
|
||||
|
||||
foreach (var e in Parse (inputEvent))
|
||||
{
|
||||
ProcessInputAfterParsing (e);
|
||||
|
||||
48
UICatalog/Scenarios/AnsiRequestsScenario.cs
Normal file
48
UICatalog/Scenarios/AnsiRequestsScenario.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using Terminal.Gui;
|
||||
|
||||
namespace UICatalog.Scenarios;
|
||||
|
||||
|
||||
|
||||
[ScenarioMetadata ("Ansi Requests", "Demonstration of how to send ansi requests.")]
|
||||
[ScenarioCategory ("Colors")]
|
||||
[ScenarioCategory ("Drawing")]
|
||||
public class AnsiRequestsScenario : Scenario
|
||||
{
|
||||
public override void Main ()
|
||||
{
|
||||
Application.Init ();
|
||||
var win = new Window { Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}" };
|
||||
|
||||
var btn = new Button ()
|
||||
{
|
||||
Text = "Send DAR",
|
||||
Width = Dim.Auto ()
|
||||
};
|
||||
|
||||
|
||||
|
||||
var tv = new TextView ()
|
||||
{
|
||||
Y = Pos.Bottom (btn),
|
||||
Width = Dim.Fill(),
|
||||
Height = Dim.Fill()
|
||||
};
|
||||
|
||||
btn.Accepting += (s, e) =>
|
||||
{
|
||||
// Ask for device attributes (DAR)
|
||||
var p = Application.Driver.GetParser ();
|
||||
p.ExpectResponse ("c", (r) => tv.Text += r + '\n');
|
||||
Application.Driver.RawWrite (EscSeqUtils.CSI_SendDeviceAttributes);
|
||||
|
||||
};
|
||||
|
||||
win.Add (tv);
|
||||
win.Add (btn);
|
||||
|
||||
Application.Run (win);
|
||||
win.Dispose ();
|
||||
Application.Shutdown ();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user