brick 2.4 → 2.5
raw patch · 6 files changed
+90/−19 lines, 6 filesdep ~microlensPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: microlens
API changes (from Hackage documentation)
+ Brick.Widgets.ProgressBar: customProgressBar :: Char -> Char -> Maybe String -> Float -> Widget n
- Brick.Widgets.Dialog: dialogButtonsL :: forall a_a1rz7 n_a1rz8 a_a1rA5. Lens (Dialog a_a1rz7 n_a1rz8) (Dialog a_a1rA5 n_a1rz8) [(String, n_a1rz8, a_a1rz7)] [(String, n_a1rz8, a_a1rA5)]
+ Brick.Widgets.Dialog: dialogButtonsL :: forall a_a1rAx n_a1rAy a_a1rBv. Lens (Dialog a_a1rAx n_a1rAy) (Dialog a_a1rBv n_a1rAy) [(String, n_a1rAy, a_a1rAx)] [(String, n_a1rAy, a_a1rBv)]
- Brick.Widgets.Dialog: dialogTitleL :: forall a_a1rz7 n_a1rz8. Lens' (Dialog a_a1rz7 n_a1rz8) (Maybe (Widget n_a1rz8))
+ Brick.Widgets.Dialog: dialogTitleL :: forall a_a1rAx n_a1rAy. Lens' (Dialog a_a1rAx n_a1rAy) (Maybe (Widget n_a1rAy))
- Brick.Widgets.Dialog: dialogWidthL :: forall a_a1rz7 n_a1rz8. Lens' (Dialog a_a1rz7 n_a1rz8) Int
+ Brick.Widgets.Dialog: dialogWidthL :: forall a_a1rAx n_a1rAy. Lens' (Dialog a_a1rAx n_a1rAy) Int
- Brick.Widgets.Edit: editContentsL :: forall t_a1jHK n_a1jHL t_a1jIv. Lens (Editor t_a1jHK n_a1jHL) (Editor t_a1jIv n_a1jHL) (TextZipper t_a1jHK) (TextZipper t_a1jIv)
+ Brick.Widgets.Edit: editContentsL :: forall t_a1jJa n_a1jJb t_a1jJV. Lens (Editor t_a1jJa n_a1jJb) (Editor t_a1jJV n_a1jJb) (TextZipper t_a1jJa) (TextZipper t_a1jJV)
- Brick.Widgets.FileBrowser: fileBrowserEntriesG :: forall n_a1Ehh. SimpleGetter (FileBrowser n_a1Ehh) (List n_a1Ehh FileInfo)
+ Brick.Widgets.FileBrowser: fileBrowserEntriesG :: forall n_a1EiH. SimpleGetter (FileBrowser n_a1EiH) (List n_a1EiH FileInfo)
- Brick.Widgets.FileBrowser: fileBrowserEntryFilterG :: forall n_a1Ehh. SimpleGetter (FileBrowser n_a1Ehh) (Maybe (FileInfo -> Bool))
+ Brick.Widgets.FileBrowser: fileBrowserEntryFilterG :: forall n_a1EiH. SimpleGetter (FileBrowser n_a1EiH) (Maybe (FileInfo -> Bool))
- Brick.Widgets.FileBrowser: fileBrowserExceptionG :: forall n_a1Ehh. SimpleGetter (FileBrowser n_a1Ehh) (Maybe IOException)
+ Brick.Widgets.FileBrowser: fileBrowserExceptionG :: forall n_a1EiH. SimpleGetter (FileBrowser n_a1EiH) (Maybe IOException)
- Brick.Widgets.FileBrowser: fileBrowserLatestResultsG :: forall n_a1Ehh. SimpleGetter (FileBrowser n_a1Ehh) [FileInfo]
+ Brick.Widgets.FileBrowser: fileBrowserLatestResultsG :: forall n_a1EiH. SimpleGetter (FileBrowser n_a1EiH) [FileInfo]
- Brick.Widgets.FileBrowser: fileBrowserNameG :: forall n_a1Ehh. SimpleGetter (FileBrowser n_a1Ehh) n_a1Ehh
+ Brick.Widgets.FileBrowser: fileBrowserNameG :: forall n_a1EiH. SimpleGetter (FileBrowser n_a1EiH) n_a1EiH
- Brick.Widgets.FileBrowser: fileBrowserSearchStringG :: forall n_a1Ehh. SimpleGetter (FileBrowser n_a1Ehh) (Maybe Text)
+ Brick.Widgets.FileBrowser: fileBrowserSearchStringG :: forall n_a1EiH. SimpleGetter (FileBrowser n_a1EiH) (Maybe Text)
- Brick.Widgets.FileBrowser: fileBrowserSelectableG :: forall n_a1Ehh. SimpleGetter (FileBrowser n_a1Ehh) (FileInfo -> Bool)
+ Brick.Widgets.FileBrowser: fileBrowserSelectableG :: forall n_a1EiH. SimpleGetter (FileBrowser n_a1EiH) (FileInfo -> Bool)
- Brick.Widgets.FileBrowser: fileBrowserSelectableL :: forall n_a1Ehh. Lens' (FileBrowser n_a1Ehh) (FileInfo -> Bool)
+ Brick.Widgets.FileBrowser: fileBrowserSelectableL :: forall n_a1EiH. Lens' (FileBrowser n_a1EiH) (FileInfo -> Bool)
- Brick.Widgets.FileBrowser: fileBrowserSelectedFilesG :: forall n_a1Ehh. SimpleGetter (FileBrowser n_a1Ehh) (Set String)
+ Brick.Widgets.FileBrowser: fileBrowserSelectedFilesG :: forall n_a1EiH. SimpleGetter (FileBrowser n_a1EiH) (Set String)
- Brick.Widgets.FileBrowser: fileBrowserWorkingDirectoryG :: forall n_a1Ehh. SimpleGetter (FileBrowser n_a1Ehh) FilePath
+ Brick.Widgets.FileBrowser: fileBrowserWorkingDirectoryG :: forall n_a1EiH. SimpleGetter (FileBrowser n_a1EiH) FilePath
- Brick.Widgets.List: listElementsL :: forall n_a1xUz t_a1xUA e_a1xUB t_a1yaa e_a1yab. Lens (GenericList n_a1xUz t_a1xUA e_a1xUB) (GenericList n_a1xUz t_a1yaa e_a1yab) (t_a1xUA e_a1xUB) (t_a1yaa e_a1yab)
+ Brick.Widgets.List: listElementsL :: forall n_a1xVZ t_a1xW0 e_a1xW1 t_a1ybA e_a1ybB. Lens (GenericList n_a1xVZ t_a1xW0 e_a1xW1) (GenericList n_a1xVZ t_a1ybA e_a1ybB) (t_a1xW0 e_a1xW1) (t_a1ybA e_a1ybB)
- Brick.Widgets.List: listItemHeightL :: forall n_a1xUz t_a1xUA e_a1xUB. Lens' (GenericList n_a1xUz t_a1xUA e_a1xUB) Int
+ Brick.Widgets.List: listItemHeightL :: forall n_a1xVZ t_a1xW0 e_a1xW1. Lens' (GenericList n_a1xVZ t_a1xW0 e_a1xW1) Int
- Brick.Widgets.List: listNameL :: forall n_a1xUz t_a1xUA e_a1xUB n_a1yac. Lens (GenericList n_a1xUz t_a1xUA e_a1xUB) (GenericList n_a1yac t_a1xUA e_a1xUB) n_a1xUz n_a1yac
+ Brick.Widgets.List: listNameL :: forall n_a1xVZ t_a1xW0 e_a1xW1 n_a1ybC. Lens (GenericList n_a1xVZ t_a1xW0 e_a1xW1) (GenericList n_a1ybC t_a1xW0 e_a1xW1) n_a1xVZ n_a1ybC
- Brick.Widgets.List: listSelectedL :: forall n_a1xUz t_a1xUA e_a1xUB. Lens' (GenericList n_a1xUz t_a1xUA e_a1xUB) (Maybe Int)
+ Brick.Widgets.List: listSelectedL :: forall n_a1xVZ t_a1xW0 e_a1xW1. Lens' (GenericList n_a1xVZ t_a1xW0 e_a1xW1) (Maybe Int)
Files
- CHANGELOG.md +8/−0
- README.md +0/−7
- brick.cabal +1/−1
- programs/CustomEventDemo.hs +3/−3
- programs/ProgressBarDemo.hs +48/−4
- src/Brick/Widgets/ProgressBar.hs +30/−4
CHANGELOG.md view
@@ -2,6 +2,14 @@ Brick changelog --------------- +2.5+---++New features:+* `Brick.Widgets.ProgressBar` got a new function, `customProgressBar`,+ which allows the customization of the fill characters used to draw a+ progress bar. (Thanks @sectore)+ 2.4 ---
README.md view
@@ -108,13 +108,6 @@ | [`brick-filetree`](https://github.com/ChrisPenner/brick-filetree) [[Hackage]](http://hackage.haskell.org/package/brick-filetree) | A widget for exploring a directory tree and selecting or flagging files and directories | | [`brick-panes`](https://github.com/kquick/brick-panes) [[Hackage]](https://hackage.haskell.org/package/brick-panes) | A Brick overlay library providing composition and isolation of screen areas for TUI apps. | -Release Announcements / News-------------------------------Find out about `brick` releases and other news on Twitter:--https://twitter.com/brick_haskell/- Getting Started ---------------
brick.cabal view
@@ -1,5 +1,5 @@ name: brick-version: 2.4+version: 2.5 synopsis: A declarative terminal user interface library description: Write terminal user interfaces (TUIs) painlessly with 'brick'! You
programs/CustomEventDemo.hs view
@@ -54,9 +54,9 @@ case e of VtyEvent (V.EvKey V.KEsc []) -> halt VtyEvent _ -> stLastBrickEvent .= (Just e)- -- AppEvent Counter -> do- -- stCounter %= (+1)- -- stLastBrickEvent .= (Just e)+ AppEvent Counter -> do+ stCounter %= (+1)+ stLastBrickEvent .= (Just e) _ -> return () initialState :: St
programs/ProgressBarDemo.hs view
@@ -21,12 +21,13 @@ import Brick.Widgets.Core ( (<+>), (<=>) , str+ , strWrap , updateAttrMap , overrideAttr ) import Brick.Util (fg, bg, on, clamp) -data MyAppState n = MyAppState { _x, _y, _z :: Float }+data MyAppState n = MyAppState { _x, _y, _z :: Float, _showLabel :: Bool } makeLenses ''MyAppState @@ -48,13 +49,32 @@ zBar = overrideAttr P.progressCompleteAttr zDoneAttr $ overrideAttr P.progressIncompleteAttr zToDoAttr $ bar $ _z p- lbl c = Just $ show $ fromEnum $ c * 100+ -- custom bars+ cBar1 = overrideAttr P.progressCompleteAttr cDoneAttr1 $+ overrideAttr P.progressIncompleteAttr cToDoAttr1+ $ bar' '▰' '▱' $ _x p+ cBar2 = overrideAttr P.progressCompleteAttr cDoneAttr2 $+ overrideAttr P.progressIncompleteAttr cToDoAttr2+ $ bar' '|' '─' $ _y p+ cBar3 = overrideAttr P.progressCompleteAttr cDoneAttr $+ overrideAttr P.progressIncompleteAttr cToDoAttr+ $ bar' '⣿' '⠶' $ _z p+ lbl c = if _showLabel p+ then Just $ " " ++ (show $ fromEnum $ c * 100) ++ " "+ else Nothing bar v = P.progressBar (lbl v) v+ bar' cc ic v = P.customProgressBar cc ic (lbl v) v ui = (str "X: " <+> xBar) <=> (str "Y: " <+> yBar) <=> (str "Z: " <+> zBar) <=>+ (str "X: " <+> cBar1) <=>+ (str "Y: " <+> cBar2) <=>+ (str "Z: " <+> cBar3) <=> str "" <=>- str "Hit 'x', 'y', or 'z' to advance progress, or 'q' to quit"+ (strWrap $ concat [ "Hit 'x', 'y', or 'z' to advance progress,"+ , "'t' to toggle labels, 'r' to revert values, "+ , "'Ctrl + r' to reset values or 'q' to quit"+ ]) appEvent :: T.BrickEvent () e -> T.EventM () (MyAppState ()) () appEvent (T.VtyEvent e) =@@ -63,12 +83,18 @@ V.EvKey (V.KChar 'x') [] -> x %= valid . (+ 0.05) V.EvKey (V.KChar 'y') [] -> y %= valid . (+ 0.03) V.EvKey (V.KChar 'z') [] -> z %= valid . (+ 0.02)+ V.EvKey (V.KChar 't') [] -> showLabel %= not+ V.EvKey (V.KChar 'r') [V.MCtrl] -> do+ x .= 0+ y .= 0+ z .= 0+ V.EvKey (V.KChar 'r') [] -> T.put initialState V.EvKey (V.KChar 'q') [] -> M.halt _ -> return () appEvent _ = return () initialState :: MyAppState ()-initialState = MyAppState 0.25 0.18 0.63+initialState = MyAppState 0.25 0.18 0.63 True theBaseAttr :: A.AttrName theBaseAttr = A.attrName "theBase"@@ -85,6 +111,18 @@ zDoneAttr = theBaseAttr <> A.attrName "Z:done" zToDoAttr = theBaseAttr <> A.attrName "Z:remaining" +cDoneAttr, cToDoAttr :: A.AttrName+cDoneAttr = A.attrName "C:done"+cToDoAttr = A.attrName "C:remaining"++cDoneAttr1, cToDoAttr1 :: A.AttrName+cDoneAttr1 = A.attrName "C1:done"+cToDoAttr1 = A.attrName "C1:remaining"++cDoneAttr2, cToDoAttr2 :: A.AttrName+cDoneAttr2 = A.attrName "C2:done"+cToDoAttr2 = A.attrName "C2:remaining"+ theMap :: A.AttrMap theMap = A.attrMap V.defAttr [ (theBaseAttr, bg V.brightBlack)@@ -93,6 +131,12 @@ , (yDoneAttr, V.magenta `on` V.yellow) , (zDoneAttr, V.blue `on` V.green) , (zToDoAttr, V.blue `on` V.red)+ , (cDoneAttr, fg V.blue)+ , (cToDoAttr, fg V.blue)+ , (cDoneAttr1, fg V.red)+ , (cToDoAttr1, fg V.brightWhite)+ , (cDoneAttr2, fg V.green)+ , (cToDoAttr2, fg V.brightGreen) , (P.progressIncompleteAttr, fg V.yellow) ]
src/Brick/Widgets/ProgressBar.hs view
@@ -3,6 +3,7 @@ -- | This module provides a progress bar widget. module Brick.Widgets.ProgressBar ( progressBar+ , customProgressBar -- * Attributes , progressCompleteAttr , progressIncompleteAttr@@ -37,17 +38,42 @@ -> Float -- ^ The progress value. Should be between 0 and 1 inclusive. -> Widget n-progressBar mLabel progress =+progressBar = customProgressBar ' ' ' '++-- | Draw a progress bar with the specified (optional) label,+-- progress value and custom characters to fill the progress.+-- This fills available horizontal space and is one row high.+-- Please be aware of using wide characters in Brick,+-- see [Wide Character Support and the TextWidth class](https://github.com/jtdaugherty/brick/blob/master/docs/guide.rst#wide-character-support-and-the-textwidth-class)+customProgressBar :: Char+ -- ^ Character to fill the completed part.+ -> Char+ -- ^ Character to fill the incomplete part.+ -> Maybe String+ -- ^ The label. If specified, this is shown in the center of+ -- the progress bar.+ -> Float+ -- ^ The progress value. Should be between 0 and 1 inclusive.+ -> Widget n+customProgressBar completeChar incompleteChar mLabel progress = Widget Greedy Fixed $ do c <- getContext let barWidth = c^.availWidthL label = fromMaybe "" mLabel labelWidth = safeWcswidth label spacesWidth = barWidth - labelWidth- leftPart = replicate (spacesWidth `div` 2) ' '- rightPart = replicate (barWidth - (labelWidth + length leftPart)) ' '+ leftWidth = spacesWidth `div` 2+ rightWidth = barWidth - labelWidth - leftWidth+ completeWidth = round $ progress * toEnum barWidth++ leftCompleteWidth = min leftWidth completeWidth+ leftIncompleteWidth = leftWidth - leftCompleteWidth+ leftPart = replicate leftCompleteWidth completeChar ++ replicate leftIncompleteWidth incompleteChar+ rightCompleteWidth = max 0 (completeWidth - labelWidth - leftWidth)+ rightIncompleteWidth = rightWidth - rightCompleteWidth+ rightPart = replicate rightCompleteWidth completeChar ++ replicate rightIncompleteWidth incompleteChar+ fullBar = leftPart <> label <> rightPart- completeWidth = round $ progress * toEnum (length fullBar) adjustedCompleteWidth = if completeWidth == length fullBar && progress < 1.0 then completeWidth - 1 else if completeWidth == 0 && progress > 0.0