2013-10-15 4 views
2

있는 메뉴 만들기 : http://www.tldp.org/HOWTO/NCURSES-Programming-HOWTO/keys.html내가이 튜토리얼을 따라하기 위해 노력하고있어 저주

을하지만 난 전혀 잘에받지 못했습니다 두려워.

이 세계에서 가장 코드가 아닙니다,하지만 내가하고 싶은 것을 보여

 require "curses" 
     include Curses 

     init_screen #initialize first screen 
     start_color # 
     noecho 

    close = false 


     t1 = Thread.new{ 
     four = Window.new(5,60,2,2) 
     four.box('|', '-') 


      t2 = Thread.new{ 

       menu = Window.new(7,40,7,2) 
       menu.box('|', '-') 
       menu.setpos 1,1 
       menu.addstr "item_one" 
       menu.setpos 2,1 

       menu.attrset(A_STANDOUT) 

       menu.addstr "item_two" 
       menu.setpos 3,1 

       menu.attrset(A_NORMAL) 

       menu.addstr "item_three" 
       menu.setpos 4,1 
       menu.addstr "item_four" 

       menu.getch 
      } 
      t2.join 

     while close == false 
      ch = four.getch 
      case ch 
       when 'w' 
        four.setpos 2,1 
        four.addstr 'move up' 
        four.refresh 
       when 's' 
        four.setpos 2,1 
        four.addstr 'move down' 
        four.refresh 
       when 'x' 
        close = true 
      end 
     end 


     } 
     t1.join 

W와 D 키를 누르면, 나는 위 메뉴 항목 아래로 하이라이트를 이동하려면 메뉴 창에서 문자 그대로 그 하이라이트를 어떻게 움직일 수 있을지 전혀 모른다. 이는 코드에서 속성 설정기를 움직이는 것을 의미합니다. 나는 정말로 모른다. 저주의 길에는 많은 자원이 없습니다.

+0

이 코드를 들여하십시오 https://github.com/piotrmurach/tty-prompt – Nakilon

+0

에서 봐 ... – Felix

답변

4

예에서 스레드가 필요하지 않습니다.

이 여기에 수행 할 수있는 방법을 볼 수 있습니다 https://gist.github.com/phoet/6988038

require "curses" 
include Curses 

init_screen 
start_color 
noecho 

def draw_menu(menu, active_index=nil) 
    4.times do |i| 
    menu.setpos(i + 1, 1) 
    menu.attrset(i == active_index ? A_STANDOUT : A_NORMAL) 
    menu.addstr "item_#{i}" 
    end 
end 

def draw_info(menu, text) 
    menu.setpos(1, 10) 
    menu.attrset(A_NORMAL) 
    menu.addstr text 
end 

position = 0 

menu = Window.new(7,40,7,2) 
menu.box('|', '-') 
draw_menu(menu, position) 
while ch = menu.getch 
    case ch 
    when 'w' 
    draw_info menu, 'move up' 
    position -= 1 
    when 's' 
    draw_info menu, 'move down' 
    position += 1 
    when 'x' 
    exit 
    end 
    position = 3 if position < 0 
    position = 0 if position > 3 
    draw_menu(menu, position) 
end 
+0

정말 좋은 답변 ! 그래도 여기에 붙여 넣어야한다고 생각하십니까? 링크 끊김을 넣으시겠습니까? – Starkers

관련 문제