开发者

Ruby handle up arrow for shell style interface

开发者 https://www.devze.com 2023-02-24 05:12 出处:网络
I am implementing a simple shell style interface开发者_高级运维 in ruby as follows: exit = false

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

精彩评论

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

关注公众号