using System.Text.Json; namespace Terminal.Gui.Examples; /// /// Defines the execution context for running an example application. /// This context is used to configure how an example should be executed, including driver selection, /// keystroke injection, timeouts, and metrics collection. /// public class ExampleContext { /// /// Gets or sets the name of the driver to use (e.g., "FakeDriver", "DotnetDriver"). /// If , the default driver for the platform is used. /// public string? DriverName { get; set; } = null; /// /// Gets or sets the list of key names to inject into the example during execution. /// Each string should be a valid key name that can be parsed by . /// public List KeysToInject { get; set; } = new (); /// /// Gets or sets the maximum time in milliseconds to allow the example to run before forcibly terminating it. /// public int TimeoutMs { get; set; } = 30000; /// /// Gets or sets the maximum number of iterations to allow before stopping the example. /// If set to -1, no iteration limit is enforced. /// public int MaxIterations { get; set; } = -1; /// /// Gets or sets a value indicating whether to collect and report performance metrics during execution. /// public bool CollectMetrics { get; set; } = false; /// /// Gets or sets the execution mode for the example. /// public ExecutionMode Mode { get; set; } = ExecutionMode.OutOfProcess; /// /// The name of the environment variable used to pass the serialized /// to example applications. /// public const string EnvironmentVariableName = "TERMGUI_TEST_CONTEXT"; /// /// Serializes this context to a JSON string for passing via environment variables. /// /// A JSON string representation of this context. public string ToJson () { return JsonSerializer.Serialize (this); } /// /// Deserializes a from a JSON string. /// /// The JSON string to deserialize. /// The deserialized context, or if deserialization fails. public static ExampleContext? FromJson (string json) { try { return JsonSerializer.Deserialize (json); } catch { return null; } } }