c++ - Ncurses mvprintw 不打印

标签 c++ ncurses

我有一个简单的程序,它有一个主窗口和一个位于底部的小窗口(没有线条,这样你就可以看到两个窗口:

+------------------+
|                  |
|                  | 
|                  |
+------------------+
|                  |
+------------------+

我希望底部区域是您可以输入的地方,这是我的源代码:

#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/

相关文章:

c - 如何在 Kali 上使用 C 中的 ncurses 编译 "Hello World"

C++ vector 源代码

c++ - Visual Studio - 调试器断点移动并且不再命中它们应该到达的行

c# - Visual Studio : C++\CLI wrapper assembly path dependency problems

c++ - 延迟执行小部件程序

c - 如何在不等待用户输入的情况下从 stdin 获取字符?

c++ - 如何正确使用 std::condition_variable?

c - 如何在从 Linux 启动时将 NCurses 输出定向到串行终端?

c - 如何在结构中保存 ncurses 窗口?

ruby - 我如何使用 ncurses 在 telnet 界面上绘制 ..?