Merge branch 'master' of git@github.com:elliottcable/nfoiled
[nfoiled.git] / examples / input.rb
blob6ba0731ab4bbbaec6c89b47f1abc8beeb8c5294c
1 ($:.unshift File.expand_path(File.join( File.dirname(__FILE__), '..', 'lib' ))).uniq!
2 require 'nfoiled'
4 ##
5 # This example shows you how to utilize an Nfoiled `Window` to accept input.
7 # Creating our first `Window` should take care of initializing the Nfoiled
8 # system for us. However, the `Ncurses.LINES` and `Ncurses.COLS` methods won't
9 # be defined until the system is initialized, so we have to prime it.
10 Nfoiled::initialize
11 output  = Nfoiled::Window.new :height => ::Ncurses.LINES - 1
12 input   = Nfoiled::Window.new :top    => ::Ncurses.LINES - 1, :height => 1
14 output.puts "Type characters to have them printed! (^C to exit)"
15 input.focus!
16 Nfoiled::update!
18 # Now we'll print each key to the output as it is typed into the input.
19 input.on_key do |key|
20   output.print key.char.to_s + " "
21   Nfoiled::update!
22 end
24 Nfoiled::read!