-
-
Notifications
You must be signed in to change notification settings - Fork 1
fix: PrintHeader kills headless startup when no console is attached #258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: NosCoreIO/NosCore.Shared
Length of output: 1244
🏁 Script executed:
Repository: NosCoreIO/NosCore.Shared
Length of output: 4817
🌐 Web query:
.NET Console.WindowWidth Console.WindowHeight Unix implementation independent columns rows ConsolePal.Unix💡 Result:
In.NET, the Console.WindowWidth and Console.WindowHeight properties are implemented on Unix-like systems via the internal ConsolePal.Unix class [1][2][3]. Key implementation details include: Retrieving Dimensions: The properties determine the console size by calling Interop.Sys.GetWindowSize [1][3]. This typically leverages an ioctl system call (specifically TIOCGWINSZ) to query the terminal's window size from the kernel [1][4][3]. If that call fails or is unavailable, the implementation falls back to values defined in TerminalFormatStrings, which are derived from the environment's terminal capabilities (often based on the terminfo database) [1][2][3]. Caching and Invalidation: To optimize performance,.NET caches these dimensions [1]. The system uses a mechanism to invalidate this cache, which is triggered when necessary [1][3]. Historically, there have been issues where the cache was not properly invalidated when the terminal resized unless other console properties (like CursorTop) were accessed, which forced a refresh of the terminal settings [5]. Setting Dimensions: The setter for both WindowWidth and WindowHeight throws a PlatformNotSupportedException on Unix [1][3]. Although attempts were made to implement SetWindowSize using the TIOCSWINSZ ioctl, these were reverted because that system call only informs the kernel of a terminal size change rather than actually resizing the graphical window hosting the terminal [4][6][3]. Consequently, programmatic resizing of the console window is not supported on Unix platforms in.NET [6][3].
Citations:
🏁 Script executed:
Repository: NosCoreIO/NosCore.Shared
Length of output: 5502
🌐 Web query:
site:github.com/dotnet/runtime ConsolePal.Unix GetWindowSize columns rows WindowWidth WindowHeight💡 Result:
In the.NET runtime's internal implementation, ConsolePal.Unix is a static class responsible for platform-specific console operations on Unix-based systems [1][2][3]. Within this class, the private method GetWindowSize is used to determine the terminal's dimensions [1][2]. The method GetWindowSize(out int width, out int height) operates as follows: - It uses a lock on Console.Out to ensure thread safety during terminal setting operations [1][3]. - It calls CheckTerminalSettingsInvalidated to verify if the terminal settings have been invalidated (e.g., due to a resize) [1][2]. - If the cached window dimensions (s_windowWidth) are uninitialized (-1), it attempts to retrieve the actual size using Interop.Sys.GetWindowSize [1][2]. - On success, it populates the width and height with values from the Interop.Sys.WinSize structure (which contains Col and Row fields) [1][2]. - If that fails, it falls back to default values provided by TerminalFormatStringsInstance.Columns and TerminalFormatStringsInstance.Lines [1][3]. Regarding the properties WindowWidth and WindowHeight, they publicly surface these dimensions by calling GetWindowSize [1][2]. Importantly, while these properties can be read, setting them on Unix platforms typically results in a PlatformNotSupportedException [2][4], as Unix terminals do not always allow the application to forcibly resize the host window [4]. The implementation details have evolved, including fixes to ensure window size is properly invalidated when the terminal is resized [5] and cleanup of the SetWindowSize method [4].
Citations:
Validate
Console.WindowWidth, notConsole.WindowHeight.If the width is zero while the height is positive,
PrintHeaderpasses-1tonew stringand throws instead of usingHeadlessWindowWidth. Read and validateConsole.WindowWidthdirectly.🤖 Prompt for AI Agents