namespace BuildTool.Interactive;
///
/// Tracks Ctrl+C press timing to detect double-press for exit.
///
public sealed class CancellationTracker
{
private DateTime _lastCancelTime = DateTime.MinValue;
private const int DoublePressMs = 500;
///
/// Checks if this is a double-press (within 500ms of last press).
/// Also updates the last press time.
///
public bool IsDoublePress()
{
var now = DateTime.UtcNow;
var isDouble = (now - _lastCancelTime).TotalMilliseconds < DoublePressMs;
_lastCancelTime = now;
return isDouble;
}
/// Global instance for app-wide tracking.
public static CancellationTracker Instance { get; } = new();
}