brick 0.65.1 → 0.66
raw patch · 6 files changed
+66/−15 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Brick.Main: makeVisible :: Ord n => n -> EventM n ()
- Brick.Types: availHeightL :: forall n_awO6. Lens' (Context n_awO6) Int
+ Brick.Types: availHeightL :: forall n_awO8. Lens' (Context n_awO8) Int
- Brick.Types: availWidthL :: forall n_awO6. Lens' (Context n_awO6) Int
+ Brick.Types: availWidthL :: forall n_awO8. Lens' (Context n_awO8) Int
- Brick.Types: bordersL :: forall n_awOa. Lens' (Result n_awOa) (BorderMap DynBorder)
+ Brick.Types: bordersL :: forall n_awOc. Lens' (Result n_awOc) (BorderMap DynBorder)
- Brick.Types: ctxAttrMapL :: forall n_awO6. Lens' (Context n_awO6) AttrMap
+ Brick.Types: ctxAttrMapL :: forall n_awO8. Lens' (Context n_awO8) AttrMap
- Brick.Types: ctxAttrNameL :: forall n_awO6. Lens' (Context n_awO6) AttrName
+ Brick.Types: ctxAttrNameL :: forall n_awO8. Lens' (Context n_awO8) AttrName
- Brick.Types: ctxBorderStyleL :: forall n_awO6. Lens' (Context n_awO6) BorderStyle
+ Brick.Types: ctxBorderStyleL :: forall n_awO8. Lens' (Context n_awO8) BorderStyle
- Brick.Types: ctxDynBordersL :: forall n_awO6. Lens' (Context n_awO6) Bool
+ Brick.Types: ctxDynBordersL :: forall n_awO8. Lens' (Context n_awO8) Bool
- Brick.Types: ctxHScrollBarOrientationL :: forall n_awO6. Lens' (Context n_awO6) (Maybe HScrollBarOrientation)
+ Brick.Types: ctxHScrollBarOrientationL :: forall n_awO8. Lens' (Context n_awO8) (Maybe HScrollBarOrientation)
- Brick.Types: ctxHScrollBarRendererL :: forall n_awO6. Lens' (Context n_awO6) (Maybe (ScrollbarRenderer n_awO6))
+ Brick.Types: ctxHScrollBarRendererL :: forall n_awO8. Lens' (Context n_awO8) (Maybe (ScrollbarRenderer n_awO8))
- Brick.Types: ctxVScrollBarOrientationL :: forall n_awO6. Lens' (Context n_awO6) (Maybe VScrollBarOrientation)
+ Brick.Types: ctxVScrollBarOrientationL :: forall n_awO8. Lens' (Context n_awO8) (Maybe VScrollBarOrientation)
- Brick.Types: ctxVScrollBarRendererL :: forall n_awO6. Lens' (Context n_awO6) (Maybe (ScrollbarRenderer n_awO6))
+ Brick.Types: ctxVScrollBarRendererL :: forall n_awO8. Lens' (Context n_awO8) (Maybe (ScrollbarRenderer n_awO8))
- Brick.Types: cursorLocationL :: forall n_awOb. Lens' (CursorLocation n_awOb) Location
+ Brick.Types: cursorLocationL :: forall n_awOd. Lens' (CursorLocation n_awOd) Location
- Brick.Types: cursorLocationNameL :: forall n_awOb n_ayUk. Lens (CursorLocation n_awOb) (CursorLocation n_ayUk) (Maybe n_awOb) (Maybe n_ayUk)
+ Brick.Types: cursorLocationNameL :: forall n_awOd n_ayWg. Lens (CursorLocation n_awOd) (CursorLocation n_ayWg) (Maybe n_awOd) (Maybe n_ayWg)
- Brick.Types: cursorsL :: forall n_awOa. Lens' (Result n_awOa) [CursorLocation n_awOa]
+ Brick.Types: cursorsL :: forall n_awOc. Lens' (Result n_awOc) [CursorLocation n_awOc]
- Brick.Types: extentsL :: forall n_awOa. Lens' (Result n_awOa) [Extent n_awOa]
+ Brick.Types: extentsL :: forall n_awOc. Lens' (Result n_awOc) [Extent n_awOc]
- Brick.Types: imageL :: forall n_awOa. Lens' (Result n_awOa) Image
+ Brick.Types: imageL :: forall n_awOc. Lens' (Result n_awOc) Image
- Brick.Types: visibilityRequestsL :: forall n_awOa. Lens' (Result n_awOa) [VisibilityRequest]
+ Brick.Types: visibilityRequestsL :: forall n_awOc. Lens' (Result n_awOc) [VisibilityRequest]
- Brick.Types: windowHeightL :: forall n_awO6. Lens' (Context n_awO6) Int
+ Brick.Types: windowHeightL :: forall n_awO8. Lens' (Context n_awO8) Int
- Brick.Types: windowWidthL :: forall n_awO6. Lens' (Context n_awO6) Int
+ Brick.Types: windowWidthL :: forall n_awO8. Lens' (Context n_awO8) Int
- Brick.Widgets.Core: clickable :: n -> Widget n -> Widget n
+ Brick.Widgets.Core: clickable :: Ord n => n -> Widget n -> Widget n
- Brick.Widgets.Core: horizontalScrollbar :: ScrollbarRenderer n -> n -> Maybe (ClickableScrollbarElement -> n -> n) -> Bool -> Int -> Int -> Int -> Widget n
+ Brick.Widgets.Core: horizontalScrollbar :: Ord n => ScrollbarRenderer n -> n -> Maybe (ClickableScrollbarElement -> n -> n) -> Bool -> Int -> Int -> Int -> Widget n
- Brick.Widgets.Core: reportExtent :: n -> Widget n -> Widget n
+ Brick.Widgets.Core: reportExtent :: Ord n => n -> Widget n -> Widget n
- Brick.Widgets.Core: verticalScrollbar :: ScrollbarRenderer n -> n -> Maybe (ClickableScrollbarElement -> n -> n) -> Bool -> Int -> Int -> Int -> Widget n
+ Brick.Widgets.Core: verticalScrollbar :: Ord n => ScrollbarRenderer n -> n -> Maybe (ClickableScrollbarElement -> n -> n) -> Bool -> Int -> Int -> Int -> Widget n
- Brick.Widgets.Dialog: dialogButtonsL :: forall a_a1eEt a_a1eF7. Lens (Dialog a_a1eEt) (Dialog a_a1eF7) [(String, a_a1eEt)] [(String, a_a1eF7)]
+ Brick.Widgets.Dialog: dialogButtonsL :: forall a_a1f64 a_a1f6I. Lens (Dialog a_a1f64) (Dialog a_a1f6I) [(String, a_a1f64)] [(String, a_a1f6I)]
- Brick.Widgets.Dialog: dialogSelectedIndexL :: forall a_a1eEt. Lens' (Dialog a_a1eEt) (Maybe Int)
+ Brick.Widgets.Dialog: dialogSelectedIndexL :: forall a_a1f64. Lens' (Dialog a_a1f64) (Maybe Int)
- Brick.Widgets.Dialog: dialogTitleL :: forall a_a1eEt. Lens' (Dialog a_a1eEt) (Maybe String)
+ Brick.Widgets.Dialog: dialogTitleL :: forall a_a1f64. Lens' (Dialog a_a1f64) (Maybe String)
- Brick.Widgets.Dialog: dialogWidthL :: forall a_a1eEt. Lens' (Dialog a_a1eEt) Int
+ Brick.Widgets.Dialog: dialogWidthL :: forall a_a1f64. Lens' (Dialog a_a1f64) Int
- Brick.Widgets.Edit: editContentsL :: forall t_a18UY n_a18UZ t_a18VD. Lens (Editor t_a18UY n_a18UZ) (Editor t_a18VD n_a18UZ) (TextZipper t_a18UY) (TextZipper t_a18VD)
+ Brick.Widgets.Edit: editContentsL :: forall t_a19mz n_a19mA t_a19ne. Lens (Editor t_a19mz n_a19mA) (Editor t_a19ne n_a19mA) (TextZipper t_a19mz) (TextZipper t_a19ne)
- Brick.Widgets.FileBrowser: fileBrowserEntryFilterL :: forall n_a1oSY. Lens' (FileBrowser n_a1oSY) (Maybe (FileInfo -> Bool))
+ Brick.Widgets.FileBrowser: fileBrowserEntryFilterL :: forall n_a1ptx. Lens' (FileBrowser n_a1ptx) (Maybe (FileInfo -> Bool))
- Brick.Widgets.FileBrowser: fileBrowserSelectableL :: forall n_a1oSY. Lens' (FileBrowser n_a1oSY) (FileInfo -> Bool)
+ Brick.Widgets.FileBrowser: fileBrowserSelectableL :: forall n_a1ptx. Lens' (FileBrowser n_a1ptx) (FileInfo -> Bool)
- Brick.Widgets.List: listElementsL :: forall n_a1jH3 t_a1jH4 e_a1jH5 t_a1jVa e_a1jVb. Lens (GenericList n_a1jH3 t_a1jH4 e_a1jH5) (GenericList n_a1jH3 t_a1jVa e_a1jVb) (t_a1jH4 e_a1jH5) (t_a1jVa e_a1jVb)
+ Brick.Widgets.List: listElementsL :: forall n_a1khC t_a1khD e_a1khE t_a1kvJ e_a1kvK. Lens (GenericList n_a1khC t_a1khD e_a1khE) (GenericList n_a1khC t_a1kvJ e_a1kvK) (t_a1khD e_a1khE) (t_a1kvJ e_a1kvK)
- Brick.Widgets.List: listItemHeightL :: forall n_a1jH3 t_a1jH4 e_a1jH5. Lens' (GenericList n_a1jH3 t_a1jH4 e_a1jH5) Int
+ Brick.Widgets.List: listItemHeightL :: forall n_a1khC t_a1khD e_a1khE. Lens' (GenericList n_a1khC t_a1khD e_a1khE) Int
- Brick.Widgets.List: listNameL :: forall n_a1jH3 t_a1jH4 e_a1jH5 n_a1jVc. Lens (GenericList n_a1jH3 t_a1jH4 e_a1jH5) (GenericList n_a1jVc t_a1jH4 e_a1jH5) n_a1jH3 n_a1jVc
+ Brick.Widgets.List: listNameL :: forall n_a1khC t_a1khD e_a1khE n_a1kvL. Lens (GenericList n_a1khC t_a1khD e_a1khE) (GenericList n_a1kvL t_a1khD e_a1khE) n_a1khC n_a1kvL
- Brick.Widgets.List: listSelectedL :: forall n_a1jH3 t_a1jH4 e_a1jH5. Lens' (GenericList n_a1jH3 t_a1jH4 e_a1jH5) (Maybe Int)
+ Brick.Widgets.List: listSelectedL :: forall n_a1khC t_a1khD e_a1khE. Lens' (GenericList n_a1khC t_a1khD e_a1khE) (Maybe Int)
Files
- CHANGELOG.md +16/−0
- brick.cabal +1/−1
- src/Brick/Forms.hs +2/−2
- src/Brick/Main.hs +14/−4
- src/Brick/Types/Internal.hs +3/−0
- src/Brick/Widgets/Core.hs +30/−8
CHANGELOG.md view
@@ -2,6 +2,22 @@ Brick changelog --------------- +0.66+----++New features:+ * Added `Brick.Main.makeVisible`, a function to requeste+ visible regions from `EventM`. This, together with+ `Brick.Widgets.Core.reportExtent`, can be used to request that a+ viewport be scrolled to make a specified named region visible on+ the next redraw. The region must be known to the renderer with+ `reportExtent` (or something that calls it, like `clickable`). Due to+ the `Ord` constraint on some of the API calls required to implement+ this, an `Ord` constraint on the resource name type (`n`) got+ propagated to various places in the API. But that shouldn't present+ a problem since other fundamental API calls already required that+ instance.+ 0.65.1 ------
brick.cabal view
@@ -1,5 +1,5 @@ name: brick-version: 0.65.1+version: 0.66 synopsis: A declarative terminal user interface library description: Write terminal user interfaces (TUIs) painlessly with 'brick'! You
src/Brick/Forms.hs view
@@ -343,7 +343,7 @@ , formFieldConcat = vBox } -renderCheckbox :: Char -> Char -> Char -> T.Text -> n -> Bool -> Bool -> Widget n+renderCheckbox :: (Ord n) => Char -> Char -> Char -> T.Text -> n -> Bool -> Bool -> Widget n renderCheckbox lb check rb label n foc val = let addAttr = if foc then withDefAttr focusedFormInputAttr else id csr = if foc then putCursor n (Location (1,0)) else id@@ -469,7 +469,7 @@ , formFieldConcat = vBox } -renderRadio :: (Eq a) => Char -> Char -> Char -> a -> n -> T.Text -> Bool -> a -> Widget n+renderRadio :: (Eq a, Ord n) => Char -> Char -> Char -> a -> n -> T.Text -> Bool -> a -> Widget n renderRadio lb check rb val name label foc cur = let addAttr = if foc then withDefAttr focusedFormInputAttr
src/Brick/Main.hs view
@@ -13,6 +13,7 @@ , continueWithoutRedraw , halt , suspendAndResume+ , makeVisible , lookupViewport , lookupExtent , findClickedExtents@@ -275,12 +276,12 @@ newVty <- buildVty run newVty (newRS { renderCache = mempty }) newAppState brickChan - let emptyES = ES [] mempty- emptyRS = RS M.empty mempty S.empty mempty mempty+ let emptyES = ES [] mempty mempty+ emptyRS = RS M.empty mempty S.empty mempty mempty mempty eventRO = EventRO M.empty initialVty mempty emptyRS (st, eState) <- runStateT (runReaderT (runEventM (appStartEvent app initialAppState)) eventRO) emptyES- let initialRS = RS M.empty (esScrollRequests eState) S.empty mempty []+ let initialRS = RS M.empty (esScrollRequests eState) S.empty mempty [] (requestedVisibleNames eState) brickChan <- newBChan 20 run initialVty initialRS st brickChan @@ -364,7 +365,7 @@ _ -> return (e, firstRS, exts) _ -> return (e, firstRS, exts) - let emptyES = ES [] mempty+ let emptyES = ES [] mempty mempty eventRO = EventRO (viewportMap nextRS) vty nextExts nextRS (next, eState) <- runStateT (runReaderT (runEventM (appHandleEvent app appState e'))@@ -373,6 +374,7 @@ , nextRS { rsScrollRequests = esScrollRequests eState , renderCache = applyInvalidations (cacheInvalidateRequests eState) $ renderCache nextRS+ , requestedVisibleNames_ = requestedVisibleNames eState } , nextExts )@@ -579,3 +581,11 @@ -- to the user. suspendAndResume :: IO s -> EventM n (Next s) suspendAndResume = return . SuspendAndResume++-- | Request that the specified UI element be made visible on the+-- next rendering. This is provided to allow event handlers to make+-- visibility requests in the same way that the 'visible' function does+-- at rendering time.+makeVisible :: (Ord n) => n -> EventM n ()+makeVisible n = EventM $ do+ lift $ modify (\s -> s { requestedVisibleNames = S.insert n $ requestedVisibleNames s })
src/Brick/Types/Internal.hs view
@@ -66,6 +66,7 @@ , clickableNamesL , renderCacheL , observedNamesL+ , requestedVisibleNames_L , vpSize , vpLeft , vpTop@@ -138,6 +139,7 @@ , observedNames :: !(S.Set n) , renderCache :: !(M.Map n ([n], Result n)) , clickableNames :: ![n]+ , requestedVisibleNames_ :: !(S.Set n) } deriving (Read, Show, Generic, NFData) -- | The type of the rendering monad. This monad is used by the@@ -222,6 +224,7 @@ data EventState n = ES { esScrollRequests :: [(n, ScrollRequest)] , cacheInvalidateRequests :: S.Set (CacheInvalidateRequest n)+ , requestedVisibleNames :: S.Set n } -- | An extent of a named area: its size, location, and origin.
src/Brick/Widgets/Core.hs view
@@ -225,7 +225,13 @@ -- | Render the specified widget and record its rendering extent using -- the specified name (see also 'lookupExtent').-reportExtent :: n -> Widget n -> Widget n+--+-- This function is the counterpart to 'makeVisible'; any visibility+-- requests made with 'makeVisible' must have a corresponding+-- 'reportExtent' in order to work. The 'clickable' function will also+-- work for this purpose to tell the renderer about the clickable+-- region.+reportExtent :: (Ord n) => n -> Widget n -> Widget n reportExtent n p = Widget (hSize p) (vSize p) $ do result <- render p@@ -233,10 +239,21 @@ sz = ( result^.imageL.to V.imageWidth , result^.imageL.to V.imageHeight )- return $ result & extentsL %~ (ext:)+ -- If the reported extent also has a visibility request+ -- from EventM via makeVisible, add a visibility request to+ -- the render state so this gets scrolled into view by any+ -- containing viewport.+ vReqs <- use requestedVisibleNames_L+ let addVisReq = if sz^._1 > 0 && sz^._2 > 0 && n `S.member` vReqs+ then visibilityRequestsL %~ (VR (Location (0, 0)) sz :)+ else id+ return $ addVisReq $ result & extentsL %~ (ext:) -- | Request mouse click events on the specified widget.-clickable :: n -> Widget n -> Widget n+--+-- Regions used with 'clickable' can be scrolled into view with+-- 'makeVisible'.+clickable :: (Ord n) => n -> Widget n -> Widget n clickable n p = Widget (hSize p) (vSize p) $ do clickableNamesL %= (n:)@@ -1400,7 +1417,8 @@ scrollbarHandleAttr :: AttrName scrollbarHandleAttr = scrollbarAttr <> "handle" -maybeClick :: n+maybeClick :: (Ord n)+ => n -> Maybe (ClickableScrollbarElement -> n -> n) -> ClickableScrollbarElement -> Widget n@@ -1416,7 +1434,8 @@ -- @withVScrollBarRenderer@. This is exposed so that if you want to -- render a scroll bar of your own, you can do so outside the @viewport@ -- context.-verticalScrollbar :: ScrollbarRenderer n+verticalScrollbar :: (Ord n)+ => ScrollbarRenderer n -- ^ The renderer to use. -> n -- ^ The viewport name associated with this scroll@@ -1442,7 +1461,8 @@ hLimit 1 $ withDefAttr scrollbarHandleAttr $ renderScrollbarHandleAfter vsRenderer ] -verticalScrollbar' :: ScrollbarRenderer n+verticalScrollbar' :: (Ord n)+ => ScrollbarRenderer n -- ^ The renderer to use. -> n -- ^ The viewport name associated with this scroll@@ -1512,7 +1532,8 @@ -- @withHScrollBarRenderer@. This is exposed so that if you want to -- render a scroll bar of your own, you can do so outside the @viewport@ -- context.-horizontalScrollbar :: ScrollbarRenderer n+horizontalScrollbar :: (Ord n)+ => ScrollbarRenderer n -- ^ The renderer to use. -> n -- ^ The viewport name associated with this scroll@@ -1539,7 +1560,8 @@ vLimit 1 $ withDefAttr scrollbarHandleAttr $ renderScrollbarHandleAfter hsRenderer ] -horizontalScrollbar' :: ScrollbarRenderer n+horizontalScrollbar' :: (Ord n)+ => ScrollbarRenderer n -- ^ The renderer to use. -> n -- ^ The viewport name associated with this scroll