packages feed

brick 0.36.3 → 0.37

raw patch · 4 files changed

+52/−8 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Brick.Widgets.List: renderListWithIndex :: (Ord n, Show n) => (Int -> Bool -> e -> Widget n) -> Bool -> List n e -> Widget n
- Brick.BorderMap: eBottomL :: forall a_aebK. Lens' (Edges a_aebK) a_aebK
+ Brick.BorderMap: eBottomL :: forall a_aebT. Lens' (Edges a_aebT) a_aebT
- Brick.BorderMap: eLeftL :: forall a_aebK. Lens' (Edges a_aebK) a_aebK
+ Brick.BorderMap: eLeftL :: forall a_aebT. Lens' (Edges a_aebT) a_aebT
- Brick.BorderMap: eRightL :: forall a_aebK. Lens' (Edges a_aebK) a_aebK
+ Brick.BorderMap: eRightL :: forall a_aebT. Lens' (Edges a_aebT) a_aebT
- Brick.BorderMap: eTopL :: forall a_aebK. Lens' (Edges a_aebK) a_aebK
+ Brick.BorderMap: eTopL :: forall a_aebT. Lens' (Edges a_aebT) a_aebT
- Brick.Types: bordersL :: forall n_aBPo. Lens' (Result n_aBPo) (BorderMap DynBorder)
+ Brick.Types: bordersL :: forall n_aBPx. Lens' (Result n_aBPx) (BorderMap DynBorder)
- Brick.Types: cursorLocationL :: forall n_aBdm. Lens' (CursorLocation n_aBdm) Location
+ Brick.Types: cursorLocationL :: forall n_aBdv. Lens' (CursorLocation n_aBdv) Location
- Brick.Types: cursorLocationNameL :: forall n_aBdm n_aCbj. Lens (CursorLocation n_aBdm) (CursorLocation n_aCbj) (Maybe n_aBdm) (Maybe n_aCbj)
+ Brick.Types: cursorLocationNameL :: forall n_aBdv n_aCbs. Lens (CursorLocation n_aBdv) (CursorLocation n_aCbs) (Maybe n_aBdv) (Maybe n_aCbs)
- Brick.Types: cursorsL :: forall n_aBPo. Lens' (Result n_aBPo) [CursorLocation n_aBPo]
+ Brick.Types: cursorsL :: forall n_aBPx. Lens' (Result n_aBPx) [CursorLocation n_aBPx]
- Brick.Types: eBottomL :: forall a_aebK. Lens' (Edges a_aebK) a_aebK
+ Brick.Types: eBottomL :: forall a_aebT. Lens' (Edges a_aebT) a_aebT
- Brick.Types: eLeftL :: forall a_aebK. Lens' (Edges a_aebK) a_aebK
+ Brick.Types: eLeftL :: forall a_aebT. Lens' (Edges a_aebT) a_aebT
- Brick.Types: eRightL :: forall a_aebK. Lens' (Edges a_aebK) a_aebK
+ Brick.Types: eRightL :: forall a_aebT. Lens' (Edges a_aebT) a_aebT
- Brick.Types: eTopL :: forall a_aebK. Lens' (Edges a_aebK) a_aebK
+ Brick.Types: eTopL :: forall a_aebT. Lens' (Edges a_aebT) a_aebT
- Brick.Types: extentsL :: forall n_aBPo. Lens' (Result n_aBPo) [Extent n_aBPo]
+ Brick.Types: extentsL :: forall n_aBPx. Lens' (Result n_aBPx) [Extent n_aBPx]
- Brick.Types: imageL :: forall n_aBPo. Lens' (Result n_aBPo) Image
+ Brick.Types: imageL :: forall n_aBPx. Lens' (Result n_aBPx) Image
- Brick.Types: visibilityRequestsL :: forall n_aBPo. Lens' (Result n_aBPo) [VisibilityRequest]
+ Brick.Types: visibilityRequestsL :: forall n_aBPx. Lens' (Result n_aBPx) [VisibilityRequest]
- Brick.Widgets.Dialog: dialogButtonsL :: forall a_a14AW a_a14BC. Lens (Dialog a_a14AW) (Dialog a_a14BC) [(String, a_a14AW)] [(String, a_a14BC)]
+ Brick.Widgets.Dialog: dialogButtonsL :: forall a_a14B5 a_a14BL. Lens (Dialog a_a14B5) (Dialog a_a14BL) [(String, a_a14B5)] [(String, a_a14BL)]
- Brick.Widgets.Dialog: dialogSelectedIndexL :: forall a_a14AW. Lens' (Dialog a_a14AW) (Maybe Int)
+ Brick.Widgets.Dialog: dialogSelectedIndexL :: forall a_a14B5. Lens' (Dialog a_a14B5) (Maybe Int)
- Brick.Widgets.Dialog: dialogTitleL :: forall a_a14AW. Lens' (Dialog a_a14AW) (Maybe String)
+ Brick.Widgets.Dialog: dialogTitleL :: forall a_a14B5. Lens' (Dialog a_a14B5) (Maybe String)
- Brick.Widgets.Dialog: dialogWidthL :: forall a_a14AW. Lens' (Dialog a_a14AW) Int
+ Brick.Widgets.Dialog: dialogWidthL :: forall a_a14B5. Lens' (Dialog a_a14B5) Int
- Brick.Widgets.Edit: editContentsL :: forall t_a107w n_a107x t_a108e. Lens (Editor t_a107w n_a107x) (Editor t_a108e n_a107x) (TextZipper t_a107w) (TextZipper t_a108e)
+ Brick.Widgets.Edit: editContentsL :: forall t_a107F n_a107G t_a108n. Lens (Editor t_a107F n_a107G) (Editor t_a108n n_a107G) (TextZipper t_a107F) (TextZipper t_a108n)
- Brick.Widgets.List: listElementsL :: forall n_a19qR e_a19qS e_a19B4. Lens (List n_a19qR e_a19qS) (List n_a19qR e_a19B4) (Vector e_a19qS) (Vector e_a19B4)
+ Brick.Widgets.List: listElementsL :: forall n_a19r0 e_a19r1 e_a19Bd. Lens (List n_a19r0 e_a19r1) (List n_a19r0 e_a19Bd) (Vector e_a19r1) (Vector e_a19Bd)
- Brick.Widgets.List: listItemHeightL :: forall n_a19qR e_a19qS. Lens' (List n_a19qR e_a19qS) Int
+ Brick.Widgets.List: listItemHeightL :: forall n_a19r0 e_a19r1. Lens' (List n_a19r0 e_a19r1) Int
- Brick.Widgets.List: listNameL :: forall n_a19qR e_a19qS n_a19B5. Lens (List n_a19qR e_a19qS) (List n_a19B5 e_a19qS) n_a19qR n_a19B5
+ Brick.Widgets.List: listNameL :: forall n_a19r0 e_a19r1 n_a19Be. Lens (List n_a19r0 e_a19r1) (List n_a19Be e_a19r1) n_a19r0 n_a19Be
- Brick.Widgets.List: listSelectedL :: forall n_a19qR e_a19qS. Lens' (List n_a19qR e_a19qS) (Maybe Int)
+ Brick.Widgets.List: listSelectedL :: forall n_a19r0 e_a19r1. Lens' (List n_a19r0 e_a19r1) (Maybe Int)

