-
-
Notifications
You must be signed in to change notification settings - Fork 517
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
Failing To Render On Windows Terminal #703
Comments
this works fine in Windows Console do note, that trying to update text WHILE it is resizing is often UB in all terminals after the console has been resized, the Row and Width info are unreliable and you cannot update test unless you restore to original or greater window size for example if you know you need to move up 5 rows to get to the start, and to resize to 2 width, then moving up 5 rows will not get you to start, corrupting your output same for columns and width also occurs when resizing smaller than what is being updated in terms of height such is very difficult to fix and standardize |
That is true. When terminals are resizing it's challenging to keep up with size.
Anyways, Big thanks for this awesome library. |
Is there a cross-platform / cross-terminal way to hook into window resize events? |
How about this goes with cross-platform & cross-terminal? DemoCode static void Main(string[] args)
{
// Store the initial terminal size
int initialWidth = Console.WindowWidth;
int initialHeight = Console.WindowHeight;
// Register for the terminal resize event
Console.CancelKeyPress += (sender, eventArgs) =>
{
// Check if the event was a terminal resize (e.g., Ctrl+C)
if (eventArgs.SpecialKey == ConsoleSpecialKey.ControlC)
{
// Handle the terminal resize event here
Console.WriteLine("Terminal resized");
}
};
// Continuously monitor and print the terminal size
while (true)
{
// Check the current terminal size
int currentWidth = Console.WindowWidth;
int currentHeight = Console.WindowHeight;
// Print the current size
Console.WriteLine($"Terminal Size: {currentWidth} columns x {currentHeight} rows");
// Sleep briefly before checking again
Thread.Sleep(1000); // Adjust the sleep interval as needed
}
} |
Other approaches include:
Mono Posix ApproachOtherwise for Unix-Like systems (like Linux or MacOS). We can also rely on this Mono Posix NuGet -
Repo: Couldn't check all the aspects of the below code fully. Only did a basic test on a VM running Ubuntu: using System;
using Mono.Unix;
using Mono.Unix.Native;
class Program
{
static void Main(string[] args)
{
// Register for the terminal resize signal
UnixSignal[] signals = new UnixSignal[] {
new UnixSignal(Signum.SIGWINCH)
};
Console.WriteLine("Listening for terminal resize events. Press Ctrl+C to exit.");
while (true)
{
// Wait for a signal (including terminal resize)
int index = UnixSignal.WaitAny(signals);
// Check if the signal is due to a terminal resize
if (signals[index].Signum == Signum.SIGWINCH)
{
Console.WriteLine("Terminal resized");
}
}
}
} |
It's an area I'm quite interested in, and thanks for the code contribution above @sangeethnandakumar. However, for me, at this time, it's unlikely I'll do anything more than simply watch this issue from the sidelines. |
Ways To Reproduce:
using Spectre.Console;
Run the program. This will print and updates an active progress bar
Now adjust the width of Windows Terminal while progress bar is running. The render fails and messes up the console.
There is no going back after this. Once console got messy, Even if we resize the console back to normal or maximized stage, The screen won't update to normal way
Please upvote 👍 this issue if you are interested in it.
The text was updated successfully, but these errors were encountered: