Printing inside window, not on borders

大兔子大兔子 提交于 2019-12-05 17:03:32

问题


I'm trying to write something inside a curses window, but it seems to write on borders too. How can I fix the code below?

win_self = newwin(LINES / 2, COLS, 0, 0);
box(win_self, 0, 0);
wrefresh(win_self);
wprintw(win_self, "foobar");

回答1:


In curses, the borders generated by box() are inside borders. As far as I can tell, there's no way to simply say "don't overwrite my border".

Nevertheless, there are three solutions that I can think of right now:

  • don't overwrite the border characters (use move())
  • draw the box after you draw window contents, then refresh() the screen (you're probably still overwriting something, but at least it's not the border characters)
  • create a "border window" with borders and a "content window" inside of it, which of course starts at (border_window_start_y + 1, border_window_start_x + 1) and is two lines/columns smaller than the "border window"


Just to make it more clear: the box() function doesn't add the property "this window has visible borders" to the window, it just prints border characters around the window.

You are:

  • free to overwrite those border characters
  • supposed to be cautious if you don't want them overwritten



回答2:


I'd say the easiest way is to create a window inside of the window borders and print in that window.

win_self = newwin(LINES / 2, COLS, 0, 0);
box(win_self, 0, 0);
derwin_self = derwin(win_self, LINES / 2 - 2, COLS - 2, 0, 0);
wprintw(derwin_self, "foobar");


来源:https://stackoverflow.com/questions/5749634/printing-inside-window-not-on-borders

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!