-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestSessionOutput.cs
More file actions
98 lines (79 loc) · 3.04 KB
/
Copy pathTestSessionOutput.cs
File metadata and controls
98 lines (79 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using ECAssistant.Core.Session;
namespace ECAssistant.TestSupport;
/// <summary>
/// Test implementation of ISessionOutput.
/// Captures all output and routes approval requests to the GuiTestHarness's queued input.
/// </summary>
public class TestSessionOutput : ISessionOutput
{
private readonly GuiTestHarness _gui;
private readonly System.Text.StringBuilder _streamBuffer = new();
private OutputState _streamState = OutputState.Raw;
private readonly List<(string text, OutputState state)> _outputLog = new();
public TestSessionOutput(GuiTestHarness gui)
{
_gui = gui;
}
public IReadOnlyList<(string text, OutputState state)> OutputLog => _outputLog;
// ── Streaming ──
public void StartStream(OutputState state)
{
lock (_streamBuffer)
{
_streamBuffer.Clear();
_streamState = state;
}
}
public void Write(string token)
{
lock (_streamBuffer)
{
_streamBuffer.Append(token);
}
}
public void StopStream()
{
// Nothing — caller will WriteLine the buffer
}
// ── Discrete output ──
public void WriteLine(string text, OutputState state = OutputState.Info)
{
_outputLog.Add((text, state));
_gui.WriteLineColored($"[{state}] {text}");
}
public void BlankLine() => WriteLine("", OutputState.Info);
public void WriteInfo(string text) => WriteLine(text, OutputState.Info);
public void WriteSuccess(string text) => WriteLine(text, OutputState.Success);
public void WriteWarning(string text) => WriteLine(text, OutputState.Warning);
public void WriteError(string text) => WriteLine(text, OutputState.Error);
public void WriteDim(string text) => WriteLine(text, OutputState.Dim);
public void WriteTag(string tag, string message, OutputState state = OutputState.Info)
=> WriteLine($"[{tag}] {message}", state);
// ── Stream buffer access ──
public string GetStreamBuffer()
{
lock (_streamBuffer) return _streamBuffer.ToString();
}
public OutputState GetStreamState()
{
lock (_streamBuffer) return _streamState;
}
// ── User approval ──
public bool RequestApproval(string message)
{
WriteLine(message, OutputState.Warning);
var response = _gui.PromptRaw("[y/N] ");
return response?.Trim().ToLower() == "y" || response?.Trim().ToLower() == "yes";
}
/// <summary>v14.9: interactive checkpoint — prompt via GUI, 1-based pick, null = cancel.</summary>
public int? RequestChoice(string prompt, System.Collections.Generic.IReadOnlyList<string> options)
{
WriteLine(prompt, OutputState.Warning);
for (int i = 0; i < options.Count; i++)
WriteLine($" {i + 1}) {options[i]}", OutputState.Info);
var response = _gui.PromptRaw($"[1-{options.Count}, Enter=skip] ");
if (int.TryParse(response?.Trim(), out var pick) && pick >= 1 && pick <= options.Count)
return pick;
return null;
}
}