# Need help for simulating up arrow key and down arrow key like in command prompt

**URL:** <https://rubytalk.org/t/need-help-for-simulating-up-arrow-key-and-down-arrow-key-like-in-command-prompt/73794>\
**Category:** ruby-talk\
**Created:** [2 September 2016 13:05 UTC](https://rubytalk.org/t/need-help-for-simulating-up-arrow-key-and-down-arrow-key-like-in-command-prompt/73794 "2016-09-02T13:05:02Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Devashish\_Bhardwaj](https://avatars.discourse-cdn.com/v4/letter/d/45deac/32.png) [@Devashish\_Bhardwaj](https://rubytalk.org/u/Devashish_Bhardwaj)\
**Post date:** [2 September 2016 13:05 UTC](https://rubytalk.org/t/need-help-for-simulating-up-arrow-key-and-down-arrow-key-like-in-command-prompt/73794/1 "2016-09-02T13:05:02Z")

</div>

I have created a command line app that takes commands as user input in a  
loop. I need to simulate up arrow key and down arrow key so that user can  
navigate through the commands just like it is done in command prompt and  
irb. I could not find a way catch up arrow key and down arrow key.

---

<div class="post-metadata">

**Author:** ![Xeno\_Campanoli1](https://avatars.discourse-cdn.com/v4/letter/x/85f322/32.png) [@Xeno\_Campanoli1](https://rubytalk.org/u/Xeno_Campanoli1)\
**Post date:** [2 September 2016 18:04 UTC](https://rubytalk.org/t/need-help-for-simulating-up-arrow-key-and-down-arrow-key-like-in-command-prompt/73794/2 "2016-09-02T18:04:14Z")

</div>

The original C based library for that kind of thing was called  
"Curses", if I understand the question right. You may find some gem  
or something with the string "curses" in it that will help. That is  
for Unix/Linux though, and there may be a cross platform thing. GTK  
is a windowing manager thingy that may have access for it for  
Ubuntu/Unix side.

I hope there is a cross platform thing. It would be cool. I've not  
found Ruby to work that well on Windows anyway, however.

xc

> **···**
>
> On Fri, Sep 2, 2016 at 10:48 AM, Rob Biedenharn \<rob.biedenharn@gmail.com\> wrote:
> 
> > On 2016-Sep-2, at 09:05 , Devashish Bhardwaj \<devashish.vhardwaj@gmail.com\> \> wrote:
> > 
> > I have created a command line app that takes commands as user input in a  
> > loop. I need to simulate up arrow key and down arrow key so that user can  
> > navigate through the commands just like it is done in command prompt and  
> > irb. I could not find a way catch up arrow key and down arrow key.
> > 
> > You should be able to use or at least learn from:  
> > [GitHub - ConnorAtherton/rb-readline: Pure-Ruby Readline Implementation](https://github.com/ConnorAtherton/rb-readline)
> > 
> > -Rob
> > 
> > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);

---

<div class="post-metadata">

**Author:** ![Rob\_Biedenharn](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/rob_biedenharn/32/1859_2.png) [@Rob\_Biedenharn](https://rubytalk.org/u/Rob_Biedenharn)\
**Post date:** [2 September 2016 17:48 UTC](https://rubytalk.org/t/need-help-for-simulating-up-arrow-key-and-down-arrow-key-like-in-command-prompt/73794/3 "2016-09-02T17:48:59Z")

</div>

You should be able to use or at least learn from: [GitHub - ConnorAtherton/rb-readline: Pure-Ruby Readline Implementation](https://github.com/ConnorAtherton/rb-readline)

-Rob

> **···**
>
> > On 2016-Sep-2, at 09:05 , Devashish Bhardwaj \<devashish.vhardwaj@gmail.com\> wrote:
> > 
> > I have created a command line app that takes commands as user input in a loop. I need to simulate up arrow key and down arrow key so that user can navigate through the commands just like it is done in command prompt and irb. I could not find a way catch up arrow key and down arrow key.

---

<div class="post-metadata">

**Author:** ![Lucas\_Buchala](https://avatars.discourse-cdn.com/v4/letter/l/67e7ee/32.png) [@Lucas\_Buchala](https://rubytalk.org/u/Lucas_Buchala)\
**Post date:** [3 September 2016 16:36 UTC](https://rubytalk.org/t/need-help-for-simulating-up-arrow-key-and-down-arrow-key-like-in-command-prompt/73794/4 "2016-09-03T16:36:06Z")

</div>

I don't know if this will work for you, but a simple alternative is  
just to wrap your program with the "rlwrap" utility:

&nbsp;&nbsp;$ rlwrap ruby script.rb

From within ruby, yes, you will need to use readline or any other  
line-editing library with history support.

---

<div class="post-metadata">

**Author:** ![James\_Pacheco](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/james_pacheco/32/2457_2.png) [@James\_Pacheco](https://rubytalk.org/u/James_Pacheco)\
**Post date:** [17 September 2016 01:34 UTC](https://rubytalk.org/t/need-help-for-simulating-up-arrow-key-and-down-arrow-key-like-in-command-prompt/73794/5 "2016-09-17T01:34:27Z")

</div>

Did you try searching google for "creating Ruby REPL  
\<[Google](https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=creating+ruby+repl&gt);  
"?

In particular, I used something like this for a project:  
[https://www.fedux.org/articles/2015/08/26/creating-an-irb-based-repl-console-for-your-project.html](https://www.fedux.org/articles/2015/08/26/creating-an-irb-based-repl-console-for-your-project.html)

Best of luck.

> **···**
>
> On Fri, Sep 2, 2016 at 6:05 AM Devashish Bhardwaj \< devashish.vhardwaj@gmail.com\> wrote:
> 
> > I have created a command line app that takes commands as user input in a  
> > loop. I need to simulate up arrow key and down arrow key so that user can  
> > navigate through the commands just like it is done in command prompt and  
> > irb. I could not find a way catch up arrow key and down arrow key.

---

<div class="post-metadata">

**Author:** ![Samuel\_Brandao](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@Samuel\_Brandao](https://rubytalk.org/u/Samuel_Brandao)\
**Post date:** [5 September 2016 07:42 UTC](https://rubytalk.org/t/need-help-for-simulating-up-arrow-key-and-down-arrow-key-like-in-command-prompt/73794/6 "2016-09-05T07:42:04Z")

</div>

I've used ncurses for this kind of stuff quite successfully in the past,  
maybe you can give it a try.

> **···**
>
> Em sáb, 3 de set de 2016 18:36, Lucas Buchala \<lucasbuchala@gmail.com\> escreveu:
> 
> > I don't know if this will work for you, but a simple alternative is  
> > just to wrap your program with the "rlwrap" utility:
> > 
> > &nbsp;&nbsp;$ rlwrap ruby script.rb
> > 
> > From within ruby, yes, you will need to use readline or any other  
> > line-editing library with history support.
> > 
> > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);

---

<div class="post-metadata">

**Author:** ![Devashish\_Bhardwaj](https://avatars.discourse-cdn.com/v4/letter/d/45deac/32.png) [@Devashish\_Bhardwaj](https://rubytalk.org/u/Devashish_Bhardwaj)\
**Post date:** [1 June 2017 22:53 UTC](https://rubytalk.org/t/need-help-for-simulating-up-arrow-key-and-down-arrow-key-like-in-command-prompt/73794/7 "2017-06-01T22:53:07Z")

</div>

Thanks for the responses guys. The readLine method used in irb finally did  
it.

> **···**
>
> On 17 Sep 2016 7:05 a.m., "James Pacheco" \<james.pacheco@gmail.com\> wrote:
> 
> > On Fri, Sep 2, 2016 at 6:05 AM Devashish Bhardwaj \< \> devashish.vhardwaj@gmail.com\> wrote:
> > 
> > > I have created a command line app that takes commands as user input in a  
> > > loop. I need to simulate up arrow key and down arrow key so that user can  
> > > navigate through the commands just like it is done in command prompt and  
> > > irb. I could not find a way catch up arrow key and down arrow key.
> > 
> > Did you try searching google for "creating Ruby REPL  
> > \<[Google](https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=creating+ruby+repl&gt);  
> > "?
> > 
> > In particular, I used something like this for a project:  
> > [https://www.fedux.org/articles/2015/08/26/creating-](https://www.fedux.org/articles/2015/08/26/creating-)  
> > an-irb-based-repl-console-for-your-project.html
> > 
> > Best of luck.
> > 
> > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);

---

<div class="post-metadata">

**Author:** ![Xeno\_Campanoli1](https://avatars.discourse-cdn.com/v4/letter/x/85f322/32.png) [@Xeno\_Campanoli1](https://rubytalk.org/u/Xeno_Campanoli1)\
**Post date:** [5 September 2016 15:57 UTC](https://rubytalk.org/t/need-help-for-simulating-up-arrow-key-and-down-arrow-key-like-in-command-prompt/73794/8 "2016-09-05T15:57:14Z")

</div>

Linux has an interface for this which is used for a lot of script automation...

> **···**
>
> On Mon, Sep 5, 2016 at 12:42 AM, Samuel Brandão \<gb.samuel@gmail.com\> wrote:
> 
> > I've used ncurses for this kind of stuff quite successfully in the past,  
> > maybe you can give it a try.
> > 
> > Em sáb, 3 de set de 2016 18:36, Lucas Buchala \<lucasbuchala@gmail.com\> \> escreveu:
> > 
> > > I don't know if this will work for you, but a simple alternative is  
> > > just to wrap your program with the "rlwrap" utility:
> > > 
> > > &nbsp;&nbsp;$ rlwrap ruby script.rb
> > > 
> > > From within ruby, yes, you will need to use readline or any other  
> > > line-editing library with history support.
> > > 
> > > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);
> > 
> > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);

---

<div class="post-metadata">

**Author:** ![Xeno\_Campanoli1](https://avatars.discourse-cdn.com/v4/letter/x/85f322/32.png) [@Xeno\_Campanoli1](https://rubytalk.org/u/Xeno_Campanoli1)\
**Post date:** [5 September 2016 15:58 UTC](https://rubytalk.org/t/need-help-for-simulating-up-arrow-key-and-down-arrow-key-like-in-command-prompt/73794/9 "2016-09-05T15:58:43Z")

</div>

Rerun comes up, but that's not what I remember. There is a facility  
that is callable from Bash, for instance, that is used in things like  
installs.

> **···**
>
> On Mon, Sep 5, 2016 at 8:57 AM, Xeno Campanoli \<xeno.campanoli@gmail.com\> wrote:
> 
> > Linux has an interface for this which is used for a lot of script automation...
> > 
> > On Mon, Sep 5, 2016 at 12:42 AM, Samuel Brandão \<gb.samuel@gmail.com\> wrote:
> > 
> > > I've used ncurses for this kind of stuff quite successfully in the past,  
> > > maybe you can give it a try.
> > > 
> > > Em sáb, 3 de set de 2016 18:36, Lucas Buchala \<lucasbuchala@gmail.com\> \>\> escreveu:
> > > 
> > > > I don't know if this will work for you, but a simple alternative is  
> > > > just to wrap your program with the "rlwrap" utility:
> > > > 
> > > > &nbsp;&nbsp;$ rlwrap ruby script.rb
> > > > 
> > > > From within ruby, yes, you will need to use readline or any other  
> > > > line-editing library with history support.
> > > > 
> > > > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > > > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);
> > > 
> > > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello](https://avatars.discourse-cdn.com/v4/letter/m/f17d59/32.png) [@Martin\_DeMello](https://rubytalk.org/u/Martin_DeMello)\
**Post date:** [5 September 2016 23:07 UTC](https://rubytalk.org/t/need-help-for-simulating-up-arrow-key-and-down-arrow-key-like-in-command-prompt/73794/10 "2016-09-05T23:07:37Z")

</div>

are you thinking of expect?

martin

> **···**
>
> On Sep 5, 2016 8:58 AM, "Xeno Campanoli" \<xeno.campanoli@gmail.com\> wrote:
> 
> > Rerun comes up, but that's not what I remember. There is a facility  
> > that is callable from Bash, for instance, that is used in things like  
> > installs.
> > 
> > On Mon, Sep 5, 2016 at 8:57 AM, Xeno Campanoli \<xeno.campanoli@gmail.com\> \> wrote:  
> > \> Linux has an interface for this which is used for a lot of script  
> > automation...  
> > \>  
> > \>  
> > \> On Mon, Sep 5, 2016 at 12:42 AM, Samuel Brandão \<gb.samuel@gmail.com\> \> wrote:  
> > \>\> I've used ncurses for this kind of stuff quite successfully in the past,  
> > \>\> maybe you can give it a try.  
> > \>\>  
> > \>\>  
> > \>\> Em sáb, 3 de set de 2016 18:36, Lucas Buchala \<lucasbuchala@gmail.com\> \> \>\> escreveu:  
> > \>\>\>  
> > \>\>\> I don't know if this will work for you, but a simple alternative is  
> > \>\>\> just to wrap your program with the "rlwrap" utility:  
> > \>\>\>  
> > \>\>\> $ rlwrap ruby script.rb  
> > \>\>\>  
> > \>\>\> From within ruby, yes, you will need to use readline or any other  
> > \>\>\> line-editing library with history support.  
> > \>\>\>  
> > \>\>\> Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=  
> > \>  
> > \>\>\> \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);  
> > \>\>  
> > \>\>  
> > \>\>  
> > \>\> Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=  
> > \>  
> > \>\> \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);  
> > \>\>
> > 
> > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);
