Skip to content
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

MacOS 10.13.6 Console.SetWindowSize() exception #27216

Closed
Petermarcu opened this issue Aug 23, 2018 · 11 comments
Closed

MacOS 10.13.6 Console.SetWindowSize() exception #27216

Petermarcu opened this issue Aug 23, 2018 · 11 comments
Labels
area-System.Console documentation Documentation bug or enhancement, does not impact product or test code os-linux Linux OS (any supported distro) os-mac-os-x macOS aka OSX
Milestone

Comments

@Petermarcu
Copy link
Member

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++;
        }
    }
}
@stephentoub
Copy link
Member

.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
Copy link
Member

wfurt commented 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)

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the Future milestone Jan 31, 2020
@devklick
Copy link

devklick commented 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
Copy link
Member

wfurt commented 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

@maryamariyan maryamariyan added the untriaged New issue has not been triaged by the area owner label Feb 23, 2020
@carlossanlop carlossanlop removed the untriaged New issue has not been triaged by the area owner label Apr 1, 2020
@junzhou98
Copy link

this problem has resolve?

@junzhou98
Copy link

it can't resolve?

@junzhou98
Copy link

help

@junzhou98
Copy link

urgent

@wfurt
Copy link
Member

wfurt commented 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
Copy link

CAMOBAP commented Sep 22, 2023

I assume there is the same exception for Linux/Docker

P.S. related breadbyte/ConsoleInteractive#9

@adamsitnik
Copy link
Member

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

@adamsitnik adamsitnik modified the milestones: Future, 8.0.0 Nov 13, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Console documentation Documentation bug or enhancement, does not impact product or test code os-linux Linux OS (any supported distro) os-mac-os-x macOS aka OSX
Projects
None yet
Development

No branches or pull requests

10 participants