本文介绍了通过fifo将curses输入发送到C中的另一个终端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的C程序在终端中运行多个线程,这些线程异步打印消息.我希望有一个线程显示curses输出,但是由于它是异步的,因此必须在另一个终端中.

My C program run multiple thread in the terminal that print messages asynchronously. I'd like a thread to show curses output, but as it is asynchronous it must be in another terminal.

我的想法是将curses输出写入FIFO,并打开一个终端cat fifo.

My idea is to write the curses output to a fifo and open a terminal withcat fifo.

但是我如何恢复诅咒的输出并将其输出到文件中?

But how could I recover the ouput the curses out and output it to a file?

谢谢.

推荐答案

curses使用终端作为其输入和输出,因此,如果要拦截该终端并使它进入终端以外的其他位置,则最简单的方法(尽管非-trivial)是使用伪终端.您可以通过调用posix_openpt来实现,这将为您提供伪终端主设备.然后,您调用grantptunlockptptsname来获取终端设备的名称,然后可以将其命名为fopen并传递给curses newterm来初始化终端.

curses uses a terminal for its input and output, so if you want to intercept that and make it go somewhere other than a terminal, the easiest method (though non-trivial) is to use a psuedoterminal. You do that by calling posix_openpt which gives you a pseudoterminal master device. You then call grantpt, unlockpt, and ptsname to get the name of a terminal device that you can then fopen and pass to curses newterm to initialize the terminal.

一旦完成,curses写入终端的所有内容都可以从master读取,而写到master的所有内容都将输入curses.就像fifo一样,还有curses期望的所有其他终端功能.

Once that is done, everything that curses writes to the terminal will be readble from the master, and everything written to the master will be input to curses. It is like a fifo, just with all the extra terminal functionality curses expects.

这篇关于通过fifo将curses输入发送到C中的另一个终端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 15:29