Murat Kasimov

More about me

Я language (β)

/Я language (β)/Tutorials/Command line-task-manager-4/

Full source codePrevious chapterNext 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:

input : World ASCII

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:

tap = exact `ha` Glyph `ha` Letter `ha` Lower `hv'he` J `ho'yo` Down `lo'ys` exact `ha` Glyph `ha` Letter `ha` Lower `hv'he` K `ho'yo` Lift `ho` Check

Since World is functor we can compose those expression together:

input `yo` tap : World `T'I_` Maybe `T'I` Shifter List `S` Shifter List

Type declaration looks a bit overwhelmed due to target Sum tensor. We can squash it with either Opted or using colimit operators directly:

outro `ha` Opted : i `S` i `AR_` i is `la` is : i `S` i `AR_` i

What's going to happen if we run this expression?

input `yo` tap `yo_'yo` is `la` is : World `T'I_` Maybe `T'I` Shifter List

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:

main = input `yok_` Retry `ha` tap `ho__'yo` is `la` is : World `T'I` Shifter List