対象èªè
- Rubyã®å ¥éæ¸ãä¸èªããæ¹
- ç·´ç¿ç¨ã«Rubyã®ããã°ã©ã ãä½ããããè¯ã課é¡ãè¦ã¤ãããªãæ¹
å¿ è¦ãªãã®
ãRubyæ¬ä½ã¨ã好ããªã¨ãã£ã¿ãç¨æãã¦ãã ãããRubyGemsãå°ã使ãã¾ãã
ãçè ã¯ä»¥ä¸ã®ç°å¢ã§å·çãã¦ãã¾ãã
ãruby 1.8.6-p111 / SAKURAã¨ãã£ã¿ / WindowsXP SP2 / gem 0.9.5
ãã®é£è¼ã®ç®æ¨
ãä½ã£ã¦ããä¾é¡ã¨ãã¦ã©ããªãã®ããããã¨ããªãèãã¾ãããä»åã¯Railsã使ããªãã¨æ±ºããã®ã§WEBã¢ããªã¯é¿ãããããå ¥éæ¸ã«ãããããããªã³ãã³ãã©ã¤ã³ä¸ã§æåãã¡ãã£ã¨åºãã ãã¨ããã®ãé¢ç½ããªãããGUIã¢ããªãæ·å± ãé«ããã§ããèããçµæãã³ã³ã½ã¼ã«ãããããå¶å¾¡ãããããªããã°ã©ã ãä½ããã¨ã«ãã¾ãããå¤ã人ã«ã¯æãããè¥ã人ã«ã¯æ°é®®ããããã¾ãããè¦ãç®ã¯å°å³ã§ãããªããªãé¢ç½ãã§ãããã§ã¯å§ãã¦ããã¾ãããã
ã³ã³ã½ã¼ã«ã©ã¤ãã©ãªã使ã£ã¦ã¿ã
ãRubyã§ã³ã³ã½ã¼ã«ã¢ããªãä½ãã«ã¯ãã³ã³ã½ã¼ã«ã©ã¤ãã©ãªãå¿ è¦ã§ãã
ãRubyç¨ã®ãã®ã¯ããã¤ãããã¾ãããæ¨æºã§ãCursesã¨ããã©ã¤ãã©ãªãå ¥ã£ã¦ãã¾ããä»åã¯ããã使ãã¾ãã
ã次ã®æé ã«å¾ã£ã¦æ¡å¼µã©ã¤ãã©ãªãã¤ã³ã¹ãã¼ã«ãã¦ãã ããã
- "http://jarp.does.notwork.org/win32/"ãããpdcurses-2.60-1-mswin32.zipãããã³ãzlib-1.1.4-1-mswin32.zipãããã¦ã³ãã¼ãã解åããã
- 解åãããåãã©ã«ãã®ãbinããã©ã«ãã«pdcurses.dllãzlib.dllãããã®ã§ããããrubyã®ã¤ã³ã¹ãã¼ã«å ã®ãbinããã©ã«ãã«ã³ãã¼ããã
åºæ¬çãªæ±ãæ¹
ãã¾ãã¯æ並ã¿ã§ãããHelloWorldãçãªããã°ã©ã ã§ãã
ãã¨ãã£ã¿ã使ã£ã¦æ¬¡ã®ããã°ã©ã ãä½æãã¦ãã ããã
require "curses" Curses::init_screen Curses::setpos(5, 2) Curses::addstr("Cursesã®ä¸çã«ãããã") Curses::refresh Curses::getch Curses::close_screen
ãåºæ¥ä¸ãã£ããwelcome.rbã¨ããååã§ä¿åãã¦ãã ããã
ãå®è¡ã¯ã³ãã³ãããã³ããã§åããããã«ãã¦ãã ããã
c:\> ruby welcome.rb
ããã®ããã°ã©ã ãå ã«Cursesã®åºæ¬çãªæ±ãæ¹ã説æãã¦ããã¾ãã
ãï¼è¡ç®ï¼ã¾ã"curses"ãrequire
ãã¾ããã¡ãªã¿ã«Cursesã©ã¤ãã©ãªã¯ã¢ã¸ã¥ã¼ã«ãªã®ã§ãªãã¸ã§ã¯ãçæç¡ãã§ã¡ã½ããã使ããã¨ãã§ãã¾ãã
ãï¼è¡ç®ï¼æåã«å¿
ãinit_screen
ãå¼ã¶å¿
è¦ãããã¾ãããã®ã¡ã½ããã¯ç»é¢ãåæåãã¾ããåæåããªãã¨Cursesã®ä»ã®ã¡ã½ãããå¼ã³åºããã¨ã¯ã§ãã¾ããã
ãå対ã«ããã°ã©ã ã®æå¾ã¯å¿
ãclose_screen
ãå¼ã³åºãå¿
è¦ãããã¾ããã¤ã¾ãã¢ããªç¬èªã®å¦çã¯init_screen
ã¨close_screen
ã®éã«æ¸ããã¨ã«ãªãã¾ãã
ãï¼è¡ç®ï¼ã«ã¼ã½ã«ãsetpos
ã¡ã½ããã使ã£ã¦ç§»åãã¾ãã座æ¨ã¯å·¦ä¸ã0,0ã¨ãã¦y軸ãx軸ã®é çªã§æå®ãã¾ããããã¦ãã®ä½ç½®ã«addstr
ã使ã£ã¦æååãæ¿å
¥ãã¦ãã¾ãã
ãï¼è¡ç®ï¼ããã¾ã§ã®å¦çãå®éã®ã³ã³ã½ã¼ã«ã«åæ ããããã«ã¯refresh
ã¡ã½ãããå¼ã¶ã¾ããç»é¢ã®ã©ãããæ¸ãæãããå¿
ãrefresh
ããªãã¨ããã¾ããã
ãï¼è¡ç®ï¼getch
ã¨ã¯ã¦ã¼ã¶ã¼ã®æåå
¥åãåãä»ããã¡ã½ããã§ããæåãå
¥ãã¾ã§ãã£ã¨å¾
ã¤åãããã¾ããããããªãã¨ãã®ããã°ã©ã ãä¸ç¬ã§çµãã£ã¦ãã¾ãã¾ãã®ã§å
¥ãã¦ããã¾ãã
ã¦ã£ã³ãã¦ãæ±ã
ãCursesã¯ã³ã³ã½ã¼ã«ä¸ã«ä»®æ³çãªã¦ã£ã³ãã¦ï¼Curses::Windowãªãã¸ã§ã¯ãï¼ãä½ããã¨ãã§ãã¾ããã¦ã£ã³ãã¦ã¯å¢çç·ãæåã使ã£ã¦æããããã«ã¼ã½ã«ä½ç½®ãåã ã§ä¿æãããã¨ãã§ãã¾ãã
ãåæç¶æ ã§ã¯ã³ã³ã½ã¼ã«ç»é¢å ¨ä½ãè¦ãã¦ã£ã³ãã¦ãã²ã¨ã¤ä½æããã¦ãã¾ãã次ã®ã¡ã½ããã«ãããã®æ¢æã®ã¦ã£ã³ãã¦ã®Curses::Windowãªãã¸ã§ã¯ããåå¾ãããã¨ãã§ãã¾ãã
Curses::stdscr
ãã¦ã£ã³ãã¦å ã«ãµãã¦ã£ã³ãã¦ãä½ããã¨ãã§ãã¾ããCurses::Windowã¯ã©ã¹ã®æ¬¡ã®ã¡ã½ããã使ãã¾ãã
subwin(height, width, y, x)
ã以ä¸ã¯ãµãã¦ã£ã³ãã¦ã表示ãããµã³ãã«ããã°ã©ã ã§ãã
ãæåã®ä¾ã¨åãããã«ã¨ãã£ã¿ã§å ¥åãã³ãã³ãããã³ããã§åããã¦ã¿ã¦ãã ããã
require "curses" include Curses init_screen begin win = stdscr.subwin(5,30,2,2) win.box(?|,?-,?*) win.setpos(2,2) win.addstr("ãµãã¦ã£ã³ãã¦ã§ã") win.refresh getch ensure close_screen end
ãååã¨ç°ãªãé¨åã®ã¿ã説æãã¦ããã¾ãã
ãã¾ãCursesãinclude
ã¡ã½ããã§Mix-inãã¦ãã¾ããããã«ããCursesã®ã¡ã½ãããèªåã®ã¡ã½ããã§ãããã®ããã«ä½¿ããã¡ã½ãããå¼ã¶åº¦ã«Curses::
ã¨æ¸ãã®ãçç¥ã§ãã¾ãã
ãç¶ãã¦init_screen
ã®äºè¡ä¸ãåè¿°ã®stdscr
ã¡ã½ããã§æ¢æã®ã¦ã£ã³ãã¦ãªãã¸ã§ã¯ããåå¾ãããã®ãµãã¦ã£ã³ãã¦ãçæãã¦ãã¾ãã
ãbox
ã¡ã½ããã¯ã¦ã£ã³ãã¦ã®å¢çç·ãæãã¾ããå¼æ°ã¨ãã¦å¢çãæãæåã®æåã³ã¼ãã渡ãã¾ããï¼"æåå"ã§ã¯ãªããã¨ã«æ³¨æãã¦ãã ãããRubyã§ã¯æåã³ã¼ãã¯ãã®æåã«?ãä»ããã¨å¾ããã¾ããä¾ãã°?*ã¯ã¢ã¹ã¿ãªã¹ã¯(*)ã®æåã³ã¼ãã«ãªãã¾ããï¼