douyue7408
2017-07-28 11:16
浏览 120
已采纳

设置另一个进程的终端大小(如ala`stty columns`)?

I'm using the github.com/kr/pty package to create a pseudo-TTY for external processes I spawn off. However the terminal size for them seems to be smaller than the terminal emulator window size (ie ncurses and other terminal UIs will only draw in the top left corner of xterm / Konsole / whatever).

I have raised a bug with the pty package as the idea way to fix this issue would be with the package itself, but as a work around it might be handy if I could set the dimensions of the TTY myself (in code).

How would I go about doing this?

NB The project is written in Go (Golang) so ideally I'd need advice in doing this in C or Go. Also the project I'm working on has a strong emphasis on cross platform compatibility so it would be handy to know if any syscalls required are OS specific.

图片转代码服务由CSDN问答提供 功能建议

我正在使用 github.com/kr/pty 包创建伪 -TTY我生成的外部进程。 但是,它们的终端大小似乎小于终端仿真器窗口的大小(即,ncurses和其他终端UI只会在xterm / Konsole /左上角绘制)。

我用pty软件包提出了一个错误,因为解决此问题的想法是使用软件包本身,但是如果可以自己设置TTY的尺寸(用代码),解决该问题可能会很方便。

我将如何去做?

NB该项目是用Go(Golang)编写的,因此理想情况下,我需要在C中进行操作的建议 或去。 另外,我正在从事的项目非常强调跨平台兼容性,因此,很容易知道所需的系统调用是否特定于操作系统。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongtuo6562 2017-07-30 00:54
    已采纳

    I found the solution. Turns out creating a new pseudo-TTY was the wrong approach and I can actually use the standard Go libraries to achieve what I wanted:

    cmd := exec.Command(name, parameters...)
    
    cmd.SysProcAttr = &syscall.SysProcAttr{
        Ctty: int(os.Stdout.Fd()) // set the TTY
    }
    
    // These must be the respective Std os.File as using a Reader/Writer 
    // wouldn't work if you're trying to assign a TTY to your terminal
    // emulator.
    cmd.Stdin = os.Stdin
    cmd.Stdout = os.Stdout
    cmd.Stderr = os.Stderr
    
    打赏 评论

相关推荐 更多相似问题