mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Start fixing null-ability
This commit is contained in:
49
Terminal.Gui/ConsoleDrivers/AnsiEscapeSequence.cs
Normal file
49
Terminal.Gui/ConsoleDrivers/AnsiEscapeSequence.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
#nullable enable
|
||||
namespace Terminal.Gui;
|
||||
|
||||
/// <summary>
|
||||
/// Describes an Ansi escape sequence. This is a 'blueprint'. If you
|
||||
/// want to send the sequence you should instead use <see cref="AnsiEscapeSequenceRequest"/>
|
||||
/// </summary>
|
||||
public class AnsiEscapeSequence
|
||||
{
|
||||
/// <summary>
|
||||
/// Request to send e.g. see
|
||||
/// <see>
|
||||
/// <cref>EscSeqUtils.CSI_SendDeviceAttributes.Request</cref>
|
||||
/// </see>
|
||||
/// </summary>
|
||||
public required string Request { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// <para>
|
||||
/// The terminator that uniquely identifies the type of response as responded
|
||||
/// by the console. e.g. for
|
||||
/// <see>
|
||||
/// <cref>EscSeqUtils.CSI_SendDeviceAttributes.Request</cref>
|
||||
/// </see>
|
||||
/// the terminator is
|
||||
/// <see>
|
||||
/// <cref>EscSeqUtils.CSI_SendDeviceAttributes.Terminator</cref>
|
||||
/// </see>
|
||||
/// .
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// After sending a request, the first response with matching terminator will be matched
|
||||
/// to the oldest outstanding request.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public required string Terminator { get; init; }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The value expected in the response e.g.
|
||||
/// <see>
|
||||
/// <cref>EscSeqUtils.CSI_ReportTerminalSizeInChars.Value</cref>
|
||||
/// </see>
|
||||
/// which will have a 't' as terminator but also other different request may return the same terminator with a
|
||||
/// different value.
|
||||
/// </summary>
|
||||
public string? Value { get; init; }
|
||||
}
|
||||
@@ -6,47 +6,19 @@ namespace Terminal.Gui;
|
||||
/// Use <see cref="ResponseReceived"/> to handle the response
|
||||
/// when console answers the request.
|
||||
/// </summary>
|
||||
public class AnsiEscapeSequenceRequest
|
||||
public class AnsiEscapeSequenceRequest : AnsiEscapeSequence
|
||||
{
|
||||
/// <summary>
|
||||
/// Request to send e.g. see
|
||||
/// <see>
|
||||
/// <cref>EscSeqUtils.CSI_SendDeviceAttributes.Request</cref>
|
||||
/// </see>
|
||||
/// </summary>
|
||||
public required string Request { get; init; }
|
||||
|
||||
// BUGBUG: Nullable issue
|
||||
/// <summary>
|
||||
/// Invoked when the console responds with an ANSI response code that matches the
|
||||
/// <see cref="Terminator"/>
|
||||
/// <see cref="AnsiEscapeSequence.Terminator"/>
|
||||
/// </summary>
|
||||
public Action<string> ResponseReceived;
|
||||
public required Action<string> ResponseReceived { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Invoked if the console fails to responds to the ANSI response code
|
||||
/// </summary>
|
||||
public Action? Abandoned;
|
||||
public Action? Abandoned { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// <para>
|
||||
/// The terminator that uniquely identifies the type of response as responded
|
||||
/// by the console. e.g. for
|
||||
/// <see>
|
||||
/// <cref>EscSeqUtils.CSI_SendDeviceAttributes.Request</cref>
|
||||
/// </see>
|
||||
/// the terminator is
|
||||
/// <see>
|
||||
/// <cref>EscSeqUtils.CSI_SendDeviceAttributes.Terminator</cref>
|
||||
/// </see>
|
||||
/// .
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// After sending a request, the first response with matching terminator will be matched
|
||||
/// to the oldest outstanding request.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public required string Terminator { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Sends the <see cref="Request"/> to the raw output stream of the current <see cref="ConsoleDriver"/>.
|
||||
@@ -55,14 +27,4 @@ public class AnsiEscapeSequenceRequest
|
||||
/// </summary>
|
||||
public void Send () { Application.Driver?.WriteRaw (Request); }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The value expected in the response e.g.
|
||||
/// <see>
|
||||
/// <cref>EscSeqUtils.CSI_ReportTerminalSizeInChars.Value</cref>
|
||||
/// </see>
|
||||
/// which will have a 't' as terminator but also other different request may return the same terminator with a
|
||||
/// different value.
|
||||
/// </summary>
|
||||
public string? Value { get; init; }
|
||||
}
|
||||
|
||||
@@ -581,8 +581,7 @@ internal class CursesDriver : ConsoleDriver
|
||||
|
||||
private Curses.Window? _window;
|
||||
private UnixMainLoop? _mainLoopDriver;
|
||||
// BUGBUG: Fix this nullable issue.
|
||||
private object _processInputToken;
|
||||
private object? _processInputToken;
|
||||
|
||||
public override MainLoop Init ()
|
||||
{
|
||||
@@ -1111,7 +1110,7 @@ internal class CursesDriver : ConsoleDriver
|
||||
StopReportingMouseMoves ();
|
||||
SetCursorVisibility (CursorVisibility.Default);
|
||||
|
||||
if (_mainLoopDriver is { })
|
||||
if (_mainLoopDriver is { } && _processInputToken != null)
|
||||
{
|
||||
_mainLoopDriver.RemoveWatch (_processInputToken);
|
||||
}
|
||||
|
||||
@@ -1799,7 +1799,7 @@ public static class EscSeqUtils
|
||||
/// https://terminalguide.namepad.de/seq/csi_sn__p-6/
|
||||
/// The terminal reply to <see cref="CSI_RequestCursorPositionReport"/>. ESC [ ? (y) ; (x) ; 1 R
|
||||
/// </summary>
|
||||
public static readonly AnsiEscapeSequenceRequest CSI_RequestCursorPositionReport = new () { Request = CSI + "?6n", Terminator = "R" };
|
||||
public static readonly AnsiEscapeSequence CSI_RequestCursorPositionReport = new () { Request = CSI + "?6n", Terminator = "R" };
|
||||
|
||||
/// <summary>
|
||||
/// The terminal reply to <see cref="CSI_RequestCursorPositionReport"/>. ESC [ ? (y) ; (x) R
|
||||
@@ -1826,30 +1826,30 @@ public static class EscSeqUtils
|
||||
/// The terminator indicating a reply to <see cref="CSI_SendDeviceAttributes"/> or
|
||||
/// <see cref="CSI_SendDeviceAttributes2"/>
|
||||
/// </summary>
|
||||
public static readonly AnsiEscapeSequenceRequest CSI_SendDeviceAttributes = new () { Request = CSI + "0c", Terminator = "c" };
|
||||
public static readonly AnsiEscapeSequence CSI_SendDeviceAttributes = new () { Request = CSI + "0c", Terminator = "c" };
|
||||
|
||||
/// <summary>
|
||||
/// ESC [ > 0 c - Send Device Attributes (Secondary DA)
|
||||
/// Windows Terminal v1.18+ emits: "\x1b[>0;10;1c" (vt100, firmware version 1.0, vt220)
|
||||
/// </summary>
|
||||
public static readonly AnsiEscapeSequenceRequest CSI_SendDeviceAttributes2 = new () { Request = CSI + ">0c", Terminator = "c" };
|
||||
public static readonly AnsiEscapeSequence CSI_SendDeviceAttributes2 = new () { Request = CSI + ">0c", Terminator = "c" };
|
||||
|
||||
/// <summary>
|
||||
/// CSI 16 t - Request sixel resolution (width and height in pixels)
|
||||
/// </summary>
|
||||
public static readonly AnsiEscapeSequenceRequest CSI_RequestSixelResolution = new () { Request = CSI + "16t", Terminator = "t" };
|
||||
public static readonly AnsiEscapeSequence CSI_RequestSixelResolution = new () { Request = CSI + "16t", Terminator = "t" };
|
||||
|
||||
/// <summary>
|
||||
/// CSI 14 t - Request window size in pixels (width x height)
|
||||
/// </summary>
|
||||
public static readonly AnsiEscapeSequenceRequest CSI_RequestWindowSizeInPixels = new () { Request = CSI + "14t", Terminator = "t" };
|
||||
public static readonly AnsiEscapeSequence CSI_RequestWindowSizeInPixels = new () { Request = CSI + "14t", Terminator = "t" };
|
||||
|
||||
/// <summary>
|
||||
/// CSI 1 8 t | yes | yes | yes | report window size in chars
|
||||
/// https://terminalguide.namepad.de/seq/csi_st-18/
|
||||
/// The terminator indicating a reply to <see cref="CSI_ReportTerminalSizeInChars"/> : ESC [ 8 ; height ; width t
|
||||
/// </summary>
|
||||
public static readonly AnsiEscapeSequenceRequest CSI_ReportTerminalSizeInChars = new () { Request = CSI + "18t", Terminator = "t", Value = "8" };
|
||||
public static readonly AnsiEscapeSequence CSI_ReportTerminalSizeInChars = new () { Request = CSI + "18t", Terminator = "t", Value = "8" };
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -127,7 +127,7 @@ public class SixelSupportDetector
|
||||
() => resultCallback (result));
|
||||
}
|
||||
|
||||
private static void QueueRequest (AnsiEscapeSequenceRequest req, Action<string> responseCallback, Action abandoned)
|
||||
private static void QueueRequest (AnsiEscapeSequence req, Action<string> responseCallback, Action abandoned)
|
||||
{
|
||||
var newRequest = new AnsiEscapeSequenceRequest
|
||||
{
|
||||
|
||||
@@ -104,7 +104,7 @@ public sealed class AnsiEscapeSequenceRequests : Scenario
|
||||
}
|
||||
|
||||
var selAnsiEscapeSequenceRequestName = scrRequests [cbRequests.SelectedItem];
|
||||
AnsiEscapeSequenceRequest selAnsiEscapeSequenceRequest = null;
|
||||
AnsiEscapeSequence selAnsiEscapeSequenceRequest = null;
|
||||
|
||||
switch (selAnsiEscapeSequenceRequestName)
|
||||
{
|
||||
@@ -157,7 +157,7 @@ public sealed class AnsiEscapeSequenceRequests : Scenario
|
||||
|
||||
btnResponse.Accepting += (s, e) =>
|
||||
{
|
||||
var ansiEscapeSequenceRequest = new AnsiEscapeSequenceRequest
|
||||
var ansiEscapeSequenceRequest = new AnsiEscapeSequence
|
||||
{
|
||||
Request = tfRequest.Text,
|
||||
Terminator = tfTerminator.Text,
|
||||
|
||||
Reference in New Issue
Block a user