packages feed

brick 0.8 → 0.9

raw patch · 9 files changed

+76/−31 lines, 9 filesdep ~text-zipperPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: text-zipper

API changes (from Hackage documentation)

- Brick.Widgets.Edit: instance Brick.Widgets.Core.Named (Brick.Widgets.Edit.Editor n) n
+ Brick.Widgets.Border.Style: instance GHC.Classes.Eq Brick.Widgets.Border.Style.BorderStyle
+ Brick.Widgets.Edit: editorText :: n -> ([Text] -> Widget n) -> Maybe Int -> Text -> Editor Text n
+ Brick.Widgets.Edit: instance Brick.Widgets.Core.Named (Brick.Widgets.Edit.Editor t n) n
- Brick.Types: cursorLocationL :: forall n_aw7h. Lens' (CursorLocation n_aw7h) Location
+ Brick.Types: cursorLocationL :: forall n_atbu. Lens' (CursorLocation n_atbu) Location
- Brick.Types: cursorLocationNameL :: forall n_aw7h n_awgq. Lens (CursorLocation n_aw7h) (CursorLocation n_awgq) (Maybe n_aw7h) (Maybe n_awgq)
+ Brick.Types: cursorLocationNameL :: forall n_atbu n_atm0. Lens (CursorLocation n_atbu) (CursorLocation n_atm0) (Maybe n_atbu) (Maybe n_atm0)
- Brick.Types: cursorsL :: forall n_azJ4 n_aAvg. Lens (Result n_azJ4) (Result n_aAvg) [CursorLocation n_azJ4] [CursorLocation n_aAvg]
+ Brick.Types: cursorsL :: forall n_axYw n_ayv0. Lens (Result n_axYw) (Result n_ayv0) [CursorLocation n_axYw] [CursorLocation n_ayv0]
- Brick.Types: imageL :: forall n_azJ4. Lens' (Result n_azJ4) Image
+ Brick.Types: imageL :: forall n_axYw. Lens' (Result n_axYw) Image
- Brick.Types: visibilityRequestsL :: forall n_azJ4. Lens' (Result n_azJ4) [VisibilityRequest]
+ Brick.Types: visibilityRequestsL :: forall n_axYw. Lens' (Result n_axYw) [VisibilityRequest]
- Brick.Widgets.Dialog: dialogButtonsL :: forall a_a1545 a_a154F. Lens (Dialog a_a1545) (Dialog a_a154F) [(String, a_a1545)] [(String, a_a154F)]
+ Brick.Widgets.Dialog: dialogButtonsL :: forall a_aXP7 a_aXPH. Lens (Dialog a_aXP7) (Dialog a_aXPH) [(String, a_aXP7)] [(String, a_aXPH)]
- Brick.Widgets.Dialog: dialogSelectedIndexL :: forall a_a1545. Lens' (Dialog a_a1545) (Maybe Int)
+ Brick.Widgets.Dialog: dialogSelectedIndexL :: forall a_aXP7. Lens' (Dialog a_aXP7) (Maybe Int)
- Brick.Widgets.Dialog: dialogTitleL :: forall a_a1545. Lens' (Dialog a_a1545) (Maybe String)
+ Brick.Widgets.Dialog: dialogTitleL :: forall a_aXP7. Lens' (Dialog a_aXP7) (Maybe String)
- Brick.Widgets.Dialog: dialogWidthL :: forall a_a1545. Lens' (Dialog a_a1545) Int
+ Brick.Widgets.Dialog: dialogWidthL :: forall a_aXP7. Lens' (Dialog a_aXP7) Int
- Brick.Widgets.Edit: applyEdit :: (TextZipper String -> TextZipper String) -> Editor n -> Editor n
+ Brick.Widgets.Edit: applyEdit :: (TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
- Brick.Widgets.Edit: data Editor n
+ Brick.Widgets.Edit: data Editor t n
- Brick.Widgets.Edit: editContentsL :: forall n_a16WI. Lens' (Editor n_a16WI) (TextZipper String)
+ Brick.Widgets.Edit: editContentsL :: forall t_aZzU n_aZzV. Lens' (Editor t_aZzU n_aZzV) (TextZipper t_aZzU)
- Brick.Widgets.Edit: editDrawContentsL :: forall n_a16WI. Lens' (Editor n_a16WI) ([String] -> Widget n_a16WI)
+ Brick.Widgets.Edit: editDrawContentsL :: forall t_aZzU n_aZzV. Lens' (Editor t_aZzU n_aZzV) ([t_aZzU] -> Widget n_aZzV)
- Brick.Widgets.Edit: editor :: n -> ([String] -> Widget n) -> Maybe Int -> String -> Editor n
+ Brick.Widgets.Edit: editor :: GenericTextZipper a => n -> ([a] -> Widget n) -> Maybe Int -> a -> Editor a n
- Brick.Widgets.Edit: getEditContents :: Editor n -> [String]
+ Brick.Widgets.Edit: getEditContents :: Monoid t => Editor t n -> [t]
- Brick.Widgets.Edit: handleEditorEvent :: Event -> Editor n -> EventM n (Editor n)
+ Brick.Widgets.Edit: handleEditorEvent :: (Eq t, Monoid t) => Event -> Editor t n -> EventM n (Editor t n)
- Brick.Widgets.Edit: renderEditor :: (Ord n, Show n) => Bool -> Editor n -> Widget n
+ Brick.Widgets.Edit: renderEditor :: (Ord n, Show n, Monoid t) => Bool -> Editor t n -> Widget n
- Brick.Widgets.List: listElementsL :: forall n_a1f4A e_a1f4B e_a1fc7. Lens (List n_a1f4A e_a1f4B) (List n_a1f4A e_a1fc7) (Vector e_a1f4B) (Vector e_a1fc7)
+ Brick.Widgets.List: listElementsL :: forall n_a158S e_a158T e_a15ey. Lens (List n_a158S e_a158T) (List n_a158S e_a15ey) (Vector e_a158T) (Vector e_a15ey)
- Brick.Widgets.List: listItemHeightL :: forall n_a1f4A e_a1f4B. Lens' (List n_a1f4A e_a1f4B) Int
+ Brick.Widgets.List: listItemHeightL :: forall n_a158S e_a158T. Lens' (List n_a158S e_a158T) Int
- Brick.Widgets.List: listNameL :: forall n_a1f4A e_a1f4B n_a1fc8. Lens (List n_a1f4A e_a1f4B) (List n_a1fc8 e_a1f4B) n_a1f4A n_a1fc8
+ Brick.Widgets.List: listNameL :: forall n_a158S e_a158T n_a15ez. Lens (List n_a158S e_a158T) (List n_a15ez e_a158T) n_a158S n_a15ez
- Brick.Widgets.List: listSelectedL :: forall n_a1f4A e_a1f4B. Lens' (List n_a1f4A e_a1f4B) (Maybe Int)
+ Brick.Widgets.List: listSelectedL :: forall n_a158S e_a158T. Lens' (List n_a158S e_a158T) (Maybe Int)

Files

CHANGELOG.md view
@@ -2,6 +2,28 @@ Brick changelog --------------- +0.9+---++Package changes:+ * Depend on text-zipper 0.7.1++API changes:+ * The editor widget state value is now polymorphic over the type of+   "string" value that can be edited, so you can now create editors over+   Text values as well as Strings. This is a breaking change but it only+   requires the addition of the string type variable to any uses of+   Editor. (thanks Jason Dagit and Getty Ritter)+ * Added some missing Eq and Show instances (thanks Grégoire Charvet)++New features:+ * The editor now binds Control-U to delete to beginning of line (thanks+   Hans-Peter Deifel)++Bug fixes:+ * List: avoid runtime exception by ensuring item height is always at+   least 1+ 0.8 --- 
README.md view
@@ -1,7 +1,7 @@ brick ----- -[![Build Status](https://travis-ci.org/jtdaugherty/brick.png)](https://travis-ci.org/jtdaugherty/brick)+[![Build Status](https://travis-ci.org/jtdaugherty/brick.svg?branch=master)](https://travis-ci.org/jtdaugherty/brick)  `brick` is a terminal user interface programming library written in Haskell, in the style of
brick.cabal view
@@ -1,5 +1,5 @@ name:                brick-version:             0.8+version:             0.9 synopsis:            A declarative terminal user interface library description:   Write terminal applications painlessly with 'brick'! You write an@@ -88,7 +88,7 @@                        vector,                        contravariant,                        text,-                       text-zipper >= 0.2.1,+                       text-zipper >= 0.7.1,                        template-haskell,                        deepseq >= 1.3 && < 1.5 
docs/guide.rst view
@@ -247,7 +247,7 @@ .. code:: haskell     data Name = Edit1-   type MyState = Edit Name+   type MyState = Editor String Name     myEvent :: MyState -> e -> EventM Name (Next MyState)    myEvent s e = continue =<< handleEditorEvent e s@@ -262,7 +262,7 @@ .. code:: haskell     data Name = Edit1-   data MyState = MyState { _theEdit :: Edit Name+   data MyState = MyState { _theEdit :: Editor String Name                           }    makeLenses ''MyState 
programs/EditDemo.hs view
@@ -28,8 +28,8 @@  data St =     St { _focusRing :: F.FocusRing Name-       , _edit1 :: E.Editor Name-       , _edit2 :: E.Editor Name+       , _edit1 :: E.Editor String Name+       , _edit2 :: E.Editor String Name        }  makeLenses ''St
src/Brick/Types/Internal.hs view
@@ -64,7 +64,7 @@     VR { vrPosition :: Location        , vrSize :: DisplayRegion        }-       deriving Show+       deriving (Show, Eq)  -- | Describes the state of a viewport as it appears as its most recent -- rendering.@@ -86,7 +86,7 @@                   -- ^ Viewports of this type are scrollable only horizontally.                   | Both                   -- ^ Viewports of this type are scrollable vertically and horizontally.-                  deriving Show+                  deriving (Show, Eq)  type EventState n = [(n, ScrollRequest)] @@ -101,12 +101,13 @@                -- ^ Up/left                | Down                -- ^ Down/right+               deriving (Show, Eq)  -- | A terminal screen location. data Location = Location { loc :: (Int, Int)                          -- ^ (Column, Row)                          }-                deriving Show+                deriving (Show, Eq)  suffixLenses ''Location @@ -150,7 +151,7 @@  -- | The rendering context. This tells widgets how to render: how much -- space they have in which to render, which attribute they should use--- to render, which bordring style should be used, and the attribute map+-- to render, which bordering style should be used, and the attribute map -- available for rendering. data Context =     Context { ctxAttrName :: AttrName@@ -159,6 +160,7 @@             , ctxBorderStyle :: BorderStyle             , ctxAttrMap :: AttrMap             }+            deriving Show  suffixLenses ''RenderState suffixLenses ''VisibilityRequest
src/Brick/Widgets/Border/Style.hs view
@@ -48,7 +48,7 @@                 , bsVertical :: Char                 -- ^ Vertical border character                 }-                deriving (Show, Read)+                deriving (Show, Read, Eq)  instance Default BorderStyle where     def = unicode
src/Brick/Widgets/Edit.hs view
@@ -15,6 +15,7 @@   ( Editor(editContents, editorName, editDrawContents)   -- * Constructing an editor   , editor+  , editorText   -- * Reading editor contents   , getEditContents   -- * Handling events@@ -36,12 +37,15 @@ import Lens.Micro import Graphics.Vty (Event(..), Key(..), Modifier(..)) -import qualified Data.Text.Zipper as Z+import qualified Data.Text as T+import qualified Data.Text.Zipper as Z hiding ( textZipper )+import qualified Data.Text.Zipper.Generic as Z  import Brick.Types import Brick.Widgets.Core import Brick.AttrMap + -- | Editor state.  Editors support the following events by default: -- -- * Ctrl-a: go to beginning of line@@ -49,12 +53,13 @@ -- * Ctrl-d, Del: delete character at cursor position -- * Backspace: delete character prior to cursor position -- * Ctrl-k: delete all from cursor to end of line+-- * Ctrl-u: delete all from cursor to beginning of line -- * Arrow keys: move cursor -- * Enter: break the current line at the cursor position-data Editor n =-    Editor { editContents :: Z.TextZipper String+data Editor t n =+    Editor { editContents :: Z.TextZipper t            -- ^ The contents of the editor-           , editDrawContents :: [String] -> Widget n+           , editDrawContents :: [t] -> Widget n            -- ^ The function the editor uses to draw its contents            , editorName :: n            -- ^ The name of the editor@@ -62,16 +67,17 @@  suffixLenses ''Editor -instance Named (Editor n) n where+instance Named (Editor t n) n where     getName = editorName -handleEditorEvent :: Event -> Editor n -> EventM n (Editor n)+handleEditorEvent :: (Eq t, Monoid t) => Event -> Editor t n -> EventM n (Editor t n) handleEditorEvent e ed =         let f = case e of                   EvKey (KChar 'a') [MCtrl] -> Z.gotoBOL                   EvKey (KChar 'e') [MCtrl] -> Z.gotoEOL                   EvKey (KChar 'd') [MCtrl] -> Z.deleteChar                   EvKey (KChar 'k') [MCtrl] -> Z.killToEOL+                  EvKey (KChar 'u') [MCtrl] -> Z.killToBOL                   EvKey KEnter [] -> Z.breakLine                   EvKey KDel [] -> Z.deleteChar                   EvKey (KChar c) [] | c /= '\t' -> Z.insertChar c@@ -83,27 +89,41 @@                   _ -> id         in return $ applyEdit f ed --- | Construct an editor.-editor :: n+-- | Construct an editor over 'Text' values+editorText :: n        -- ^ The editor's name (must be unique)-       -> ([String] -> Widget n)+       -> ([T.Text] -> Widget n)        -- ^ The content rendering function        -> Maybe Int        -- ^ The limit on the number of lines in the editor ('Nothing'        -- means no limit)-       -> String+       -> T.Text        -- ^ The initial content-       -> Editor n-editor name draw limit s = Editor (Z.stringZipper (lines s) limit) draw name+       -> Editor T.Text n+editorText = editor +-- | Construct an editor over 'String' values+editor :: Z.GenericTextZipper a+       => n+       -- ^ The editor's name (must be unique)+       -> ([a] -> Widget n)+       -- ^ The content rendering function+       -> Maybe Int+       -- ^ The limit on the number of lines in the editor ('Nothing'+       -- means no limit)+       -> a+       -- ^ The initial content+       -> Editor a n+editor name draw limit s = Editor (Z.textZipper (Z.lines s) limit) draw name+ -- | Apply an editing operation to the editor's contents. Bear in mind -- that you should only apply zipper operations that operate on the -- current line; the editor will only ever render the first line of -- text.-applyEdit :: (Z.TextZipper String -> Z.TextZipper String)+applyEdit :: (Z.TextZipper t -> Z.TextZipper t)           -- ^ The 'Data.Text.Zipper' editing transformation to apply-          -> Editor n-          -> Editor n+          -> Editor t n+          -> Editor t n applyEdit f e = e & editContentsL %~ f  -- | The attribute assigned to the editor when it does not have focus.@@ -116,15 +136,15 @@ editFocusedAttr = editAttr <> "focused"  -- | Get the contents of the editor.-getEditContents :: Editor n -> [String]+getEditContents :: Monoid t => Editor t n -> [t] getEditContents e = Z.getText $ e^.editContentsL  -- | Turn an editor state value into a widget-renderEditor :: (Ord n, Show n)+renderEditor :: (Ord n, Show n, Monoid t)              => Bool              -- ^ Whether the editor has focus. It will report a cursor              -- position if and only if it has focus.-             -> Editor n+             -> Editor t n              -- ^ The editor.              -> Widget n renderEditor foc e =
src/Brick/Widgets/List.hs view
@@ -127,7 +127,8 @@      -> List n e list name es h =     let selIndex = if V.null es then Nothing else Just 0-    in List es selIndex name h+        safeHeight = max 1 h+    in List es selIndex name safeHeight  -- | Turn a list state value into a widget given an item drawing -- function.