[Haskell-cafe] Arrow key functionality for REPL written in Haskell

Emma Peng u3502350 at connect.hku.hk
Sun Sep 28 09:15:39 UTC 2014


Hi Travis & Mateusz,

Thanks for your advice! 
However I just found out that I didn't need to implement this functionality 
by hand since Haskeline 
<http://hackage.haskell.org/package/haskeline-0.6.2.2/docs/System-Console-Haskeline.html> 
does exactly what I need... 

Cheers,
Emma

On Sunday, September 28, 2014 5:01:30 PM UTC+8, Mateusz Kowalczyk wrote:
>
> On 09/28/2014 09:43 AM, Travis Cardwell wrote:
> > On 2014年09月28日 16:42, PENG, BO YA wrote:
> >> I'm trying to implement the arrow key functionality for a systemf REPL 
> to
> >> recall previously entered lines. I think I should save the previous 
> lines
> >> in a list and then traverse through the list when an arrow key is 
> pressed,
> >> but I'm no sure how to detect an arrow key and implement this 
> functionality.
> >> Can anyone give a brief description about the implementation or point 
> me to
> >> some other resources?
> >> Thanks!
> > 
> > Perhaps readline would work for you?
> > 
> > http://hackage.haskell.org/package/readline
> > 
> > Cheers,
> > 
> > Travis
> > _______________________________________________
> > Haskell-Cafe mailing list
> > Haskel... at haskell.org <javascript:>
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
> > 
>
> For keeping track itself, you can use something like a pointed list[1]
> pretty easily which frees you from having to keep track of indexes,
> looping around, going back and forth &c. I use it for quick-and-dirty
> selection in a menu in the game I'm writing. Once you have a way to get
> key presses, it becomes trivial (+ some lenses for clarity):
>
> whenM (keyPress KeyUp) $ screenState . maps %= C.previous
> whenM (keyPress KeyDown) $ screenState . maps %= C.next
>
> where ‘maps’ is my PointedList and C is Data.List.Pointed.Circular.
>
> [1]: http://hackage.haskell.org/package/pointedlist
>
> -- 
> Mateusz K.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskel... at haskell.org <javascript:>
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140928/b1ce7b70/attachment-0001.html>


More information about the Haskell-Cafe mailing list