on develop help sign in
Add buttons; Make example widgets escapable
commit6fc2815025718aefa06ea366b2ec0a0ed5435606 authorAli Abrar <aliabrar@gmail.com> dateMon 5 Nov 2018, 00:08 (8 years ago) parentd333d0c
1 file changed+13−6
src-bin/example.hs+13−6
src-bin/example.hs+13−6
@@ -36,7 +36,7 @@ main = mainWidget $ do
3636 V.EvKey (V.KChar 'c') [V.MCtrl] -> Just ()
3737 _ -> Nothing
3838 let buttons = do
39− text $ pure "Select an example. Ctrl+c to quit."
39+ text $ pure "Select an example. Esc will bring you back here. Ctrl+c to quit."
4040 let region1 = ffor size $ \(w,h) ->
4141 Region (w `div` 6) (h `div` 6) (w `div` 6) (h `div` 6)
4242 region2 = ffor size $ \(w,h) ->
@@ -44,12 +44,19 @@ main = mainWidget $ do
4444 todo' <- pane region1 (pure True) $ button "Todo List"
4545 editor <- pane region2 (pure True) $ button "Text Editor"
4646 return $ leftmost
47− [ Example_TextEditor <$ editor
48− , Example_Todo <$ todo'
47+ [ Left Example_TextEditor <$ editor
48+ , Left Example_Todo <$ todo'
4949 ]
50− rec out <- networkHold buttons $ ffor (switch $ current out) $ \case
51− Example_TextEditor -> testBoxes >> return never
52− Example_Todo -> taskList >> return never
50+ escapable w = do
51+ w
52+ i <- input
53+ return $ fforMaybe i $ \case
54+ V.EvKey V.KEsc [] -> Just $ Right ()
55+ _ -> Nothing
56+ rec out <- networkHold buttons $ ffor (switch (current out)) $ \case
57+ Left Example_TextEditor -> escapable testBoxes
58+ Left Example_Todo -> escapable taskList
59+ Right () -> buttons
5360 return ()
5461
5562taskList