Skip to content

Commit 994bf55

Browse files
committed
Start fixing null-ability
1 parent 21f0cc1 commit 994bf55

File tree

6 files changed

+64
-54
lines changed

6 files changed

+64
-54
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#nullable enable
2+
namespace Terminal.Gui;
3+
4+
/// <summary>
5+
/// Describes an Ansi escape sequence. This is a 'blueprint'. If you
6+
/// want to send the sequence you should instead use <see cref="AnsiEscapeSequenceRequest"/>
7+
/// </summary>
8+
public class AnsiEscapeSequence
9+
{
10+
/// <summary>
11+
/// Request to send e.g. see
12+
/// <see>
13+
/// <cref>EscSeqUtils.CSI_SendDeviceAttributes.Request</cref>
14+
/// </see>
15+
/// </summary>
16+
public required string Request { get; init; }
17+
18+
/// <summary>
19+
/// <para>
20+
/// The terminator that uniquely identifies the type of response as responded
21+
/// by the console. e.g. for
22+
/// <see>
23+
/// <cref>EscSeqUtils.CSI_SendDeviceAttributes.Request</cref>
24+
/// </see>
25+
/// the terminator is
26+
/// <see>
27+
/// <cref>EscSeqUtils.CSI_SendDeviceAttributes.Terminator</cref>
28+
/// </see>
29+
/// .
30+
/// </para>
31+
/// <para>
32+
/// After sending a request, the first response with matching terminator will be matched
33+
/// to the oldest outstanding request.
34+
/// </para>
35+
/// </summary>
36+
public required string Terminator { get; init; }
37+
38+
39+
40+
/// <summary>
41+
/// The value expected in the response e.g.
42+
/// <see>
43+
/// <cref>EscSeqUtils.CSI_ReportTerminalSizeInChars.Value</cref>
44+
/// </see>
45+
/// which will have a 't' as terminator but also other different request may return the same terminator with a
46+
/// different value.
47+
/// </summary>
48+
public string? Value { get; init; }
49+
}

Terminal.Gui/ConsoleDrivers/AnsiEscapeSequenceRequest.cs

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,19 @@ namespace Terminal.Gui;
66
/// Use <see cref="ResponseReceived"/> to handle the response
77
/// when console answers the request.
88
/// </summary>
9-
public class AnsiEscapeSequenceRequest
9+
public class AnsiEscapeSequenceRequest : AnsiEscapeSequence
1010
{
11-
/// <summary>
12-
/// Request to send e.g. see
13-
/// <see>
14-
/// <cref>EscSeqUtils.CSI_SendDeviceAttributes.Request</cref>
15-
/// </see>
16-
/// </summary>
17-
public required string Request { get; init; }
18-
19-
// BUGBUG: Nullable issue
2011
/// <summary>
2112
/// Invoked when the console responds with an ANSI response code that matches the
22-
/// <see cref="Terminator"/>
13+
/// <see cref="AnsiEscapeSequence.Terminator"/>
2314
/// </summary>
24-
public Action<string> ResponseReceived;
15+
public required Action<string> ResponseReceived { get; init; }
2516

2617
/// <summary>
2718
/// Invoked if the console fails to responds to the ANSI response code
2819
/// </summary>
29-
public Action? Abandoned;
20+
public Action? Abandoned { get; init; }
3021

31-
/// <summary>
32-
/// <para>
33-
/// The terminator that uniquely identifies the type of response as responded
34-
/// by the console. e.g. for
35-
/// <see>
36-
/// <cref>EscSeqUtils.CSI_SendDeviceAttributes.Request</cref>
37-
/// </see>
38-
/// the terminator is
39-
/// <see>
40-
/// <cref>EscSeqUtils.CSI_SendDeviceAttributes.Terminator</cref>
41-
/// </see>
42-
/// .
43-
/// </para>
44-
/// <para>
45-
/// After sending a request, the first response with matching terminator will be matched
46-
/// to the oldest outstanding request.
47-
/// </para>
48-
/// </summary>
49-
public required string Terminator { get; init; }
5022

5123
/// <summary>
5224
/// Sends the <see cref="Request"/> to the raw output stream of the current <see cref="ConsoleDriver"/>.
@@ -55,14 +27,4 @@ public class AnsiEscapeSequenceRequest
5527
/// </summary>
5628
public void Send () { Application.Driver?.WriteRaw (Request); }
5729

58-
59-
/// <summary>
60-
/// The value expected in the response e.g.
61-
/// <see>
62-
/// <cref>EscSeqUtils.CSI_ReportTerminalSizeInChars.Value</cref>
63-
/// </see>
64-
/// which will have a 't' as terminator but also other different request may return the same terminator with a
65-
/// different value.
66-
/// </summary>
67-
public string? Value { get; init; }
6830
}

Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,7 @@ private bool SetCursorPosition (int col, int row)
581581

582582
private Curses.Window? _window;
583583
private UnixMainLoop? _mainLoopDriver;
584-
// BUGBUG: Fix this nullable issue.
585-
private object _processInputToken;
584+
private object? _processInputToken;
586585

