From ffb9da9fa00e8b18ddf474a367dcfc6720dc018e Mon Sep 17 00:00:00 2001 From: zzak Date: Mon, 29 Jul 2013 13:25:46 +0000 Subject: [PATCH] * 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 --- ChangeLog | 7 +++ ext/curses/curses.c | 6 +-- ext/curses/hello.rb | 30 ------------- ext/curses/mouse.rb | 53 ----------------------- ext/curses/rain.rb | 76 --------------------------------- sample/curses/hello.rb | 27 ++++++++++++ sample/curses/mouse.rb | 52 ++++++++++++++++++++++ sample/curses/rain.rb | 74 ++++++++++++++++++++++++++++++++ {ext => sample}/curses/view.rb | 0 {ext => sample}/curses/view2.rb | 0 10 files changed, 163 insertions(+), 162 deletions(-) delete mode 100644 ext/curses/hello.rb delete mode 100644 ext/curses/mouse.rb delete mode 100644 ext/curses/rain.rb create mode 100644 sample/curses/hello.rb create mode 100644 sample/curses/mouse.rb create mode 100644 sample/curses/rain.rb rename {ext => sample}/curses/view.rb (100%) rename {ext => sample}/curses/view2.rb (100%) diff --git a/ChangeLog b/ChangeLog index 89bfa0a74b..43b9f7707d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Mon Jul 29 22:25:20 2013 Zachary Scott + + * 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 * bignum.c (LOG2_KARATSUBA_BIG2STR_DIGITS): Renamed from diff --git a/ext/curses/curses.c b/ext/curses/curses.c index 49704cbe4e..b8c82387ea 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 f176583a95..0000000000 --- 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 c42bc31f33..0000000000 --- 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 a6019b26e0..0000000000 --- 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 0000000000..a630fb999b --- /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 0000000000..cc4beeb83d --- /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 0000000000..845da2f522 --- /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 similarity index 100% rename from ext/curses/view.rb rename to sample/curses/view.rb diff --git a/ext/curses/view2.rb b/sample/curses/view2.rb similarity index 100% rename from ext/curses/view2.rb rename to sample/curses/view2.rb