Repository navigation
Draw an element at the position passed to IConsoleProvider.Render [patch] - #204
Merged
Merged
Conversation
…r [patch] SpectreConsoleProvider.Render moved the cursor to the position and then let the element draw, but every write moves the cursor itself from the element's own Position, so the position was ignored. It then "restored" a cursor read from System.Console rather than the injected console. Render now draws through an OffsetConsoleProvider that shifts every write by the difference between the requested position and the element's own, which moves a container and its children together and leaves the element's layout untouched. The System.Console save and restore is gone. Fixes #156 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GJ23oLAT8FnLaMo3MfBviR
matt-edmondson
pushed a commit
that referenced
this pull request
Oct 7, 2026
…f their files Keeps this change clear of the lines #204 edits, so the two merge in either order without a conflict. No behaviour change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GJ23oLAT8FnLaMo3MfBviR
SonarCloud measured 40% coverage on the new code because the provider's pass-through members were never exercised. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GJ23oLAT8FnLaMo3MfBviR
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #156
What was wrong
SpectreConsoleProvider.Render(element, position)moved the cursor topositionand then calledelement.Render(this). Every element draws throughWriteAtat absolute coordinates taken from its ownPosition, and eachWriteAtmoves the cursor itself, so the requested position was silently ignored. The method then "restored" a cursor position read fromSystem.Console, not from the injectedIAnsiConsole, which moved the Spectre cursor somewhere unrelated.Change
This takes the "honor the position" option from the issue, so it is not a breaking change:
OffsetConsoleProviderforwards to another provider and shifts every position (WriteAt,SetCursorPosition, nestedRender) by a fixed offset.Renderdraws through it withoffset = position - element.Position, or directly when the offset is zero. A container's children draw through the same provider, so the whole subtree moves together, and the element'sPositionand layout are left untouched.System.Consolesave and restore and the now-unusedGetCursorPositionare removed.IConsoleProvider.Renderdocs now say that the element's top-left corner goes atposition.Tests (
SpectreConsoleProviderTests)RenderDrawsTheElementAtTheGivenPosition: the issue's repro.Hiis written atESC[3;5Hand nothing else, and the element's own position is unchanged.RenderShiftsAContainerAndItsChildrenTogether: aBorderElementwith a child, rendered elsewhere, matches the output of the same border laid out at that position.RenderAtTheElementsOwnPositionDrawsItThereWith the fix reverted, all 3 fail. With it applied, the full suite passes (256/256). A trial merge (
git merge-tree) shows this branch combines cleanly with #202 and #203.🤖 Generated with Claude Code
https://claude.ai/code/session_01GJ23oLAT8FnLaMo3MfBviR