我有一个简单的程序,它有一个主窗口和一个位于底部的小窗口(没有线条,这样你就可以看到两个窗口:
+------------------+
| |
| |
| |
+------------------+
| |
+------------------+
我希望底部区域是您可以输入的地方,这是我的源代码:
#include <termios.h>
#include <bits/stdc++.h>
#include <ncurses.h>
int main()
{
int scrx;
int scry;
initscr();
cbreak();
noecho();
clear();
raw();
getmaxyx(stdscr, scrx, scry);
WINDOW* input = newwin(1, scrx, scry, 0);
std::string cmdbuf;
while(true)
{
int newx;
int newy;
getmaxyx(stdscr, newx, newy);
if(newx != scrx || newy != scry)
{
// do stuff;
}
char c = wgetch(input);
cmdbuf.push_back(c);
werase(input);
mvwprintw(input, 0, 0, cmdbuf.c_str());
refresh();
wrefresh(input);
}
}
但是,它似乎没有打印任何内容,只是移动我的光标(它在屏幕的一半处被吸住了)。我怎样才能使文本真正打印出来并且我的光标实际上在整个屏幕上移动?
最佳答案
为您整理了一下。按“q”退出。你明白了。
#include <termios.h>
#include <bits/stdc++.h>
#include <ncurses.h>
int main()
{
int scrx, scry;
initscr();
getmaxyx(stdscr, scry, scrx);
WINDOW *w = newwin(1, scrx, scry - 1, 0);
std::string cmdbuf {};
char c = '\0';
while (c != 'q')
{
int newx, newy;
getmaxyx(stdscr, newx, newy);
if(newx != scrx || newy != scry)
{
// do stuff;
}
c = wgetch(w);
cmdbuf += c;
mvwprintw(w, 0, 0, "%s", cmdbuf.c_str());
wrefresh(w);
}
delwin(w);
endwin();
}
关于c++ - Ncurses mvprintw 不打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63026448/