Repository navigation
Closed
Labels
area-System.ConsoledocumentationDocumentation bug or enhancement, does not impact product or test codeos-linuxLinux OS (any supported distro)os-macosmacOS aka OSX
Milestone
Description
I'm opening this on behalf of a user from VS Feedback. https://developercommunity.visualstudio.com/content/problem/318400/macos-10136-consolesetwindowsize-exception.html
dotnet core 2.1 document say support macos
Unhandled Exception: System.PlatformNotSupportedException: Operation is not supported on this platform.
at System.ConsolePal.SetWindowSize(Int32 width, Int32 height)
at System.Console.SetWindowSize(Int32 width, Int32 height)
at ColorConsoleDemo.Program.Main(String[] args) in /Users/zhm/OneDrive/CodeStudy/dotnetcore/ColorConsoleDemo/Program.cs:line 26
code:
using System;
using System.Collections.Generic;
namespace ColorConsoleDemo {
class Program {
static void Main (string[] args) {
List<ConsoleColor> colors = new List<ConsoleColor> ();
// 遍历枚举的写法,高级用法,把各种颜色保存到List里
foreach (ConsoleColor color in Enum.GetValues (typeof (ConsoleColor))) {
colors.Add (color);
}
int i = 0;
// 清楚屏幕,屏幕会被刷为空的背景色
Console.Clear ();
// 指定前景色
Console.ForegroundColor = colors[i % colors.Count];
// 指定背景色
Console.BackgroundColor = colors[(i + 1) % colors.Count];
Console.Write ("Hello");
Console.ForegroundColor = colors[(i + 2) % colors.Count];
int origWidth = Console.WindowWidth;
int origHeight = Console.WindowHeight;
Console.SetWindowSize (origWidth / 2, origHeight / 2);
Console.Write (" world!", Console.WindowWidth, Console.WindowHeight);
Console.SetCursorPosition (80, 15);
Console.Write ("test");
Console.SetCursorPosition (81, 16);
Console.Write ("test");
Console.SetCursorPosition (82, 17);
Console.Write ("test");
Console.SetCursorPosition (83, 18);
Console.Write ("test");
Console.SetCursorPosition (84, 19);
Console.Write ("test");
System.Threading.Thread.Sleep (1000);
i++;
}
}
}Metadata
Metadata
Assignees
Labels
area-System.ConsoledocumentationDocumentation bug or enhancement, does not impact product or test codeos-linuxLinux OS (any supported distro)os-macosmacOS aka OSX
Activity
stephentoub commentedon Sep 25, 2018
.NET Core 2.1 is supported on macOS, but there are a limited number of APIs that don't work because of platform limitations, and Console.SetWindowSize is one of them, hence the exception.
@terrajobst or @mairaw can probably comment on the best way tooling or docs could be updated to reflect this, but at present there's no bug here in the implementation; it's by design that it throws PlatformNotSupportedException.
wfurt commentedon Oct 15, 2018
note that I get same result on Linux. there is ioctl(TIOCSWINSZ) but that is generally informational.
It is up to the application to handle it. Also note, that there may not be window at all - at least not local managed by OS. (ssh or serial port access)
devklick commentedon Feb 4, 2020
I understand that this will be a pretty low priority, as there really arent that many use cases for setting the console size, but I'd love to see this functionality implemented on Linux, if possible.
wfurt commentedon Feb 4, 2020
It is not a matter of priority but more so technical feasibility. Unix "Console" is text-based and does not have window. When starting .NET console app, the app does not own or control the window - it is owned by the terminal app. There is more technical discussion here: #31658
cc: @tmds
junzhou98 commentedon Jul 29, 2021
this problem has resolve?
junzhou98 commentedon Jul 29, 2021
it can't resolve?
junzhou98 commentedon Jul 29, 2021
help
junzhou98 commentedon Jul 29, 2021
urgent
wfurt commentedon Jul 29, 2021
Are you on 2.1 @junzhou98? 2.1 support will expire in ~ month. Just catch the exception if you cannot avoid the call.
Alternatively you can p/invoke the icon but that may or may not work. And if it is not, there is no real way IMHO how .NET can make it.
CAMOBAP commentedon Sep 22, 2023
I assume there is the same exception for Linux/Docker
P.S. related breadbyte/ConsoleInteractive#9
adamsitnik commentedon Nov 13, 2023
The issue got fixed by #75824, which is included in .NET 8.
Some OSes still don't support it, but there is nothing we can do about it:
https://github.com/dotnet/runtime/blob/0e6e35f3e378e299736fbe07d83ebc339658bbf7/src/libraries/System.Console/src/System/
Console.cs#L440C1-L450