Murat Kasimov

More about me

Я language (β)

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

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:

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

Challenge: add aliases of navigation keys.

Since World is functor we can compose those expression together:

input `yo` match : 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` match : World `T'I` Shifter List

Challenge: use default behaviour - so it tries to match for a key only once.