[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[dennou-ruby:000395] Re: improved NumArray
���Ȥ���Ǥ�
�������ޥХ��Ȥ��鵢�ä���ޤ�����
In message "[dennou-ruby:000394] Re: improved NumArray"
on 00/09/07, Masato Shiotani <shiotani@xxxxxx> writes:
>�ޤ� readline �ȡ��뤷��, ruby �� make ��ľ�����餤���Ȥ�����
>�Ȥʤ�Ǥ��礦��, ����Ȥ� ruby �� readline �Υ饤�֥�꤬�Ĥ��Ƥ����
>��?
�����Ǥ���
ftp://ftp.eos.hokudai.ac.jp/pub/GNU/gnu.org/readline/readline-4.1.tar.gz
In message "[dennou-ruby:000393] Re: improved NumArray"
on 00/09/07, Takeshi Horinouchi <horinout@xxxxxx> writes:
>�Ȥ����ǡ������ history ���Ǥ�����Ȳ���10��ΰ������Ф�Ȥ���
>ɬ�פ˱������Ǥ��������Τ� log ���Ȥ줿�ꤷ�ʤ����ʤȻפ��Τ�
>����������ʵ�ǽ�Τ�ޤ��� �� ���Ȥ���
�Ƥߤ�����������ޤ��͡�Readline::completion_proc �ϥ���
��ɥ饤���䴰�Τ����Proc�ǡ���������ꤷ�Ƥ�����bash�Τ褦
�ʥ��ޥ�ɥ饤�Ȥ��ޤ���Readline::HISTORY �������ɤ���
������ɤ��ʤΤǡ�����ˤ���ˤ� to_a ��Ȥ�ɬ�פ�����ޤ���
Readline��¾�ε�ǽ��
http://www.math.sci.hokudai.ac.jp/~gotoken/ruby/r/readline.shtml
��USAGE�Ʋ�������INSTALLATION�ι��ܤ�readline��ɸ������
�Ǥʤ��ä������äʤΤ�̵�뤷�Ʋ������ޤ���
#!/usr/bin/env ruby
require "readline"
class Frontend
include Readline
Me = File.basename($0)
Prompt = "#{Me}> "
History = true
Command = {}
Readline::completion_proc =
lambda{|s| Command.keys.find_all{|elm| elm =~ s}}
def start
catch(:exit) {
while line = readline(Prompt, History)
next if /^\s*$/ =~ line
argv0, *argv = line.split
job = Command[argv0]
if job
job.call(argv)
else
puts "#{Me}: #{argv0}: no such command"
end
end
print "\n"
}
end
def define_command(*name, &job)
name.each do |n|
Command[n] = job
end
end
def initialize
define_command("history") do |*max|
max = (max[0]||10).to_i
s = Readline::HISTORY.size
(s-1).downto([0, s-max].max){|i|
puts HISTORY[i]
}
end
define_command("exit", "quit", "bye") do
throw(:exit)
end
end
end
if __FILE__ == $0
f = Frontend.new
f.define_command("date") do puts Time.now end
f.start
end