From: shugo@... (MAEDA Shugo) Date: 1997-10-03T03:25:05+09:00 Subject: [ruby-list:4759] Re: rbc.rb 前田です。 In message "[ruby-list:4741] rbc.rb" Keiju ISHITSUKA wrote: |2. いつかは, readline.rbを取り込みたいなと思っています. 手元に | readline.cがないので... readlineを使えるようにしてみました。 例外を表示する部分は、 $! = RuntimeError.new("exception raised") unless $! print $!.type ": ", $!, "\n" のように例外クラスが表示された方がうれしいような気がします。 それと$INSPECTはデフォルトでTRUEの方が使いやすいかなと。 # やっぱりこういうシェルがあるとちょっと試したい時に便利ですね。 -- 前田 修吾 --- rbc.rb.orig Fri Oct 3 02:49:47 1997 +++ rbc.rb Fri Oct 3 03:10:21 1997 @@ -18,6 +18,11 @@ #$DEBUG = TRUE +begin + require "readline" +rescue +end + class BC__ RCS_ID='-$Header: /home/keiju/var/src/var.lib/header/RCS/ruby-mode,v 1.1 1997/08/08 00:57:08 keiju Exp keiju $-' @@ -38,10 +43,25 @@ @indent = 0 @lex_state = EXPR_BEG - printf PROMPTi, @indent + if $".include? "readline.so" and io == $stdin + @readline_proc = Proc.new { + if str = Readline.readline(@prompt, TRUE) + str + "\n" + else + str + end + } + else + @readline_proc = Proc.new { + print @prompt + io.gets + } + end + + @prompt = format(PROMPTi, @indent) loop do @continue = FALSE - l = io.gets + l = @readline_proc.call print l if $ECHO unless l @@ -52,13 +72,13 @@ lex(l) if l != "\n" print @quoted.inspect, "\n" if $DEBUG if @ltype - printf PROMPTs, @indent, @ltype + @prompt = format(PROMPTs, @indent, @ltype) next elsif @continue - printf PROMPTe, @indent + @prompt = format(PROMPTe, @indent) next elsif @indent > 0 - printf PROMPTi, @indent + @prompt = format(PROMPTi, @indent) next end end @@ -76,7 +96,7 @@ break if not l line = '' indent = 0 - printf PROMPTi, indent + @prompt = format(PROMPTi, indent) end print "\n" end