mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/curses, sample/curses: removed curses.
* NEWS: added an entry for the above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44089 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d3363a96df
commit
9c5b2fd8aa
15 changed files with 11 additions and 4892 deletions
|
@ -1,3 +1,9 @@
|
|||
Mon Dec 9 13:36:55 2013 Shugo Maeda <shugo@ruby-lang.org>
|
||||
|
||||
* ext/curses, sample/curses: removed curses.
|
||||
|
||||
* NEWS: added an entry for the above change.
|
||||
|
||||
Mon Dec 9 12:26:05 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* ext/objspace/object_tracing.c (newobj_i): use cached class path
|
||||
|
|
5
NEWS
5
NEWS
|
@ -327,6 +327,11 @@ String
|
|||
It gets encoding argument to convert before percent encode.
|
||||
UTF-16 strings aren't converted to UTF-8 before percent encode by default.
|
||||
|
||||
* curses
|
||||
* Removed.
|
||||
curses is now available as a gem.
|
||||
See https://rubygems.org/gems/curses for details.
|
||||
|
||||
=== Built-in global variables compatibility issues
|
||||
|
||||
* $SAFE
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#Win32API
|
||||
#bigdecimal
|
||||
#curses
|
||||
#dbm
|
||||
#digest
|
||||
#digest/md5
|
||||
|
|
|
@ -2,7 +2,6 @@ option nodynamic
|
|||
|
||||
#Win32API
|
||||
bigdecimal
|
||||
curses
|
||||
dbm
|
||||
digest
|
||||
digest/md5
|
||||
|
|
|
@ -4,7 +4,6 @@ option nodynamic
|
|||
|
||||
#Win32API
|
||||
bigdecimal
|
||||
curses
|
||||
#dbm
|
||||
digest
|
||||
digest/md5
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
# bigdecimal
|
||||
# continuation
|
||||
# coverage
|
||||
# #curses
|
||||
# date
|
||||
# #dbm
|
||||
# digest/bubblebabble
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
Win32API
|
||||
bigdecimal
|
||||
#curses
|
||||
#dbm
|
||||
digest
|
||||
digest/md5
|
||||
|
|
4348
ext/curses/curses.c
4348
ext/curses/curses.c
File diff suppressed because it is too large
Load diff
|
@ -1,5 +0,0 @@
|
|||
$(OBJS): $(HDRS) $(ruby_headers) \
|
||||
$(hdrdir)/ruby/io.h \
|
||||
$(hdrdir)/ruby/encoding.h \
|
||||
$(hdrdir)/ruby/oniguruma.h \
|
||||
$(hdrdir)/ruby/thread.h
|
|
@ -1,141 +0,0 @@
|
|||
require 'mkmf'
|
||||
|
||||
def have_all(*args) # :nodoc:
|
||||
old_libs = $libs.dup
|
||||
old_defs = $defs.dup
|
||||
result = []
|
||||
begin
|
||||
args.each {|arg|
|
||||
r = arg.call(*result)
|
||||
if !r
|
||||
return nil
|
||||
end
|
||||
result << r
|
||||
}
|
||||
result
|
||||
ensure
|
||||
if result.length != args.length
|
||||
$libs = old_libs
|
||||
$defs = old_defs
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
dir_config('curses')
|
||||
dir_config('ncurses')
|
||||
dir_config('termcap')
|
||||
|
||||
have_library("mytinfo", "tgetent") if /bow/ =~ RUBY_PLATFORM
|
||||
have_library("tinfo", "tgetent") or have_library("termcap", "tgetent")
|
||||
|
||||
header_library = nil
|
||||
[
|
||||
["ncurses.h", ["ncursesw", "ncurses"]],
|
||||
["ncurses/curses.h", ["ncurses"]],
|
||||
["curses_colr/curses.h", ["cur_colr"]],
|
||||
["curses.h", ["curses", "pdcurses"]],
|
||||
# ["xcurses.h", ["XCurses"]], # XCurses (PDCurses for X11)
|
||||
].each {|hdr, libs|
|
||||
header_library = have_all(
|
||||
lambda { have_header(hdr) && hdr },
|
||||
lambda {|h| libs.find {|lib| have_library(lib, "initscr", h) } })
|
||||
if header_library
|
||||
break;
|
||||
end
|
||||
}
|
||||
|
||||
if header_library
|
||||
header, library = header_library
|
||||
puts "header: #{header}"
|
||||
puts "library: #{library}"
|
||||
|
||||
curses = [header]
|
||||
if header == 'curses_colr/curses.h'
|
||||
curses.unshift("varargs.h")
|
||||
end
|
||||
|
||||
for f in %w(beep bkgd bkgdset curs_set deleteln doupdate flash
|
||||
getbkgd getnstr init isendwin keyname keypad resizeterm
|
||||
scrl set setscrreg ungetch
|
||||
wattroff wattron wattrset wbkgd wbkgdset wdeleteln wgetnstr
|
||||
wresize wscrl wsetscrreg
|
||||
def_prog_mode reset_prog_mode timeout wtimeout nodelay
|
||||
init_color wcolor_set use_default_colors newpad)
|
||||
have_func(f) || (have_macro(f, curses) && $defs.push(format("-DHAVE_%s", f.upcase)))
|
||||
end
|
||||
flag = "-D_XOPEN_SOURCE_EXTENDED"
|
||||
if try_static_assert("sizeof(char*)>sizeof(int)",
|
||||
%w[stdio.h stdlib.h]+curses,
|
||||
flag)
|
||||
$defs << flag
|
||||
end
|
||||
have_var("ESCDELAY", curses)
|
||||
have_var("TABSIZE", curses)
|
||||
have_var("COLORS", curses)
|
||||
have_var("COLOR_PAIRS", curses)
|
||||
|
||||
# SVR4 curses has a (undocumented) variable char *curses_version.
|
||||
# ncurses and PDcurses has a function char *curses_version().
|
||||
# Note that the original BSD curses doesn't provide version information.
|
||||
#
|
||||
# configure option:
|
||||
# --with-curses-version=function for SVR4
|
||||
# --with-curses-version=variable for ncurses and PDcurses
|
||||
# (not given) automatically determined
|
||||
|
||||
case with_curses_version = with_config("curses-version")
|
||||
when "function"
|
||||
$defs << '-DHAVE_FUNC_CURSES_VERSION'
|
||||
when "variable"
|
||||
$defs << '-DHAVE_VAR_CURSES_VERSION'
|
||||
when nil
|
||||
func_test_program = cpp_include(curses) + <<-"End"
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
curses_version();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
End
|
||||
var_test_program = cpp_include(curses) + <<-"End"
|
||||
extern char *curses_version;
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i = 0;
|
||||
for (i = 0; i < 100; i++) {
|
||||
if (curses_version[i] == 0)
|
||||
return 0 < i ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
if (curses_version[i] & 0x80)
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
End
|
||||
try = method(CROSS_COMPILING ? :try_link : :try_run)
|
||||
function_p = checking_for(checking_message('function curses_version', curses)) { try[func_test_program] }
|
||||
variable_p = checking_for(checking_message('variable curses_version', curses)) { try[var_test_program] }
|
||||
if function_p and variable_p
|
||||
if [header, library].grep(/ncurses|pdcurses|xcurses/i)
|
||||
variable_p = false
|
||||
else
|
||||
warn "found curses_version but cannot determin whether it is a"
|
||||
warn "function or a variable, so assume a variable in old SVR4"
|
||||
warn "ncurses."
|
||||
function_p = false
|
||||
end
|
||||
end
|
||||
$defs << '-DHAVE_FUNC_CURSES_VERSION' if function_p
|
||||
$defs << '-DHAVE_VAR_CURSES_VERSION' if variable_p
|
||||
else
|
||||
warn "unexpeted value for --with-curses-version: #{with_curses_version}"
|
||||
end
|
||||
|
||||
for type in ["long", "int"]
|
||||
if try_static_assert("sizeof(chtype) == sizeof(unsigned #{type})",
|
||||
%w[stdio.h stdlib.h]+curses)
|
||||
$defs << "-DCHTYPE_IS_U#{type.upcase}"
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
create_makefile("curses")
|
||||
end
|
|
@ -1,27 +0,0 @@
|
|||
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
|
|
@ -1,52 +0,0 @@
|
|||
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
|
|
@ -1,74 +0,0 @@
|
|||
# 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
|
|
@ -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
|
|
@ -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
|
Loading…
Add table
Reference in a new issue