c++ - Ncurses mvwprintw 不打印
问题描述
我有一个简单的程序,它有一个主窗口和一个底部的小窗口(没有线条,这只是为了让您可以看到两个窗口:
+------------------+
| |
| |
| |
+------------------+
| |
+------------------+
我希望底部区域是您可以输入的地方,这是我的源代码:
#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();
}
推荐阅读
- vim - 在 vim 中使用占位符
- 3d - 计算 3D 网格边界框的对角线长度的简单方法是什么?
- node.js - 詹金斯。指定的代理类型“docker”无效。必须是 [any, label, none] 之一
- ios - 如何使用 SKAction 连续循环 SKSprite 节点
- mongodb - 在 API 端点中使用 mongdb 对象 ID 的 base64 编码是否安全?
- javascript - 还有什么是规范的 javascript,console.log
- swift - Firebase 观察关闭未调用
- laravel - Laravel:如果将用户上传的文件上传到我的公共文件夹,我该如何隐藏它们
- json - Dart 布尔值在更新后保持不变
- corda - Corda OS 的冷热高可用性