Full source code ⋅ Previous chapter ⋅ Next chapter
Let us step back from what we have done before and spend some time on user interaction - at least they should be able to walk over listed items which means we somehow should accept navigation commands. For such a purpose we can use Shifter since we use Scrolling List.
But how we get an actual user interaction? Since we operate in command line we can accept a single character from standart input:
Following VIM convention for navigation, let's bind J and K lowercase letters to vertical movement - we do it by inspecting received ASCII character and designating Shifter variants:
Since World is functor we can compose those expression together:
Type declaration looks a bit overwhelmed due to target Sum tensor. We can squash it with either Opted or using colimit operators directly:
What's going to happen if we run this expression?
If user inputs something except J and K computation wouldn't proceed since we don't get a command in this case. Good news is that we can torture user to repeatedly ask for a proper input until we get one: