summaryrefslogtreecommitdiff
path: root/sample/curses/hello.rb
diff options
context:
space:
mode:
authorzzak <zzak@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-29 13:25:46 +0000
committerzzak <zzak@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-29 13:25:46 +0000
commitffb9da9fa00e8b18ddf474a367dcfc6720dc018e (patch)
tree9ed708cc74d945652e5f308e981e08b38b6719e6 /sample/curses/hello.rb
parent16bf45bf38d5b7ce3024c3af324921da1e6ef07d (diff)
* ext/curses/curses.c: [DOC] Update location of samples
* samples/curses/*: Move Curses samples and refactor from mixin The samples are included in rdoc for module and use of mixin is confusing git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42241 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sample/curses/hello.rb')
-rw-r--r--sample/curses/hello.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/sample/curses/hello.rb b/sample/curses/hello.rb
new file mode 100644
index 00000000000..a630fb999b8
--- /dev/null
+++ b/sample/curses/hello.rb
@@ -0,0 +1,27 @@
+require "curses"
+
+def show_message(message)
+ width = message.length + 6
+ win = Curses::Window.new(5, width,
+ (Curses.lines - 5) / 2, (Curses.cols - width) / 2)
+ win.box('|', '-')
+ win.setpos(2, 3)
+ win.addstr(message)
+ win.refresh
+ win.getch
+ win.close
+end
+
+Curses.init_screen
+begin
+ Curses.crmode
+# show_message("Hit any key")
+ Curses.setpos((Curses.lines - 5) / 2, (Curses.cols - 10) / 2)
+ Curses.addstr("Hit any key")
+ Curses.refresh
+ char = Curses.getch
+ show_message("You typed: #{char}")
+ Curses.refresh
+ensure
+ Curses.close_screen
+end