我一直在寻找一种从我的C程序中获取终端宽度的方法.我一直想出的是:
#include <sys/ioctl.h>
#include <stdio.h>
int main (void)
{
struct ttysize ts;
ioctl(0, TIOCGSIZE, &ts);
printf ("lines %d\n", ts.ts_lines);
printf ("columns %d\n", ts.ts_cols);
}
Run Code Online (Sandbox Code Playgroud)
但每次我尝试我得到
austin@:~$ gcc test.c -o test
test.c: In function ‘main’:
test.c:6: error: storage size of ‘ts’ isn’t known
test.c:7: error: ‘TIOCGSIZE’ undeclared (first use in this function)
test.c:7: error: (Each undeclared identifier is reported only once
test.c:7: error: for each function it appears in.)
Run Code Online (Sandbox Code Playgroud)
这是最好的方法吗,还是有更好的方法?如果不是,我怎么能让它工作?
编辑:固定代码是
#include <sys/ioctl.h>
#include <stdio.h>
int main (void)
{
struct winsize …Run Code Online (Sandbox Code Playgroud) 我可以使用gevent和zeromq实现聊天守护程序,但我想为其创建一个控制台UI。
我与ncurses的第一次尝试失败了,所以我尝试Urwid,发现该项目寿司正想正是我想要的:

我研究了源代码,但是由于不熟悉控制台UI编程,因此未能找出产生此结果的部分(特别是因为它使用了多个选项卡),而我想我必须使用connect信号。
是否有人可以做到这一点?
我不需要整个程序,我可以自己处理通信,守护程序,选项以及所有其他内容。
只是设置UI的基础知识,在底部输入一些文本,然后异步通知顶部面板在不阻止底部输出的情况下添加一些文本。
谢谢