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 ();
}
}
}
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 ();
}
}
}
2 回答
更新:我忽略了'调整大小'来自XQuartz(xserver / xterm)软件包的事实,苹果不再直接提供或维护;有关信息,请参阅XQuartz项目 . 请参阅Swell的答案,因为它使用术语大小转义序列(所有调整大小的确实在做) .
您可以使用系统调用'resize'( man resize 了解详细信息) . 这是所有(?)xterm和shell(bash / tsh / csh / ...)的标准
假设您没有使用ncurses,但如果您正在使用调整大小处理程序集,则会获得resize事件,就像用户使用鼠标调整终端大小一样 .
我将此示例添加到CursesSharp repo,github链接到源:https://github.com/sushihangover/CursesSharp/blob/368906549512446dc5e97f8c9214c482d6847aac/CursesSharp.Demo/Demo.Native.ResizeTerm/Program.cs
以下是适用于Yosemite的最终解决方案:
感谢来自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