587586
public override MainLoop Init ()
588587
{
@@ -1111,7 +1110,7 @@ public override void End ()
11111110
StopReportingMouseMoves ();
11121111
SetCursorVisibility (CursorVisibility.Default);
11131112

1114-
if (_mainLoopDriver is { })
1113+
if (_mainLoopDriver is { } && _processInputToken != null)
11151114
{
11161115
_mainLoopDriver.RemoveWatch (_processInputToken);
11171116
}

Terminal.Gui/ConsoleDrivers/EscSeqUtils/EscSeqUtils.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,7 +1799,7 @@ public enum DECSCUSR_Style
17991799
/// https://terminalguide.namepad.de/seq/csi_sn__p-6/
18001800
/// The terminal reply to <see cref="CSI_RequestCursorPositionReport"/>. ESC [ ? (y) ; (x) ; 1 R
18011801
/// </summary>
1802-
public static readonly AnsiEscapeSequenceRequest CSI_RequestCursorPositionReport = new () { Request = CSI + "?6n", Terminator = "R" };
1802+
public static readonly AnsiEscapeSequence CSI_RequestCursorPositionReport = new () { Request = CSI + "?6n", Terminator = "R" };
18031803

18041804
/// <summary>
18051805
/// The terminal reply to <see cref="CSI_RequestCursorPositionReport"/>. ESC [ ? (y) ; (x) R
@@ -1826,30 +1826,30 @@ public enum DECSCUSR_Style
18261826
/// The terminator indicating a reply to <see cref="CSI_SendDeviceAttributes"/> or
18271827
/// <see cref="CSI_SendDeviceAttributes2"/>
18281828
/// </summary>
1829-
public static readonly AnsiEscapeSequenceRequest CSI_SendDeviceAttributes = new () { Request = CSI + "0c", Terminator = "c" };
1829+
public static readonly AnsiEscapeSequence CSI_SendDeviceAttributes = new () { Request = CSI + "0c", Terminator = "c" };
18301830

18311831
/// <summary>
18321832
/// ESC [ > 0 c - Send Device Attributes (Secondary DA)
18331833
/// Windows Terminal v1.18+ emits: "\x1b[>0;10;1c" (vt100, firmware version 1.0, vt220)
18341834
/// </summary>
1835-
public static readonly AnsiEscapeSequenceRequest CSI_SendDeviceAttributes2 = new () { Request = CSI + ">0c", Terminator = "c" };
1835+
public static readonly AnsiEscapeSequence CSI_SendDeviceAttributes2 = new () { Request = CSI + ">0c", Terminator = "c" };
18361836

18371837
/// <summary>
18381838
/// CSI 16 t - Request sixel resolution (width and height in pixels)
18391839
/// </summary>
1840-
public static readonly AnsiEscapeSequenceRequest CSI_RequestSixelResolution = new () { Request = CSI + "16t", Terminator = "t" };
1840+
public static readonly AnsiEscapeSequence CSI_RequestSixelResolution = new () { Request = CSI + "16t", Terminator = "t" };
18411841

18421842
/// <summary>
18431843
/// CSI 14 t - Request window size in pixels (width x height)
18441844
/// </summary>
1845-
public static readonly AnsiEscapeSequenceRequest CSI_RequestWindowSizeInPixels = new () { Request = CSI + "14t", Terminator = "t" };
1845+
public static readonly AnsiEscapeSequence CSI_RequestWindowSizeInPixels = new () { Request = CSI + "14t", Terminator = "t" };
18461846

18471847
/// <summary>
18481848
/// CSI 1 8 t | yes | yes | yes | report window size in chars
18491849
/// https://terminalguide.namepad.de/seq/csi_st-18/
18501850
/// The terminator indicating a reply to <see cref="CSI_ReportTerminalSizeInChars"/> : ESC [ 8 ; height ; width t
18511851
/// </summary>
1852-
public static readonly AnsiEscapeSequenceRequest CSI_ReportTerminalSizeInChars = new () { Request = CSI + "18t", Terminator = "t", Value = "8" };
1852+
public static readonly AnsiEscapeSequence CSI_ReportTerminalSizeInChars = new () { Request = CSI + "18t", Terminator = "t", Value = "8" };
18531853

18541854

18551855
/// <summary>

Terminal.Gui/Drawing/Sixel/SixelSupportDetector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private void IsSixelSupportedByDar (SixelSupportResult result, Action<SixelSuppo
127127
() => resultCallback (result));
128128
}
129129

130-
private static void QueueRequest (AnsiEscapeSequenceRequest req, Action<string> responseCallback, Action abandoned)
130+
private static void QueueRequest (AnsiEscapeSequence req, Action<string> responseCallback, Action abandoned)
131131
{
132132
var newRequest = new AnsiEscapeSequenceRequest
133133
{

UICatalog/Scenarios/AnsiRequestsScenario.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private View BuildSingleTab ()
104104
}
105105

106106
var selAnsiEscapeSequenceRequestName = scrRequests [cbRequests.SelectedItem];
107-
AnsiEscapeSequenceRequest selAnsiEscapeSequenceRequest = null;
107+
AnsiEscapeSequence selAnsiEscapeSequenceRequest = null;
108108

109109
switch (selAnsiEscapeSequenceRequestName)
110110
{
@@ -157,7 +157,7 @@ private View BuildSingleTab ()
157157

158158
btnResponse.Accepting += (s, e) =>
159159
{
160-
var ansiEscapeSequenceRequest = new AnsiEscapeSequenceRequest
160+
var ansiEscapeSequenceRequest = new AnsiEscapeSequence
161161
{
162162
Request = tfRequest.Text,
163163
Terminator = tfTerminator.Text,

0 commit comments

Comments
 (0)