summaryrefslogtreecommitdiff
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
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
-rw-r--r--ChangeLog7
-rw-r--r--ext/curses/curses.c6
-rw-r--r--ext/curses/hello.rb30
-rw-r--r--ext/curses/mouse.rb53
-rw-r--r--ext/curses/rain.rb76
-rw-r--r--sample/curses/hello.rb27
-rw-r--r--sample/curses/mouse.rb52
-rw-r--r--sample/curses/rain.rb74
-rw-r--r--sample/curses/view.rb (renamed from ext/curses/view.rb)0
-rw-r--r--sample/curses/view2.rb (renamed from ext/curses/view2.rb)0
10 files changed, 163 insertions, 162 deletions
diff --git a/ChangeLog b/ChangeLog
index 89bfa0a..43b9f77 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Mon Jul 29 22:25:20 2013 Zachary Scott <e@zzak.io>
+
+ * 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
+
Mon Jul 29 22:16:11 2013 Tanaka Akira <akr@fsij.org>
* bignum.c (LOG2_KARATSUBA_BIG2STR_DIGITS): Renamed from
diff --git a/ext/curses/curses.c b/ext/curses/curses.c
index 49704cb..b8c8238 100644
--- a/ext/curses/curses.c
+++ b/ext/curses/curses.c
@@ -2643,11 +2643,11 @@ pad_noutrefresh(VALUE obj, VALUE pminrow, VALUE pmincol, VALUE sminrow,
* == Examples
*
* * hello.rb
- * :include: hello.rb
+ * :include: sample/curses/hello.rb
*
*
* * rain.rb
- * :include: rain.rb
+ * :include: sample/curses/rain.rb
*
*
*/
@@ -2680,7 +2680,7 @@ Init_curses(void)
* == Example
*
* * mouse.rb
- * :include: mouse.rb
+ * :include: sample/curses/mouse.rb
*
*/
cMouseEvent = rb_define_class_under(mCurses,"MouseEvent",rb_cObject);
diff --git a/ext/curses/hello.rb b/ext/curses/hello.rb
deleted file mode 100644
index f176583..0000000
--- a/ext/curses/hello.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/usr/local/bin/ruby
-
-require "curses"
-include Curses
-
-def show_message(message)
- width = message.length + 6
- win = Window.new(5, width,
- (lines - 5) / 2, (cols - width) / 2)
- win.box('|', '-')
- win.setpos(2, 3)
- win.addstr(message)
- win.refresh
- win.getch
- win.close
-end
-
-init_screen
-begin
- crmode
-# show_message("Hit any key")
- setpos((lines - 5) / 2, (cols - 10) / 2)
- addstr("Hit any key")
- refresh
- getch
- show_message("Hello, World!")
- refresh
-ensure
- close_screen
-end
diff --git a/ext/curses/mouse.rb b/ext/curses/mouse.rb
deleted file mode 100644
index c42bc31..0000000
--- a/ext/curses/mouse.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-#!/usr/local/bin/ruby
-
-require "curses"
-include Curses
-
-def show_message(*msgs)
- message = msgs.join
- width = message.length + 6
- win = Window.new(5, width,
- (lines - 5) / 2, (cols - width) / 2)
- win.keypad = true
- win.attron(color_pair(COLOR_RED)){
- win.box(?|, ?-, ?+)
- }
- win.setpos(2, 3)
- win.addstr(message)
- win.refresh
- win.getch
- win.close
-end
-
-init_screen
-start_color
-init_pair(COLOR_BLUE,COLOR_BLUE,COLOR_WHITE)
-init_pair(COLOR_RED,COLOR_RED,COLOR_WHITE)
-crmode
-noecho
-stdscr.keypad(true)
-
-begin
- mousemask(BUTTON1_CLICKED|BUTTON2_CLICKED|BUTTON3_CLICKED|BUTTON4_CLICKED)
- setpos((lines - 5) / 2, (cols - 10) / 2)
- attron(color_pair(COLOR_BLUE)|A_BOLD){
- addstr("click")
- }
- refresh
- while( true )
- c = getch
- case c
- when KEY_MOUSE
- m = getmouse
- if( m )
- show_message("getch = #{c.inspect}, ",
- "mouse event = #{'0x%x' % m.bstate}, ",
- "axis = (#{m.x},#{m.y},#{m.z})")
- end
- break
- end
- end
- refresh
-ensure
- close_screen
-end
diff --git a/ext/curses/rain.rb b/ext/curses/rain.rb
deleted file mode 100644
index a6019b2..0000000
--- a/ext/curses/rain.rb
+++ /dev/null
@@ -1,76 +0,0 @@
-#!/usr/local/bin/ruby
-# rain for a curses test
-
-require "curses"
-include Curses
-
-def onsig(sig)
- close_screen
- exit sig
-end
-
-def ranf
- rand(32767).to_f / 32767
-end
-
-# main #
-for i in %w[HUP INT QUIT TERM]
- if trap(i, "SIG_IGN") != 0 then # 0 for SIG_IGN
- trap(i) {|sig| onsig(sig) }
- end
-end
-
-init_screen
-nl
-noecho
-srand
-
-xpos = {}
-ypos = {}
-r = lines - 4
-c = cols - 4
-for i in 0 .. 4
- xpos[i] = (c * ranf).to_i + 2
- ypos[i] = (r * ranf).to_i + 2
-end
-
-i = 0
-while TRUE
- x = (c * ranf).to_i + 2
- y = (r * ranf).to_i + 2
-
-
- setpos(y, x); addstr(".")
-
- setpos(ypos[i], xpos[i]); addstr("o")
-
- i = if i == 0 then 4 else i - 1 end
- setpos(ypos[i], xpos[i]); addstr("O")
-
- i = if i == 0 then 4 else i - 1 end
- setpos(ypos[i] - 1, xpos[i]); addstr("-")
- setpos(ypos[i], xpos[i] - 1); addstr("|.|")
- setpos(ypos[i] + 1, xpos[i]); addstr("-")
-
- i = if i == 0 then 4 else i - 1 end
- setpos(ypos[i] - 2, xpos[i]); addstr("-")
- setpos(ypos[i] - 1, xpos[i] - 1); addstr("/ \\")
- setpos(ypos[i], xpos[i] - 2); addstr("| O |")
- setpos(ypos[i] + 1, xpos[i] - 1); addstr("\\ /")
- setpos(ypos[i] + 2, xpos[i]); addstr("-")
-
- i = if i == 0 then 4 else i - 1 end
- setpos(ypos[i] - 2, xpos[i]); addstr(" ")
- setpos(ypos[i] - 1, xpos[i] - 1); addstr(" ")
- setpos(ypos[i], xpos[i] - 2); addstr(" ")
- setpos(ypos[i] + 1, xpos[i] - 1); addstr(" ")
- setpos(ypos[i] + 2, xpos[i]); addstr(" ")
-
-
- xpos[i] = x
- ypos[i] = y
- refresh
- sleep(0.5)
-end
-
-# end of main
diff --git a/sample/curses/hello.rb b/sample/curses/hello.rb
new file mode 100644
index 0000000..a630fb9
--- /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
diff --git a/sample/curses/mouse.rb b/sample/curses/mouse.rb
new file mode 100644
index 0000000..cc4beeb
--- /dev/null
+++ b/sample/curses/mouse.rb
@@ -0,0 +1,52 @@
+require "curses"
+
+def show_message(*msgs)
+ message = msgs.join
+ width = message.length + 6
+ win = Curses::Window.new(5, width,
+ (Curses.lines - 5) / 2, (Curses.cols - width) / 2)
+ win.keypad = true
+ win.attron(Curses.color_pair(Curses::COLOR_RED)){
+ win.box(?|, ?-, ?+)
+ }
+ win.setpos(2, 3)
+ win.addstr(message)
+ win.refresh
+ win.getch
+ win.close
+end
+
+Curses.init_screen
+Curses.start_color
+Curses.init_pair(Curses::COLOR_BLUE, Curses::COLOR_BLUE, Curses::COLOR_WHITE)
+Curses.init_pair(Curses::COLOR_RED, Curses::COLOR_RED, Curses::COLOR_WHITE)
+Curses.crmode
+Curses.noecho
+Curses.stdscr.keypad(true)
+
+begin
+ Curses.mousemask(
+ Curses::BUTTON1_CLICKED|Curses::BUTTON2_CLICKED|Curses::BUTTON3_CLICKED|Curses::BUTTON4_CLICKED
+ )
+ Curses.setpos((Curses.lines - 5) / 2, (Curses.cols - 10) / 2)
+ Curses.attron(Curses.color_pair(Curses::COLOR_BLUE)|Curses::A_BOLD){
+ Curses.addstr("click")
+ }
+ Curses.refresh
+ while( true )
+ c = Curses.getch
+ case c
+ when Curses::KEY_MOUSE
+ m = Curses::getmouse
+ if( m )
+ show_message("getch = #{c.inspect}, ",
+ "mouse event = #{'0x%x' % m.bstate}, ",
+ "axis = (#{m.x},#{m.y},#{m.z})")
+ end
+ break
+ end
+ end
+ Curses.refresh
+ensure
+ Curses.close_screen
+end
diff --git a/sample/curses/rain.rb b/sample/curses/rain.rb
new file mode 100644
index 0000000..845da2f
--- /dev/null
+++ b/sample/curses/rain.rb
@@ -0,0 +1,74 @@
+# rain for a curses test
+
+require "curses"
+
+def onsig(sig)
+ Curses.close_screen
+ exit sig
+end
+
+def ranf
+ rand(32767).to_f / 32767
+end
+
+# main #
+for i in %w[HUP INT QUIT TERM]
+ if trap(i, "SIG_IGN") != 0 then # 0 for SIG_IGN
+ trap(i) {|sig| onsig(sig) }
+ end
+end
+
+Curses.init_screen
+Curses.nl
+Curses.noecho
+srand
+
+xpos = {}
+ypos = {}
+r = Curses.lines - 4
+c = Curses.cols - 4
+for i in 0 .. 4
+ xpos[i] = (c * ranf).to_i + 2
+ ypos[i] = (r * ranf).to_i + 2
+end
+
+i = 0
+while TRUE
+ x = (c * ranf).to_i + 2
+ y = (r * ranf).to_i + 2
+
+
+ Curses.setpos(y, x); Curses.addstr(".")
+
+ Curses.setpos(ypos[i], xpos[i]); Curses.addstr("o")
+
+ i = if i == 0 then 4 else i - 1 end
+ Curses.setpos(ypos[i], xpos[i]); Curses.addstr("O")
+
+ i = if i == 0 then 4 else i - 1 end
+ Curses.setpos(ypos[i] - 1, xpos[i]); Curses.addstr("-")
+ Curses.setpos(ypos[i], xpos[i] - 1); Curses.addstr("|.|")
+ Curses.setpos(ypos[i] + 1, xpos[i]); Curses.addstr("-")
+
+ i = if i == 0 then 4 else i - 1 end
+ Curses.setpos(ypos[i] - 2, xpos[i]); Curses.addstr("-")
+ Curses.setpos(ypos[i] - 1, xpos[i] - 1); Curses.addstr("/ \\")
+ Curses.setpos(ypos[i], xpos[i] - 2); Curses.addstr("| O |")
+ Curses.setpos(ypos[i] + 1, xpos[i] - 1); Curses.addstr("\\ /")
+ Curses.setpos(ypos[i] + 2, xpos[i]); Curses.addstr("-")
+
+ i = if i == 0 then 4 else i - 1 end
+ Curses.setpos(ypos[i] - 2, xpos[i]); Curses.addstr(" ")
+ Curses.setpos(ypos[i] - 1, xpos[i] - 1); Curses.addstr(" ")
+ Curses.setpos(ypos[i], xpos[i] - 2); Curses.addstr(" ")
+ Curses.setpos(ypos[i] + 1, xpos[i] - 1); Curses.addstr(" ")
+ Curses.setpos(ypos[i] + 2, xpos[i]); Curses.addstr(" ")
+
+
+ xpos[i] = x
+ ypos[i] = y
+ Curses.refresh
+ sleep(0.5)
+end
+
+# end of main
diff --git a/ext/curses/view.rb b/sample/curses/view.rb
index bc54aeb..bc54aeb 100644
--- a/ext/curses/view.rb
+++ b/sample/curses/view.rb
diff --git a/ext/curses/view2.rb b/sample/curses/view2.rb
index 037771a..037771a 100644
--- a/ext/curses/view2.rb
+++ b/sample/curses/view2.rb