brick-list-skip 0.1.0.0 → 0.1.1.0
raw patch · 3 files changed
+71/−88 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Brick.Widgets.List.Skip: listShow :: Searchable t => (e -> Bool) -> Dir -> EventM n (GenericList n t e) ()
Files
- CHANGELOG.md +4/−13
- brick-list-skip.cabal +5/−1
- src/Brick/Widgets/List/Skip.hs +62/−74
CHANGELOG.md view
@@ -1,18 +1,9 @@ # Revision history for brick-list-search -## 0.1.2.1 -- 2023-02-26--* Improved documentation-* Made `listSearchBy` and `listSearchByPages` a bit more efficient--## 0.1.2.0 -- 2023-02-22--* Added `listShowTheTop` and `listShowTheBottom`.--## 0.1.1.0 -- 2023-02-21+## 0.1.1.0 -- 2023-04-12 -* Added `listSearchBy` and `listSearchByPages`.+* Added `listShow`. -## 0.1.0.0 -- 2023-02-20+## 0.1.0.0 -- 2023-04-12 -* First version with proper documentation.+* First version
brick-list-skip.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: brick-list-skip-version: 0.1.0.0+version: 0.1.1.0 synopsis: Skip a certain kind of items when moving in brick list @@ -11,6 +11,10 @@ For example, you can skip a separator because selecting a separator doesn't make sense. You can run demo programs to see how it works.++ == For Contributors++ This library tries not to exceed 120 characters per line. homepage: https://codeberg.org/amano.kenji/brick-list-skip bug-reports: https://codeberg.org/amano.kenji/brick-list-skip/issues
src/Brick/Widgets/List/Skip.hs view
@@ -12,6 +12,7 @@ -- * Functions , listSkip , listSearchFromCurrent+, listShow -- * Classes , Searchable(..) ) where@@ -58,9 +59,9 @@ NoMove deriving (Show, Eq) --- | Move by a specified amount. Skip elements that pass the test. After moving, if there is no more element that fails--- the test in the specified direction, this function tries to show as many elements that pass the test as possible in--- the direction.+-- | Move by a specified amount. Skip elements that pass the test.+--+-- After moving, this function calls 'listShow' with the direction of 'Move'. listSkip :: (Foldable t, L.Splittable t, Searchable t, Ord n) => (e -> Bool) -- ^ The test -> Move@@ -72,14 +73,14 @@ Most -> modify $ listSkipToBeginning t Page -> listSkipByPages t (-1.0) HalfPage -> listSkipByPages t (-0.5)- listShowAbove t+ listShow t Bwd Move a Fwd -> do case a of One -> modify $ listSkipForward t Most -> modify $ listSkipToEnd t Page -> listSkipByPages t 1.0 HalfPage -> listSkipByPages t 0.5- listShowBelow t+ listShow t Fwd NoMove -> return () -- | From the current element, search for an element that fails the test, and go to it.@@ -89,54 +90,71 @@ -> EventM n (L.GenericList n t e) () listSearchFromCurrent t d = let searchList = case d of- Bwd -> searchListBackward- Fwd -> searchListForward+ Bwd -> skipListBackward+ Fwd -> skipListForward in modify $ \l -> case searchList IncludeCurrent t l of Nothing -> l Just ix -> l & L.listSelectedL ?~ ix +-- | If searching for an element that fails the test in the specified direction fails, show as many elements as possible+-- in the direction.+--+-- The current element is not included in the search.+listShow :: Searchable t+ => (e -> Bool) -- ^ The test+ -> Dir+ -> EventM n (L.GenericList n t e) ()+listShow t d = do+ l <- get+ let (skipList, vScroll) = case d of+ Bwd -> (skipListBackward, vScrollToBeginning)+ Fwd -> (skipListForward, vScrollToEnd)+ case skipList ExcludeCurrent t l of+ Nothing -> vScroll $ viewportScroll $ l ^. L.listNameL+ Just _ -> return ()+ -- | Search forward for the first element index that fails the test-searchListForward :: Searchable t+skipListForward :: Searchable t => IncludeCurrent -> (e -> Bool) -- ^ The test -> L.GenericList n t e -> Maybe Int -- ^ The first element index that fails the test-searchListForward incCur test l = let- skipForward idx es = case viewHead es of- Nothing -> Nothing- Just (e, es') -> if test e- then skipForward (idx+1) es'- else Just idx- -- Start with the current list element index. If the current element is excluded, then add 1 to the current index.- start = case l ^. L.listSelectedL of- Nothing -> 0- Just i -> i + case incCur of- IncludeCurrent -> 0- ExcludeCurrent -> 1- es = drop start $ l ^. L.listElementsL- in skipForward start es+skipListForward incCur test l = let+ skipForward idx es = case viewHead es of+ Nothing -> Nothing+ Just (e, es') -> if test e+ then skipForward (idx+1) es'+ else Just idx+ -- Start with the current list element index. If the current element is excluded, then add 1 to the current index.+ start = case l ^. L.listSelectedL of+ Nothing -> 0+ Just i -> i + case incCur of+ IncludeCurrent -> 0+ ExcludeCurrent -> 1+ es = drop start $ l ^. L.listElementsL+ in skipForward start es -- | Search backward for the first element index that fails the test-searchListBackward :: Searchable t+skipListBackward :: Searchable t => IncludeCurrent -> (e -> Bool) -- ^ The test -> L.GenericList n t e -> Maybe Int -- ^ The first element index that fails the test-searchListBackward incCur test l = let- skipBackward idx es = case viewLast es of- Nothing -> Nothing- Just (es', e) -> if test e- then skipBackward (idx-1) es'- else Just idx- -- Start with the current list element index + 1 so that the current index is included. If the current element is- -- excluded, don't add 1 to the current index.- start = case l ^. L.listSelectedL of- Nothing -> 0- Just i -> i + case incCur of- IncludeCurrent -> 1- ExcludeCurrent -> 0- es = take start $ l ^. L.listElementsL- in skipBackward (start-1) es+skipListBackward incCur test l = let+ skipBackward idx es = case viewLast es of+ Nothing -> Nothing+ Just (es', e) -> if test e+ then skipBackward (idx-1) es'+ else Just idx+ -- Start with the current list element index + 1 so that the current index is included. If the current element is+ -- excluded, don't add 1 to the current index.+ start = case l ^. L.listSelectedL of+ Nothing -> 0+ Just i -> i + case incCur of+ IncludeCurrent -> 1+ ExcludeCurrent -> 0+ es = take start $ l ^. L.listElementsL+ in skipBackward (start-1) es -- | Search backward for the first element that fails the test. --@@ -147,7 +165,7 @@ => (e -> Bool) -- ^ The test -> L.GenericList n t e -> L.GenericList n t e-listSkipBackward test l = case searchListBackward ExcludeCurrent test l of+listSkipBackward test l = case skipListBackward ExcludeCurrent test l of Nothing -> l Just idx -> l & L.listSelectedL ?~ idx @@ -160,7 +178,7 @@ => (e -> Bool) -- ^ The test -> L.GenericList n t e -> L.GenericList n t e-listSkipForward test l = case searchListForward ExcludeCurrent test l of+listSkipForward test l = case skipListForward ExcludeCurrent test l of Nothing -> l Just idx -> l & L.listSelectedL ?~ idx @@ -186,8 +204,8 @@ origL <- get L.listMoveByPages p let (searchList, searchListOpposite) = if p < 0- then (searchListBackward, searchListForward)- else (searchListForward, searchListBackward)+ then (skipListBackward, skipListForward)+ else (skipListForward, skipListBackward) modify $ \l -> case searchList IncludeCurrent test l of Nothing -> case searchListOpposite ExcludeCurrent test l of Nothing -> origL@@ -203,7 +221,7 @@ => (e -> Bool) -- ^ The test -> L.GenericList n t e -> L.GenericList n t e-listSkipToBeginning test l = case searchListForward IncludeCurrent test (L.listMoveToBeginning l) of+listSkipToBeginning test l = case skipListForward IncludeCurrent test (L.listMoveToBeginning l) of Nothing -> l Just idx -> l & L.listSelectedL ?~ idx @@ -216,39 +234,9 @@ => (e -> Bool) -- ^ The test -> L.GenericList n t e -> L.GenericList n t e-listSkipToEnd test l = case searchListBackward IncludeCurrent test (L.listMoveToEnd l) of+listSkipToEnd test l = case skipListBackward IncludeCurrent test (L.listMoveToEnd l) of Nothing -> l Just idx -> l & L.listSelectedL ?~ idx---- | If searching backward for a list element that fails the test fails, show as many list elements as possible above--- the current element.------ The current list element is not included in the backward search.------ Call this after moving backward by calling one of list manipulation functions.-listShowAbove :: Searchable t- => (e -> Bool) -- ^ The test- -> EventM n (L.GenericList n t e) ()-listShowAbove test = do- l <- get- case searchListBackward ExcludeCurrent test l of- Nothing -> vScrollToBeginning $ viewportScroll $ l ^. L.listNameL- Just _ -> return ()---- | If searching forward for a list element that fails the test fails, show as many list elements as possible below--- the current element.------ The current list element is not included in the forward search.------ Call this after moving forward by calling one of list manipulation functions.-listShowBelow :: Searchable t- => (e -> Bool) -- ^ The test- -> EventM n (L.GenericList n t e) ()-listShowBelow test = do- l <- get- case searchListForward ExcludeCurrent test l of- Nothing -> vScrollToEnd $ viewportScroll $ l ^. L.listNameL- Just _ -> return () -- | Functions for searching elements. class Searchable (t :: * -> *) where