Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'curses'
- include Curses
- init_screen
- begin
- crmode
- win0 = Window.new(10,10,10,10)
- win0.addstr "Press 'x' to exit"
- win0.box '|', '-'
- 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.
- #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.
- height = 30
- width = 10
- posy = (lines - height) / 2 ##
- posx = (cols - height) / 2 # These calculations provide parameters for a window that is always centered.
- win1 = Window.new(height, width, posy, posx) # creates a new window. Parameters are width of window, heighth of window, x coordinate and y coordinate
- 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.
- close_window = false
- while close_window == false
- ch = win1.getch
- case ch
- when 'a'
- win1.clear
- win1 = Window.new(height, width, posy, posx-=1)
- win1.box '|', '-'
- when 's'
- win1.clear
- win1 = Window.new(height, width, posy+=1, posx)
- win1.box '|', '-'
- when 'd'
- win1.clear
- win1 = Window.new(height, width, posy, posx+=1)
- win1.box '|', '-'
- when 'w'
- win1.clear
- win1 = Window.new(height, width, posy-=1, posx)
- win1.box '|', '-'
- when 'x'
- close_window = true
- else
- win1.addstr 'Error: ' + ch.to_s
- win1.getch
- end
- end
- win0.getch
- ensure
- close_screen
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement