summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@shackspace.de>2014-12-28 03:58:41 +0100
committertv <tv@shackspace.de>2014-12-28 03:58:41 +0100
commit4c1239c2e846d8f1987257e1fc76232ec295804f (patch)
treef1d44a48ab4114781e78c68d5fa8b16b27fab6da
parent9edccfb36aa2d266d6f8038f6195c78697b3d0be (diff)
moveToParent with backspace (\DEL)
-rw-r--r--test4.hs10
1 files changed, 10 insertions, 0 deletions
diff --git a/test4.hs b/test4.hs
index f493e6a..b9990a0 100644
--- a/test4.hs
+++ b/test4.hs
@@ -160,6 +160,7 @@ keymap "\ESC[b" = Just $ moveTreeUp 1
keymap "\ESC[5~" = Just $ \q -> moveTreeDown (screenHeight q `div` 2) q -- PgUp
keymap "\ESC[6~" = Just $ \q -> moveTreeUp (screenHeight q `div` 2) q -- PgDn
keymap "\n" = Just toggleFold
+keymap "\DEL" = Just moveToParent -- backspace
keymap ('\ESC':'[':'9':';':xs) = Just $ \q@State{..} -> do
let (h,';':w) = break (==';') (take (length xs - 1) xs) -- ^ drop (assumed) trailing 't'
@@ -213,6 +214,15 @@ moveTreeDown n q@State{..} =
i -> moveCursorUp i q'
+moveToParent q@State{..} =
+ case Z.parent cursor of
+ Nothing -> return q { flashMessage = "cannot go further up" }
+ Just cursor' ->
+ let q' = q { cursor = cursor' }
+ in case topOverrun q' of
+ 0 -> return q'
+ i -> moveTreeDown i q'
+
toggleFold :: State -> IO State
toggleFold q@State{..} = case Z.label cursor of