packages feed

cursor-brick 0.1.0.0 → 0.1.0.1

raw patch · 13 files changed

+348/−205 lines, 13 filessetup-changedPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ Cursor.Brick.Forest: verticalPaddedForestCursorWidget :: forall a b n. (a -> Widget n) -> (b -> Widget n) -> Int -> ForestCursor a b -> Widget n
+ Cursor.Brick.Forest: verticalPaddedForestCursorWidgetM :: forall a b n m. Monad m => (a -> m (Widget n)) -> (b -> m (Widget n)) -> Int -> ForestCursor a b -> m (Widget n)
+ Cursor.Brick.List.NonEmpty: tableWidget :: [[Widget n]] -> Widget n
+ Cursor.Brick.List.NonEmpty: verticalNonEmptyCursorTable :: (b -> [Widget n]) -> (a -> [Widget n]) -> (b -> [Widget n]) -> NonEmptyCursor a b -> Widget n
+ Cursor.Brick.List.NonEmpty: verticalNonEmptyCursorTableM :: Applicative f => (b -> f [Widget n]) -> (a -> f [Widget n]) -> (b -> f [Widget n]) -> NonEmptyCursor a b -> f (Widget n)
+ Cursor.Brick.List.NonEmpty: verticalNonEmptyCursorTableWithHeader :: (b -> [Widget n]) -> (a -> [Widget n]) -> (b -> [Widget n]) -> [Widget n] -> NonEmptyCursor a b -> Widget n
+ Cursor.Brick.List.NonEmpty: verticalNonEmptyCursorTableWithHeaderM :: Applicative f => (b -> f [Widget n]) -> (a -> f [Widget n]) -> (b -> f [Widget n]) -> [Widget n] -> NonEmptyCursor a b -> f (Widget n)
+ Cursor.Brick.Tree: verticalPaddedTreeCursorWidget :: forall a b n. (a -> Widget n) -> (b -> Widget n) -> Int -> TreeCursor a b -> Widget n
+ Cursor.Brick.Tree: verticalPaddedTreeCursorWidgetM :: forall a b n m. Monad m => (a -> m (Widget n)) -> (b -> m (Widget n)) -> Int -> TreeCursor a b -> m (Widget n)

Files

