【问题标题】:Setting the terminal size (ala `stty columns` ) of another process?设置另一个进程的终端大小(ala `stty columns`)?
【发布时间】:2017-07-28 11:16:31
【问题描述】:

我正在使用 github.com/kr/pty 包为我产生的外部进程创建一个伪 TTY。然而,它们的终端尺寸似乎小于终端模拟器窗口尺寸(即 ncurses 和其他终端 UI 只会在 xterm / Konsole / 的左上角绘制)。

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

我该怎么做呢?

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

【问题讨论】:

    标签: go terminal tty


    【解决方案1】:

    我找到了解决方案。结果证明创建一个新的伪 TTY 是错误的方法,我实际上可以使用标准 Go 库来实现我想要的:

    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
    

    【讨论】:

      猜你喜欢
      • 2019-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-30
      • 2018-12-01
      • 1970-01-01
      相关资源
      最近更新 更多