[Haskell-cafe] Arrow key functionality for REPL written in Haskell
Mateusz Kowalczyk
fuuzetsu at fuuzetsu.co.uk
Sun Sep 28 09:01:14 UTC 2014
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
> Haskell-Cafe at haskell.org
> 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.
More information about the Haskell-Cafe
mailing list