packages feed

brick-tabular-list 2.1.0.0 → 2.2.0.0

raw patch · 8 files changed

+57/−42 lines, 8 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Brick.Widgets.TabularList.Grid: instance GHC.Classes.Eq Brick.Widgets.TabularList.Grid.VisibleColumns
- Brick.Widgets.TabularList.Grid: instance GHC.Generics.Generic (Brick.Widgets.TabularList.Grid.GridRenderers n e r)
- Brick.Widgets.TabularList.Grid: instance GHC.Show.Show Brick.Widgets.TabularList.Grid.VisibleColumns
- Brick.Widgets.TabularList.Mixed: instance GHC.Generics.Generic (Brick.Widgets.TabularList.Mixed.MixedRenderers n e w r)
- Brick.Widgets.TabularList.Types: CHRH :: (ListFocused -> WidthDeficit -> Widget n) -> ColHdrRowHdr n
- Brick.Widgets.TabularList.Types: instance GHC.Generics.Generic (Brick.Widgets.TabularList.Types.RowHdr n e r)
+ Brick.Widgets.TabularList.Grid: instance GHC.Classes.Eq Brick.Widgets.TabularList.Grid.VisibleGridColumns
+ Brick.Widgets.TabularList.Grid: instance GHC.Generics.Generic (Brick.Widgets.TabularList.Grid.GridRenderers n e)
+ Brick.Widgets.TabularList.Grid: instance GHC.Show.Show Brick.Widgets.TabularList.Grid.VisibleGridColumns
+ Brick.Widgets.TabularList.Mixed: instance GHC.Generics.Generic (Brick.Widgets.TabularList.Mixed.MixedRenderers n e w)
+ Brick.Widgets.TabularList.Types: ColHdrRowHdr :: (ListFocused -> WidthDeficit -> Widget n) -> ColHdrRowHdr n
- Brick.Widgets.TabularList.Grid: GridRenderers :: (ListFocused -> WidthDeficit -> GridCtxt -> e -> Widget n) -> Maybe (RowHdr n e r) -> Maybe (GridColHdr n) -> Maybe (ColHdrRowHdr n) -> GridRenderers n e r
+ Brick.Widgets.TabularList.Grid: GridRenderers :: (ListFocused -> WidthDeficit -> GridCtxt -> e -> Widget n) -> Maybe (RowHdr n e) -> Maybe (GridColHdr n) -> Maybe (ColHdrRowHdr n) -> GridRenderers n e
- Brick.Widgets.TabularList.Grid: [$sel:cell:GridRenderers] :: GridRenderers n e r -> ListFocused -> WidthDeficit -> GridCtxt -> e -> Widget n
+ Brick.Widgets.TabularList.Grid: [$sel:cell:GridRenderers] :: GridRenderers n e -> ListFocused -> WidthDeficit -> GridCtxt -> e -> Widget n
- Brick.Widgets.TabularList.Grid: [$sel:colHdr:GridRenderers] :: GridRenderers n e r -> Maybe (GridColHdr n)
+ Brick.Widgets.TabularList.Grid: [$sel:colHdr:GridRenderers] :: GridRenderers n e -> Maybe (GridColHdr n)
- Brick.Widgets.TabularList.Grid: [$sel:colHdrRowHdr:GridRenderers] :: GridRenderers n e r -> Maybe (ColHdrRowHdr n)
+ Brick.Widgets.TabularList.Grid: [$sel:colHdrRowHdr:GridRenderers] :: GridRenderers n e -> Maybe (ColHdrRowHdr n)
- Brick.Widgets.TabularList.Grid: [$sel:rowHdr:GridRenderers] :: GridRenderers n e r -> Maybe (RowHdr n e r)
+ Brick.Widgets.TabularList.Grid: [$sel:rowHdr:GridRenderers] :: GridRenderers n e -> Maybe (RowHdr n e)
- Brick.Widgets.TabularList.Grid: data GridRenderers n e r
+ Brick.Widgets.TabularList.Grid: data GridRenderers n e
- Brick.Widgets.TabularList.Grid: gridMovePageDown :: Ord n => GridRenderers n e r -> EventM n (GridTabularList n e) ()
+ Brick.Widgets.TabularList.Grid: gridMovePageDown :: Ord n => GridRenderers n e -> EventM n (GridTabularList n e) ()
- Brick.Widgets.TabularList.Grid: gridMovePageUp :: Ord n => GridRenderers n e r -> EventM n (GridTabularList n e) ()
+ Brick.Widgets.TabularList.Grid: gridMovePageUp :: Ord n => GridRenderers n e -> EventM n (GridTabularList n e) ()
- Brick.Widgets.TabularList.Grid: handleGridListEvent :: Ord n => GridRenderers n e r -> Event -> EventM n (GridTabularList n e) ()
+ Brick.Widgets.TabularList.Grid: handleGridListEvent :: Ord n => GridRenderers n e -> Event -> EventM n (GridTabularList n e) ()
- Brick.Widgets.TabularList.Grid: handleGridListEventVi :: Ord n => GridRenderers n e r -> Event -> EventM n (GridTabularList n e) ()
+ Brick.Widgets.TabularList.Grid: handleGridListEventVi :: Ord n => GridRenderers n e -> Event -> EventM n (GridTabularList n e) ()
- Brick.Widgets.TabularList.Grid: renderGridTabularList :: (Ord n, Show n) => GridRenderers n e r -> ListFocused -> GridTabularList n e -> Widget n
+ Brick.Widgets.TabularList.Grid: renderGridTabularList :: (Ord n, Show n) => GridRenderers n e -> ListFocused -> GridTabularList n e -> Widget n
- Brick.Widgets.TabularList.Mixed: MixedRenderers :: (ListFocused -> MixedCtxt -> e -> Widget n) -> Maybe (RowHdr n e r) -> Maybe (MixedColHdr n w) -> Maybe (ColHdrRowHdr n) -> MixedRenderers n e w r
+ Brick.Widgets.TabularList.Mixed: MixedRenderers :: (ListFocused -> MixedCtxt -> e -> Widget n) -> Maybe (RowHdr n e) -> Maybe (MixedColHdr n w) -> Maybe (ColHdrRowHdr n) -> MixedRenderers n e w
- Brick.Widgets.TabularList.Mixed: [$sel:cell:MixedRenderers] :: MixedRenderers n e w r -> ListFocused -> MixedCtxt -> e -> Widget n
+ Brick.Widgets.TabularList.Mixed: [$sel:cell:MixedRenderers] :: MixedRenderers n e w -> ListFocused -> MixedCtxt -> e -> Widget n
- Brick.Widgets.TabularList.Mixed: [$sel:colHdr:MixedRenderers] :: MixedRenderers n e w r -> Maybe (MixedColHdr n w)
+ Brick.Widgets.TabularList.Mixed: [$sel:colHdr:MixedRenderers] :: MixedRenderers n e w -> Maybe (MixedColHdr n w)
- Brick.Widgets.TabularList.Mixed: [$sel:colHdrRowHdr:MixedRenderers] :: MixedRenderers n e w r -> Maybe (ColHdrRowHdr n)
+ Brick.Widgets.TabularList.Mixed: [$sel:colHdrRowHdr:MixedRenderers] :: MixedRenderers n e w -> Maybe (ColHdrRowHdr n)
- Brick.Widgets.TabularList.Mixed: [$sel:rowHdr:MixedRenderers] :: MixedRenderers n e w r -> Maybe (RowHdr n e r)
+ Brick.Widgets.TabularList.Mixed: [$sel:rowHdr:MixedRenderers] :: MixedRenderers n e w -> Maybe (RowHdr n e)
- Brick.Widgets.TabularList.Mixed: data MixedRenderers n e w r
+ Brick.Widgets.TabularList.Mixed: data MixedRenderers n e w
- Brick.Widgets.TabularList.Mixed: renderMixedTabularList :: (Show n, Ord n) => MixedRenderers n e w r -> ListFocused -> MixedTabularList n e w -> Widget n
+ Brick.Widgets.TabularList.Mixed: renderMixedTabularList :: (Show n, Ord n) => MixedRenderers n e w -> ListFocused -> MixedTabularList n e w -> Widget n
- Brick.Widgets.TabularList.Types: RowHdr :: (ListFocused -> WidthDeficit -> RowHdrCtxt -> r -> Widget n) -> (AvailWidth -> [r] -> RowHdrWidth) -> (e -> Index -> r) -> RowHdr n e r
+ Brick.Widgets.TabularList.Types: RowHdr :: (ListFocused -> WidthDeficit -> RowHdrCtxt -> r -> Widget n) -> (AvailWidth -> [r] -> RowHdrWidth) -> (e -> Index -> r) -> RowHdr n e
- Brick.Widgets.TabularList.Types: [$sel:draw:RowHdr] :: RowHdr n e r -> ListFocused -> WidthDeficit -> RowHdrCtxt -> r -> Widget n
+ Brick.Widgets.TabularList.Types: [$sel:draw:RowHdr] :: RowHdr n e -> ListFocused -> WidthDeficit -> RowHdrCtxt -> r -> Widget n
- Brick.Widgets.TabularList.Types: [$sel:toRH:RowHdr] :: RowHdr n e r -> e -> Index -> r
+ Brick.Widgets.TabularList.Types: [$sel:toRH:RowHdr] :: RowHdr n e -> e -> Index -> r
- Brick.Widgets.TabularList.Types: [$sel:width:RowHdr] :: RowHdr n e r -> AvailWidth -> [r] -> RowHdrWidth
+ Brick.Widgets.TabularList.Types: [$sel:width:RowHdr] :: RowHdr n e -> AvailWidth -> [r] -> RowHdrWidth
- Brick.Widgets.TabularList.Types: data RowHdr n e r
+ Brick.Widgets.TabularList.Types: data RowHdr n e

Files

CHANGELOG.md view
@@ -1,5 +1,10 @@ # Revision history for brick-tabular-list +## 2.2.0.0 -- 2023-03-28++* Hide row header type in `RowHdr`.+* Change the name of `ColHdrRowHdr` newtype constructor to improve readability.+ ## 2.1.0.0 -- 2023-03-16  * Wrap `ColHdrRowHdr` in `Maybe` for semantic correctness.
brick-tabular-list.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: brick-tabular-list-version: 2.1.0.0+version: 2.2.0.0  synopsis: Tabular list widgets for brick. 
demo/GridTabularList.hs view
@@ -45,7 +45,7 @@ } deriving Generic  type LibraryList = GridTabularList Name Song-type LibraryRenderers = GridRenderers Name Song Int+type LibraryRenderers = GridRenderers Name Song  songs :: Seq Song songs = S.fromList $@@ -112,7 +112,7 @@ colSelectedAttr :: AttrName colSelectedAttr = attrName "selectedColumn" -rowHdr :: RowHdr Name Song Int+rowHdr :: RowHdr Name Song rowHdr = RowHdr {   draw = \_ (WdthD wd) (RowHdrCtxt (Sel s)) r -> let     attrFn = if s@@ -157,7 +157,7 @@       _ -> fill ' ' , rowHdr = Just rowHdr , colHdr = Just colHdr-, colHdrRowHdr = Just $ CHRH $ \_ _ -> vLimit 1 (fill ' ') <=> hBorder+, colHdrRowHdr = Just $ ColHdrRowHdr $ \_ _ -> vLimit 1 (fill ' ') <=> hBorder }  theList :: LibraryList
demo/MixedTabularList.hs view
@@ -51,7 +51,7 @@ } deriving Generic  type LibraryList = MixedTabularList Name LibraryEntry Widths-type LibraryRenderers = MixedRenderers Name LibraryEntry Widths Int+type LibraryRenderers = MixedRenderers Name LibraryEntry Widths  libraryEntries :: Seq LibraryEntry libraryEntries = let@@ -140,7 +140,7 @@   LibSong _ -> song   LibFolder _ -> folder -rowHdr :: RowHdr Name LibraryEntry Int+rowHdr :: RowHdr Name LibraryEntry rowHdr = RowHdr {   draw = \_ (WdthD wd) (RowHdrCtxt (Sel s)) rh -> let     attrFn = if s@@ -168,7 +168,7 @@           cell = dc         , rowHdr = Just rowHdr         , colHdr = Just colHdr-        , colHdrRowHdr = Just $ CHRH $ \_ _ -> vLimit 1 (fill ' ') <=> hBorder+        , colHdrRowHdr = Just $ ColHdrRowHdr $ \_ _ -> vLimit 1 (fill ' ') <=> hBorder         }       , listWidth = 80       }
src/Brick/Widgets/TabularList.hs view
@@ -10,12 +10,16 @@ -- * Type Variables #TypeVariables# -- -- $TypeVariables--- * @__n__@ is the type of the resource name for the list. This is not for column headers because column headers are+-- Shared type variables+--+-- * n - the type of the resource name for the list. This is not for column headers because column headers are -- above the list. Read [brick user guide](https://github.com/jtdaugherty/brick/blob/master/docs/guide.rst) for more -- details.--- * @__e__@ is the type of list elements which are also called list rows in tabular list widgets.--- * @__w__@ is the type that contains widths per row kind. mixed-tabular-list demo program shows how to utilize it.--- * @__r__@ is the type for row headers. If you don't want to show row headers, set this to @__()__@ or 'Void'.+-- * e - the type of list elements which are also called list rows in tabular list widgets.+--+-- Mixed type variables+--+-- * w - the type that contains widths per row kind. mixed-tabular-list demo program shows how to utilize it.  -- * Rendering #Rendering# --
src/Brick/Widgets/TabularList/Grid.hs view
@@ -94,9 +94,9 @@ -- -- * [Type Variables]("Brick.Widgets.TabularList#g:TypeVariables") -- * [Rendering]("Brick.Widgets.TabularList#g:Rendering")-data GridRenderers n e r = GridRenderers {+data GridRenderers n e = GridRenderers {   cell :: ListFocused -> WidthDeficit -> GridCtxt -> e -> Widget n-, rowHdr :: Maybe (RowHdr n e r)+, rowHdr :: Maybe (RowHdr n e) , colHdr :: Maybe (GridColHdr n) , colHdrRowHdr :: Maybe (ColHdrRowHdr n) } deriving Generic@@ -128,7 +128,7 @@ -- | Width accumulated in the process of traversing columns newtype AccWidth = AccW Int deriving (Eq, Show) -data VisibleColumns =+data VisibleGridColumns =   -- | No column is visible   NoColumn |   -- | Only current column is visible@@ -162,8 +162,8 @@ -- | Calculate visible columns with the width available for columns. It tries to show the current column in the center. -- If it can't show the current column in the center, the first column is shown at the left corner, or the last column -- is shown at the right corner.-visibleColumns :: GridTabularList n e -> AvailWidth -> VisibleColumns-visibleColumns l (AvlW aW) = let+visibleGridColumns :: GridTabularList n e -> AvailWidth -> VisibleGridColumns+visibleGridColumns l (AvlW aW) = let   (Ix curCol) = l ^. #currentColumn   ws = l ^. #widths   in case S.splitAt curCol ws of@@ -222,13 +222,14 @@ -- | Height for tabular list components newtype Height = H Int deriving (Eq, Show) -renderColumns+-- | Render column headers or row columns+renderGridColumns   :: GridTabularList n e-  -> VisibleColumns+  -> VisibleGridColumns   -> (WidthDeficit -> Index -> ColWidth -> Widget n)   -> Height   -> Widget n-renderColumns l vCs dC (H h) = Widget Greedy Fixed $ do+renderGridColumns l vCs dC (H h) = Widget Greedy Fixed $ do   c <- getContext   let cWs = l ^. #widths       Ix curCol = l ^. #currentColumn@@ -246,7 +247,7 @@  -- | Render grid tabular list renderGridTabularList :: (Ord n, Show n)-  => GridRenderers n e r+  => GridRenderers n e   -> ListFocused   -> GridTabularList n e -- ^ The list   -> Widget n@@ -261,21 +262,21 @@         Nothing -> emptyWidget         Just (GridColHdr {draw, height=ColHdrH chh}) -> let           col wd c (ColW w) = sz (w, chh) $ draw (LstFcs f) wd $ GColC c $ Sel (c == curCol)-          chrw = case r ^. #colHdrRowHdr of+          chrh = case r ^. #colHdrRowHdr of             Nothing -> fill ' '-            Just (CHRH chrh) -> chrh (LstFcs f) (WdthD rhwd)-          in sz (rhw, chh) chrw <+> renderColumns l vCs col (H chh)+            Just (ColHdrRowHdr chrh) -> chrh (LstFcs f) (WdthD rhwd)+          in sz (rhw, chh) chrh <+> renderGridColumns l vCs col (H chh)       row vCs i f r = let         col wd c (ColW w) = let gc = GrdCtxt (GRowC (Ix i) (Sel f)) $ GColC c $ Sel (c == curCol)           in sz (w, iH) $ cell (LstFcs f) wd gc r-        in renderColumns l vCs col (H iH)-      lst = let vCs = visibleColumns l (AvlW aW) in+        in renderGridColumns l vCs col (H iH)+      lst = let vCs = visibleGridColumns l (AvlW aW) in         render $ colHdrRow vCs (RowHdrW 0) (WdthD 0) <=> L.renderListWithIndex (row vCs) f l'       hdrLst (RowHdr {draw=drw, width, toRH=tR}) = let         RowHdrW rhw' = width (AvlW aW) $ uncurry (zipWith tR) $ visibleRowIdx l' (AvlH aH)         rhw = min rhw' aW         rhwd = WdthD $ max 0 $ rhw' - aW-        vCs = visibleColumns l $ AvlW $ aW - rhw+        vCs = visibleGridColumns l $ AvlW $ aW - rhw         hdrRow i f r = sz (rhw, iH) (drw (LstFcs f) rhwd (RowHdrCtxt $ Sel f) $ tR r (Ix i)) <+> row vCs i f r         in render $ colHdrRow vCs (RowHdrW rhw) rhwd <=> L.renderListWithIndex hdrRow f l'   maybe lst hdrLst $ r ^. #rowHdr@@ -323,8 +324,8 @@  -- | 'GridRenderers' are needed because if row header renderer doesn't exist, width calculation is affected. gridMovePage :: Ord n-  => GridRenderers n e r-  -> (VisibleColumns -> EventM n (GridTabularList n e) ())+  => GridRenderers n e+  -> (VisibleGridColumns -> EventM n (GridTabularList n e) ())   -> EventM n (GridTabularList n e) () gridMovePage r f = do   l <- get@@ -338,13 +339,13 @@         RowHdrW rhw = case r ^. #rowHdr of           Nothing -> RowHdrW 0           Just (RowHdr {width, toRH}) -> width (AvlW aW) $ uncurry (zipWith toRH) $ visibleRowIdx l' (AvlH aH)-        in f $ visibleColumns l $ AvlW $ aW - rhw+        in f $ visibleGridColumns l $ AvlW $ aW - rhw  -- | Move to the previous page of columns. -- -- 'GridRenderers' are needed because if row header doesn't exist, width calculation is affected. gridMovePageUp :: Ord n-  => GridRenderers n e r -- ^ Renderers+  => GridRenderers n e -- ^ Renderers   -> EventM n (GridTabularList n e) () gridMovePageUp r = gridMovePage r $ \case   NoColumn -> return ()@@ -357,7 +358,7 @@ -- -- 'GridRenderers' are needed because if row header doesn't exist, width calculation is affected. gridMovePageDown :: Ord n-  => GridRenderers n e r -- ^ Renderers+  => GridRenderers n e -- ^ Renderers   -> EventM n (GridTabularList n e) () gridMovePageDown r = gridMovePage r $ \case   NoColumn -> return ()@@ -379,7 +380,7 @@ -- -- 'GridRenderers' are needed because if row header doesn't exist, width calculation is affected. handleGridListEvent :: Ord n-  => GridRenderers n e r -- ^ Renderers+  => GridRenderers n e -- ^ Renderers   -> Event -> EventM n (GridTabularList n e) () handleGridListEvent r e = case e of   EvKey KLeft [] -> modify gridMoveLeft@@ -403,7 +404,7 @@ -- -- 'GridRenderers' are needed because if row header doesn't exist, width calculation is affected. handleGridListEventVi :: Ord n-  => GridRenderers n e r -- ^ Renderers+  => GridRenderers n e -- ^ Renderers   -> Event -> EventM n (GridTabularList n e) () handleGridListEventVi r e = case e of   EvKey (KChar 'h') [] -> modify gridMoveLeft
src/Brick/Widgets/TabularList/Mixed.hs view
@@ -84,9 +84,9 @@ -- -- * [Type Variables]("Brick.Widgets.TabularList#g:TypeVariables") -- * [Rendering]("Brick.Widgets.TabularList#g:Rendering")-data MixedRenderers n e w r = MixedRenderers {+data MixedRenderers n e w = MixedRenderers {   cell :: ListFocused -> MixedCtxt -> e -> Widget n-, rowHdr :: Maybe (RowHdr n e r)+, rowHdr :: Maybe (RowHdr n e) , colHdr :: Maybe (MixedColHdr n w) , colHdrRowHdr :: Maybe (ColHdrRowHdr n) } deriving Generic@@ -124,7 +124,7 @@  -- | Render mixed tabular list. renderMixedTabularList :: (Show n, Ord n)-  => MixedRenderers n e w r -- ^ Renderers+  => MixedRenderers n e w -- ^ Renderers   -> ListFocused   -> MixedTabularList n e w -- ^ The list   -> Widget n@@ -139,10 +139,10 @@         Nothing -> emptyWidget         Just (MixedColHdr {draw, widths, height=ColHdrH chh}) -> let           col ci (ColW w) = sz (w, chh) $ draw (LstFcs f) (MColC ci)-          chrw = case r ^. #colHdrRowHdr of+          chrh = case r ^. #colHdrRowHdr of             Nothing -> fill ' '-            Just (CHRH chrw) -> chrw (LstFcs f) (WdthD rhwd)-          in sz (rhw, chh) chrw <+> hBox (zipWith col [Ix 0..] $ widths wprk)+            Just (ColHdrRowHdr chrh) -> chrh (LstFcs f) (WdthD rhwd)+          in sz (rhw, chh) chrh <+> hBox (zipWith col [Ix 0..] $ widths wprk)       row wprk i f r = let         col ci (ColW w) = sz (w, iH) $ cell (LstFcs f) (MxdCtxt (MRowC (Ix i) (Sel f)) $ MColC ci) r         in hBox $ zipWith col [Ix 0..] $ wpr wprk r
src/Brick/Widgets/TabularList/Types.hs view
@@ -2,6 +2,7 @@ {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE NoFieldSelectors #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE ExistentialQuantification #-} -- | Types shared by tabular list widgets. -- -- You don't have to import this module because modules for tabular list widgets re-export this module.@@ -83,16 +84,20 @@ -- -- * [Type Variables]("Brick.Widgets.TabularList#g:TypeVariables") -- * [Rendering]("Brick.Widgets.TabularList#g:Rendering")-data RowHdr n e r = RowHdr {+--+-- Type Variables+--+-- * r - the type of row header+data RowHdr n e = forall r. RowHdr {   draw :: ListFocused -> WidthDeficit -> RowHdrCtxt -> r -> Widget n   -- | Calculate row header width from visible row headers and the width available for a list row. , width :: AvailWidth -> [r] -> RowHdrWidth   -- | Get a row header from a list row and row index. , toRH :: e -> Index -> r-} deriving Generic+}  -- | The renderer for column header row header. -- -- If row headers and column headers exist and 'ColHdrRowHdr' doesn't exist, then column header row header is filled -- with empty space. 'ColHdrRowHdr' merely allows you to customize column header row header.-newtype ColHdrRowHdr n = CHRH (ListFocused -> WidthDeficit -> Widget n) deriving Generic+newtype ColHdrRowHdr n = ColHdrRowHdr (ListFocused -> WidthDeficit -> Widget n) deriving Generic