-------------------------------------------------------------------------------- ¡º UNIX ¿Ã¹õ¾É¦Vµ{¦¡ªºµo®i§Q¾¹ - curses --------------------------------------------------------------------------------============================================================================== ¦¹¨â½g¤å³¹­ì¸ü©ó¡§¥æ¤j­p¤¤³q°T¡¨, 1993.11 -- 1993.12. ============================================================================== UNIX ¿Ã¹õ¾É¦Vµ{¦¡ªºµo®i§Q¾¹ - curses ®Õ¶éºô¸ôµ¦¶i·| ·|ªø ªL«Ø§» ¡½ «e¨¥ ¬Û«H±z¦bºô¸ô¤W¤@©w¥Î¹L¦p tin,elm µ¥¤u¨ã, ³o¨Ç³nÅ馳¶µ¦@¦Pªº¯S¦â, §Y¥L­Ì¯à§Q¥Î¤W¤U¥ª¥kµ¥¤è¦VÁä¨Ó±±¨î´å¼Ðªº¦ì¸m. °£¦¹¤§¥~, ³o¨Çµ{¦¡ ªºµe­±¤]¸û¬°¬üÆ[. ¹ï Programming ¦³¿³½ìªºªB¤Í¤@©w¹ï¦¹·P¨ì¦n©_, ¤] ³\¥L¯à¦b PC ¤W¥Î Turbo C »´©ö¦a¼g¥XÃþ¦üªºµ{¦¡, µM¦Ó, ¦ý·í¥L±N¬Û¦P ªºµ{¦¡¤@¦r¤£Åܦa²¾¨ì¤u§@¯¸¤W¨Ó½sĶ®É, «o¥X²{¤@°ï§ì¤]§ì¤£§¹ªº¿ù»~. ¨ä¹ê, ­ì¦]«Ü²³æ, ¥L¨Ï¥Îªº¨ç¦¡®w¥i¯à¦b UNIX ¤W¬O¨S¦³©w¸qªº. ¦³¨Ç ¦b Turbo-C ¤W³Q¼sªx¨Ï¥Îªº¤@¨Ç¨ç¦¡, ¥i¯à¦b UNIX ¤W¬O¤£³Q©w¸qªº. ¬°¤F¦]À³ºô¸ô¤W¦U¦¡¦U¼Ëªº²×ºÝ¾÷§ÎºA (terminal), UNIX ¤W¯S§Oµo®i¥X ¤@®M¨ç¦¡®w, ±Mªù¥Î¨Ó³B²z UNIX ¤W´å¼Ð²¾°Ê¤Î¿Ã¹õªºÅã¥Ü. ³o´N¬O¥»½g ¤å³¹­n¬°±z¤¶²Ðªº - curses.h ¨ç¦¡®w. §Q¥Î³o­Ó¨ç¦¡®w, ±z¤]¥i¥H¼g¥X ¹³ elm ¯ë§Q¥Î¤è¦VÁä¨Ó²¾°Ê¥ú´Î¦ì¸mªºµ{¦¡. (CCCA ªñ¨Ó©Ò´£¨Ñªº½u¤W¿ï ½Òµ{¦¡, ¤Îµ{¦¡ªA°È¬É­±, §Y¬Oµ§ªÌ§Q¥Î curses µo®i¦Ó¦¨ªº ) ¡½ curses ªº¾ú¥v»Pª©¥» cureses ³Ì¦­¬O¥Ñ¬f§JµÜ¤j¾Çªº Bill Joy ¤Î Ken Arnold ©Òµo®i¥X¨Óªº. ·í®Éµo®i¦¹¤@¨ç¦¡®w¥D­n­ì¦]¬O¬°¤F´£°ªµ{¦¡¹ï¤£¦P²×ºÝ¾÷ªº¬Û®e©Ê¦Ó³] ­pªº. ¦]¦¹, §Q¥Î curses µo®i¥X¨Óªºµ{¦¡±N©M±z©Ò¨Ï¥Îªº²×ºÝ¾÷µLÃö. ¤]´N¬O»¡, ±z¤£¥²¾á¤ß±zªºµ{¦¡¦]¬°´«¤F¤@³¡²×ºÝ¾÷¦ÓµLªk¨Ï¥Î. ³o¹ïµ{ ¦¡³]­p®v¦Ó¨¥, ¤×¨ä¬Oºô¸ô¤Wµ{¦¡ªº¼¶¼g, ¬O¥ó¬Û·í­«­nªº¤@¥ó¨Æ. curses¤§©Ò¥H¯à¹ï¤W¦ÊºØ¥H¤Wªº²×ºÝ¾÷¤u§@, ¬O¦]¬°¥¦±N©Ò¦³²×ºÝ¾÷ªº¸ê ®Æ, ¦s©ñ¦b¤@­Ó¥s termcap ªº¸ê®Æ®w, ( ¦Ó¦b²Ä¤Gª©ªº System V ¨t²Î¤¤ , ·sª©ªº curses ¥H terminfo ¨ú¥N­ì¨Óªº termcap). ¦³¤F³o¨Ç°O¿ý, µ{ ¦¡´N¯à°÷ª¾¹D¹J¨ì­þ¤@ºØ²×ºÝ¾÷®É, ¶·°e¤°»ò¦r¤¸¤~¯à²¾°Ê´å¼Ðªº¦ì¸m, °e¤°»ò¦r¤¸¤~¯à²M°£¾ã­Ó¿Ã¹õ²M°£. (* µù¤@) ¥t¥~, ¥»¤åªº¤¶²Ð ¥H System V ªº curses ª©¥»¬°¥D. ¡½ ¦p¦ó¦b±zªºµ{¦¡¨Ï¥Î curses ? ¦b±zªº C µ{¦¡ªºÀÉÀY±N include ¶i¨Ó.·í±z¤Þ¶i curses.h ³o­Ó¨ç¦¡®w«á, ¨t²Î·|¦Û°Ê±N ©M ¤@¨Ö include ¶i ¨Ó. ¥t¥~, ¦b System V ª©¥»¤¤, ³o­Ó¨ç¦¡®w¤]±N¤@¨Ö include¶i¨Ó. #include main() { : : : : } ·íµM, ±zªº¨t²Î¤º¥²¶·©ñ¦³ curses.h ³o­Ó¨ç¦¡®w. ¡½ ¦p¦ó½sĶ(compile) ·í±z½s¿è¦n±zªºµ{¦¡, ¦b UNIX ´£¥Ü²Å¸¹¤UÁä¤J: % /usr/5bin/cc [file.c] -lcurses ^^^^^^^ ¤Þ¶i curses.h ³o­Ó library ©Î % /usr/5bin/cc [file.c] -lcurses -ltermlib (*µù¤G) ¡½ ¦p¦ó¶}©l§Úªº²Ä¤@­Ó curses µ{¦¡? ¦b¶}©l¨Ï¥Î curses ªº¤@¤Á©R¥O¤§«e, ±z¥²¶·¥ý§Q¥Î initscr()³o­Ó¨ç¦¡ ¨Ó¶}±Ò curses ¼Ò¦¡. ¬Û¹ïªº, ¦bµ²§ô curses ¼Ò¦¡«e ( ³q±`¦b±zµ²§ôµ{¦¡«e ) ¤]¥²¶·¥H endwin()¨ÓÃö³¬ curses ¼Ò¦¡. #include main() { initscr(); : : : : : : endwin(); } ³o¬O¤@¯ë curses µ{¦¡¼Ð·Çªº¼Ò¦¡. ¦¹¥~, ±z¥i¥H´N±zµ{¦¡©Ò»Ý, ¦Ó°µ¤£¦Pªº³]©w. ·íµM, ±z¥i¥H¤£°µ³]©w, ¦Ó ¥u¬O©I¥s initscr(). ±z¥i¥H¦Û¤v¼g¤@­Ó¨ç¦¡¨Ó¦s©ñ©Ò¦³±z©Ò¶·­nªº³]©w. ¥­±`¨Ï¥Î®É, ¥u­n©I¥s ³o­Ó¨ç¦¡§Y¥i±Ò°Ê curses ¨Ã§¹¦¨¤@¤Á³]©w. ¤U­±ªº¨Ò¤l, §Y¬Oµ§ªÌ±N¥­±`¸û±`¥Îªº¤@¨Ç³]©w©ñ¦b¤@­Ó¥s initial()ªº¨ç ¦¡¤º. void initial() { initscr(); cbreak(); nonl(); noecho(); intrflush(stdscr,FALSE); keypad(stdscr,TRUE); refresh(); } ¦U¨ç¦¡¤À§O¤¶²Ð¦p¤U: ¡¼ initscr() initscr() ¬O¤@¯ë curses µ{¦¡¥²¶·¥ý©I¥sªº¨ç¼Æ, ¤@¦ý³o­Ó¨ç¼Æ ³Q©I¥s¤§«á, ¨t²Î±N®Ú¾Ú²×ºÝ¾÷ªº§ÎºA¨Ã±Ò°Ê curses ¼Ò¦¡. ¡¼ endwin() curses ³q±`¥H©I¥s endwin() ¨Óµ²§ôµ{¦¡. endwin() ¥i¥Î¨ÓÃö³¬ curses ¼Ò¦¡, ©Î¬O¼È®Éªº¸õÂ÷ curses ¼Ò¦¡.¦pªG±z¦bµ{¦¡¤¤¶·­n call shell ( ¦p©I¥s system() ¨ç¦¡ ) ©Î¬O»Ý­n°µ system call, ´N¥²¶·¥ý¥H endwin() ¼È®É¸õÂ÷ curses ¼Ò¦¡. ³Ì«á¦A¥H wrefresh() doupdate() ¨Ó­«ªð curses ¼Ò¦¡. ¡¼ cbreak() nocbreak() ·í cbreak ¼Ò¦¡³Q¶}±Ò«á, °£¤F DELETE ©Î CTRL µ¥¤´³Qµø¬°¯S®í ±±¨î¦r¤¸¥~¤@¤Á¿é¤Jªº¦r¤¸±N¥ß¨è³Q¤@¤@Ū¨ú.·í³B©ó nocbreak ¼Ò ¦¡®É, ±qÁä½L¿é¤Jªº¦r¤¸±N³QÀx¦s¦b buffer ¸Ìª½¨ì¿é¤J RETURN ©Î NEWLINE. ¦b¸ûª©ªº curses ¶·©I¥s crmode(),nocrmode() ¨Ó ¨ú¥N cbreak(),nocbreak() ¡¼ nl() nonl() ¥Î¨Ó¨M©w·í¿é¤J¸ê®Æ®É, «ö¤U RETURN Áä¬O§_³Q¹ïÀ³¬° NEWLINE ¦r ¤¸ ( ¦p \n ). ¦Ó¿é¥X¸ê®Æ®É, NEWLINE ¦r¤¸¬O§_³Q¹ïÀ³¬° RETURN ©M LINDFEED ¨t²Î¹w³]¬O¶}±Òªº. ¡¼ echo() noecho() ¦¹¨ç¦¡¥Î¨Ó±±¨î±qÁä½L¿é¤J¦r¤¸®É¬O§_±N¦r¤¸Åã¥Ü¦b²×ºÝ¾÷¤W. ¨t²Î ¹w³]¬O¶}±Òªº. ¡¼ intrflush(win,bf) ©I¥s intrflush ®É¶·¶Ç¤J¨â­Ó­È: win ¬°¤@ WINDOW «¬ºA«ü¼Ð, ³q±`¶Ç¤J¼Ð·Ç¿é¥X¤J¿Ã¹õ stdscr bf ¬° TRUE ©Î FALSE ·í bf ¬° true ®É, ·í¿é¤J¤¤Â_¦r¤¸ ( ¦p break) ®É, ¤¤Â_ªº¤ÏÀ³ ±N¸û¬°§Ö³t. ¦ý¥i¯à·|³y¦¨¿Ã¹õªº¿ù¶Ã. ¡¼ keypad(win,bf) ©I¥s keypad ®É¶·¶Ç¤J¨â­Ó­È: win ¬°¤@ WINDOW «¬ºA«ü¼Ð, ³q±`¶Ç¤J¼Ð·Ç¿é¥X¤J¿Ã¹õ stdscr bf ¬° TRUE ©Î FALSE ·í¶}±Ò keypad «á, ¥i¥H¨Ï¥ÎÁä½L¤Wªº¤@¨Ç¯S®í¦r¤¸, ¦p¤W¤U¥ª¥k µ¥¤è¦VÁä, curses ·|±N³o¨Ç¯S®í¦r¤¸Âà´«¦¨ curses.h ¤º©w¸qªº¤@ ¨Ç¯S®íÁä. ³o¨Ç©w¸qªº¯S®íÁä³q±`¥H KEY_ ¶}ÀY. ¡¼ refresh() refresh() ¬° curses ³Ì±`©I¥sªº¤@­Ó¨ç¦¡. curses ¬°¤F¨Ï¿Ã¹õ¿é¥X¤J¹F³Ì¨Î¤Æ, ·í±z©I¥s¿Ã¹õ¿é¥X¨ç¦¡¥ø¹Ï§ï Åܿùõ¤Wªºµe­±®É, curses ¨Ã¤£·|¥ß¨è¹ï¿Ã¹õ°µ§ïÅÜ, ¦Ó¬Oµ¥¨ì Åܿùõ¤Wªºµe­±®É, curses ¨Ã¤£·|¥ß¨è¹ï¿Ã¹õ°µ§ïÅÜ, ¦Ó¬Oµ¥¨ì refresh() ©I¥s«á, ¤~±N­è¤~©Ò°µªºÅܰʤ@¦¸§¹¦¨. ¨ä¾lªº¸ê®Æ±N ºû«ù¤£ÅÜ. ¥HºÉ¥i¯à°e³Ì¤Öªº¦r¤¸¦Ü¿Ã¹õ¤W. ´î¤Ö¿Ã¹õ­«Ã¸ªº®É¶¡. ¦pªG¬O initscr() «á²Ä¤@¦¸©I¥s refresh(), curses ±N°µ²M°£¿Ã ¹õªº¤u§@. ¡½ ´å¼Ðªº±±¨î move(y,x) ±N´å¼Ð²¾°Ê¦Ü x,y ªº¦ì¸m getyx(win,y,x) ±o¨ì¥Ø«e´å¼Ðªº¦ì¸m (½Ðª`·N! ¬O y,x ¦Ó¤£¬O &y,&x ) ¡½ ¦³Ãö²M°£¿Ã¹õªº¨ç¦¡ clear() erase() ±N¾ã­Ó¿Ã¹õ²M°£ (½Ðª`·N°t¦X refresh() ¨Ï¥Î) ¡½ ¦p¦ó¦b¿Ã¹õ¤WÅã¥Ü¦r¤¸ echochar(ch) Åã¥Ü¬Y­Ó¦r¤¸ addch(ch) Åã¥Ü¬Y­Ó¦r¤¸ mvaddch(y,x,ch) ¦b(x,y) ¤WÅã¥Ü¬Y­Ó¦r¤¸ ¬Û·í©ó©I¥s move(y,x);addch(ch); addstr(str) Åã¥Ü¤@¦ê¦r¦ê mvaddstr(y,x,str) ¦b(x,y) ¤WÅã¥Ü¤@¦ê¦r¦ê ¬Û·í©ó©I¥s move(y,x);addstr(str); printw(format,str) Ãþ¦ü printf() , ¥H¤@©wªº®æ¦¡¿é¥X¦Ü¿Ã¹õ mvprintw(y,x,format,str) ¦b(x,y) ¦ì¸m¤W°µ printw ªº¤u§@. ¬Û·í©ó©I¥s move(y,x);printw(format,str); ¡½ ¦p¦ó±qÁä½L¤WŪ¨ú¦r¤¸ getch() ±qÁä½LŪ¨ú¤@­Ó¦r¤¸ (ª`·N! ¶Ç¦^ªº¬O¾ã¼Æ­È) getstr() ±qÁä½LŪ¨ú¤@¦ê¦r¤¸ scanw(format,&arg1,&arg2...) ¦p¦P scanf, ±qÁä½LŪ¨ú¤@¦ê¦r¤¸ ½d¨Ò: int ch; char string1[80]; /* ½Ðª`·N! ¤£¥i«Å§i¬° char *string1; */ char string2[80]; echo(); /* ¶}±Ò echo ¼Ò¦¡, ¨Ï¿é¤J¥ß¨èÅã¥Ü¦b¿Ã¹õ¤W */ ch=getch(); string1=getstr(); scanw("%s",string2); mvprintw(10,10,"String1=%s",string1); mvprintw(11,10,"String2=%s",string2); ¡½ ¦p¦ó§Q¥Î¤è¦VÁä curses ±N¤@¨Ç¦p¤è¦VÁäµ¥¯S®í±±¨î¦r¤¸, ¥H KEY_ ¬°¶}ÀY©w¸q¦b curses.h ³o­ÓÀɮ׸ÌÀY, ¦p KEY_UP §Y¥Nªí¤è¦VÁ䪺 " ¡ô ". ¦ý, ¦pªG±z·Q¨Ï¥Î curses.h ©Ò¬°±z©w¸qªº³o¨Ç¯S®íÁ䪺¸Ü, ±z´N¥²¶·±N keypad ³]©w¬° TRUE. §_«h, ±z´N¥²¶·¦Û¤v¬°©Ò¦³ªº¯S®íÁä©w¸q¤F. curses.h ¬°¤@¨Ç¯S®íÁ䪺©w¸q¦p¤U: KEY_UP 0403 ¡ô KEY_DOWN 0402 ¡õ KEY_LEFT 0404 ¡ö KEY_RIGHT 0405 ¡÷ KEY_HOME 0406 Home key (upward+left arrow) KEY_BACKSPACE 0407 backspace (unreliable) KEY_F0 0410 Function keys. KEY_F(n) (KEY_F0+(n)) Formula for f . KEY_NPAGE 0522 Next page KEY_PPAGE 0523 Previous page ¥H¤W¶È¦C¥Xµ§ªÌ¸û±`¨Ï¥Îªº¤@¨Ç±±¨îÁä, ¦Ü©ó¨ä¥L±±¨îÁ䪺©w¸q, ½Ð¦Û¦æ°Ñ ¾\ man curses (* µù¤T) ¤@¨Ö¬°±z¦C¥X¨ä¥L±`¥Îªº¤@¨Ç¯S®í¦r¤¸ [TAB] /t [ENTER] /r [ESC] 27 [BACKSPACE] 127 ¡½ ¦p¦ó§ïÅܿùõÅã¥Ü¦r¤¸ªºÄÝ©Ê ¬°¤F¨Ï¿é¥Xªº¿Ã¹õµe­±§ó¬°¥Í°Ê¬üÄR, §Ú­Ì±`¶·­n¦b¿Ã¹õ¤W°µ¤@¨Ç¦p¤Ï¥Õ, °{Ã{µ¥ÅܤÆ. curses ©w¸q¤F¤@¨Ç¯S®íªºÄÝ©Ê, ³z¹L³o¨Ç©w¸q, §Ú­Ì¤]¥i¥H ¦b curses µ{¦¡ùر±¨î¿Ã¹õªº¿é¥XÅܤÆ. attron(mod) ¶}±ÒÄÝ©Ê attroff(mod) Ãö³¬ÄÝ©Ê curses.h ¸ÌÀY©w¸q¤F¤@¨ÇÄÝ©Ê, ¦p: A_UNDERLINE ¥[©³½u A_REVERSE ¤Ï¥Õ A_BLINK °{Ã{ A_BOLD °ª«G«× A_NORMAL ¼Ð·Ç¼Ò¦¡ (¥u¯à°t¦X attrset() ¨Ï¥Î) ·í¨Ï¥Î attron() ¶}±Ò¬Y¤@ºØ¯S®íÄݩʼҦ¡«á, ±µ¤U¨Ó¦b¿Ã¹õªº¿é¥X³£·|¥H ¸ÓºØÄÝ©Ê¥X²{. ª½¨ì±z©I¥s attroff() ±N¦¹¼Ò¦¡Ãö³¬. ½Ðª`·N, ·í±z±ý attron() ¶}±Ò¥t¤@ºØÄÝ©Ê®É, ½Ð°O±o§Q¥Î attroff()¥ýÃö ³¬­ì¨ÓªºÄÝ©Ê, ©Îª½±µ¥H attrset(A_NORMAL) ±N©Ò¦³¯S®íÄÝ©ÊÃö³¬.§_«h, curses ·|±N¨âºØÄÝ©Ê°µ­«Å|³B²z. ½d¨Ò: attrset(A_NORMAL); /* ¥ý±NÄݩʳ]©w¬°¥¿±`¼Ò¦¡ */ attron(A_UNDERLINE); /* ¥[©³½u */ mvaddstr(9,10,"¥[©³½u"); /* ¥[©³½u¿é¥X¤@¦ê¦r¤¸ */ attroff(A_UNDERLINE); /* Ãö³¬¥[©³½u¼Ò¦¡, «ì´_¥¿±`¼Ò¦¡ */ attron(A_REVERSE); /* ¶}±Ò¤Ï¥Õ¼Ò¦¡ */ mvaddstr(10,10,"¤Ï¥Õ"); /* ¿é¥X¤@¦ê¤Ï¥Õ¦r¤¸ */ attroff(A_REVERSE); /* Ãö³¬¤Ï¥Õ¼Ò¦¡, «ì´_¥¿±`¼Ò¦¡ */ attron(A_BLINK); /* ¶}±Ò°{Ã{¼Ò¦¡ */ mvaddstr(11,10,"°{Ã{"); /* ¿é¥X¤@¦ê°{Ã{¦r¤¸ */ attroff(A_BLINK); /* Ãö³¬°{Ã{¼Ò¦¡, «ì´_¥¿±`¼Ò¦¡ */ attron(A_BOLD); /* ¶}±Ò°ª«G«×¼Ò¦¡ */ mvaddstr(12,10,"°ª«G«×"); /* ¿é¥X¤@¦ê°ª«G«×¦r¤¸ */ attroff(A_BOLD); /* Ãö³¬°ª«G«×¼Ò¦¡, «ì´_¥¿±`¼Ò¦¡ */ ¡½ ¨ä¥L±`¥Îªº¤@¨Ç¨ç¦¡ beep() µo¥X¤@Án¹ÍÁn box(win,ch1,ch2) ¦Û°Êµe¤è®Ø ch1: µe¤è®Ø®É««ª½¤è¦V©Ò¥Î¦r¤¸ ch2: µe¤è®Ø®É¤ô¥­¤è¦V©Ò¥Î¦r¤¸ example: box(stdscr,'|','-'); ±N¥H | ¤Î - ³ò¦¨¤@­Ó¤è®Ø ¡½ À³¥Î§¹¾ã½d¨Ò ¤U­±©ÒÁ|ªº¨Ò¤l, §Y§¹¥þ§Q¥Î­è­è©Ò¤¶²Ðªº¨ç¦¡¨Ó§¹¦¨. ³o­Óµ{¦¡¥i±N±qÁä ½L¤WŪ¨úªº¦r¤¸Åã¥Ü¦b¿Ã¹õ¤W, ¨Ã¥B¥i¥H¤W¤U¥ª¥k¤è¦VÁä¨Ó±±¨î´å¼Ðªº¦ì¸m , ·í«ö¤U [ESC] «á, µ{¦¡§Yµ²§ô. ±z¦³¨S¦³µo²{, ³o¤£´N¬O¤@­Ó²³æ¥þ¿Ã¹õ½s¿è¾¹ªºÂú§Î¶Ü? #include /* ¤Þ¶i curses.h, ¨Ã¦Û°Ê¤Þ¶i stdio.h */ #define StartX 1 /* ¨M©w´å¼Ðªì©l¦ì¸m */ #define StartY 1 void initial(); main() { int x=StartX; /* «Å§i x,y ¨Ã³]©w¨äªì­È */ int y=StartY; int ch; /* «Å§i ch ¬°¾ã¼Æ,°t¦X getch() ¨Ï¥Î */ initial(); /* ©I¥s initial(), ±Ò°Ê curses ¼Ò¦¡, */ /* ¨Ã§¹¦¨¨ä¥¦³]©w */ box(stdscr,'|','-'); /* µe¤è®Ø */ attron(A_REVERSE); /* ¶}±Ò¤Ï¥Õ¼Ò¦¡ */ mvaddstr(0,20,"Curses Program"); /* ¦b (20,0) ³B¿é¥X¤Ï¥Õ¦r¤¸ */ attroff(A_REVERSE); /* Ãö³¬¤Ï¥Õ¼Ò¦¡ */ move(x,y); /* ±N´å¼Ð²¾¦Üªì©l¦ì¸m */ do { /* ¥HµL­­°j°é¤£Â_µ¥«Ý¿é¤J */ ch=getch(); /* µ¥«Ý¦ÛÁä½L¿é¤J¦r¤¸ */ switch(ch) { /* §PÂ_¿é¤J¦r¤¸¬°¦ó */ case KEY_UP: --y; /* §PÂ_¬O§_"¡ô"Áä³Q«ö¤U */ break; case KEY_DOWN: ++y; /* §PÂ_¬O§_"¡õ"Áä³Q«ö¤U */ break; case KEY_RIGHT: ++x; /* §PÂ_¬O§_"¡÷"Áä³Q«ö¤U */ break; case KEY_LEFT: --x; /* §PÂ_¬O§_"¡ö"Áä³Q«ö¤U */ break; case '\r': /* §PÂ_¬O§_ ENTER Áä³Q«ö¤U */ ++y; x=0; break; case '\t': /* §PÂ_¬O§_ TAB Áä³Q«ö¤U */ x+=7; break; case 127: /* §PÂ_¬O§_ BACKSPACE Áä³Q«ö¤U */ mvaddch(y,--x,' ');/* delete ¤@­Ó¦r¤¸ */ break; case 27: endwin(); /* §PÂ_¬O§_[ESC]Áä³Q«ö¤U */ exit(1); /* µ²§ô curses ¼Ò¦¡ */ /* µ²§ô¦¹µ{¦¡ */ default: addch(ch); /* ¦pªG¤£¬O¯S®í¦r¤¸, ±N¦¹¦r¤¸¦L¥X */ x++; break; } move(y,x); /* ²¾°Ê´å¼Ð¦Ü²{¦b¦ì¸m */ } while (1); } void initial() /* ¦Û©w¶}±Ò curses ¨ç¦¡ */ { initscr(); cbreak(); nonl(); noecho(); intrflush(stdscr,FALSE); keypad(stdscr,TRUE); refresh(); } ¡½ «á°O ¾Ç§¹¤F¤W­zªº¤@¨Ç©R¥O, ¬Û¤£¬Û«H±z¤w¸g¥i¥H¼g¥X¤@­Óº}«Gªº¥þ¿Ã¹õ½s¿è ¾¹¤F? ¨Æ¹ê¤W, curses ´£¨Ñªº¨ç¦¡¤£¤U 200 ­Ó, ¥i¬Oµ§ªÌ»{¬°, ¤@¤Á¦A ½ÆÂøªº¨ç¦¡³£¥i¥H¥Î¥»¤å´£¨ìªº¤@¨Ç²Õ¦XÅܤƦӦ¨, ¾Ç¤F¤Ó¦hªº¨ç¦¡, ¥u ¬O®{¼W¦Û¤v§xÂZ½}¤F. ·íµM, ¦pªG±z¹ï¨ä¥¦¨ç¦¡¦³¿³½ì, ¥i¥H¦Û¦æ°Ñ¾\ curses »¡©úÀÉ. ( ¤èªk: % man curses ) ¥»¤å¤£¹L¦æ©ß¿j¤Þ¥É¤§®Ä, ¤] §Æ±æ¥¼¨Ó¯à³°Äò¥X²{§ó¦h¦P¾Ç¦Û¦æ³Ð§@ªºµ{¦¡. * ¥ô¦óºÃ°Ý¤Î«Øij, Åwªï e-mail ¦Ü ljh@CCCA.NCTU.edu.tw. ÁÂÁ ! * µù¤@: ½Ð°Ñ¦Ò /usr/share/lib/termcup /usr/share/lib/terminfo/s/sun µù¤G: 1.¦pªG¬O BSD ªºª©¥», »Ý¨Ï¥Î cc [file.c] -lcurses -ltermcap ¨Ó§¹¦¨ compile. 2.­p¤¤¤u§@¯¸¤£ª¾¦ó¬G±N­ì¨Óªº /usr/5bin/cc §ó§ï¬° /usr/5bin/cc.org ¦]¦¹, ±z­Y·Q¦b­p¤¤¤u§@¯¸ compile curses µ{¦¡.»Ý¥H /usr/5bin/cc.org ¨ú¥N /usr/5bin/cc , §_«h compile ¥i¯àµo¥Í¿ù»~. 3.¸ûª©ªº curses »Ý¦P®É¤Þ¶i curses ©M termlib ³o¨â­Ó library, ¦]¦¹, ±z¥²¶·¨Ï¥Î /usr/5bin/cc [file.c] -lcurses -ltermlib ¨Ó compile. µù¤T: ®Ú¾Úµ§ªÌªº¸gÅç, ¤W¤U¥ª¥k¤è¦VÁäÀ³¥i¥¿±`¨Ï¥Î¦Ó¤£·|µo¥Í°ÝÃD, ¦ý¨ä¥¦ ¦p PgUp,PgDn,¥\¯àÁä,Home,End µ¥¯S®íÁä, «Ü®e©ö¦]¾÷¾¹¡NÁä½L¤£¦P¦ÓµL ªk¨Ï¥Î, ¦]¦¹, ­Y±zªºµ{¦¡¶·­n¦b¤£¦Pªº¾÷¾¹¤W¨Ï¥Î, «Øij±z¥u¥Î¤è¦VÁä¨Ó ±±¨î, ¨ä¥¦ªº¯S®íÁä¤Ö¥Î¬°§®. ¦Ü©ó PgUp,PgDn ¤@¨Ç¯S®íÁ䪺±±¨î¤èªk, ¥Ñ©ó¸û¬°½ÆÂø, ¦³¿³½ìªº¦P¾Ç¥i°Ñ ¦Ò tin ­ì©lµ{¦¡ curses.c ¤º©Ò¨Ï¥Îªº¤@¨Ç¤èªk. ============================================================================= UNIX ¿Ã¹õ¾É¦Vµ{¦¡ªºµo®i§Q¾¹ - curses (¤G) ®Õ¶éºô¸ôµ¦¶i·| ·|ªø ªL«Ø§» ¦b¤W´Á¬°±z¤¶²Ð§¹¤F curses.h ¨ç¦¡®wªº¤@¨Ç°ò¥»¨ç¦¡©I¥s«á¦b, ¦b¥»´Á¸Ì , §Ú­Ì±NÄ~Äò¬°±z¤¶²Ð curses ¦³Ãö¦hµøµ¡³B²zªº¨ç¦¡. ¦³¤F³o¨Ç¨ç¦¡, §Ú­Ì ¥i¥H¦bµ{¦¡¸Ì¦P®É³B²z¦h­Ó¤£¦Pªºµøµ¡. ¦p joe ½s¿è¾¹¤º§Ú­Ì¥i±N¿Ã¹õ¤Á³Î ¦¨¦n´X­Ó¤p¿Ã¹õ, ¨Ã¥B¥i¥H¦b³o¨Ç¤£¦Pªº¿Ã¹õ¶¡°µ¤Á´«¨Ã½s¿è¤£¦PªºÀÉ®×, ³o ´N¬O¦hµø³B²zªºÀ³¥Î. ¥t¥~, ¦³Ãö POP-UP µøµ¡ªº»s§@, ¥H¤Îµøµ¡ªº±²°Ê, ¦b ¥»¤å¸Ì, §Ú­Ì±N¥H²³æªº¨Ò¤l, §i¶D±z³o¨Ç¥\¯à¬O¦p¦ó°µ¨ìªº. Ãö©ó¤@¨Ç¸û°ò ¥»¨ç¦¡ªº¥Îªk, §Ú­Ì±N¤£¦A¯S§O¤¶²Ð. ¦pªG±z©|¥¼¼ô±x curses °ò¥»¨ç¦¡¨Ï¥Î ¤èªk, ½Ð°Ñ¾\¤W¤@´Á (80 ´Á ) ³q°T. ¡½ µøµ¡ªº«Ø¥ß µøµ¡ªº«Ø¥ß, ¥H newwin() ³o­Ó¨ç¦¡¨Ó§¹¦¨. ¦P®É, »Ý«Å§i¦¹µøµ¡¬° WINDOW µ²ºcÅܼÆ. WINDOW *newwin(lines,colums,start_y,start_x); WINDOW *win; win=newwin(10,20,0,0); ¦p¦¹, ±N¥H (0,0) ¬°­ìÂI, ¨ú¤@­Ó 10 ¦C 20 ¦æªº¯x§Î¬°¤@·sªºµøµ¡. ¤µ«á §Ú­Ì¥u­n©I¥s win ³o­ÓÅܼÆ, ´N¥i¥H¹ï³o·sµøµ¡°µ³B²z. ¦p: wmove(win,3,2); ¡½ ¦hµøµ¡³B²z¨ç¦¡ªº®æ¦¡ ³o¤@Ãþ¨ç¦¡©M¤@¯ëªº°ò¥»¨ç¦¡·¥¬°Ãþ¦ü, ´X¥G¨C¤@­Ó°ò¥»¨ç¦¡³£¦³¤@­Ó¹ïÀ³ªº µøµ¡³B²z¨ç¦¡. ¤@¯ë±N 'w' ¥[¦b¨ç¦¡ªº¸ÌÀY§@¬°°Ï§O, 'w' ¤D 'window' ¤§ ·N. ¥t¥~, ¦]¬°¥i¦P®É³B²z¦h­Óµøµ¡, ¦b©I¥s¨Ï¥Î®É, »Ý¯S§O«ü©w±ý³B²zªºµø µ¡. ·íµM, ¦pªG±z«ü©w¹ï stdscr °µ³B²z, ¥Ñ©ó¬O¹ï¼Ð·Ç¿é¥X¤J¿Ã¹õ³B²z, ¨ä §@¥Î±N¬Û·í©ó¤@¯ë°ò¥»ªº¨ç¦¡. ¦p: wmove(win,y,x) §Y¹ï win ³o­Óµøµ¡°µ move() °Ê§@. wmove(stdscr,y,x) ¬Û·í©ó move(y,x) ¤¶²Ð¤@¨Ç¸û­«­nªº¨ç¦¡ wmove(win,y,x) touchwin(win) wrefresh(win) mvwaddstr(win,y,x,str) wattron(attr) delwin(win) subwin(win,ny,nx,y,x) ¨ä¥L¨ç¦¡¦h©M°ò¥»¨ç¦¡¤¬¬°¹ïÀ³, ¬G¤£¥þ³¡¦C¥X, ¸Ô²Ó¦WºÙ¥i°Ñ¦Ò curses ªº online manual. ¡½ µøµ¡¤ºªº®y¼Ð¨t µøµ¡¤ºªº®y¼Ð¨t, ±N¥H¦¹µøµ¡ªº°_©lÂI¬°·s­ìÂI, ¨Ã¥H¨ä¬Û¹ï¦ì¸m§@¬°·sªº ®y¼Ð. Á|¨Ò¨Ó»¡ win=newwin(10,20,5,5); wmove(win,2,3); ±N¥H (5,5) ¬°·s­ìÂI, y ¤è¦V²¾°Ê 2 ³æ¦ì, x ¤è¦V²¾°Ê 3 ³æ¦ì. ¦]¦¹¹ê»Ú ¤W, ´å¼Ð±N²¾°Ê¦Ü y=7 x=8 ªº¦ì¸m¤W. ¡½ POP-UP µøµ¡ªº«Ø¥ß §Q¥Î curses ©Ò´£¨Ñªºµøµ¡³B²z¨ç¦¡, §Ú­Ì¥i¥H°µ¥X¹³ ONLINE HELP ªº POP -UP µe­±. ·í«ö¤U¬YÁä«á, ¤@­Ó·sªºµøµ¡±N¹³ " ¸õ " ¥X¨Ó¤@¯ëÂл\­ì¨Óªºµe ­±. ·íÃö±¼¦¹µøµ¡«á, ¤S¤£·|¼vÅT¨ì­ì¨Ó³QÂл\ªºµe­±. ¤U­±ªº¨Ò¤l, §Ú­Ì¤Î¼ÒÀÀ ONLINE HELP ªº§Î¦¡, ·í«ö¤U 'h' Áä®É, µøµ¡§Y¥X²{ #include main() { int ch,x,y; WINDOW *win; initscr(); ¡ö¢{ cbreak; ¢x ±Ò°Ê curses ¼Ò¦¡ noecho(); ¢x nonl(); ¡ö¢} win=newwin(4,30,LINES/2-3, COLS/2-15);/* «Ø¥ß¤@­Ó·sµøµ¡, ¨ä¤¤LINES,COLS */ box(win,'|','-'); /* ¬° curses ¤º©w­È, §Y¿Ã¹õ¦æ/¦C¼Æ*/ mvwaddstr(win,1,4,"This is another screen"); mvwaddstr(win,2,2,"Press anykey to continue.."); for (y=0;y main() { int i; WINDOW *scrwin,*boxwin; initscr(); ¡ö¢{ cbreak; ¢x ±Ò°Ê curses ¼Ò¦¡ noecho(); ¢x nonl(); ¡ö¢} scrwin=newwin(10,40,LINES/2-6,COLS/2-25); /* ³]©w¥t¤@µøµ¡¤j¤p */ boxwin=newwin(12,42,LINES/2-7,COLS/2-26); /* ³]©w¥~®Øµøµ¡¤j¤p */ scrollok(scrwin,TRUE); /* ¶}±Òµøµ¡±²°Ê¥\¯à */ box(boxwin,'|','-'); refresh(); wrefresh(boxwin); for (i=0;;++i) /* ¤£Â_¦a¦bµøµ¡¤º¿é¥X 0-8 ªº¼Æ¦r,¨Ïµøµ¡±²°Ê */ { wprintw(scrwin,"%d",i%9); wrefresh(scrwin); } } °õ¦æµ²ªG: ¢z¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢{ ¢x --------------------- ¢x ¢x |3456780123456780123412| ¡ô µø ¢x ¢x |3456780123456780123456| ¢x µ¡ ¢x ¢x |7801234567801234567801| ¢x ¤£ ¢x ¢x |2345678012345678012345| ¢x °± ¢x ¢x |6780123456780123456780| ¢x ©¹ ¢x ¢x |1234567801234567801234| ¢x ¤W ¢x ¢x |5678012345678012345678| ¢x ±² ¢x ¢x |0123456780123456780123| ¢x °Ê ¢x ¢x --------------------- ¢x ¢x ¢x ¢|¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢} ¡½ ½d¨Ò - ¼ÒÀÀ joe ¤À³Îµe­±¦P®É½s¿è¨â­ÓÀÉ®× ¦b¤U­±ªº¨Ò¤l¸Ì, §Ú­ÌÀ³¥Î¤F¦hµøµ¡³B²zªº¨ç¦¡, §ï¨}¤W¦^¤¶²Ðªº½s¿è¾¹, ¦b³o­Óµ{¦¡¸Ì, §Ú­Ì¥i¥H¦P®É½s¿è¨â­Óµe­±, ¨Ã¥H [ESC] °µ¤£¦Pµøµ¡¶¡ªº ¤Á´«. ¦P®É, «ö¤U [TAB] Áä, ·|¥X²{ POP-UP ªº ONLINE HELP. #include void initial(); main() { WINDOW *win[2],*curwin,*helpwin; int nowwin; int x,y; int i; int ch; initial(); win[0]=newwin(LINES/2-1,COLS-1,0,0); /* ³]©w¨â­Óµøµ¡ªº¤j¤p*/ win[1]=newwin(LINES/2-1,COLS-1,LINES/2,0); helpwin=newwin(3,30,2,COLS/2-15 ); /* ONLINE HELP ªº¤j¤p */ box(helpwin,'|','-'); mvwaddstr(helpwin,0,10,"ONLINE HELP"); /* ONLINE HELP ªº¤º®e */ mvwaddstr(helpwin,1,4,"Hit any key to continue.."); for (i=0;i