Move focus ring code to library

This commit is contained in:
Jonathan Daugherty 2015-05-09 00:57:53 -07:00
parent a699e172ba
commit 7f09d6e5d1
2 changed files with 24 additions and 23 deletions

View File

@ -12,29 +12,6 @@ data St =
, focus :: FocusRing , focus :: FocusRing
} }
data FocusRing = FocusRingEmpty
| FocusRingNonemtpy [Name] Int
focusRing :: [Name] -> FocusRing
focusRing [] = FocusRingEmpty
focusRing names = FocusRingNonemtpy names 0
focusNext :: FocusRing -> FocusRing
focusNext FocusRingEmpty = FocusRingEmpty
focusNext (FocusRingNonemtpy ns i) = FocusRingNonemtpy ns i'
where
i' = (i + 1) `mod` (length ns)
focusPrev :: FocusRing -> FocusRing
focusPrev FocusRingEmpty = FocusRingEmpty
focusPrev (FocusRingNonemtpy ns i) = FocusRingNonemtpy ns i'
where
i' = (i + (length ns) - 1) `mod` (length ns)
focusGetCurrent :: FocusRing -> Maybe Name
focusGetCurrent FocusRingEmpty = Nothing
focusGetCurrent (FocusRingNonemtpy ns i) = Just $ ns !! i
drawUI :: St -> Widget drawUI :: St -> Widget
drawUI st = drawUI st =
hBox [ hLimit 25 $ vBox [ "-- header --" hBox [ hLimit 25 $ vBox [ "-- header --"

View File

@ -161,3 +161,27 @@ runVty draw chooseCursor handleEv state vty = do
shutdown vty shutdown vty
exitWith status exitWith status
Right newState -> runVty draw chooseCursor handleEv newState vty Right newState -> runVty draw chooseCursor handleEv newState vty
data FocusRing = FocusRingEmpty
| FocusRingNonemtpy [Name] Int
focusRing :: [Name] -> FocusRing
focusRing [] = FocusRingEmpty
focusRing names = FocusRingNonemtpy names 0
focusNext :: FocusRing -> FocusRing
focusNext FocusRingEmpty = FocusRingEmpty
focusNext (FocusRingNonemtpy ns i) = FocusRingNonemtpy ns i'
where
i' = (i + 1) `mod` (length ns)
focusPrev :: FocusRing -> FocusRing
focusPrev FocusRingEmpty = FocusRingEmpty
focusPrev (FocusRingNonemtpy ns i) = FocusRingNonemtpy ns i'
where
i' = (i + (length ns) - 1) `mod` (length ns)
focusGetCurrent :: FocusRing -> Maybe Name
focusGetCurrent FocusRingEmpty = Nothing
focusGetCurrent (FocusRingNonemtpy ns i) = Just $ ns !! i