简体   繁体   English

Mac OS X上的Mono调整大小终端

[英]Mono resize terminal on Mac OS X

In Windows public static void SetWindowSize(int width, int height) works fine. 在Windows中, 公共静态void SetWindowSize(int width,int height)可以正常工作。

With mono this method is not supported. 对于单声道,不支持此方法。

Is there a way under Mac OS X with some DllImport to do the same? 在Mac OS X下,是否可以通过某些DllImport做到这一点?

Here is the final solution that works on Yosemite: 这是适用于优胜美地的最终解决方案:

Thanks to RobertN & Chris Page from apple.stackexchange: https://apple.stackexchange.com/questions/33736/can-a-terminal-window-be-resized-with-a-terminal-command/47841#47841?newreg=7290606aabbc45468a3f3ee640cd1d09 感谢apple.stackexchange的RobertN和Chris Page: https ://apple.stackexchange.com/questions/33736/can-a-terminal-window-be-resized-with-a-terminal-command/47841#47841 ? newreg = 7290606aabbc45468a3f3ee640cd1d09

using System;
using System.Runtime.InteropServices;

namespace Demo.Native.ResizeTerm
{
    class MainClass
    {
        [DllImport ("libc")]
        private static extern int system (string exec);


        public static void Main (string[] args)
        {
            system(@"printf '\e[8;50;100t'");
            Console.WriteLine ("We will be 50 lines and 100 columns in Terminal.app now");
            Console.ReadKey ();
        }
    }
}

Update: I overlooked the fact that 'resize' is coming from XQuartz's (xserver/xterm) package which Apple no longer supplies directly nor maintains; 更新:我忽略了“调整大小”来自XQuartz(xserver / xterm)软件包的事实,Apple不再直接提供或维护该软件包。 see the XQuartz project for info. 有关信息,请参见XQuartz项目。 See Swell's answer as it uses the term size escape sequence (all that resize is really doing). 请参阅Swell的答案,因为它使用了术语大小转义序列(所有调整大小实际上都在做)。

You can use system call to 'resize' ( man resize for details). 您可以使用系统调用来“调整大小”(有关详细信息,请使用man调整大小 )。 This is standard across all(?) xterm and shells (bash/tsh/csh/...) 这是所有(?)xterm和shell(bash / tsh / csh / ...)的标准配置

Assuming you are not using ncurses, but if you are and had a resize handler set, you will get the resize event just like if the user resize the terminal using their mouse. 假设您没有使用ncurses,但是如果您正在使用ncurses并设置了调整大小处理程序,则将获得resize事件,就像用户使用鼠标调整终端大小一样。

using System;
using System.Runtime.InteropServices;

namespace Demo.Native.ResizeTerm
{
    class MainClass
    {
        [DllImport ("libc")]
        private static extern int system (string exec);


        public static void Main (string[] args)
        {
            system("resize -s 50 100 > /dev/null");
            Console.WriteLine ("We will be 50 lines and 100 columns in Terminal.app now");
            Console.ReadKey ();
        }
    }
}

I added this sample to the CursesSharp repo, github link to source : https://github.com/sushihangover/CursesSharp/blob/368906549512446dc5e97f8c9214c482d6847aac/CursesSharp.Demo/Demo.Native.ResizeTerm/Program.cs 我将此示例添加到了CursesSharp存储库中,该链接是github的源链接: https : //github.com/sushihangover/CursesSharp/blob/368906549512446dc5e97f8c9214c482d6847aac/CursesSharp.Demo/Demo.Native.Native.ResizeTerm/Program.cs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM