使用 ncurses 在运行时动态创建 window
Dynamic window creation at runtime using ncurses
不确定 ncurses 是否可行。所有文档和示例都表明多个 windows 的创建在编译时是已知的。
我想做这样的事情。
#include <ncurses.h>
WINDOW *create_newwin(int height, int width, int starty, int startx);
void star(int x,int y,int r);
void newbox(int x,int y,int r);
int main(int argc, char *argv[])
{
int startx, starty, width, height;
int ch,sze;
initscr(); /* Start curses mode */
cbreak(); /* Line buffering disabled, Pass on
* everty thing to me */
//printf("%s\n",argv[1]);
sze = atoi(argv[1]);
starty = (LINES - sze) / 2; /* Calculating for a center placement */
startx = (COLS - sze) / 2; /* of the window */
refresh();
star(startx,starty,sze);
endwin(); /* End curses mode */
return 0;
}
WINDOW *create_newwin(int height, int width, int starty, int startx)
{ WINDOW *local_win;
local_win = newwin(height, width, starty, startx);
box(local_win, 0 , 0); /* 0, 0 gives default characters
* for the vertical and horizontal
* lines */
wrefresh(local_win); /* Show that box */
return local_win;
}
void star(int x,int y,int r)
{
if(r>0)
{
star(x-r,y+r,r/2);
star(x+r,y+r,r/2);
star(x-r,y-r,r/2);
star(x+r,y-r,r/2);
newbox(x,y,r);
}
}
void newbox(int x,int y,int r)
{
WINDOW *mywin;
mywin = create_newwin(2*r, 2*r, y, x);
}
我认为您会使用 new 关键字和 malloc。我期望的目标是生成一种具有重叠 windows.The 函数的分形显示类型 star 是一个递归函数,它将创建要传递给 newbox 函数的参数。有人在运行时使用 ncurses 创建 windows 吗?
(n)curses 函数newwin
allocates space for a WINDOW
structure and returns that. The stdscr
and curscr
windows likewise are allocated in initscr
or newterm
(using newwin
). The main difference between stdscr
and curscr
versus other windows is that these are used throughout the library in a predefined manner, and cannot be freed. The other windows can be freed using delwin
。 None 其中 "static".
相应的手册页有此基本信息。
ncurses example programs show how windows can be created which are not explicit in the code, e.g., prompting for the user to move the cursor to begin creating a window, then moving to select the end (top-left versus bottom-right, in menu item g
below). Likewise, several use recursion, e.g., to draw a series of nested, boxed windows (menu item a
or A
below, used to test resizeterm
)。这些都是在主测试程序中完成的,其菜单如下所示:
Welcome to ncurses 5.9.20150502. Press ? for help.
This is the ncurses main menu
a = keyboard and mouse input test
A = wide-character keyboard and mouse input test
b = character attribute test
B = wide-character attribute test
c = color test pattern
C = color test pattern using wide-character calls
d = edit RGB color values
e = exercise soft keys
E = exercise soft keys using wide-characters
f = display ACS characters
F = display Wide-ACS characters
g = display windows and scrolling
i = test of flushinp()
k = display character attributes
m = menu code test
o = exercise panels library
O = exercise panels with wide-characters
p = exercise pad features
q = quit
r = exercise forms code
s = overlapping-refresh test
t = set trace level
? = repeat this command summary
>
不确定 ncurses 是否可行。所有文档和示例都表明多个 windows 的创建在编译时是已知的。 我想做这样的事情。
#include <ncurses.h>
WINDOW *create_newwin(int height, int width, int starty, int startx);
void star(int x,int y,int r);
void newbox(int x,int y,int r);
int main(int argc, char *argv[])
{
int startx, starty, width, height;
int ch,sze;
initscr(); /* Start curses mode */
cbreak(); /* Line buffering disabled, Pass on
* everty thing to me */
//printf("%s\n",argv[1]);
sze = atoi(argv[1]);
starty = (LINES - sze) / 2; /* Calculating for a center placement */
startx = (COLS - sze) / 2; /* of the window */
refresh();
star(startx,starty,sze);
endwin(); /* End curses mode */
return 0;
}
WINDOW *create_newwin(int height, int width, int starty, int startx)
{ WINDOW *local_win;
local_win = newwin(height, width, starty, startx);
box(local_win, 0 , 0); /* 0, 0 gives default characters
* for the vertical and horizontal
* lines */
wrefresh(local_win); /* Show that box */
return local_win;
}
void star(int x,int y,int r)
{
if(r>0)
{
star(x-r,y+r,r/2);
star(x+r,y+r,r/2);
star(x-r,y-r,r/2);
star(x+r,y-r,r/2);
newbox(x,y,r);
}
}
void newbox(int x,int y,int r)
{
WINDOW *mywin;
mywin = create_newwin(2*r, 2*r, y, x);
}
我认为您会使用 new 关键字和 malloc。我期望的目标是生成一种具有重叠 windows.The 函数的分形显示类型 star 是一个递归函数,它将创建要传递给 newbox 函数的参数。有人在运行时使用 ncurses 创建 windows 吗?
(n)curses 函数newwin
allocates space for a WINDOW
structure and returns that. The stdscr
and curscr
windows likewise are allocated in initscr
or newterm
(using newwin
). The main difference between stdscr
and curscr
versus other windows is that these are used throughout the library in a predefined manner, and cannot be freed. The other windows can be freed using delwin
。 None 其中 "static".
相应的手册页有此基本信息。
ncurses example programs show how windows can be created which are not explicit in the code, e.g., prompting for the user to move the cursor to begin creating a window, then moving to select the end (top-left versus bottom-right, in menu item g
below). Likewise, several use recursion, e.g., to draw a series of nested, boxed windows (menu item a
or A
below, used to test resizeterm
)。这些都是在主测试程序中完成的,其菜单如下所示:
Welcome to ncurses 5.9.20150502. Press ? for help.
This is the ncurses main menu
a = keyboard and mouse input test
A = wide-character keyboard and mouse input test
b = character attribute test
B = wide-character attribute test
c = color test pattern
C = color test pattern using wide-character calls
d = edit RGB color values
e = exercise soft keys
E = exercise soft keys using wide-characters
f = display ACS characters
F = display Wide-ACS characters
g = display windows and scrolling
i = test of flushinp()
k = display character attributes
m = menu code test
o = exercise panels library
O = exercise panels with wide-characters
p = exercise pad features
q = quit
r = exercise forms code
s = overlapping-refresh test
t = set trace level
? = repeat this command summary
>