Skip to content

Commit

Permalink
warnings and xml doc
Browse files Browse the repository at this point in the history
  • Loading branch information
tznind committed Dec 28, 2024
1 parent 26e4776 commit 5ca3c39
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 14 deletions.
6 changes: 5 additions & 1 deletion Terminal.Gui/Application/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ internal static void ResetState (bool ignoreDisposed = false)
SynchronizationContext.SetSynchronizationContext (null);
}

// Only return true if the Current has changed.

/// <summary>
/// Adds specified idle handler function to main iteration processing. The handler function will be called
/// once per iteration of the main loop after other events have been handled.
/// </summary>
public static void AddIdle (Func<bool> func) => ApplicationImpl.Instance.AddIdle (func);
}
17 changes: 12 additions & 5 deletions Terminal.Gui/Application/ApplicationImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,29 @@

namespace Terminal.Gui;

/// <summary>
/// Original Terminal.Gui implementation of core <see cref="Application"/> methods.
/// </summary>
public class ApplicationImpl : IApplication
{
// Private static readonly Lazy instance of Application
private static Lazy<IApplication> lazyInstance = new (() => new ApplicationImpl ());
private static Lazy<IApplication> _lazyInstance = new (() => new ApplicationImpl ());

// Public static property to access the instance
public static IApplication Instance => lazyInstance.Value;
/// <summary>
/// Gets the currently configured backend implementation of <see cref="Application"/> gateway methods.
/// Change to your own implementation by using <see cref="ChangeInstance"/> (before init).
/// </summary>
public static IApplication Instance => _lazyInstance.Value;

/// <summary>
/// Change the singleton implementation, should not be called except before application
/// startup.
/// startup. This method lets you provide alternative implementations of core static gateway
/// methods of <see cref="Application"/>.
/// </summary>
/// <param name="newApplication"></param>
public static void ChangeInstance (IApplication newApplication)
{
lazyInstance = new Lazy<IApplication> (newApplication);
_lazyInstance = new Lazy<IApplication> (newApplication);
}

/// <inheritdoc/>
Expand Down
23 changes: 23 additions & 0 deletions Terminal.Gui/Application/IApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,30 @@ public T Run<T> (Func<Exception, bool>? errorHandler = null, IConsoleDriver? dri
void Invoke (Action action);

bool IsLegacy { get; }

/// <summary>
/// Adds specified idle handler function to main iteration processing. The handler function will be called
/// once per iteration of the main loop after other events have been handled.
/// </summary>
void AddIdle (Func<bool> func);

/// <summary>Adds a timeout to the application.</summary>
/// <remarks>
/// When time specified passes, the callback will be invoked. If the callback returns true, the timeout will be
/// reset, repeating the invocation. If it returns false, the timeout will stop and be removed. The returned value is a
/// token that can be used to stop the timeout by calling <see cref="RemoveTimeout(object)"/>.
/// </remarks>
object AddTimeout (TimeSpan time, Func<bool> callback);

/// <summary>Removes a previously scheduled timeout</summary>
/// <remarks>The token parameter is the value returned by <see cref="AddTimeout"/>.</remarks>
/// <returns>
/// <c>true</c>
/// if the timeout is successfully removed; otherwise,
/// <c>false</c>
/// .
/// This method also returns
/// <c>false</c>
/// if the timeout is not found.</returns>
bool RemoveTimeout (object token);
}
7 changes: 5 additions & 2 deletions Terminal.Gui/Application/MainLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ internal interface IMainLoopDriver
/// </remarks>
public class MainLoop : IDisposable
{
/// <summary>
/// Gets the class responsible for handling idles and timeouts
/// </summary>
public ITimedEvents TimedEvents { get; } = new TimedEvents();

/// <summary>Creates a new MainLoop.</summary>
Expand Down Expand Up @@ -77,13 +80,13 @@ public void Dispose ()
/// once per iteration of the main loop after other events have been handled.
/// </summary>
/// <remarks>
/// <para>Remove an idle handler by calling <see cref="RemoveIdle(Func{bool})"/> with the token this method returns.</para>
/// <para>Remove an idle handler by calling <see cref="TimedEvents.RemoveIdle(Func{bool})"/> with the token this method returns.</para>
/// <para>
/// If the <paramref name="idleHandler"/> returns <see langword="false"/> it will be removed and not called
/// subsequently.
/// </para>
/// </remarks>
/// <param name="idleHandler">Token that can be used to remove the idle handler with <see cref="RemoveIdle(Func{bool})"/> .</param>
/// <param name="idleHandler">Token that can be used to remove the idle handler with <see cref="TimedEvents.RemoveIdle(Func{bool})"/> .</param>
// QUESTION: Why are we re-inventing the event wheel here?
// PERF: This is heavy.
// CONCURRENCY: Race conditions exist here.
Expand Down
2 changes: 1 addition & 1 deletion Terminal.Gui/Application/TimeoutEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Terminal.Gui;

/// <summary><see cref="EventArgs"/> for timeout events (e.g. <see cref="MainLoop.TimeoutAdded"/>)</summary>
/// <summary><see cref="EventArgs"/> for timeout events (e.g. <see cref="TimedEvents.TimeoutAdded"/>)</summary>
public class TimeoutEventArgs : EventArgs
{
/// <summary>Creates a new instance of the <see cref="TimeoutEventArgs"/> class.</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public AnsiRequestScheduler (IAnsiResponseParser parser, Func<DateTime>? now = n

/// <summary>
/// Sends the <paramref name="request"/> immediately or queues it if there is already
/// an outstanding request for the given <see cref="AnsiEscapeSequenceRequest.Terminator"/>.
/// an outstanding request for the given <see cref="AnsiEscapeSequence.Terminator"/>.
/// </summary>
/// <param name="request"></param>
/// <returns><see langword="true"/> if request was sent immediately. <see langword="false"/> if it was queued.</returns>
Expand Down
3 changes: 1 addition & 2 deletions Terminal.Gui/ConsoleDrivers/IConsoleDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public interface IConsoleDriver

// BUGBUG: This should not be publicly settable.
/// <summary>
/// Gets or sets the contents of the application output. The driver outputs this buffer to the terminal when
/// <see cref="UpdateScreen"/> is called.
/// Gets or sets the contents of the application output. The driver outputs this buffer to the terminal.
/// <remarks>The format of the array is rows, columns. The first index is the row, the second index is the column.</remarks>
/// </summary>
Cell [,]? Contents { get; set; }
Expand Down
3 changes: 1 addition & 2 deletions Terminal.Gui/ConsoleDrivers/V2/ConsoleDriverFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ public int Cols
}

/// <summary>
/// The contents of the application output. The driver outputs this buffer to the terminal when
/// <see cref="UpdateScreen"/> is called.
/// The contents of the application output. The driver outputs this buffer to the terminal.
/// <remarks>The format of the array is rows, columns. The first index is the row, the second index is the column.</remarks>
/// </summary>
public Cell [,] Contents
Expand Down

0 comments on commit 5ca3c39

Please sign in to comment.