brick-list-search 0.1.1.0 → 0.1.2.0
raw patch · 5 files changed
+74/−16 lines, 5 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Brick.Widgets.List.Search: listShowTheBottom :: Searchable t => (e -> Bool) -> EventM n (GenericList n t e) ()
+ Brick.Widgets.List.Search: listShowTheTop :: Searchable t => (e -> Bool) -> EventM n (GenericList n t e) ()
- Brick.Widgets.List.Search: listSearchByPages :: (Searchable t, Foldable t, Splittable t, Ord n, RealFrac m) => (e -> Bool) -> m -> EventM n (GenericList n t e) ()
+ Brick.Widgets.List.Search: listSearchByPages :: (Searchable t, Foldable t, Splittable t, Ord n, RealFrac pages) => (e -> Bool) -> pages -> EventM n (GenericList n t e) ()
Files
- CHANGELOG.md +4/−0
- brick-list-search.cabal +1/−1
- demo-02.png binary
- demos/BrickListSearch.hs +33/−13
- src/Brick/Widgets/List/Search.hs +36/−2
CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for brick-list-search +## 0.1.2.0 -- 2023-02-22++* Added `listShowTheTop` and `listShowTheBottom`.+ ## 0.1.1.0 -- 2023-02-21 * Added `listSearchBy` and `listSearchByPages`.
brick-list-search.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: brick-list-search-version: 0.1.1.0+version: 0.1.2.0 synopsis: Search forward or backward for certain kinds of items in brick list
demo-02.png view
binary file changed (24740 → 25710 bytes)
demos/BrickListSearch.hs view
@@ -31,16 +31,36 @@ handleEvent e = case e of VtyEvent (EvKey KEsc []) -> halt VtyEvent (EvKey (KChar 'q') []) -> halt- VtyEvent (EvKey KUp []) -> modify $ listSearchUp isItem- VtyEvent (EvKey KDown []) -> modify $ listSearchDown isItem- VtyEvent (EvKey KHome []) -> modify $ listSearchFromBeginning isItem- VtyEvent (EvKey KEnd []) -> modify $ listSearchFromEnd isItem- VtyEvent (EvKey KPageUp []) -> listSearchPageUp isItem- VtyEvent (EvKey KPageDown []) -> listSearchPageDown isItem- VtyEvent (EvKey (KChar 'u') [MCtrl]) -> listSearchByPages isItem (-0.5)- VtyEvent (EvKey (KChar 'd') [MCtrl]) -> listSearchByPages isItem 0.5- VtyEvent (EvKey (KChar 'k') []) -> modify $ listSearchBy isItem (-2)- VtyEvent (EvKey (KChar 'j') []) -> modify $ listSearchBy isItem 2+ VtyEvent (EvKey KUp []) -> do+ modify $ listSearchUp isItem+ listShowTheTop isItem+ VtyEvent (EvKey KDown []) -> do+ modify $ listSearchDown isItem+ listShowTheBottom isItem+ VtyEvent (EvKey KHome []) -> do+ modify $ listSearchFromBeginning isItem+ listShowTheTop isItem+ VtyEvent (EvKey KEnd []) -> do+ modify $ listSearchFromEnd isItem+ listShowTheBottom isItem+ VtyEvent (EvKey KPageUp []) -> do+ listSearchPageUp isItem+ listShowTheTop isItem+ VtyEvent (EvKey KPageDown []) -> do+ listSearchPageDown isItem+ listShowTheBottom isItem+ VtyEvent (EvKey (KChar 'u') [MCtrl]) -> do+ listSearchByPages isItem (-0.5)+ listShowTheTop isItem+ VtyEvent (EvKey (KChar 'd') [MCtrl]) -> do+ listSearchByPages isItem 0.5+ listShowTheBottom isItem+ VtyEvent (EvKey KUp [MCtrl]) -> do+ modify $ listSearchBy isItem (-2)+ listShowTheTop isItem+ VtyEvent (EvKey KDown [MCtrl]) -> do+ modify $ listSearchBy isItem 2+ listShowTheBottom isItem _ -> return () renderListElement :: Bool -> ListElem -> Widget Name@@ -59,8 +79,8 @@ , "Press PageDown to move down one page" , "Press Ctrl+u to move up half page" , "Press Ctrl+d to move down half page"- , "Press k to move up two items"- , "Press j to move down two items"]+ , "Press Ctrl+Up arrow to move up two items"+ , "Press Ctrl+Down arrow to move down two items"] in [vCenter $ vBox $ hCenter (border $ vLimit 20 $ hLimit 30 $ renderList renderListElement True l) : map (hCenter . str) msgs] @@ -68,7 +88,7 @@ listElems = fromList $ [Sep (Just "First separator"), Str "New account", Sep (Just "Accounts")] ++ map (Str . ("Account "<>) . show) [1..1000]- ++ [Sep Nothing, Str "Show account statistics.", Sep (Just "Yet Another Separator"), Str "End of List",+ ++ [Sep Nothing, Str "Show account statistics.", Sep (Just "Yet Another Separator"), Str "Last list element", Sep (Just "Last separator")] theList :: GenericList Name Vector ListElem
src/Brick/Widgets/List/Search.hs view
@@ -22,6 +22,9 @@ , listSearchPageDown , listSearchFromBeginning , listSearchFromEnd+-- * List display+, listShowTheTop+, listShowTheBottom -- * Classes , Searchable(..) ) where@@ -37,6 +40,7 @@ -- brick import qualified Brick.Widgets.List as L import Brick.Types+import Brick.Main -- | Should the search include the current location? type IncludeCurrent = Bool@@ -147,9 +151,9 @@ -- After calling 'L.listMoveByPages', if the number of pages to move by was negative, search backward for the first -- element that passes the test. If backward search fails, then search forward for the first such element. If forward -- search fails too, cancel movements made by this function.-listSearchByPages :: (Searchable t, Foldable t, L.Splittable t, Ord n, RealFrac m)+listSearchByPages :: (Searchable t, Foldable t, L.Splittable t, Ord n, RealFrac pages) => (e -> Bool) -- ^ The test- -> m -- ^ Pages to move by+ -> pages -- ^ Pages to move by -> EventM n (L.GenericList n t e) () listSearchByPages test p = if p == 0 then return ()@@ -214,6 +218,36 @@ listSearchFromEnd test l = case searchListBackward True test (L.listMoveToEnd l) of Nothing -> l Just idx -> l & L.listSelectedL ?~ idx++-- | If searching backward for a list element that passes 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.+listShowTheTop :: Searchable t+ => (e -> Bool) -- ^ The test+ -> EventM n (L.GenericList n t e) ()+listShowTheTop test = do+ l <- get+ case searchListBackward False test l of+ Nothing -> vScrollToBeginning $ viewportScroll $ l ^. L.listNameL+ Just _ -> return ()++-- | If searching forward for a list element that passes 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.+listShowTheBottom :: Searchable t+ => (e -> Bool) -- ^ The test+ -> EventM n (L.GenericList n t e) ()+listShowTheBottom test = do+ l <- get+ case searchListForward False test l of+ Nothing -> vScrollToEnd $ viewportScroll $ l ^. L.listNameL+ Just _ -> return () -- | Functions for searching elements. class Searchable (t :: * -> *) where