|
| 1 | +# Add stream access APIs to IConsole |
| 2 | + |
| 3 | +## Description |
| 4 | + |
| 5 | +Add raw stream access methods to `IConsole` to match `System.Console` capabilities. This enables scenarios where code needs direct `Stream` access to stdin/stdout/stderr, or needs to redirect I/O via `TextReader`/`TextWriter`. |
| 6 | + |
| 7 | +Parent: #020 |
| 8 | + |
| 9 | +## Checklist |
| 10 | + |
| 11 | +### Implementation |
| 12 | +- [x] Add `OpenStandardInput()` → `Stream` to `IConsole` |
| 13 | +- [x] Add `OpenStandardOutput()` → `Stream` to `IConsole` |
| 14 | +- [x] Add `OpenStandardError()` → `Stream` to `IConsole` |
| 15 | +- [x] Add `In` → `TextReader` property to `IConsole` |
| 16 | +- [x] Add `Out` → `TextWriter` property to `IConsole` |
| 17 | +- [x] Add `Error` → `TextWriter` property to `IConsole` |
| 18 | +- [x] Add `SetIn(TextReader)` method to `IConsole` |
| 19 | +- [x] Add `SetOut(TextWriter)` method to `IConsole` |
| 20 | +- [x] Add `SetError(TextWriter)` method to `IConsole` |
| 21 | +- [x] Implement in `TimeWarpConsole` |
| 22 | +- [x] Implement in `TimeWarpTerminal` |
| 23 | + |
| 24 | +### Testing |
| 25 | +- [x] Add `TestConsole` implementations for all new members |
| 26 | +- [x] Add `TestTerminal` implementations for all new members |
| 27 | +- [x] Add mock stream support to test implementations |
| 28 | +- [x] Add mock TextReader/TextWriter support to test implementations |
| 29 | +- [x] Write unit tests for `OpenStandardInput()` |
| 30 | +- [x] Write unit tests for `OpenStandardOutput()` |
| 31 | +- [x] Write unit tests for `OpenStandardError()` |
| 32 | +- [x] Write unit tests for `In`/`Out`/`Error` properties |
| 33 | +- [x] Write unit tests for `SetIn()`/`SetOut()`/`SetError()` |
| 34 | + |
| 35 | +## Session |
| 36 | + |
| 37 | +- Created: ses_2f2ab32c3ffeoD0gwPTVU0agTi (2026-03-22) |
| 38 | +- Completed: ses_2e9f62f66ffeh05Tj3xKWlwLsS (2026-03-22) |
| 39 | + |
| 40 | +## Notes |
| 41 | + |
| 42 | +### Files to modify |
| 43 | +- `iconsole.cs` - add interface members |
| 44 | +- `timewarp-console.cs` - implement in TimeWarpConsole |
| 45 | +- `timewarp-terminal.cs` - implement in TimeWarpTerminal |
| 46 | +- `test-console.cs` - add test implementations |
| 47 | +- `test-terminal.cs` - add test implementations |
| 48 | + |
| 49 | +### Design considerations |
| 50 | +- `OpenStandard*()` methods return `Stream` - test implementations need mock streams (e.g., `MemoryStream`) |
| 51 | +- `In`/`Out`/`Error` are `TextReader`/`TextWriter` - test implementations can use `StringReader`/`StringWriter` |
| 52 | +- RS0030 analyzer currently flags `Console.OpenStandard*` usage - this task satisfies that analyzer |
| 53 | + |
| 54 | +### Reference |
| 55 | +- https://learn.microsoft.com/en-us/dotnet/api/system.console.openstandardinput |
| 56 | + |
| 57 | +### Coding Standards |
| 58 | +Follow the `/csharp` skill for all implementation work. |
| 59 | + |
| 60 | +## Results |
| 61 | + |
| 62 | +### What was implemented |
| 63 | +Added 9 stream access members to `IConsole`: |
| 64 | +- `Stream OpenStandardInput()` - opens stdin as a stream |
| 65 | +- `Stream OpenStandardOutput()` - opens stdout as a stream |
| 66 | +- `Stream OpenStandardError()` - opens stderr as a stream |
| 67 | +- `TextReader In { get; }` - standard input reader |
| 68 | +- `TextWriter Out { get; }` - standard output writer |
| 69 | +- `TextWriter Error { get; }` - standard error writer |
| 70 | +- `void SetIn(TextReader)` - sets standard input |
| 71 | +- `void SetOut(TextWriter)` - sets standard output |
| 72 | +- `void SetError(TextWriter)` - sets standard error |
| 73 | + |
| 74 | +### Files changed |
| 75 | +- `source/timewarp-terminal/iconsole.cs` - added 9 interface members |
| 76 | +- `source/timewarp-terminal/timewarp-console.cs` - implemented all 9 members |
| 77 | +- `source/timewarp-terminal/timewarp-terminal.cs` - implemented all 9 members |
| 78 | +- `source/timewarp-terminal/test-console.cs` - added mock streams and implementations |
| 79 | +- `source/timewarp-terminal/test-terminal.cs` - added mock streams and implementations |
| 80 | +- `Directory.Build.props` - added CA1716 to NoWarn (matching System.Console API names) |
| 81 | +- `tests/stream-access-01-basic.cs` - new test file (26 tests) |
| 82 | + |
| 83 | +### Test results |
| 84 | +- All 26 new tests pass |
| 85 | +- All existing tests pass |
| 86 | +- Build succeeds with 0 warnings |
| 87 | + |
| 88 | +### Design decisions |
| 89 | +- TestConsole/TestTerminal use MemoryStream for OpenStandard* methods |
| 90 | +- In/Out/Error properties use StringReader/StringWriter in test implementations |
| 91 | +- SetIn/SetOut/SetError update the internal readers/writers |
| 92 | +- Added CA1716 suppression for naming conflict with System.Console API (In/Out/Error/SetIn/SetOut/SetError) |
0 commit comments