ChangeLog.md view
@@ -1,3 +1,5 @@-# Changelog for cursor-brick+# Changelog -## Unreleased changes+## [0.1.0.1] - 2021-11-21++* Code cleanup using hlint
LICENSE view
@@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 Tom Sydney Kerckhove+Copyright (c) 2019-2021 Tom Sydney Kerckhove  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
− Setup.hs
@@ -1,3 +0,0 @@-import Distribution.Simple--main = defaultMain
cursor-brick.cabal view
@@ -1,19 +1,19 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.31.1.+-- This file has been generated from package.yaml by hpack version 0.34.4. -- -- see: https://github.com/sol/hpack ----- hash: dd4cb07a29abf9dd36525dc5fa9f67eb370539e7b2f41f461bafbd5e117883d9+-- hash: 82a9a86981d41920d447ea66bb4dd96699c682e74f16c813673d5ede5e28fdb9  name:           cursor-brick-version:        0.1.0.0+version:        0.1.0.1 description:    Please see the README on GitHub at <https://github.com/NorfairKing/cursor-brick#readme> homepage:       https://github.com/NorfairKing/cursor-brick#readme bug-reports:    https://github.com/NorfairKing/cursor-brick/issues author:         Tom Sydney Kerckhove maintainer:     syd@cs-syd.eu-copyright:      Copyright: (c) 2019 Tom Sydney Kerckhove+copyright:      Copyright: (c) 2019-2021 Tom Sydney Kerckhove license:        MIT license-file:   LICENSE build-type:     Simple
src/Cursor/Brick.hs view
@@ -1,13 +1,14 @@ module Cursor.Brick-  ( module Cursor.Brick.Forest-  , module Cursor.Brick.List-  , module Cursor.Brick.List.NonEmpty-  , module Cursor.Brick.Map-  , module Cursor.Brick.Map.KeyValue-  , module Cursor.Brick.Text-  , module Cursor.Brick.TextField-  , module Cursor.Brick.Tree-  ) where+  ( module Cursor.Brick.Forest,+    module Cursor.Brick.List,+    module Cursor.Brick.List.NonEmpty,+    module Cursor.Brick.Map,+    module Cursor.Brick.Map.KeyValue,+    module Cursor.Brick.Text,+    module Cursor.Brick.TextField,+    module Cursor.Brick.Tree,+  )+where  import Cursor.Brick.Forest import Cursor.Brick.List
src/Cursor/Brick/Forest.hs view
@@ -1,65 +1,112 @@-{-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE LambdaCase #-} {-# LANGUAGE ScopedTypeVariables #-}  module Cursor.Brick.Forest where -import Cursor.Forest-import Cursor.Tree- import Brick.Types-+import Brick.Widgets.Core import Cursor.Brick.List.NonEmpty+import Cursor.Brick.Tree+import Cursor.Forest+import Cursor.Tree+import qualified Data.List.NonEmpty as NE  horizontalForestCursorWidgetM ::-     Monad m-  => (CTree b -> m (Widget n))-  -> (TreeCursor a b -> m (Widget n))-  -> (CTree b -> m (Widget n))-  -> ForestCursor a b-  -> m (Widget n)+  Monad m =>+  (CTree b -> m (Widget n)) ->+  (TreeCursor a b -> m (Widget n)) ->+  (CTree b -> m (Widget n)) ->+  ForestCursor a b ->+  m (Widget n) horizontalForestCursorWidgetM prevFunc curFunc nextFunc =-  horizontalNonEmptyCursorWidgetM prevFunc curFunc nextFunc .-  forestCursorListCursor+  horizontalNonEmptyCursorWidgetM prevFunc curFunc nextFunc+    . forestCursorListCursor  horizontalForestCursorWidget ::-     (CTree b -> Widget n)-  -> (TreeCursor a b -> Widget n)-  -> (CTree b -> Widget n)-  -> ForestCursor a b-  -> Widget n+  (CTree b -> Widget n) ->+  (TreeCursor a b -> Widget n) ->+  (CTree b -> Widget n) ->+  ForestCursor a b ->+  Widget n horizontalForestCursorWidget prevFunc curFunc nextFunc =-  horizontalNonEmptyCursorWidget prevFunc curFunc nextFunc .-  forestCursorListCursor+  horizontalNonEmptyCursorWidget prevFunc curFunc nextFunc+    . forestCursorListCursor +verticalPaddedForestCursorWidgetM ::+  forall a b n m.+  Monad m =>+  (a -> m (Widget n)) ->+  (b -> m (Widget n)) ->+  Int ->+  ForestCursor a b ->+  m (Widget n)+verticalPaddedForestCursorWidgetM goA goB padding =+  verticalForestCursorWidgetM+    goCTree+    (verticalPaddedTreeCursorWidgetM goA goB padding)+    goCTree+  where+    goCTree :: CTree b -> m (Widget n)+    goCTree (CNode b cf) = do+      top <- goB b+      bot <- goCForest cf+      pure $ top <=> padLeft (Pad padding) bot+    goCForest :: CForest b -> m (Widget n)+    goCForest = \case+      EmptyCForest -> pure emptyWidget+      ClosedForest _ -> pure emptyWidget+      OpenForest nect -> fmap vBox $ traverse goCTree $ NE.toList nect++verticalPaddedForestCursorWidget ::+  forall a b n.+  (a -> Widget n) ->+  (b -> Widget n) ->+  Int ->+  ForestCursor a b ->+  Widget n+verticalPaddedForestCursorWidget goA goB padding =+  verticalForestCursorWidget+    goCTree+    (verticalPaddedTreeCursorWidget goA goB padding)+    goCTree+  where+    goCTree :: CTree b -> Widget n+    goCTree (CNode b cf) = goB b <=> padLeft (Pad padding) (goCForest cf)+    goCForest :: CForest b -> Widget n+    goCForest = \case+      EmptyCForest -> emptyWidget+      ClosedForest _ -> emptyWidget+      OpenForest nect -> vBox $ map goCTree $ NE.toList nect+ verticalForestCursorWidgetM ::-     Monad m-  => (CTree b -> m (Widget n))-  -> (TreeCursor a b -> m (Widget n))-  -> (CTree b -> m (Widget n))-  -> ForestCursor a b-  -> m (Widget n)+  Monad m =>+  (CTree b -> m (Widget n)) ->+  (TreeCursor a b -> m (Widget n)) ->+  (CTree b -> m (Widget n)) ->+  ForestCursor a b ->+  m (Widget n) verticalForestCursorWidgetM prevFunc curFunc nextFunc =-  verticalNonEmptyCursorWidgetM prevFunc curFunc nextFunc .-  forestCursorListCursor+  verticalNonEmptyCursorWidgetM prevFunc curFunc nextFunc+    . forestCursorListCursor  verticalForestCursorWidget ::-     (CTree b -> Widget n)-  -> (TreeCursor a b -> Widget n)-  -> (CTree b -> Widget n)-  -> ForestCursor a b-  -> Widget n+  (CTree b -> Widget n) ->+  (TreeCursor a b -> Widget n) ->+  (CTree b -> Widget n) ->+  ForestCursor a b ->+  Widget n verticalForestCursorWidget prevFunc curFunc nextFunc =-  verticalNonEmptyCursorWidget prevFunc curFunc nextFunc .-  forestCursorListCursor+  verticalNonEmptyCursorWidget prevFunc curFunc nextFunc+    . forestCursorListCursor  forestCursorWidgetM ::-     ([CTree b] -> TreeCursor a b -> [CTree b] -> m (Widget n))-  -> ForestCursor a b-  -> m (Widget n)+  ([CTree b] -> TreeCursor a b -> [CTree b] -> m (Widget n)) ->+  ForestCursor a b ->+  m (Widget n) forestCursorWidgetM = foldForestCursor  forestCursorWidget ::-     ([CTree b] -> TreeCursor a b -> [CTree b] -> Widget n)-  -> ForestCursor a b-  -> Widget n+  ([CTree b] -> TreeCursor a b -> [CTree b] -> Widget n) ->+  ForestCursor a b ->+  Widget n forestCursorWidget = foldForestCursor
src/Cursor/Brick/List.hs view
@@ -1,13 +1,10 @@-{-# LANGUAGE RecordWildCards #-}- module Cursor.Brick.List where -import Cursor.List- import Brick.Types+import Cursor.List  listCursorWidgetM ::-     ([a] -> [a] -> m (Widget n)) -> ListCursor a -> m (Widget n)+  ([a] -> [a] -> m (Widget n)) -> ListCursor a -> m (Widget n) listCursorWidgetM = foldListCursor  listCursorWidget :: ([a] -> [a] -> Widget n) -> ListCursor a -> Widget n
src/Cursor/Brick/List/NonEmpty.hs view
@@ -1,64 +1,99 @@-{-# LANGUAGE RecordWildCards #-}- module Cursor.Brick.List.NonEmpty where -import Cursor.List.NonEmpty- import Brick.Types as B import Brick.Widgets.Core as B+import Cursor.List.NonEmpty+import Data.List +verticalNonEmptyCursorTableWithHeader ::+  (b -> [Widget n]) -> (a -> [Widget n]) -> (b -> [Widget n]) -> [Widget n] -> NonEmptyCursor a b -> Widget n+verticalNonEmptyCursorTableWithHeader prevFunc curFunc nextFunc header =+  nonEmptyCursorWidget (\ps c ns -> tableWidget $ header : (map prevFunc ps ++ [curFunc c] ++ map nextFunc ns))++verticalNonEmptyCursorTableWithHeaderM ::+  Applicative f =>+  (b -> f [Widget n]) ->+  (a -> f [Widget n]) ->+  (b -> f [Widget n]) ->+  [Widget n] ->+  NonEmptyCursor a b ->+  f (Widget n)+verticalNonEmptyCursorTableWithHeaderM prevFunc curFunc nextFunc header =+  nonEmptyCursorWidgetM (\ps c ns -> tableWidget <$> sequenceA (pure header : (map prevFunc ps ++ [curFunc c] ++ map nextFunc ns)))++verticalNonEmptyCursorTable ::+  (b -> [Widget n]) -> (a -> [Widget n]) -> (b -> [Widget n]) -> NonEmptyCursor a b -> Widget n+verticalNonEmptyCursorTable prevFunc curFunc nextFunc =+  nonEmptyCursorWidget+    ( \ps c ns ->+        tableWidget $ map prevFunc ps ++ [curFunc c] ++ map nextFunc ns+    )++verticalNonEmptyCursorTableM ::+  Applicative f =>+  (b -> f [Widget n]) ->+  (a -> f [Widget n]) ->+  (b -> f [Widget n]) ->+  NonEmptyCursor a b ->+  f (Widget n)+verticalNonEmptyCursorTableM prevFunc curFunc nextFunc =+  nonEmptyCursorWidgetM (\ps c ns -> tableWidget <$> sequenceA (map prevFunc ps ++ [curFunc c] ++ map nextFunc ns))++tableWidget :: [[Widget n]] -> Widget n+tableWidget = hBox . intersperse (str " ") . map vBox . transpose+ horizontalNonEmptyCursorWidgetM ::-     Applicative f-  => (b -> f (Widget n))-  -> (a -> f (Widget n))-  -> (b -> f (Widget n))-  -> NonEmptyCursor a b-  -> f (Widget n)+  Applicative f =>+  (b -> f (Widget n)) ->+  (a -> f (Widget n)) ->+  (b -> f (Widget n)) ->+  NonEmptyCursor a b ->+  f (Widget n) horizontalNonEmptyCursorWidgetM beforeFunc curFunc afterFunc =   nonEmptyCursorWidgetM $ \befores current afters ->-    hBox <$>-    sequenceA-      (concat [map beforeFunc befores, [curFunc current], map afterFunc afters])+    hBox+      <$> sequenceA+        (concat [map beforeFunc befores, [curFunc current], map afterFunc afters])  horizontalNonEmptyCursorWidget ::-     (b -> Widget n)-  -> (a -> Widget n)-  -> (b -> Widget n)-  -> NonEmptyCursor a b-  -> Widget n+  (b -> Widget n) ->+  (a -> Widget n) ->+  (b -> Widget n) ->+  NonEmptyCursor a b ->+  Widget n horizontalNonEmptyCursorWidget beforeFunc curFunc afterFunc =   nonEmptyCursorWidget $ \befores current afters ->     hBox $-    concat [map beforeFunc befores, [curFunc current], map afterFunc afters]+      concat [map beforeFunc befores, [curFunc current], map afterFunc afters]  verticalNonEmptyCursorWidgetM ::-     Applicative f-  => (b -> f (Widget n))-  -> (a -> f (Widget n))-  -> (b -> f (Widget n))-  -> NonEmptyCursor a b-  -> f (Widget n)+  Applicative f =>+  (b -> f (Widget n)) ->+  (a -> f (Widget n)) ->+  (b -> f (Widget n)) ->+  NonEmptyCursor a b ->+  f (Widget n) verticalNonEmptyCursorWidgetM beforeFunc curFunc afterFunc =   nonEmptyCursorWidgetM $ \befores current afters ->-    vBox <$>-    sequenceA-      (concat [map beforeFunc befores, [curFunc current], map afterFunc afters])+    vBox+      <$> sequenceA+        (concat [map beforeFunc befores, [curFunc current], map afterFunc afters])  verticalNonEmptyCursorWidget ::-     (b -> Widget n)-  -> (a -> Widget n)-  -> (b -> Widget n)-  -> NonEmptyCursor a b-  -> Widget n+  (b -> Widget n) ->+  (a -> Widget n) ->+  (b -> Widget n) ->+  NonEmptyCursor a b ->+  Widget n verticalNonEmptyCursorWidget beforeFunc curFunc afterFunc =   nonEmptyCursorWidget $ \befores current afters ->     vBox $-    concat [map beforeFunc befores, [curFunc current], map afterFunc afters]+      concat [map beforeFunc befores, [curFunc current], map afterFunc afters]  nonEmptyCursorWidgetM ::-     ([b] -> a -> [b] -> m (Widget n)) -> NonEmptyCursor a b -> m (Widget n)+  ([b] -> a -> [b] -> m (Widget n)) -> NonEmptyCursor a b -> m (Widget n) nonEmptyCursorWidgetM = foldNonEmptyCursor  nonEmptyCursorWidget ::-     ([b] -> a -> [b] -> Widget n) -> NonEmptyCursor a b -> Widget n+  ([b] -> a -> [b] -> Widget n) -> NonEmptyCursor a b -> Widget n nonEmptyCursorWidget = foldNonEmptyCursor
src/Cursor/Brick/Map.hs view
@@ -1,85 +1,85 @@-{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-}  module Cursor.Brick.Map where -import Cursor.Map- import Brick.Types import Brick.Widgets.Core+import Cursor.Map  horizontalMapCursorWidget ::-     (k -> v -> Widget n)-  -> (KeyValueCursor kc vc k v -> Widget n)-  -> (k -> v -> Widget n)-  -> MapCursor kc vc k v-  -> Widget n+  (k -> v -> Widget n) ->+  (KeyValueCursor kc vc k v -> Widget n) ->+  (k -> v -> Widget n) ->+  MapCursor kc vc k v ->+  Widget n horizontalMapCursorWidget beforeFunc curFunc afterFunc =   mapCursorWidget $ \befores current afters ->     hBox $-    concat-      [ map (uncurry beforeFunc) befores-      , [curFunc current]-      , map (uncurry afterFunc) afters-      ]+      concat+        [ map (uncurry beforeFunc) befores,+          [curFunc current],+          map (uncurry afterFunc) afters+        ]  horizontalMapCursorWidgetM ::-     Applicative f-  => (k -> v -> f (Widget n))-  -> (KeyValueCursor kc vc k v -> f (Widget n))-  -> (k -> v -> f (Widget n))-  -> MapCursor kc vc k v-  -> f (Widget n)+  Applicative f =>+  (k -> v -> f (Widget n)) ->+  (KeyValueCursor kc vc k v -> f (Widget n)) ->+  (k -> v -> f (Widget n)) ->+  MapCursor kc vc k v ->+  f (Widget n) horizontalMapCursorWidgetM beforeFunc curFunc afterFunc =   mapCursorWidgetM $ \befores current afters ->-    hBox <$>-    sequenceA-      (concat-         [ map (uncurry beforeFunc) befores-         , [curFunc current]-         , map (uncurry afterFunc) afters-         ])+    hBox+      <$> sequenceA+        ( concat+            [ map (uncurry beforeFunc) befores,+              [curFunc current],+              map (uncurry afterFunc) afters+            ]+        )  verticalMapCursorWidget ::-     (k -> v -> Widget n)-  -> (KeyValueCursor kc vc k v -> Widget n)-  -> (k -> v -> Widget n)-  -> MapCursor kc vc k v-  -> Widget n+  (k -> v -> Widget n) ->+  (KeyValueCursor kc vc k v -> Widget n) ->+  (k -> v -> Widget n) ->+  MapCursor kc vc k v ->+  Widget n verticalMapCursorWidget beforeFunc curFunc afterFunc =   mapCursorWidget $ \befores current afters ->     vBox $-    concat-      [ map (uncurry beforeFunc) befores-      , [curFunc current]-      , map (uncurry afterFunc) afters-      ]+      concat+        [ map (uncurry beforeFunc) befores,+          [curFunc current],+          map (uncurry afterFunc) afters+        ]  verticalMapCursorWidgetM ::-     Applicative f-  => (k -> v -> f (Widget n))-  -> (KeyValueCursor kc vc k v -> f (Widget n))-  -> (k -> v -> f (Widget n))-  -> MapCursor kc vc k v-  -> f (Widget n)+  Applicative f =>+  (k -> v -> f (Widget n)) ->+  (KeyValueCursor kc vc k v -> f (Widget n)) ->+  (k -> v -> f (Widget n)) ->+  MapCursor kc vc k v ->+  f (Widget n) verticalMapCursorWidgetM beforeFunc curFunc afterFunc =   mapCursorWidgetM $ \befores current afters ->-    vBox <$>-    sequenceA-      (concat-         [ map (uncurry beforeFunc) befores-         , [curFunc current]-         , map (uncurry afterFunc) afters-         ])+    vBox+      <$> sequenceA+        ( concat+            [ map (uncurry beforeFunc) befores,+              [curFunc current],+              map (uncurry afterFunc) afters+            ]+        )  mapCursorWidget ::-     ([(k, v)] -> KeyValueCursor kc vc k v -> [(k, v)] -> Widget n)-  -> MapCursor kc vc k v-  -> Widget n+  ([(k, v)] -> KeyValueCursor kc vc k v -> [(k, v)] -> Widget n) ->+  MapCursor kc vc k v ->+  Widget n mapCursorWidget = foldMapCursor  mapCursorWidgetM ::-     ([(k, v)] -> KeyValueCursor kc vc k v -> [(k, v)] -> m (Widget n))-  -> MapCursor kc vc k v-  -> m (Widget n)+  ([(k, v)] -> KeyValueCursor kc vc k v -> [(k, v)] -> m (Widget n)) ->+  MapCursor kc vc k v ->+  m (Widget n) mapCursorWidgetM = foldMapCursor
src/Cursor/Brick/Map/KeyValue.hs view
@@ -1,22 +1,18 @@-{-# LANGUAGE RecordWildCards #-}-{-# LANGUAGE ScopedTypeVariables #-}- module Cursor.Brick.Map.KeyValue where -import Cursor.Map- import Brick.Types+import Cursor.Map  keyValueWidget ::-     (kc -> v -> Widget n)-  -> (k -> vc -> Widget n)-  -> KeyValueCursor kc vc k v-  -> Widget n+  (kc -> v -> Widget n) ->+  (k -> vc -> Widget n) ->+  KeyValueCursor kc vc k v ->+  Widget n keyValueWidget = foldKeyValueCursor  keyValueWidgetM ::-     (kc -> v -> f (Widget n))-  -> (k -> vc -> f (Widget n))-  -> KeyValueCursor kc vc k v-  -> f (Widget n)+  (kc -> v -> f (Widget n)) ->+  (k -> vc -> f (Widget n)) ->+  KeyValueCursor kc vc k v ->+  f (Widget n) keyValueWidgetM = foldKeyValueCursor
src/Cursor/Brick/Text.hs view
@@ -2,13 +2,11 @@  module Cursor.Brick.Text where -import qualified Data.Text as T-import Data.Text (Text)--import Cursor.Text- import Brick.Types as Brick import Brick.Widgets.Core as Brick+import Cursor.Text+import Data.Text (Text)+import qualified Data.Text as T  -- | Make a text cursor widget with a blink-y box. --@@ -18,7 +16,7 @@ selectedTextCursorWidget :: n -> TextCursor -> Widget n selectedTextCursorWidget n tc =   Brick.showCursor n (Brick.Location (textCursorIndex tc, 0)) $-  textCursorWidget tc+    textCursorWidget tc  -- | Make a text cursor widget without a blink-y box. --@@ -26,10 +24,10 @@ textCursorWidget :: TextCursor -> Widget n textCursorWidget tc =   txt $-  let t = sanitiseText $ rebuildTextCursor tc-   in if T.null t-        then " "-        else t+    let t = sanitiseText $ rebuildTextCursor tc+     in if T.null t+          then " "+          else t  -- | Draw an arbitrary Text, it will be sanitised. textWidget :: Text -> Widget n
src/Cursor/Brick/TextField.hs view
@@ -1,12 +1,10 @@ module Cursor.Brick.TextField where -import Cursor.List.NonEmpty-import Cursor.TextField- import Brick.Types as Brick import Brick.Widgets.Core as Brick- import Cursor.Brick.Text+import Cursor.List.NonEmpty+import Cursor.TextField  -- | Make a textfield cursor widget with a blink-y box. --@@ -16,11 +14,11 @@ selectedTextFieldCursorWidget n (TextFieldCursor tfc) =   flip foldNonEmptyCursor tfc $ \befores current afters ->     vBox $-    concat-      [ map textWidget befores-      , [selectedTextCursorWidget n current]-      , map textWidget afters-      ]+      concat+        [ map textWidget befores,+          [selectedTextCursorWidget n current],+          map textWidget afters+        ]  -- | Make a textfield cursor widget without a blink-y box. --@@ -29,8 +27,8 @@ textFieldCursorWidget (TextFieldCursor tfc) =   flip foldNonEmptyCursor tfc $ \befores current afters ->     vBox $-    concat-      [ map textWidget befores-      , [textCursorWidget current]-      , map textWidget afters-      ]+      concat+        [ map textWidget befores,+          [textCursorWidget current],+          map textWidget afters+        ]
src/Cursor/Brick/Tree.hs view
@@ -1,24 +1,96 @@-{-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE LambdaCase #-} {-# LANGUAGE ScopedTypeVariables #-}  module Cursor.Brick.Tree where +import Brick.Types+import Brick.Widgets.Core import Cursor.Tree+import qualified Data.List.NonEmpty as NE -import Brick.Types+verticalPaddedTreeCursorWidgetM ::+  forall a b n m.+  Monad m =>+  (a -> m (Widget n)) ->+  (b -> m (Widget n)) ->+  Int ->+  TreeCursor a b ->+  m (Widget n)+verticalPaddedTreeCursorWidgetM goA goB padding = treeCursorWidgetM wrap cur+  where+    goCTree :: CTree b -> m (Widget n)+    goCTree (CNode b cf) = do+      top <- goB b+      bot <- goCForest cf+      pure $ top <=> padLeft (Pad padding) bot+    goCForest :: CForest b -> m (Widget n)+    goCForest = \case+      EmptyCForest -> pure emptyWidget+      ClosedForest _ -> pure emptyWidget+      OpenForest nect -> fmap vBox $ traverse goCTree $ NE.toList nect+    wrap :: [CTree b] -> b -> [CTree b] -> Widget n -> m (Widget n)+    wrap lefts above rights curW = do+      top <- goB above+      bot <-+        vBox+          <$> sequenceA+            ( concat+                [ map goCTree lefts,+                  [pure curW],+                  map goCTree rights+                ]+            )+      pure $ top <=> padLeft (Pad padding) bot+    cur :: a -> CForest b -> m (Widget n)+    cur a cf = do+      top <- goA a+      bot <- goCForest cf+      pure $ top <=> padLeft (Pad padding) bot +verticalPaddedTreeCursorWidget ::+  forall a b n.+  (a -> Widget n) ->+  (b -> Widget n) ->+  Int ->+  TreeCursor a b ->+  Widget n+verticalPaddedTreeCursorWidget goA goB padding = treeCursorWidget wrap cur+  where+    goCTree :: CTree b -> Widget n+    goCTree (CNode b cf) = goB b <=> padLeft (Pad padding) (goCForest cf)+    goCForest :: CForest b -> Widget n+    goCForest = \case+      EmptyCForest -> emptyWidget+      ClosedForest _ -> emptyWidget+      OpenForest nect -> vBox $ map goCTree $ NE.toList nect+    wrap :: [CTree b] -> b -> [CTree b] -> Widget n -> Widget n+    wrap lefts above rights curW =+      goB above+        <=> padLeft+          (Pad 2)+          ( vBox $+              concat+                [ map goCTree lefts,+                  [curW],+                  map goCTree rights+                ]+          )+    cur :: a -> CForest b -> Widget n+    cur a cf = goA a <=> padLeft (Pad padding) (goCForest cf)+ treeCursorWidgetM ::-     forall a b n m. Monad m-  => ([CTree b] -> b -> [CTree b] -> Widget n -> m (Widget n))-  -> (a -> CForest b -> m (Widget n))-  -> TreeCursor a b-  -> m (Widget n)+  forall a b n m.+  Monad m =>+  ([CTree b] -> b -> [CTree b] -> Widget n -> m (Widget n)) ->+  (a -> CForest b -> m (Widget n)) ->+  TreeCursor a b ->+  m (Widget n) treeCursorWidgetM = traverseTreeCursor  treeCursorWidget ::-     forall a b n.-     ([CTree b] -> b -> [CTree b] -> Widget n -> Widget n)-  -> (a -> CForest b -> Widget n)-  -> TreeCursor a b-  -> Widget n+  forall a b n.+  ([CTree b] -> b -> [CTree b] -> Widget n -> Widget n) ->+  (a -> CForest b -> Widget n) ->+  TreeCursor a b ->+  Widget n treeCursorWidget = foldTreeCursor