From 3b83e3b4f583ac31452908b9355d2fddb27f4526 Mon Sep 17 00:00:00 2001 From: elliottcable Date: Fri, 13 Mar 2009 21:38:57 -0400 Subject: [PATCH] Added a basic input example. Really messy right now. --- examples/input.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 examples/input.rb diff --git a/examples/input.rb b/examples/input.rb new file mode 100644 index 0000000..6ba0731 --- /dev/null +++ b/examples/input.rb @@ -0,0 +1,24 @@ +($:.unshift File.expand_path(File.join( File.dirname(__FILE__), '..', 'lib' ))).uniq! +require 'nfoiled' + +## +# This example shows you how to utilize an Nfoiled `Window` to accept input. + +# Creating our first `Window` should take care of initializing the Nfoiled +# system for us. However, the `Ncurses.LINES` and `Ncurses.COLS` methods won't +# be defined until the system is initialized, so we have to prime it. +Nfoiled::initialize +output = Nfoiled::Window.new :height => ::Ncurses.LINES - 1 +input = Nfoiled::Window.new :top => ::Ncurses.LINES - 1, :height => 1 + +output.puts "Type characters to have them printed! (^C to exit)" +input.focus! +Nfoiled::update! + +# Now we'll print each key to the output as it is typed into the input. +input.on_key do |key| + output.print key.char.to_s + " " + Nfoiled::update! +end + +Nfoiled::read! -- 2.11.4.GIT