Files

CHANGELOG.md view
@@ -2,6 +2,19 @@ Brick changelog --------------- +0.37+----++Behavior changes:+ * `listMoveBy` now automatically moves to the first or last position+   in the list if called when the list is non-empty but has no selected+   element (thanks Philip Kamenarsky)++API changes:+ * Added `Brick.Widgets.List.renderListWithIndex` that passes+   the index of each element to the item rendering function (thanks+   liam@magicseaweed.com)+ 0.36.3 ------ 
README.md view
@@ -166,3 +166,8 @@    codebase.  - Please adjust or provide Haddock and/or user guide documentation    relevant to any changes you make.+ - New commits should be `-Wall` clean.+ - Please do NOT include package version changes in your patches.+   Package version changes are only done at release time when the full+   scope of a release's changes can be evaluated to determine the+   appropriate version change.
brick.cabal view
@@ -1,5 +1,5 @@ name:                brick-version:             0.36.3+version:             0.37 synopsis:            A declarative terminal user interface library description:   Write terminal applications painlessly with 'brick'! You write an
src/Brick/Widgets/List.hs view
@@ -16,6 +16,7 @@    -- * Rendering a list   , renderList+  , renderListWithIndex    -- * Handling events   , handleListEvent@@ -180,11 +181,25 @@            -- ^ The List to be rendered            -> Widget n            -- ^ rendered widget-renderList drawElem foc l =+renderList drawElem = renderListWithIndex $ const drawElem++-- | Like 'renderList', except the render function is also provided+-- with the index of each element.+renderListWithIndex :: (Ord n, Show n)+           => (Int -> Bool -> e -> Widget n)+           -- ^ Rendering function, taking index, and True for the+           -- selected element+           -> Bool+           -- ^ Whether the list has focus+           -> List n e+           -- ^ The List to be rendered+           -> Widget n+           -- ^ rendered widget+renderListWithIndex drawElem foc l =     withDefAttr listAttr $     drawListElements foc l drawElem -drawListElements :: (Ord n, Show n) => Bool -> List n e -> (Bool -> e -> Widget n) -> Widget n+drawListElements :: (Ord n, Show n) => Bool -> List n e -> (Int -> Bool -> e -> Widget n) -> Widget n drawListElements foc l drawElem =     Widget Greedy Greedy $ do         c <- getContext@@ -214,8 +229,9 @@             off = start * (l^.listItemHeightL)              drawnElements = flip V.imap es $ \i e ->-                let isSelected = Just (i + start) == l^.listSelectedL-                    elemWidget = drawElem isSelected e+                let j = i + start+                    isSelected = Just j == l^.listSelectedL+                    elemWidget = drawElem j isSelected e                     selItemAttr = if foc                                   then withDefAttr listSelectedFocusedAttr                                   else withDefAttr listSelectedAttr@@ -306,11 +322,21 @@           in             return $ listMoveBy nElems theList --- | Move the list selected index by the specified amount, subject to--- validation.+-- | Move the list selected index. If the index is `Just x`, adjust by the+-- specified amount; if it is `Nothing` (i.e. there is no selection) and the+-- direction is positive, set to `Just 0` (first element), otherwise set to+-- `Just (length - 1)` (last element). Subject to validation. listMoveBy :: Int -> List n e -> List n e listMoveBy amt l =-    let newSel = clamp 0 (V.length (l^.listElementsL) - 1) <$> (amt +) <$> (l^.listSelectedL)+    let current = case l^.listSelectedL of+          Nothing+            | amt > 0 -> Just 0+            | otherwise -> Just (V.length (l^.listElementsL) - 1)+          cur -> cur+        clamp' a b c+          | a <= b = Just (clamp a b c)+          | otherwise = Nothing+        newSel = clamp' 0 (V.length (l^.listElementsL) - 1) =<< (amt +) <$> current     in l & listSelectedL .~ newSel  -- | Set the selected index for a list to the specified index, subject