c++ - 如何通过 NCurses 的 C++ 绑定(bind)在屏幕上显示 NCursesPanel

标签 c++ ncurses

Demo我正在试用 ncurses-5.9 附带的 c++ 绑定(bind)。似乎不容易在屏幕上轻松显示带有窗口的面板。这是我的代码

class SpiderApplication : NCursesApplication
{
protected:
  int titlesize() const { return 2; };
  void title();

public:
  SpiderApplication() : NCursesApplication(TRUE) {}

  int run();
};

void SpiderApplication::title()
{
  const char * const titleText = "Demo";
  const int len = ::strlen(titleText);

  titleWindow->bkgd(screen_titles());
  titleWindow->addstr(0, (titleWindow->cols() - len) / 2, titleText);
  titleWindow->noutrefresh();
}

int SpiderApplication::run()
{
  NCursesPanel mystd;
  NCursesPanel P(mystd.lines() - titlesize(), mystd.cols(), titlesize() - 1, 0);
  P.label("Demo", NULL);
  P.show();
  ::getch();
  P.clear();

  return 0;
}

我想应该有一个面板显示在这个应用程序的标题行下。然而,事实并非如此。我在这里错过了重要的事情吗?有没有关于如何使用 ncurses 的 c++ 绑定(bind)的示例?

谢谢。

最佳答案

我找到了我自己问题的答案。

要使面板显示在屏幕上,不能省略 refresh() 调用。这是工作代码:

NCursesPanel mystd;
NCursesPanel P(mystd.lines() - titlesize(), mystd.cols(), titlesize() - 1, 0);
P.label("Demo", NULL);
P.show();
mystd.refresh();
::getch();
P.clear();

关于c++ - 如何通过 NCurses 的 C++ 绑定(bind)在屏幕上显示 NCursesPanel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25112116/

相关文章:

c++ - 迭代器实际上指向容器中的什么?

c++ - 集合与重复的组合

c++ - 如何使用C++在Windows中获取系统信息

c++ - 如何检查目录是文件还是文件夹?

python - _curses.error : addwstr() returned ERR on changing nlines to 1 on newwin method

python - 在不清除屏幕的情况下读取Linux终端中的特殊键

c++ - 在我的代码中,scoped_ptr 指向一个堆栈变量——这会延长堆栈变量的生命周期吗?

python - 使用 Python curses 自定义 RGB 颜色

Python Ncurses 打印单个字符以定位

C 禁用命令行输入