diff --git a/Terminal.Gui/ConsoleDrivers/AnsiEscapeSequenceRequest.cs b/Terminal.Gui/ConsoleDrivers/AnsiEscapeSequenceRequest.cs
index 4b9ecc833..9b1f6b29e 100644
--- a/Terminal.Gui/ConsoleDrivers/AnsiEscapeSequenceRequest.cs
+++ b/Terminal.Gui/ConsoleDrivers/AnsiEscapeSequenceRequest.cs
@@ -16,6 +16,7 @@ public class AnsiEscapeSequenceRequest
///
public required string Request { get; init; }
+ // BUGBUG: Nullable issue
///
/// Invoked when the console responds with an ANSI response code that matches the
///
diff --git a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/AnsiRequestScheduler.cs b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/AnsiRequestScheduler.cs
index f7d6c4d9e..d2a7841c4 100644
--- a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/AnsiRequestScheduler.cs
+++ b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/AnsiRequestScheduler.cs
@@ -14,8 +14,8 @@ public class AnsiRequestScheduler
private readonly IAnsiResponseParser _parser;
///
- /// Function for returning the current time. Use in unit tests to
- /// ensure repeatable tests.
+ /// Function for returning the current time. Use in unit tests to
+ /// ensure repeatable tests.
///
internal Func Now { get; set; }
@@ -54,6 +54,11 @@ public class AnsiRequestScheduler
private readonly DateTime _lastRun;
+ ///
+ /// Creates a new instance.
+ ///
+ ///
+ ///
public AnsiRequestScheduler (IAnsiResponseParser parser, Func? now = null)
{
_parser = parser;
@@ -67,11 +72,9 @@ public class AnsiRequestScheduler
///
///
/// if request was sent immediately. if it was queued.
- public bool SendOrSchedule (AnsiEscapeSequenceRequest request)
- {
- return SendOrSchedule (request, true);
- }
- private bool SendOrSchedule (AnsiEscapeSequenceRequest request,bool addToQueue)
+ public bool SendOrSchedule (AnsiEscapeSequenceRequest request) { return SendOrSchedule (request, true); }
+
+ private bool SendOrSchedule (AnsiEscapeSequenceRequest request, bool addToQueue)
{
if (CanSend (request, out ReasonCannotSend reason))
{
@@ -105,13 +108,13 @@ public class AnsiRequestScheduler
private void EvictStaleRequests ()
{
- foreach (var stale in _lastSend.Where (v => IsStale (v.Value)).Select (k => k.Key))
+ foreach (string stale in _lastSend.Where (v => IsStale (v.Value)).Select (k => k.Key))
{
EvictStaleRequests (stale);
}
}
- private bool IsStale (DateTime dt) => Now () - dt > _staleTimeout;
+ private bool IsStale (DateTime dt) { return Now () - dt > _staleTimeout; }
///
/// Looks to see if the last time we sent
@@ -155,7 +158,7 @@ public class AnsiRequestScheduler
}
// Get oldest request
- Tuple? opportunity = _queuedRequests.MinBy (r=>r.Item2);
+ Tuple? opportunity = _queuedRequests.MinBy (r => r.Item2);
if (opportunity != null)
{
@@ -163,6 +166,7 @@ public class AnsiRequestScheduler
if (SendOrSchedule (opportunity.Item1, false))
{
_queuedRequests.Remove (opportunity);
+
return true;
}
}
@@ -172,7 +176,6 @@ public class AnsiRequestScheduler
return false;
}
-
private void Send (AnsiEscapeSequenceRequest r)
{
_lastSend.AddOrUpdate (r.Terminator, _ => Now (), (_, _) => Now ());
@@ -210,23 +213,4 @@ public class AnsiRequestScheduler
return false;
}
-}
-
-internal enum ReasonCannotSend
-{
- ///
- /// No reason given.
- ///
- None = 0,
-
- ///
- /// The parser is already waiting for a request to complete with the given terminator.
- ///
- OutstandingRequest,
-
- ///
- /// There have been too many requests sent recently, new requests will be put into
- /// queue to prevent console becoming unresponsive.
- ///
- TooManyRequests
-}
+}
\ No newline at end of file
diff --git a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/AnsiResponseParser.cs b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/AnsiResponseParser.cs
index a2bc4d0ce..503a63769 100644
--- a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/AnsiResponseParser.cs
+++ b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/AnsiResponseParser.cs
@@ -4,29 +4,29 @@ namespace Terminal.Gui;
internal abstract class AnsiResponseParserBase : IAnsiResponseParser
{
- protected object lockExpectedResponses = new ();
+ protected object _lockExpectedResponses = new ();
- protected object lockState = new ();
+ protected object _lockState = new ();
///
/// Responses we are expecting to come in.
///
- protected readonly List expectedResponses = new ();
+ protected readonly List _expectedResponses = [];
///
/// Collection of responses that we .
///
- protected readonly List lateResponses = new ();
+ protected readonly List _lateResponses = [];
///
/// Responses that you want to look out for that will come in continuously e.g. mouse events.
/// Key is the terminator.
///
- protected readonly List persistentExpectations = new ();
+ protected readonly List _persistentExpectations = [];
private AnsiResponseParserState _state = AnsiResponseParserState.Normal;
- ///
+ ///
public AnsiResponseParserState State
{
get => _state;
@@ -37,7 +37,7 @@ internal abstract class AnsiResponseParserBase : IAnsiResponseParser
}
}
- protected readonly IHeld heldContent;
+ protected readonly IHeld _heldContent;
///
/// When was last changed.
@@ -48,8 +48,7 @@ internal abstract class AnsiResponseParserBase : IAnsiResponseParser
// see CSI in https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s
// No - N or O
protected readonly HashSet _knownTerminators = new (
- new []
- {
+ [
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
// No - N or O
@@ -58,14 +57,18 @@ internal abstract class AnsiResponseParserBase : IAnsiResponseParser
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'l', 'm', 'n',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
- });
+ ]);
- protected AnsiResponseParserBase (IHeld heldContent) { this.heldContent = heldContent; }
+ protected AnsiResponseParserBase (IHeld heldContent) { _heldContent = heldContent; }
protected void ResetState ()
{
State = AnsiResponseParserState.Normal;
- heldContent.ClearHeld ();
+
+ lock (_lockState)
+ {
+ _heldContent.ClearHeld ();
+ }
}
///
@@ -87,7 +90,7 @@ internal abstract class AnsiResponseParserBase : IAnsiResponseParser
int inputLength
)
{
- lock (lockState)
+ lock (_lockState)
{
ProcessInputBaseImpl (getCharAtIndex, getObjectAtIndex, appendOutput, inputLength);
}
@@ -116,7 +119,7 @@ internal abstract class AnsiResponseParserBase : IAnsiResponseParser
{
// Escape character detected, move to ExpectingBracket state
State = AnsiResponseParserState.ExpectingBracket;
- heldContent.AddToHeld (currentObj); // Hold the escape character
+ _heldContent.AddToHeld (currentObj); // Hold the escape character
}
else
{
@@ -131,13 +134,13 @@ internal abstract class AnsiResponseParserBase : IAnsiResponseParser
{
// Second escape so we must release first
ReleaseHeld (appendOutput, AnsiResponseParserState.ExpectingBracket);
- heldContent.AddToHeld (currentObj); // Hold the new escape
+ _heldContent.AddToHeld (currentObj); // Hold the new escape
}
else if (currentChar == '[')
{
// Detected '[', transition to InResponse state
State = AnsiResponseParserState.InResponse;
- heldContent.AddToHeld (currentObj); // Hold the '['
+ _heldContent.AddToHeld (currentObj); // Hold the '['
}
else
{
@@ -149,7 +152,7 @@ internal abstract class AnsiResponseParserBase : IAnsiResponseParser
break;
case AnsiResponseParserState.InResponse:
- heldContent.AddToHeld (currentObj);
+ _heldContent.AddToHeld (currentObj);
// Check if the held content should be released
if (ShouldReleaseHeldContent ())
@@ -166,73 +169,76 @@ internal abstract class AnsiResponseParserBase : IAnsiResponseParser
private void ReleaseHeld (Action appendOutput, AnsiResponseParserState newState = AnsiResponseParserState.Normal)
{
- foreach (object o in heldContent.HeldToObjects ())
+ foreach (object o in _heldContent.HeldToObjects ())
{
appendOutput (o);
}
State = newState;
- heldContent.ClearHeld ();
+ _heldContent.ClearHeld ();
}
// Common response handler logic
protected bool ShouldReleaseHeldContent ()
{
- string cur = heldContent.HeldToString ();
-
- lock (lockExpectedResponses)
+ lock (_lockState)
{
- // Look for an expected response for what is accumulated so far (since Esc)
- if (MatchResponse (
- cur,
- expectedResponses,
- true,
- true))
+ string cur = _heldContent.HeldToString ();
+
+ lock (_lockExpectedResponses)
{
- return false;
+ // Look for an expected response for what is accumulated so far (since Esc)
+ if (MatchResponse (
+ cur,
+ _expectedResponses,
+ true,
+ true))
+ {
+ return false;
+ }
+
+ // Also try looking for late requests - in which case we do not invoke but still swallow content to avoid corrupting downstream
+ if (MatchResponse (
+ cur,
+ _lateResponses,
+ false,
+ true))
+ {
+ return false;
+ }
+
+ // Look for persistent requests
+ if (MatchResponse (
+ cur,
+ _persistentExpectations,
+ true,
+ false))
+ {
+ return false;
+ }
}
- // Also try looking for late requests - in which case we do not invoke but still swallow content to avoid corrupting downstream
- if (MatchResponse (
- cur,
- lateResponses,
- false,
- true))
+ // Finally if it is a valid ansi response but not one we are expect (e.g. its mouse activity)
+ // then we can release it back to input processing stream
+ if (_knownTerminators.Contains (cur.Last ()) && cur.StartsWith (EscSeqUtils.CSI))
{
- return false;
+ // We have found a terminator so bail
+ State = AnsiResponseParserState.Normal;
+
+ // Maybe swallow anyway if user has custom delegate
+ bool swallow = ShouldSwallowUnexpectedResponse ();
+
+ if (swallow)
+ {
+ _heldContent.ClearHeld ();
+
+ // Do not send back to input stream
+ return false;
+ }
+
+ // Do release back to input stream
+ return true;
}
-
- // Look for persistent requests
- if (MatchResponse (
- cur,
- persistentExpectations,
- true,
- false))
- {
- return false;
- }
- }
-
- // Finally if it is a valid ansi response but not one we are expect (e.g. its mouse activity)
- // then we can release it back to input processing stream
- if (_knownTerminators.Contains (cur.Last ()) && cur.StartsWith (EscSeqUtils.CSI))
- {
- // We have found a terminator so bail
- State = AnsiResponseParserState.Normal;
-
- // Maybe swallow anyway if user has custom delegate
- bool swallow = ShouldSwallowUnexpectedResponse ();
-
- if (swallow)
- {
- heldContent.ClearHeld ();
-
- // Do not send back to input stream
- return false;
- }
-
- // Do release back to input stream
- return true;
}
return false; // Continue accumulating
@@ -241,7 +247,7 @@ internal abstract class AnsiResponseParserBase : IAnsiResponseParser
///
///
/// When overriden in a derived class, indicates whether the unexpected response
- /// currently in should be released or swallowed.
+ /// currently in should be released or swallowed.
/// Use this to enable default event for escape codes.
///
///
@@ -261,7 +267,7 @@ internal abstract class AnsiResponseParserBase : IAnsiResponseParser
{
if (invokeCallback)
{
- matchingResponse.Response.Invoke (heldContent);
+ matchingResponse.Response.Invoke (_heldContent);
}
ResetState ();
@@ -278,17 +284,17 @@ internal abstract class AnsiResponseParserBase : IAnsiResponseParser
}
///
- public void ExpectResponse (string terminator, Action response,Action? abandoned, bool persistent)
+ public void ExpectResponse (string terminator, Action response, Action? abandoned, bool persistent)
{
- lock (lockExpectedResponses)
+ lock (_lockExpectedResponses)
{
if (persistent)
{
- persistentExpectations.Add (new (terminator, h => response.Invoke (h.HeldToString ()), abandoned));
+ _persistentExpectations.Add (new (terminator, h => response.Invoke (h.HeldToString ()), abandoned));
}
else
{
- expectedResponses.Add (new (terminator, h => response.Invoke (h.HeldToString ()), abandoned));
+ _expectedResponses.Add (new (terminator, h => response.Invoke (h.HeldToString ()), abandoned));
}
}
}
@@ -296,36 +302,36 @@ internal abstract class AnsiResponseParserBase : IAnsiResponseParser
///
public bool IsExpecting (string terminator)
{
- lock (lockExpectedResponses)
+ lock (_lockExpectedResponses)
{
// If any of the new terminator matches any existing terminators characters it's a collision so true.
- return expectedResponses.Any (r => r.Terminator.Intersect (terminator).Any ());
+ return _expectedResponses.Any (r => r.Terminator.Intersect (terminator).Any ());
}
}
///
public void StopExpecting (string terminator, bool persistent)
{
- lock (lockExpectedResponses)
+ lock (_lockExpectedResponses)
{
if (persistent)
{
- AnsiResponseExpectation [] removed = persistentExpectations.Where (r => r.Matches (terminator)).ToArray ();
+ AnsiResponseExpectation [] removed = _persistentExpectations.Where (r => r.Matches (terminator)).ToArray ();
- foreach (var toRemove in removed)
+ foreach (AnsiResponseExpectation toRemove in removed)
{
- persistentExpectations.Remove (toRemove);
+ _persistentExpectations.Remove (toRemove);
toRemove.Abandoned?.Invoke ();
}
}
else
{
- AnsiResponseExpectation [] removed = expectedResponses.Where (r => r.Terminator == terminator).ToArray ();
+ AnsiResponseExpectation [] removed = _expectedResponses.Where (r => r.Terminator == terminator).ToArray ();
foreach (AnsiResponseExpectation r in removed)
{
- expectedResponses.Remove (r);
- lateResponses.Add (r);
+ _expectedResponses.Remove (r);
+ _lateResponses.Add (r);
r.Abandoned?.Invoke ();
}
}
@@ -333,10 +339,8 @@ internal abstract class AnsiResponseParserBase : IAnsiResponseParser
}
}
-internal class AnsiResponseParser : AnsiResponseParserBase
+internal class AnsiResponseParser () : AnsiResponseParserBase (new GenericHeld ())
{
- public AnsiResponseParser () : base (new GenericHeld ()) { }
-
///
public Func>, bool> UnexpectedResponseHandler { get; set; } = _ => false;
@@ -353,10 +357,10 @@ internal class AnsiResponseParser : AnsiResponseParserBase
return output;
}
- public Tuple[] Release ()
+ public Tuple [] Release ()
{
// Lock in case Release is called from different Thread from parse
- lock (lockState)
+ lock (_lockState)
{
Tuple [] result = HeldToEnumerable ().ToArray ();
@@ -366,7 +370,7 @@ internal class AnsiResponseParser : AnsiResponseParserBase
}
}
- private IEnumerable> HeldToEnumerable () { return (IEnumerable>)heldContent.HeldToObjects (); }
+ private IEnumerable> HeldToEnumerable () { return (IEnumerable>)_heldContent.HeldToObjects (); }
///
/// 'Overload' for specifying an expectation that requires the metadata as well as characters. Has
@@ -376,17 +380,17 @@ internal class AnsiResponseParser : AnsiResponseParserBase
///
///
///
- public void ExpectResponseT (string terminator, Action>> response,Action? abandoned, bool persistent)
+ public void ExpectResponseT (string terminator, Action>> response, Action? abandoned, bool persistent)
{
- lock (lockExpectedResponses)
+ lock (_lockExpectedResponses)
{
if (persistent)
{
- persistentExpectations.Add (new (terminator, h => response.Invoke (HeldToEnumerable ()), abandoned));
+ _persistentExpectations.Add (new (terminator, h => response.Invoke (HeldToEnumerable ()), abandoned));
}
else
{
- expectedResponses.Add (new (terminator, h => response.Invoke (HeldToEnumerable ()), abandoned));
+ _expectedResponses.Add (new (terminator, h => response.Invoke (HeldToEnumerable ()), abandoned));
}
}
}
@@ -395,7 +399,7 @@ internal class AnsiResponseParser : AnsiResponseParserBase
protected override bool ShouldSwallowUnexpectedResponse () { return UnexpectedResponseHandler.Invoke (HeldToEnumerable ()); }
}
-internal class AnsiResponseParser : AnsiResponseParserBase
+internal class AnsiResponseParser () : AnsiResponseParserBase (new StringHeld ())
{
///
///
@@ -410,8 +414,6 @@ internal class AnsiResponseParser : AnsiResponseParserBase
///
public Func UnknownResponseHandler { get; set; } = _ => false;
- public AnsiResponseParser () : base (new StringHeld ()) { }
-
public string ProcessInput (string input)
{
var output = new StringBuilder ();
@@ -427,9 +429,9 @@ internal class AnsiResponseParser : AnsiResponseParserBase
public string Release ()
{
- lock (lockState)
+ lock (_lockState)
{
- string output = heldContent.HeldToString ();
+ string output = _heldContent.HeldToString ();
ResetState ();
return output;
@@ -437,5 +439,11 @@ internal class AnsiResponseParser : AnsiResponseParserBase
}
///
- protected override bool ShouldSwallowUnexpectedResponse () { return UnknownResponseHandler.Invoke (heldContent.HeldToString ()); }
+ protected override bool ShouldSwallowUnexpectedResponse ()
+ {
+ lock (_lockState)
+ {
+ return UnknownResponseHandler.Invoke (_heldContent.HeldToString ());
+ }
+ }
}
diff --git a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/IAnsiResponseParser.cs b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/IAnsiResponseParser.cs
index bc7014227..dbcd16b95 100644
--- a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/IAnsiResponseParser.cs
+++ b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/IAnsiResponseParser.cs
@@ -30,7 +30,7 @@ public interface IAnsiResponseParser
/// that already has one.
/// exists.
///
- void ExpectResponse (string terminator, Action response,Action? abandoned, bool persistent);
+ void ExpectResponse (string terminator, Action response, Action? abandoned, bool persistent);
///
/// Returns true if there is an existing expectation (i.e. we are waiting a response
diff --git a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/ReasonCannotSend.cs b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/ReasonCannotSend.cs
new file mode 100644
index 000000000..c2e31a6c3
--- /dev/null
+++ b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/ReasonCannotSend.cs
@@ -0,0 +1,21 @@
+#nullable enable
+namespace Terminal.Gui;
+
+internal enum ReasonCannotSend
+{
+ ///
+ /// No reason given.
+ ///
+ None = 0,
+
+ ///
+ /// The parser is already waiting for a request to complete with the given terminator.
+ ///
+ OutstandingRequest,
+
+ ///
+ /// There have been too many requests sent recently, new requests will be put into
+ /// queue to prevent console becoming unresponsive.
+ ///
+ TooManyRequests
+}
diff --git a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/StringHeld.cs b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/StringHeld.cs
index 4a03bc3b5..f8b7f4e0a 100644
--- a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/StringHeld.cs
+++ b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/StringHeld.cs
@@ -6,13 +6,13 @@ namespace Terminal.Gui;
///
internal class StringHeld : IHeld
{
- private readonly StringBuilder held = new ();
+ private readonly StringBuilder _held = new ();
- public void ClearHeld () { held.Clear (); }
+ public void ClearHeld () { _held.Clear (); }
- public string HeldToString () { return held.ToString (); }
+ public string HeldToString () { return _held.ToString (); }
- public IEnumerable HeldToObjects () { return held.ToString ().Select (c => (object)c); }
+ public IEnumerable HeldToObjects () { return _held.ToString ().Select (c => (object)c); }
- public void AddToHeld (object o) { held.Append ((char)o); }
+ public void AddToHeld (object o) { _held.Append ((char)o); }
}
diff --git a/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs b/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs
index 373cea16b..24e1347ea 100644
--- a/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs
+++ b/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs
@@ -710,6 +710,10 @@ public abstract class ConsoleDriver : IConsoleDriver
internal abstract IAnsiResponseParser GetParser ();
+ ///
+ /// Gets the for this .
+ ///
+ ///
public AnsiRequestScheduler GetRequestScheduler ()
{
// Lazy initialization because GetParser is virtual
diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs
index cb2cb9140..43236fa75 100644
--- a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs
+++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs
@@ -581,6 +581,7 @@ internal class CursesDriver : ConsoleDriver
private Curses.Window? _window;
private UnixMainLoop? _mainLoopDriver;
+ // BUGBUG: Fix this nullable issue.
private object _processInputToken;
public override MainLoop Init ()
@@ -730,6 +731,7 @@ internal class CursesDriver : ConsoleDriver
while (wch2 == Curses.KeyMouse)
{
+ // BUGBUG: Fix this nullable issue.
Key kea = null;
ConsoleKeyInfo [] cki =
@@ -739,6 +741,7 @@ internal class CursesDriver : ConsoleDriver
new ('<', 0, false, false, false)
};
code = 0;
+ // BUGBUG: Fix this nullable issue.
HandleEscSeqResponse (ref code, ref k, ref wch2, ref kea, ref cki);
}
@@ -796,6 +799,7 @@ internal class CursesDriver : ConsoleDriver
k = KeyCode.AltMask | MapCursesKey (wch);
}
+ // BUGBUG: Fix this nullable issue.
Key key = null;
if (code == 0)
@@ -826,6 +830,7 @@ internal class CursesDriver : ConsoleDriver
[
new ((char)KeyCode.Esc, 0, false, false, false), new ((char)wch2, 0, false, false, false)
];
+ // BUGBUG: Fix this nullable issue.
HandleEscSeqResponse (ref code, ref k, ref wch2, ref key, ref cki);
return;
@@ -954,6 +959,7 @@ internal class CursesDriver : ConsoleDriver
if (wch2 == 0 || wch2 == 27 || wch2 == Curses.KeyMouse)
{
+ // BUGBUG: Fix this nullable issue.
EscSeqUtils.DecodeEscSeq (
ref consoleKeyInfo,
ref ck,
@@ -977,6 +983,7 @@ internal class CursesDriver : ConsoleDriver
OnMouseEvent (new () { Flags = mf, Position = pos });
}
+ // BUGBUG: Fix this nullable issue.
cki = null;
if (wch2 == 27)
diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs
index 28df408ea..4b2daea40 100644
--- a/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs
+++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs
@@ -247,6 +247,7 @@ internal class UnixMainLoop : IMainLoopDriver
private class Watch
{
+ // BUGBUG: Fix this nullable issue.
public Func Callback;
public Condition Condition;
public int File;
diff --git a/Terminal.Gui/ConsoleDrivers/IConsoleDriver.cs b/Terminal.Gui/ConsoleDrivers/IConsoleDriver.cs
index 99a6a916e..7fbb9b837 100644
--- a/Terminal.Gui/ConsoleDrivers/IConsoleDriver.cs
+++ b/Terminal.Gui/ConsoleDrivers/IConsoleDriver.cs
@@ -31,8 +31,9 @@ public interface IConsoleDriver
/// The number of columns visible in the terminal.
int Cols { get; set; }
+ // BUGBUG: This should not be publicly settable.
///
- /// The contents of the application output. The driver outputs this buffer to the terminal when
+ /// Gets or sets 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.
///
@@ -92,11 +93,13 @@ public interface IConsoleDriver
///
bool IsRuneSupported (Rune rune);
+ // BUGBUG: This is not referenced. Can it be removed?
/// Tests whether the specified coordinate are valid for drawing.
/// The column.
/// The row.
///
- /// if the coordinate is outside the screen bounds or outside of .
+ /// if the coordinate is outside the screen bounds or outside of
+ /// .
/// otherwise.
///
bool IsValidLocation (int col, int row);
@@ -106,19 +109,23 @@ public interface IConsoleDriver
/// The column.
/// The row.
///
- /// if the coordinate is outside the screen bounds or outside of .
+ /// 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.
+ /// 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
+ /// If or are negative or beyond
+ /// and
/// , the method still sets those properties.
///
///
@@ -130,12 +137,15 @@ public interface IConsoleDriver
///
///
/// 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
+ /// 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)
+ /// 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.
///
///
@@ -144,7 +154,8 @@ public interface IConsoleDriver
///
/// Adds the specified to the display at the current cursor position. This method is a
- /// convenience method that calls with the constructor.
+ /// convenience method that calls with the
+ /// constructor.
///
/// Character to add.
void AddRune (char c);
@@ -153,7 +164,8 @@ public interface IConsoleDriver
///
///
/// When the method returns, will be incremented by the number of columns
- /// required, unless the new column value is outside of the or screen
+ /// 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.
@@ -161,9 +173,12 @@ public interface IConsoleDriver
/// String.
void AddStr (string str);
- /// Fills the specified rectangle with the specified rune, using
+ ///
+ /// 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 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
@@ -185,12 +200,14 @@ public interface IConsoleDriver
///
event EventHandler? ClearedContents;
+ // BUGBUG: This is not referenced. Can it be removed?
///
- /// Sets as dirty for situations where views
- /// don't need layout and redrawing, but just refresh the screen.
+ /// Sets as dirty for situations where views
+ /// don't need layout and redrawing, but just refresh the screen.
///
void SetContentsAsDirty ();
+ // BUGBUG: This is not referenced. Can it be removed?
/// Determines if the terminal cursor should be visible or not and sets it accordingly.
/// upon success
bool EnsureCursorVisibility ();
@@ -224,7 +241,10 @@ public interface IConsoleDriver
/// This is only implemented in .
void Suspend ();
- /// Sets the position of the terminal cursor to and .
+ ///
+ /// 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.
@@ -263,6 +283,7 @@ public interface IConsoleDriver
/// Event fired when a key is pressed down. This is a precursor to .
event EventHandler? KeyDown;
+ // BUGBUG: This is not referenced. Can it be removed?
///
/// Called when a key is pressed down. Fires the event. This is a precursor to
/// .
@@ -272,14 +293,17 @@ public interface IConsoleDriver
/// Event fired when a key is released.
///
- /// Drivers that do not support key release events will fire this event after processing is
+ /// Drivers that do not support key release events will fire this event after
+ /// processing is
/// complete.
///
event EventHandler? KeyUp;
+ // BUGBUG: This is not referenced. Can it be removed?
/// Called when a key is released. Fires the event.
///
- /// Drivers that do not support key release events will call this method after processing
+ /// Drivers that do not support key release events will call this method after
+ /// processing
/// is complete.
///
///
@@ -294,15 +318,19 @@ public interface IConsoleDriver
void SendKeys (char keyChar, ConsoleKey key, bool shift, bool alt, bool ctrl);
///
- /// How long after Esc has been pressed before we give up on getting an Ansi escape sequence
+ /// How long after Esc has been pressed before we give up on getting an Ansi escape sequence
///
public TimeSpan EscTimeout { get; }
///
- /// Queues the given for execution
+ /// Queues the given for execution
///
///
public void QueueAnsiRequest (AnsiEscapeSequenceRequest request);
+ ///
+ /// Gets the for the driver
+ ///
+ ///
public AnsiRequestScheduler GetRequestScheduler ();
}
diff --git a/Terminal.Gui/ConsoleDrivers/NetDriver/NetDriver.cs b/Terminal.Gui/ConsoleDrivers/NetDriver/NetDriver.cs
index ac871c820..d8e7e1d3e 100644
--- a/Terminal.Gui/ConsoleDrivers/NetDriver/NetDriver.cs
+++ b/Terminal.Gui/ConsoleDrivers/NetDriver/NetDriver.cs
@@ -223,6 +223,8 @@ internal class NetDriver : ConsoleDriver
return updated;
}
#region Init/End/MainLoop
+
+ // BUGBUG: Fix this nullable issue.
///
internal override IAnsiResponseParser GetParser () => _mainLoopDriver._netEvents.Parser;
internal NetMainLoop? _mainLoopDriver;
diff --git a/Terminal.Gui/ConsoleDrivers/WindowsDriver/WindowsDriver.cs b/Terminal.Gui/ConsoleDrivers/WindowsDriver/WindowsDriver.cs
index 58ca75965..4998b27c7 100644
--- a/Terminal.Gui/ConsoleDrivers/WindowsDriver/WindowsDriver.cs
+++ b/Terminal.Gui/ConsoleDrivers/WindowsDriver/WindowsDriver.cs
@@ -41,6 +41,7 @@ internal class WindowsDriver : ConsoleDriver
private Point _pointMove;
private bool _processButtonClick;
+ // BUGBUG: Fix this nullable issue.
public WindowsDriver ()
{
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
diff --git a/Terminal.Gui/Drawing/AnsiColorCode.cs b/Terminal.Gui/Drawing/Color/AnsiColorCode.cs
similarity index 100%
rename from Terminal.Gui/Drawing/AnsiColorCode.cs
rename to Terminal.Gui/Drawing/Color/AnsiColorCode.cs
diff --git a/Terminal.Gui/Drawing/Color.ColorExtensions.cs b/Terminal.Gui/Drawing/Color/Color.ColorExtensions.cs
similarity index 100%
rename from Terminal.Gui/Drawing/Color.ColorExtensions.cs
rename to Terminal.Gui/Drawing/Color/Color.ColorExtensions.cs
diff --git a/Terminal.Gui/Drawing/Color.ColorName.cs b/Terminal.Gui/Drawing/Color/Color.ColorName.cs
similarity index 100%
rename from Terminal.Gui/Drawing/Color.ColorName.cs
rename to Terminal.Gui/Drawing/Color/Color.ColorName.cs
diff --git a/Terminal.Gui/Drawing/Color.ColorParseException.cs b/Terminal.Gui/Drawing/Color/Color.ColorParseException.cs
similarity index 100%
rename from Terminal.Gui/Drawing/Color.ColorParseException.cs
rename to Terminal.Gui/Drawing/Color/Color.ColorParseException.cs
diff --git a/Terminal.Gui/Drawing/Color.Formatting.cs b/Terminal.Gui/Drawing/Color/Color.Formatting.cs
similarity index 100%
rename from Terminal.Gui/Drawing/Color.Formatting.cs
rename to Terminal.Gui/Drawing/Color/Color.Formatting.cs
diff --git a/Terminal.Gui/Drawing/Color.Operators.cs b/Terminal.Gui/Drawing/Color/Color.Operators.cs
similarity index 100%
rename from Terminal.Gui/Drawing/Color.Operators.cs
rename to Terminal.Gui/Drawing/Color/Color.Operators.cs
diff --git a/Terminal.Gui/Drawing/Color.cs b/Terminal.Gui/Drawing/Color/Color.cs
similarity index 100%
rename from Terminal.Gui/Drawing/Color.cs
rename to Terminal.Gui/Drawing/Color/Color.cs
diff --git a/Terminal.Gui/Drawing/ColorEventArgs.cs b/Terminal.Gui/Drawing/Color/ColorEventArgs.cs
similarity index 100%
rename from Terminal.Gui/Drawing/ColorEventArgs.cs
rename to Terminal.Gui/Drawing/Color/ColorEventArgs.cs
diff --git a/Terminal.Gui/Drawing/ColorModel.cs b/Terminal.Gui/Drawing/Color/ColorModel.cs
similarity index 100%
rename from Terminal.Gui/Drawing/ColorModel.cs
rename to Terminal.Gui/Drawing/Color/ColorModel.cs
diff --git a/Terminal.Gui/Drawing/Quant/ColorQuantizer.cs b/Terminal.Gui/Drawing/Color/ColorQuantizer.cs
similarity index 100%
rename from Terminal.Gui/Drawing/Quant/ColorQuantizer.cs
rename to Terminal.Gui/Drawing/Color/ColorQuantizer.cs
diff --git a/Terminal.Gui/Drawing/ColorScheme.Colors.cs b/Terminal.Gui/Drawing/Color/ColorScheme.Colors.cs
similarity index 100%
rename from Terminal.Gui/Drawing/ColorScheme.Colors.cs
rename to Terminal.Gui/Drawing/Color/ColorScheme.Colors.cs
diff --git a/Terminal.Gui/Drawing/ColorScheme.cs b/Terminal.Gui/Drawing/Color/ColorScheme.cs
similarity index 100%
rename from Terminal.Gui/Drawing/ColorScheme.cs
rename to Terminal.Gui/Drawing/Color/ColorScheme.cs
diff --git a/Terminal.Gui/Drawing/ColorStrings.cs b/Terminal.Gui/Drawing/Color/ColorStrings.cs
similarity index 100%
rename from Terminal.Gui/Drawing/ColorStrings.cs
rename to Terminal.Gui/Drawing/Color/ColorStrings.cs
diff --git a/Terminal.Gui/Drawing/Quant/IColorDistance.cs b/Terminal.Gui/Drawing/Color/IColorDistance.cs
similarity index 100%
rename from Terminal.Gui/Drawing/Quant/IColorDistance.cs
rename to Terminal.Gui/Drawing/Color/IColorDistance.cs
diff --git a/Terminal.Gui/Drawing/IColorNameResolver.cs b/Terminal.Gui/Drawing/Color/IColorNameResolver.cs
similarity index 100%
rename from Terminal.Gui/Drawing/IColorNameResolver.cs
rename to Terminal.Gui/Drawing/Color/IColorNameResolver.cs
diff --git a/Terminal.Gui/Drawing/ICustomColorFormatter.cs b/Terminal.Gui/Drawing/Color/ICustomColorFormatter.cs
similarity index 100%
rename from Terminal.Gui/Drawing/ICustomColorFormatter.cs
rename to Terminal.Gui/Drawing/Color/ICustomColorFormatter.cs
diff --git a/Terminal.Gui/Drawing/W3CColors.cs b/Terminal.Gui/Drawing/Color/W3CColors.cs
similarity index 100%
rename from Terminal.Gui/Drawing/W3CColors.cs
rename to Terminal.Gui/Drawing/Color/W3CColors.cs
diff --git a/Terminal.Gui/Drawing/IntersectionDefinition.cs b/Terminal.Gui/Drawing/LineCanvas/IntersectionDefinition.cs
similarity index 100%
rename from Terminal.Gui/Drawing/IntersectionDefinition.cs
rename to Terminal.Gui/Drawing/LineCanvas/IntersectionDefinition.cs
diff --git a/Terminal.Gui/Drawing/IntersectionRuneType.cs b/Terminal.Gui/Drawing/LineCanvas/IntersectionRuneType.cs
similarity index 100%
rename from Terminal.Gui/Drawing/IntersectionRuneType.cs
rename to Terminal.Gui/Drawing/LineCanvas/IntersectionRuneType.cs
diff --git a/Terminal.Gui/Drawing/IntersectionType.cs b/Terminal.Gui/Drawing/LineCanvas/IntersectionType.cs
similarity index 100%
rename from Terminal.Gui/Drawing/IntersectionType.cs
rename to Terminal.Gui/Drawing/LineCanvas/IntersectionType.cs
diff --git a/Terminal.Gui/Drawing/LineCanvas.cs b/Terminal.Gui/Drawing/LineCanvas/LineCanvas.cs
similarity index 100%
rename from Terminal.Gui/Drawing/LineCanvas.cs
rename to Terminal.Gui/Drawing/LineCanvas/LineCanvas.cs
diff --git a/Terminal.Gui/Drawing/LineStyle.cs b/Terminal.Gui/Drawing/LineCanvas/LineStyle.cs
similarity index 100%
rename from Terminal.Gui/Drawing/LineStyle.cs
rename to Terminal.Gui/Drawing/LineCanvas/LineStyle.cs
diff --git a/Terminal.Gui/Drawing/StraightLine.cs b/Terminal.Gui/Drawing/LineCanvas/StraightLine.cs
similarity index 100%
rename from Terminal.Gui/Drawing/StraightLine.cs
rename to Terminal.Gui/Drawing/LineCanvas/StraightLine.cs
diff --git a/Terminal.Gui/Drawing/StraightLineExtensions.cs b/Terminal.Gui/Drawing/LineCanvas/StraightLineExtensions.cs
similarity index 100%
rename from Terminal.Gui/Drawing/StraightLineExtensions.cs
rename to Terminal.Gui/Drawing/LineCanvas/StraightLineExtensions.cs
diff --git a/Terminal.Gui/Drawing/SixelEncoder.cs b/Terminal.Gui/Drawing/Sixel/SixelEncoder.cs
similarity index 95%
rename from Terminal.Gui/Drawing/SixelEncoder.cs
rename to Terminal.Gui/Drawing/Sixel/SixelEncoder.cs
index 70d9a44bc..22e205c7d 100644
--- a/Terminal.Gui/Drawing/SixelEncoder.cs
+++ b/Terminal.Gui/Drawing/Sixel/SixelEncoder.cs
@@ -47,11 +47,11 @@ public class SixelEncoder
///
public string EncodeSixel (Color [,] pixels)
{
- const string start = "\u001bP"; // Start sixel sequence
+ const string START = "\u001bP"; // Start sixel sequence
string defaultRatios = AnyHasAlphaOfZero (pixels) ? "0;1;0" : "0;0;0"; // Defaults for aspect ratio and grid size
- const string completeStartSequence = "q"; // Signals beginning of sixel image data
- const string noScaling = "\"1;1;"; // no scaling factors (1x1);
+ const string COMPLETE_START_SEQUENCE = "q"; // Signals beginning of sixel image data
+ const string NO_SCALING = "\"1;1;"; // no scaling factors (1x1);
string fillArea = GetFillArea (pixels);
@@ -61,7 +61,7 @@ public class SixelEncoder
const string terminator = "\u001b\\"; // End sixel sequence
- return start + defaultRatios + completeStartSequence + noScaling + fillArea + pallette + pixelData + terminator;
+ return START + defaultRatios + COMPLETE_START_SEQUENCE + NO_SCALING + fillArea + pallette + pixelData + terminator;
}
private string WriteSixel (Color [,] pixels)
diff --git a/Terminal.Gui/Drawing/SixelSupportDetector.cs b/Terminal.Gui/Drawing/Sixel/SixelSupportDetector.cs
similarity index 53%
rename from Terminal.Gui/Drawing/SixelSupportDetector.cs
rename to Terminal.Gui/Drawing/Sixel/SixelSupportDetector.cs
index ce97bce50..3a784ce98 100644
--- a/Terminal.Gui/Drawing/SixelSupportDetector.cs
+++ b/Terminal.Gui/Drawing/Sixel/SixelSupportDetector.cs
@@ -9,12 +9,14 @@ namespace Terminal.Gui;
public class SixelSupportDetector
{
///
- /// Sends Ansi escape sequences to the console to determine whether
- /// sixel is supported (and
- /// etc).
+ /// Sends Ansi escape sequences to the console to determine whether
+ /// sixel is supported (and
+ /// etc).
///
- /// Description of sixel support, may include assumptions where
- /// expected response codes are not returned by console.
+ ///
+ /// Description of sixel support, may include assumptions where
+ /// expected response codes are not returned by console.
+ ///
public void Detect (Action resultCallback)
{
var result = new SixelSupportResult ();
@@ -22,75 +24,76 @@ public class SixelSupportDetector
IsSixelSupportedByDar (result, resultCallback);
}
-
private void TryGetResolutionDirectly (SixelSupportResult result, Action resultCallback)
{
// Expect something like:
//[6;20;10t
- QueueRequest (EscSeqUtils.CSI_RequestSixelResolution,
- (r) =>
+ QueueRequest (
+ EscSeqUtils.CSI_RequestSixelResolution,
+ r =>
{
// Terminal supports directly responding with resolution
- var match = Regex.Match (r, @"\[\d+;(\d+);(\d+)t$");
+ Match match = Regex.Match (r, @"\[\d+;(\d+);(\d+)t$");
if (match.Success)
{
- if (int.TryParse (match.Groups [1].Value, out var ry) &&
- int.TryParse (match.Groups [2].Value, out var rx))
+ if (int.TryParse (match.Groups [1].Value, out int ry) && int.TryParse (match.Groups [2].Value, out int rx))
{
- result.Resolution = new Size (rx, ry);
+ result.Resolution = new (rx, ry);
}
}
// Finished
resultCallback.Invoke (result);
-
},
- // Request failed, so try to compute instead
- ()=>TryComputeResolution (result,resultCallback));
- }
+ // Request failed, so try to compute instead
+ () => TryComputeResolution (result, resultCallback));
+ }
private void TryComputeResolution (SixelSupportResult result, Action resultCallback)
{
string windowSize;
string sizeInChars;
- QueueRequest (EscSeqUtils.CSI_RequestWindowSizeInPixels,
- (r1)=>
+ QueueRequest (
+ EscSeqUtils.CSI_RequestWindowSizeInPixels,
+ r1 =>
{
windowSize = r1;
- QueueRequest (EscSeqUtils.CSI_ReportTerminalSizeInChars,
- (r2) =>
+ QueueRequest (
+ EscSeqUtils.CSI_ReportTerminalSizeInChars,
+ r2 =>
{
sizeInChars = r2;
- ComputeResolution (result,windowSize,sizeInChars);
+ ComputeResolution (result, windowSize, sizeInChars);
resultCallback (result);
-
- }, abandoned: () => resultCallback (result));
- },abandoned: ()=>resultCallback(result));
+ },
+ () => resultCallback (result));
+ },
+ () => resultCallback (result));
}
private void ComputeResolution (SixelSupportResult result, string windowSize, string sizeInChars)
{
// Fallback to window size in pixels and characters
// Example [4;600;1200t
- var pixelMatch = Regex.Match (windowSize, @"\[\d+;(\d+);(\d+)t$");
+ Match pixelMatch = Regex.Match (windowSize, @"\[\d+;(\d+);(\d+)t$");
// Example [8;30;120t
- var charMatch = Regex.Match (sizeInChars, @"\[\d+;(\d+);(\d+)t$");
+ Match charMatch = Regex.Match (sizeInChars, @"\[\d+;(\d+);(\d+)t$");
if (pixelMatch.Success && charMatch.Success)
{
// Extract pixel dimensions
- if (int.TryParse (pixelMatch.Groups [1].Value, out var pixelHeight)
- && int.TryParse (pixelMatch.Groups [2].Value, out var pixelWidth)
+ if (int.TryParse (pixelMatch.Groups [1].Value, out int pixelHeight)
+ && int.TryParse (pixelMatch.Groups [2].Value, out int pixelWidth)
&&
// Extract character dimensions
- int.TryParse (charMatch.Groups [1].Value, out var charHeight)
- && int.TryParse (charMatch.Groups [2].Value, out var charWidth)
+ int.TryParse (charMatch.Groups [1].Value, out int charHeight)
+ && int.TryParse (charMatch.Groups [2].Value, out int charWidth)
&& charWidth != 0
&& charHeight != 0) // Avoid divide by zero
{
@@ -99,31 +102,32 @@ public class SixelSupportDetector
var cellHeight = (int)Math.Round ((double)pixelHeight / charHeight);
// Set the resolution based on the character cell size
- result.Resolution = new Size (cellWidth, cellHeight);
+ result.Resolution = new (cellWidth, cellHeight);
}
}
}
- private void IsSixelSupportedByDar (SixelSupportResult result,Action resultCallback)
+ private void IsSixelSupportedByDar (SixelSupportResult result, Action resultCallback)
{
QueueRequest (
- EscSeqUtils.CSI_SendDeviceAttributes,
- (r) =>
- {
- result.IsSupported = ResponseIndicatesSupport (r);
+ EscSeqUtils.CSI_SendDeviceAttributes,
+ r =>
+ {
+ result.IsSupported = ResponseIndicatesSupport (r);
- if (result.IsSupported)
- {
- TryGetResolutionDirectly (result, resultCallback);
- }
- else
- {
- resultCallback (result);
- }
- },abandoned: () => resultCallback(result));
+ if (result.IsSupported)
+ {
+ TryGetResolutionDirectly (result, resultCallback);
+ }
+ else
+ {
+ resultCallback (result);
+ }
+ },
+ () => resultCallback (result));
}
- private void QueueRequest (AnsiEscapeSequenceRequest req, Action responseCallback, Action abandoned)
+ private static void QueueRequest (AnsiEscapeSequenceRequest req, Action responseCallback, Action abandoned)
{
var newRequest = new AnsiEscapeSequenceRequest
{
@@ -133,29 +137,29 @@ public class SixelSupportDetector
Abandoned = abandoned
};
- Application.Driver.QueueAnsiRequest (newRequest);
+ Application.Driver?.QueueAnsiRequest (newRequest);
}
- private bool ResponseIndicatesSupport (string response)
+ private static bool ResponseIndicatesSupport (string response) { return response.Split (';').Contains ("4"); }
+
+ private static bool IsWindowsTerminal ()
{
- return response.Split (';').Contains ("4");
+ return !string.IsNullOrWhiteSpace (Environment.GetEnvironmentVariable ("WT_SESSION"));
+
+ ;
}
- private bool IsWindowsTerminal ()
- {
- return !string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable ("WT_SESSION"));;
- }
- private bool IsXtermWithTransparency ()
+ private static bool IsXtermWithTransparency ()
{
// Check if running in real xterm (XTERM_VERSION is more reliable than TERM)
- var xtermVersionStr = Environment.GetEnvironmentVariable ("XTERM_VERSION");
+ string xtermVersionStr = Environment.GetEnvironmentVariable ("XTERM_VERSION");
// If XTERM_VERSION exists, we are in a real xterm
- if (!string.IsNullOrWhiteSpace (xtermVersionStr) && int.TryParse (xtermVersionStr, out var xtermVersion) && xtermVersion >= 370)
+ if (!string.IsNullOrWhiteSpace (xtermVersionStr) && int.TryParse (xtermVersionStr, out int xtermVersion) && xtermVersion >= 370)
{
return true;
}
return false;
}
-}
\ No newline at end of file
+}
diff --git a/Terminal.Gui/Drawing/SixelSupportResult.cs b/Terminal.Gui/Drawing/Sixel/SixelSupportResult.cs
similarity index 97%
rename from Terminal.Gui/Drawing/SixelSupportResult.cs
rename to Terminal.Gui/Drawing/Sixel/SixelSupportResult.cs
index bb8a61e0d..ddd182b4d 100644
--- a/Terminal.Gui/Drawing/SixelSupportResult.cs
+++ b/Terminal.Gui/Drawing/Sixel/SixelSupportResult.cs
@@ -2,7 +2,7 @@
///
/// Describes the discovered state of sixel support and ancillary information
-/// e.g. . You can use any
+/// e.g. . You can use any
/// to discover this information.
///
public class SixelSupportResult
diff --git a/Terminal.Gui/Drawing/SixelToRender.cs b/Terminal.Gui/Drawing/Sixel/SixelToRender.cs
similarity index 100%
rename from Terminal.Gui/Drawing/SixelToRender.cs
rename to Terminal.Gui/Drawing/Sixel/SixelToRender.cs
diff --git a/UICatalog/Scenarios/AnsiRequestsScenario.cs b/UICatalog/Scenarios/AnsiRequestsScenario.cs
index a0f711593..723a0c6e3 100644
--- a/UICatalog/Scenarios/AnsiRequestsScenario.cs
+++ b/UICatalog/Scenarios/AnsiRequestsScenario.cs
@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Terminal.Gui;
-using static System.Runtime.InteropServices.JavaScript.JSType;
namespace UICatalog.Scenarios;
@@ -13,14 +12,13 @@ public sealed class AnsiEscapeSequenceRequests : Scenario
{
private GraphView _graphView;
- private DateTime start = DateTime.Now;
private ScatterSeries _sentSeries;
private ScatterSeries _answeredSeries;
- private List sends = new ();
+ private readonly List _sends = new ();
- private object lockAnswers = new object ();
- private Dictionary answers = new ();
+ private readonly object _lockAnswers = new object ();
+ private readonly Dictionary _answers = new ();
private Label _lblSummary;
public override void Main ()
@@ -82,7 +80,7 @@ public sealed class AnsiEscapeSequenceRequests : Scenario
"CSI_RequestCursorPositionReport",
"CSI_SendDeviceAttributes2"
};
-
+ // TODO: This UI would be cleaner/less rigid if Pos.Align were used
var cbRequests = new ComboBox () { Width = 40, Height = 5, ReadOnly = true, Source = new ListWrapper (new (scrRequests)) };
w.Add (cbRequests);
@@ -225,7 +223,7 @@ public sealed class AnsiEscapeSequenceRequests : Scenario
TimeSpan.FromMilliseconds (1000),
() =>
{
- lock (lockAnswers)
+ lock (_lockAnswers)
{
UpdateGraph ();
@@ -327,15 +325,15 @@ public sealed class AnsiEscapeSequenceRequests : Scenario
private string GetSummary ()
{
- if (answers.Count == 0)
+ if (_answers.Count == 0)
{
return "No requests sent yet";
}
- var last = answers.Last ().Value;
+ var last = _answers.Last ().Value;
- var unique = answers.Values.Distinct ().Count ();
- var total = answers.Count;
+ var unique = _answers.Values.Distinct ().Count ();
+ var total = _answers.Count;
return $"Last:{last} U:{unique} T:{total}";
}
@@ -361,12 +359,12 @@ public sealed class AnsiEscapeSequenceRequests : Scenario
private void UpdateGraph ()
{
- _sentSeries.Points = sends
+ _sentSeries.Points = _sends
.GroupBy (ToSeconds)
.Select (g => new PointF (g.Key, g.Count ()))
.ToList ();
- _answeredSeries.Points = answers.Keys
+ _answeredSeries.Points = _answers.Keys
.GroupBy (ToSeconds)
.Select (g => new PointF (g.Key, g.Count ()))
.ToList ();
@@ -389,14 +387,14 @@ public sealed class AnsiEscapeSequenceRequests : Scenario
Terminator = EscSeqUtils.CSI_SendDeviceAttributes.Terminator,
ResponseReceived = HandleResponse
});
- sends.Add (DateTime.Now);
+ _sends.Add (DateTime.Now);
}
private void HandleResponse (string response)
{
- lock (lockAnswers)
+ lock (_lockAnswers)
{
- answers.Add (DateTime.Now, response);
+ _answers.Add (DateTime.Now, response);
}
}
}
diff --git a/UICatalog/Scenarios/Images.cs b/UICatalog/Scenarios/Images.cs
index 023f72ee0..2450d20e4 100644
--- a/UICatalog/Scenarios/Images.cs
+++ b/UICatalog/Scenarios/Images.cs
@@ -62,7 +62,7 @@ public class Images : Scenario
private SixelToRender _sixelImage;
// Start by assuming no support
- private SixelSupportResult _sixelSupportResult = new SixelSupportResult ();
+ private SixelSupportResult _sixelSupportResult = new ();
private CheckBox _cbSupportsSixel;
public override void Main ()
@@ -95,8 +95,8 @@ public class Images : Scenario
Text = "supports true color "
};
_win.Add (cbSupportsTrueColor);
-
- _cbSupportsSixel = new CheckBox
+
+ _cbSupportsSixel = new()
{
X = Pos.Right (lblDriverName) + 2,
Y = 1,
@@ -104,26 +104,24 @@ public class Images : Scenario
Text = "Supports Sixel"
};
- var lblSupportsSixel = new Label ()
+ var lblSupportsSixel = new Label
{
-
X = Pos.Right (lblDriverName) + 2,
Y = Pos.Bottom (_cbSupportsSixel),
Text = "(Check if your terminal supports Sixel)"
};
-
/* CheckedState = _sixelSupportResult.IsSupported
? CheckState.Checked
: CheckState.UnChecked;*/
_cbSupportsSixel.CheckedStateChanging += (s, e) =>
- {
- _sixelSupportResult.IsSupported = e.NewValue == CheckState.Checked;
- SetupSixelSupported (e.NewValue == CheckState.Checked);
- ApplyShowTabViewHack ();
- };
-
+ {
+ _sixelSupportResult.IsSupported = e.NewValue == CheckState.Checked;
+ SetupSixelSupported (e.NewValue == CheckState.Checked);
+ ApplyShowTabViewHack ();
+ };
+
_win.Add (_cbSupportsSixel);
var cbUseTrueColor = new CheckBox
@@ -174,7 +172,6 @@ public class Images : Scenario
_cbSupportsSixel.CheckedState = newResult.IsSupported ? CheckState.Checked : CheckState.UnChecked;
_pxX.Value = _sixelSupportResult.Resolution.Width;
_pxY.Value = _sixelSupportResult.Resolution.Height;
-
}
private void SetupSixelSupported (bool isSupported)
@@ -311,7 +308,7 @@ public class Images : Scenario
{
// TODO HACK: This hack seems to be required to make tabview actually refresh itself
_tabView.SetNeedsDraw ();
- var orig = _tabView.SelectedTab;
+ Tab orig = _tabView.SelectedTab;
_tabView.SelectedTab = _tabView.Tabs.Except (new [] { orig }).ElementAt (0);
_tabView.SelectedTab = orig;
}
diff --git a/UnitTests/ConsoleDrivers/AnsiResponseParserTests.cs b/UnitTests/ConsoleDrivers/AnsiResponseParserTests.cs
index d3019e8d4..cbbfd24d1 100644
--- a/UnitTests/ConsoleDrivers/AnsiResponseParserTests.cs
+++ b/UnitTests/ConsoleDrivers/AnsiResponseParserTests.cs
@@ -416,8 +416,6 @@ public class AnsiResponseParserTests (ITestOutputHelper output)
[Fact]
public void ShouldSwallowUnknownResponses_WhenDelegateSaysSo ()
{
- int i = 0;
-
// Swallow all unknown escape codes
_parser1.UnexpectedResponseHandler = _ => true;
_parser2.UnknownResponseHandler = _ => true;