【发布时间】:2013-09-18 00:05:47
【问题描述】:
每个人。我还是编程新手。我真的需要一些关于我面临的问题的帮助。所以,这里的情况是我试图在终端尺寸低于 80x24 时显示警告。作为记录,我的操作系统是 Window,但我使用虚拟机运行 Linux,因为所有文件都在 Linux 中。当我使用终端运行文件时,警告显示正确。但问题是当我尝试使用 PuTTY 从 Windows 运行文件时。警告没有出现。我确定是因为我使用的功能只能读取 Linux 环境而不能读取 Windows。任何人都可以帮助我或指出如何使其能够获得窗户尺寸的方向。这些文件都应该保留在 Linux 中。我正在使用 C。
这里只是显示警告和获取维度的部分代码。
//This is to display warning
int display_warning()
{
CDKSCREEN *cdkscreen = 0;
WINDOW *cursesWin = 0;
char *mesg[5];
char *buttons[] = {"[ OK ]"};
CDKDIALOG *confirm;
cursesWin = initscr();
cdkscreen = initCDKScreen (cursesWin);
initCDKColor();
mesg[0] = "</2>"The size of Window must be at least 80x24.";
confirm = newCDKDialog(cdkscreen, CENTER, CENTER, mesg, 1, buttons, A_REVERSE, TRUE,TRUE, FALSE);
setCDKDialogBackgroundColor(confirm, "</2>");
injectCDKDialog(confirm,TAB);
activateCDKDialog(confirm,0);
if (confirm -> exitType == vNORMAL){
destroyCDKDialog (confirm);
destroyCDKScreen (cdkscreen);
endCDK();
}
return 0;
}
//This is to get the dimension
int get_terminal_size()
{
int cols;
int lines;
#ifdef TIOCGSIZE
struct ttysize ts;
ioctl(0,TIOCGSIZE, &ts);
lines = ts.ts_linesl;
cols = ts.ts_cols;
#elif defined(TIOCGWINSZ)
struct winsize ts;
ioctl(0, TIOCGWINSZ, &ts);
lines = ts.ws_row;
cols = ts.ws_col;
#endif
if((lines <= 23)||(cols <= 79)){
display_warning();
}
return 0;
}
//then there will be the main function that i think is not necessary to put the code here.
非常感谢所有评论和帮助。我是编程初学者,如果有一些基本的不懂的地方请多多包涵。
菲克里
【问题讨论】:
-
如果你使用 curses 来做到这一点,我本来希望它可以工作。
-
似乎有一个错字:
#ifdef TIOCFSIZE而不是#ifdef TIOCGSIZE。我对么?这有什么改变吗? -
对不起,这是我在这里输入的错误,真正的代码是 TIOCGSIZE。谢谢你告诉我。
-
@trojanfoe 是的。当我在 Linux 中使用终端运行文件时,它确实有效。当我在 Windows 上使用 PuTTY 运行时,我只是无法工作。