ruby-changes:32010
From: shugo <ko1@a...>
Date: Mon, 9 Dec 2013 13:39:58 +0900 (JST)
Subject: [ruby-changes:32010] shugo:r44089 (trunk): * ext/curses, sample/curses: removed curses.
shugo 2013-12-09 13:39:49 +0900 (Mon, 09 Dec 2013) New Revision: 44089 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44089 Log: * ext/curses, sample/curses: removed curses. * NEWS: added an entry for the above change. Removed files: trunk/ext/curses/curses.c trunk/ext/curses/depend trunk/ext/curses/extconf.rb trunk/sample/curses/hello.rb trunk/sample/curses/mouse.rb trunk/sample/curses/rain.rb trunk/sample/curses/view.rb trunk/sample/curses/view2.rb Modified files: trunk/ChangeLog trunk/NEWS trunk/ext/Setup trunk/ext/Setup.atheos trunk/ext/Setup.emx trunk/ext/Setup.nacl trunk/ext/Setup.nt Index: ChangeLog =================================================================== --- ChangeLog (revision 44088) +++ ChangeLog (revision 44089) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Dec 9 13:36:55 2013 Shugo Maeda <shugo@r...> + + * ext/curses, sample/curses: removed curses. + + * NEWS: added an entry for the above change. + Mon Dec 9 12:26:05 2013 Nobuyoshi Nakada <nobu@r...> * ext/objspace/object_tracing.c (newobj_i): use cached class path Index: sample/curses/hello.rb =================================================================== --- sample/curses/hello.rb (revision 44088) +++ sample/curses/hello.rb (revision 44089) @@ -1,27 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/sample/curses/hello.rb#L0 -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 Index: sample/curses/mouse.rb =================================================================== --- sample/curses/mouse.rb (revision 44088) +++ sample/curses/mouse.rb (revision 44089) @@ -1,52 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/sample/curses/mouse.rb#L0 -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 Index: sample/curses/rain.rb =================================================================== --- sample/curses/rain.rb (revision 44088) +++ sample/curses/rain.rb (revision 44089) @@ -1,74 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/sample/curses/rain.rb#L0 -# 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 Index: sample/curses/view.rb =================================================================== --- sample/curses/view.rb (revision 44088) +++ sample/curses/view.rb (revision 44089) @@ -1,91 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/sample/curses/view.rb#L0 -#!/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 Index: sample/curses/view2.rb =================================================================== --- sample/curses/view2.rb (revision 44088) +++ sample/curses/view2.rb (revision 44089) @@ -1,149 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/sample/curses/view2.rb#L0 -#!/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..@s...].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 Index: ext/Setup.nt =================================================================== --- ext/Setup.nt (revision 44088) +++ ext/Setup.nt (revision 44089) @@ -3,7 +3,6 @@ https://github.com/ruby/ruby/blob/trunk/ext/Setup.nt#L3 Win32API bigdecimal -#curses #dbm digest digest/md5 Index: ext/Setup =================================================================== --- ext/Setup (revision 44088) +++ ext/Setup (revision 44089) @@ -2,7 +2,6 @@ https://github.com/ruby/ruby/blob/trunk/ext/Setup#L2 #Win32API #bigdecimal -#curses #dbm #digest #digest/md5 Index: ext/curses/depend =================================================================== --- ext/curses/depend (revision 44088) +++ ext/curses/depend (revision 44089) @@ -1,5 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/ext/curses/depend#L0 -$(OBJS): $(HDRS) $(ruby_headers) \ - $(hdrdir)/ruby/io.h \ - $(hdrdir)/ruby/encoding.h \ - $(hdrdir)/ruby/oniguruma.h \ - $(hdrdir)/ruby/thread.h Index: ext/curses/curses.c =================================================================== --- ext/curses/curses.c (revision 44088) +++ ext/curses/curses.c (revision 44089) @@ -1,4348 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/ext/curses/curses.c#L0 -/* -*- C -*- - * $Id$ - * - * ext/curses/curses.c - * - * by MAEDA Shugo (ender@p...) - * modified by Yukihiro Matsumoto (matz@n...), - * Toki Yoshinori, - * Hitoshi Takahashi, - * and Takaaki Tateishi (ttate@k...) - * - * maintainers: - * - Takaaki Tateishi (ttate@k...) - * - * documentation: - * - Vincent Batts (vbatts@h...) - */ - -#include "ruby.h" -#include "ruby/io.h" -#include "ruby/thread.h" - -#if defined(HAVE_NCURSES_H) -# include <ncurses.h> -#elif defined(HAVE_NCURSES_CURSES_H) -# include <ncurses/curses.h> -#elif defined(HAVE_CURSES_COLR_CURSES_H) -# ifdef HAVE_STDARG_PROTOTYPES -# include <stdarg.h> -# else -# include <varargs.h> -# endif -# include <curses_colr/curses.h> -#else -# include <curses.h> -# if defined(__bsdi__) || defined(__NetBSD__) || defined(__APPLE__) -# if !defined(_maxx) -# define _maxx maxx -# endif -# if !defined(_maxy) -# define _maxy maxy -# endif -# if !defined(_begx) -# define _begx begx -# endif -# if !defined(_begy) -# define _begy begy -# endif -# endif -#endif - -#ifdef HAVE_INIT_COLOR -# define USE_COLOR 1 -#endif - -/* supports only ncurses mouse routines */ -#ifdef NCURSES_MOUSE_VERSION -# define USE_MOUSE 1 -#endif - -#if CHTYPE_IS_ULONG -# define NUM2CH NUM2ULONG -# define CH2NUM ULONG2NUM -#else -# if CHTYPE_IS_UINT -# define NUM2CH NUM2UINT -# define CH2NUM UINT2NUM -# else -# define NUM2CH NUM2CHR -# define CH2NUM CHR2FIX -# endif -#endif - -static VALUE mCurses; -static VALUE mKey; -static VALUE cWindow; -static VALUE cPad; -#ifdef USE_MOUSE -static VALUE cMouseEvent; -#endif - -static VALUE rb_stdscr; - -struct windata { - WINDOW *window; -}; - -static VALUE window_attroff(VALUE obj, VALUE attrs); -static VALUE window_attron(VALUE obj, VALUE attrs); -static VALUE window_attrset(VALUE obj, VALUE attrs); - -static void -no_window(void) -{ - rb_raise(rb_eRuntimeError, "already closed window"); -} - -#define GetWINDOW(obj, winp) do {\ - if (!OBJ_TAINTED(obj) && rb_safe_level() >= 4)\ - rb_raise(rb_eSecurityError, "Insecure: operation on untainted window");\ - TypedData_Get_Struct((obj), struct windata, &windata_type, (winp));\ - if ((winp)->window == 0) no_window();\ -} while (0) - -static void -window_free(void *p) -{ - struct windata *winp = p; - if (winp->window && winp->window != stdscr) delwin(winp->window); - winp->window = 0; - xfree(winp); -} - -static size_t -window_memsize(const void *p) -{ - const struct windata *winp = p; - size_t size = sizeof(*winp); - if (!winp) return 0; - if (winp->window && winp->window != stdscr) size += sizeof(winp->window); - return size; -} - -static const rb_data_type_t windata_type = { - "windata", - {0, window_free, window_memsize,} -}; - -static VALUE -prep_window(VALUE class, WINDOW *window) -{ - VALUE obj; - struct windata *winp; - - if (window == NULL) { - rb_raise(rb_eRuntimeError, "failed to create window"); - } - - obj = rb_obj_alloc(class); - TypedData_Get_Struct(obj, struct windata, &windata_type, winp); - winp->window = window; - - return obj; -} - -/*-------------------------- module Curses --------------------------*/ - -/* - * Document-method: Curses.init_screen - * - * Initialize a standard screen - * - * see also Curses.stdscr - */ -static VALUE -curses_init_screen(void) -{ - if (rb_stdscr) return rb_stdscr; - initscr(); - if (stdscr == 0) { - rb_raise(rb_eRuntimeError, "can't initialize curses"); - } - clear(); - rb_stdscr = prep_window(cWindow, stdscr); - return rb_stdscr; -} - -/* - * Document-method: Curses.stdscr - * - * The Standard Screen. - * - * Upon initializing curses, a default window called stdscr, - * which is the size of the terminal screen, is created. - * - * Many curses functions use this window. - */ -#define curses_stdscr curses_init_screen - -/* - * Document-method: Curses.close_screen - * - * A program should always call Curses.close_screen before exiting or - * escaping from curses mode temporarily. This routine - * restores tty modes, moves the cursor to the lower - * left-hand corner of the screen and resets the terminal - * into the proper non-visual mode. - * - * Calling Curses.refresh or Curses.doupdate after a temporary - * escape causes the program to resume visual mode. - * - */ -static VALUE -curses_close_screen(void) -{ - curses_stdscr(); -#ifdef HAVE_ISENDWIN - if (!isendwin()) -#endif - endwin(); - rb_stdscr = 0; - return Qnil; -} - -/* - * This is no runtime method, - * but a function called before the proc ends - * - * Similar to Curses.close_screen, except that it also - * garbage collects/unregisters the Curses.stdscr - */ -static void -curses_finalize(VALUE dummy) -{ - if (stdscr -#ifdef HAVE_ISENDWIN - && !isendwin() -#endif - ) - endwin(); - rb_stdscr = 0; - rb_gc_unregister_address(&rb_stdscr); -} - -#ifdef HAVE_ISENDWIN -/* - * Document-method: Curses.closed? - * - * Returns +true+ if the window/screen has been closed, - * without any subsequent Curses.refresh calls, - * returns +false+ otherwise. - */ -static VALUE -curses_closed(void) -{ - curses_stdscr(); - if (isendwin()) { - return Qtrue; - } - return Qfalse; -} -#else -#define curses_closed rb_f_notimplement -#endif - -/* - * Document-method: Curses.clear - * - * Clears every position on the screen completely, - * so that a subsequent call by Curses.refresh for the screen/window - * will be repainted from scratch. - */ -static VALUE -curses_clear(VALUE obj) -{ - curses_stdscr(); - wclear(stdscr); - return Qnil; -} - -/* - * Document-method: Curses.clrtoeol - * - * Clears to the end of line, that the cursor is currently on. - */ -static VALUE -curses_clrtoeol(void) -{ - curses_stdscr(); - clrtoeol(); - return Qnil; -} - -/* - * Document-method: Curses.refresh - * - * Refreshes the windows and lines. - * - */ -static VALUE -curses_refresh(VALUE obj) -{ - curses_stdscr(); - refresh(); - return Qnil; -} - -/* - * Document-method: Curses.doupdate - * - * Refreshes the windows and lines. - * - * Curses.doupdate allows multiple updates with - * more efficiency than Curses.refresh alone. - */ -static VALUE -curses_doupdate(VALUE obj) -{ - curses_stdscr(); -#ifdef HAVE_DOUPDATE - doupdate(); -#else - refresh(); -#endif - return Qnil; -} - -/* - * Document-method: Curses.echo - * - * Enables characters typed by the user - * to be echoed by Curses.getch as they are typed. - */ -static VALUE -curses_echo(VALUE obj) -{ - curses_stdscr(); - echo(); - return Qnil; -} - -/* - * Document-method: Curses.noecho - * - * Disables characters typed by the user - * to be echoed by Curses.getch as they are typed. - */ -static VALUE -curses_noecho(VALUE obj) -{ - curses_stdscr(); - noecho(); - return Qnil; -} - -/* - * Document-method: Curses.raw - * - * Put the terminal into raw mode. - * - * Raw mode is similar to Curses.cbreak mode, in that characters typed - * are immediately passed through to the user program. - * - * The differences are that in raw mode, the interrupt, quit, - * suspend, and flow control characters are all passed through - * uninterpreted, instead of generating a signal. The behavior - * of the BREAK key depends on other bits in the tty driver - * that are not set by curses. - */ -static VALUE -curses_raw(VALUE obj) -{ - curses_stdscr(); - raw(); - return Qnil; -} - -/* - * Document-method: Curses.noraw - * - * Put the terminal out of raw mode. - * - * see Curses.raw for more detail - */ -static VALUE -curses_noraw(VALUE obj) -{ - curses_stdscr(); - noraw(); - return Qnil; -} - -/* - * Document-method: Curses.cbreak - * - * Put the terminal into cbreak mode. - * - * Normally, the tty driver buffers typed characters until - * a newline or carriage return is typed. The Curses.cbreak - * routine disables line buffering and erase/kill - * character-processing (interrupt and flow control characters - * are unaffected), making characters typed by the user - * immediately available to the program. - * - * The Curses.nocbreak routine returns the terminal to normal (cooked) mode. - * - * Initially the terminal may or may not be in cbreak mode, - * as the mode is inherited; therefore, a program should - * call Curses.cbreak or Curses.nocbreak explicitly. - * Most interactive programs using curses set the cbreak mode. - * Note that Curses.cbreak overrides Curses.raw. - * - * see also Curses.raw - */ -static VALUE -curses_cbreak(VALUE obj) -{ - curses_stdscr(); - cbreak(); - return Qnil; -} (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/