Advertisement
Guest User

Untitled

a guest
Oct 14th, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 1.82 KB | None | 0 0
  1.     require 'curses'
  2.     include Curses
  3.  
  4.     init_screen
  5.  
  6.     begin
  7.     crmode
  8.  
  9.     win0 = Window.new(10,10,10,10)
  10.     win0.addstr "Press 'x' to exit"
  11.     win0.box '|', '-'
  12.     win0.refresh # This is neccary for showing 2 windows at the same time. Without it, we'd have this window, then it would dissapear, and then we would have the second window. Refreshing populates a window before its getch.
  13.  
  14.     #note that we have a window within a window here. addstr, refresh and getch are all refering to the unnamed 'master window, and win1 is inside this master, but placed ontop of it, because comes later on in the code.
  15.  
  16.     height = 30
  17.     width = 10
  18.     posy = (lines - height) / 2 ##
  19.     posx = (cols - height) / 2  # These calculations provide parameters for a window that is always centered.
  20.  
  21.     win1 = Window.new(height, width, posy, posx) # creates a new window. Parameters are width of window, heighth of window, x coordinate and y coordinate
  22.     win1.box '|', '-' # creates a border around the window. The first parameter is the character we want to replicate inorder to create the vertical side of the box. The second paramter is the character we want to replicate to create the horizontal sides of the box.
  23.  
  24.  
  25.     close_window = false
  26.     while close_window == false
  27.         ch = win1.getch
  28.         case ch
  29.             when 'a'
  30.                 win1.clear
  31.                 win1 = Window.new(height, width, posy, posx-=1)
  32.                 win1.box '|', '-'
  33.             when 's'
  34.                 win1.clear
  35.                 win1 = Window.new(height, width, posy+=1, posx)
  36.                 win1.box '|', '-'
  37.             when 'd'
  38.                 win1.clear
  39.                 win1 = Window.new(height, width, posy, posx+=1)
  40.                 win1.box '|', '-'
  41.             when 'w'
  42.                 win1.clear
  43.                 win1 = Window.new(height, width, posy-=1, posx)
  44.                 win1.box '|', '-'
  45.             when 'x'
  46.                 close_window = true
  47.             else
  48.                 win1.addstr 'Error: ' + ch.to_s
  49.                 win1.getch
  50.         end
  51.     end
  52.    
  53.     win0.getch
  54.     ensure
  55.         close_screen
  56.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement