开发者

Ruby handle up arrow for shell style interface

I am implementing a simple shell style interface开发者_高级运维 in ruby as follows:

exit = false
while(not exit)
        print '?> '
        case gets("\n").strip
        when "quit"
                exit = true
        when "xxx"
            #handle xxx command 
        end
end

If I press the up arrow, I get ^[[A. Is there anyway to implement this as would be done in a shell where it fills in the previous command?


You should use readline for this. Ruby has an implementation: http://bogojoker.com/readline/

Here is the ruby api for it http://www.ruby-doc.org/stdlib/libdoc/readline/rdoc/index.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