diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/curses/curses.c | 6 | ||||
-rw-r--r-- | ext/curses/hello.rb | 30 | ||||
-rw-r--r-- | ext/curses/mouse.rb | 53 | ||||
-rw-r--r-- | ext/curses/rain.rb | 76 | ||||
-rw-r--r-- | ext/curses/view.rb | 91 | ||||
-rw-r--r-- | ext/curses/view2.rb | 149 |
6 files changed, 3 insertions, 402 deletions
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/ext/curses/view.rb b/ext/curses/view.rb deleted file mode 100644 index bc54aeb9af..0000000000 --- a/ext/curses/view.rb +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/local/bin/ruby - -require "curses" -include Curses - -# -# main -# - -if ARGV.size != 1 then - printf("usage: view file\n"); - exit -end -begin - fp = open(ARGV[0], "r") -rescue - raise "cannot open file: #{ARGV[1]}" -end - -# signal(SIGINT, finish) - -init_screen -#keypad(stdscr, TRUE) -nonl -cbreak -noecho -#scrollok(stdscr, TRUE) - -# slurp the file -data_lines = [] -fp.each_line { |l| - data_lines.push(l) -} -fp.close - - -lptr = 0 -while TRUE - i = 0 - while i < lines - setpos(i, 0) - #clrtoeol - addstr(data_lines[lptr + i] || '') - i += 1 - end - refresh - - explicit = FALSE - n = 0 - while TRUE - c = getch - if c =~ /[0-9]/ - n = 10 * n + c.to_i - else - break - end - end - - n = 1 if !explicit && n == 0 - - case c - when "n" #when KEY_DOWN - i = 0 - while i < n - if lptr + lines < data_lines.size then - lptr += 1 - else - break - end - i += 1 - end - #wscrl(i) - - when "p" #when KEY_UP - i = 0 - while i < n - if lptr > 0 then - lptr -= 1 - else - break - end - i += 1 - end - #wscrl(-i) - - when "q" - break - end - -end -close_screen diff --git a/ext/curses/view2.rb b/ext/curses/view2.rb deleted file mode 100644 index 037771a226..0000000000 --- a/ext/curses/view2.rb +++ /dev/null @@ -1,149 +0,0 @@ -#!/usr/local/bin/ruby - -require "curses" - - -# A curses based file viewer -class FileViewer - - # Create a new fileviewer, and view the file. - def initialize(filename) - @data_lines = [] - @screen = nil - @top = nil - init_curses - load_file(filename) - interact - end - - # Perform the curses setup - def init_curses - # signal(SIGINT, finish) - - Curses.init_screen - Curses.nonl - Curses.cbreak - Curses.noecho - - @screen = Curses.stdscr - - @screen.scrollok(true) - #$screen.keypad(true) - end - - # Load the file into memory, and put - # the first part on the curses display. - def load_file(filename) - fp = open(filename, "r") do |fp| - # slurp the file - fp.each_line { |l| - @data_lines.push(l.chop) - } - end - @top = 0 - @data_lines[0..@screen.maxy-1].each_with_index{|line, idx| - @screen.setpos(idx, 0) - @screen.addstr(line) - } - @screen.setpos(0,0) - @screen.refresh - rescue - raise "cannot open file '#{filename}' for reading" - end - - - # Scroll the display up by one line - def scroll_up - if( @top > 0 ) - @screen.scrl(-1) - @top -= 1 - str = @data_lines[@top] - if( str ) - @screen.setpos(0, 0) - @screen.addstr(str) - end - return true - else - return false - end - end - - # Scroll the display down by one line - def scroll_down - if( @top + @screen.maxy < @data_lines.length ) - @screen.scrl(1) - @top += 1 - str = @data_lines[@top + @screen.maxy - 1] - if( str ) - @screen.setpos(@screen.maxy - 1, 0) - @screen.addstr(str) - end - return true - else - return false - end - end - - # Allow the user to interact with the display. - # This uses EMACS-like keybindings, and also - # vi-like keybindings as well, except that left - # and right move to the beginning and end of the - # file, respectively. - def interact - while true - result = true - c = Curses.getch - case c - when Curses::KEY_DOWN, Curses::KEY_CTRL_N, ?j - result = scroll_down - when Curses::KEY_UP, Curses::KEY_CTRL_P, ?k - result = scroll_up - when Curses::KEY_NPAGE, ?\s # white space - for i in 0..(@screen.maxy - 2) - if( ! scroll_down ) - if( i == 0 ) - result = false - end - break - end - end - when Curses::KEY_PPAGE - for i in 0..(@screen.maxy - 2) - if( ! scroll_up ) - if( i == 0 ) - result = false - end - break - end - end - when Curses::KEY_LEFT, Curses::KEY_CTRL_T, ?h - while( scroll_up ) - end - when Curses::KEY_RIGHT, Curses::KEY_CTRL_B, ?l - while( scroll_down ) - end - when ?q - break - else - @screen.setpos(0,0) - @screen.addstr("[unknown key `#{Curses.keyname(c)}'=#{c}] ") - end - if( !result ) - Curses.beep - end - @screen.setpos(0,0) - end - Curses.close_screen - end -end - - -# If we are being run as a main program... -if __FILE__ == $0 - if ARGV.size != 1 then - printf("usage: #{$0} file\n"); - exit - end - - viewer = FileViewer.new(ARGV[0]) -end |