cursor-brick 0.0.0.0 → 0.1.0.0
raw patch · 11 files changed
+189/−44 lines, 11 filesdep +textsetup-changedPVP ok
version bump matches the API change (PVP)
Dependencies added: text
API changes (from Hackage documentation)
+ Cursor.Brick.Text: nonNullLinesText :: Text -> Text
+ Cursor.Brick.Text: nonNullText :: Text -> Text
+ Cursor.Brick.Text: sanitiseText :: Text -> Text
+ Cursor.Brick.Text: selectedTextCursorWidget :: n -> TextCursor -> Widget n
+ Cursor.Brick.Text: textCursorWidget :: TextCursor -> Widget n
+ Cursor.Brick.Text: textLineWidget :: Text -> Widget n
+ Cursor.Brick.Text: textLineWidgetWrap :: Text -> Widget n
+ Cursor.Brick.Text: textWidget :: Text -> Widget n
+ Cursor.Brick.Text: textWidgetWrap :: Text -> Widget n
+ Cursor.Brick.TextField: selectedTextFieldCursorWidget :: n -> TextFieldCursor -> Widget n
+ Cursor.Brick.TextField: textFieldCursorWidget :: TextFieldCursor -> Widget n
Files
- Setup.hs +1/−0
- cursor-brick.cabal +5/−2
- src/Cursor/Brick.hs +13/−1
- src/Cursor/Brick/Forest.hs +14/−10
- src/Cursor/Brick/List.hs +3/−3
- src/Cursor/Brick/List/NonEmpty.hs +24/−8
- src/Cursor/Brick/Map.hs +20/−10
- src/Cursor/Brick/Map/KeyValue.hs +4/−7
- src/Cursor/Brick/Text.hs +69/−0
- src/Cursor/Brick/TextField.hs +36/−0
- src/Cursor/Brick/Tree.hs +0/−3
Setup.hs view
@@ -1,2 +1,3 @@ import Distribution.Simple+ main = defaultMain
cursor-brick.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 7d8cfb93a2e1e9e9cbfb16cbe022245b498e38c2b591cb9da187759a356bee6f+-- hash: dd4cb07a29abf9dd36525dc5fa9f67eb370539e7b2f41f461bafbd5e117883d9 name: cursor-brick-version: 0.0.0.0+version: 0.1.0.0 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@@ -32,6 +32,8 @@ Cursor.Brick.List.NonEmpty Cursor.Brick.Map Cursor.Brick.Map.KeyValue+ Cursor.Brick.Text+ Cursor.Brick.TextField Cursor.Brick.Tree other-modules: Paths_cursor_brick@@ -41,4 +43,5 @@ base >=4.7 && <5 , brick , cursor+ , text default-language: Haskell2010
src/Cursor/Brick.hs view
@@ -1,7 +1,19 @@ module Cursor.Brick- ( module Cursor.Brick.List+ ( 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 import Cursor.Brick.List.NonEmpty+import Cursor.Brick.Map+import Cursor.Brick.Map.KeyValue+import Cursor.Brick.Text+import Cursor.Brick.TextField+import Cursor.Brick.Tree
src/Cursor/Brick/Forest.hs view
@@ -3,16 +3,12 @@ module Cursor.Brick.Forest where -import Control.Monad- import Cursor.Forest import Cursor.Tree import Brick.Types-import Brick.Widgets.Core import Cursor.Brick.List.NonEmpty-import Cursor.Brick.Tree horizontalForestCursorWidgetM :: Monad m@@ -22,7 +18,8 @@ -> 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)@@ -31,7 +28,8 @@ -> ForestCursor a b -> Widget n horizontalForestCursorWidget prevFunc curFunc nextFunc =- horizontalNonEmptyCursorWidget prevFunc curFunc nextFunc . forestCursorListCursor+ horizontalNonEmptyCursorWidget prevFunc curFunc nextFunc .+ forestCursorListCursor verticalForestCursorWidgetM :: Monad m@@ -41,7 +39,8 @@ -> 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)@@ -50,12 +49,17 @@ -> 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
@@ -4,10 +4,10 @@ import Cursor.List -import Brick.Types as B-import Brick.Widgets.Core as B+import Brick.Types -listCursorWidgetM :: ([a] -> [a] -> m (Widget n)) -> ListCursor a -> m (Widget n)+listCursorWidgetM ::+ ([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
@@ -16,13 +16,20 @@ -> 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]+ hBox $+ concat [map beforeFunc befores, [curFunc current], map afterFunc afters] verticalNonEmptyCursorWidgetM :: Applicative f@@ -33,16 +40,25 @@ -> 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]+ vBox $+ concat [map beforeFunc befores, [curFunc current], map afterFunc afters] -nonEmptyCursorWidgetM :: ([b] -> a -> [b] -> m (Widget n)) -> NonEmptyCursor a b -> m (Widget n)+nonEmptyCursorWidgetM ::+ ([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+nonEmptyCursorWidget ::+ ([b] -> a -> [b] -> Widget n) -> NonEmptyCursor a b -> Widget n nonEmptyCursorWidget = foldNonEmptyCursor
src/Cursor/Brick/Map.hs view
@@ -3,17 +3,11 @@ module Cursor.Brick.Map where -import Control.Monad--import Cursor.List.NonEmpty import Cursor.Map import Brick.Types import Brick.Widgets.Core -import Cursor.Brick.List.NonEmpty-import Cursor.Brick.Map.KeyValue- horizontalMapCursorWidget :: (k -> v -> Widget n) -> (KeyValueCursor kc vc k v -> Widget n)@@ -23,7 +17,11 @@ 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@@ -36,7 +34,11 @@ mapCursorWidgetM $ \befores current afters -> hBox <$> sequenceA- (concat [map (uncurry beforeFunc) befores, [curFunc current], map (uncurry afterFunc) afters])+ (concat+ [ map (uncurry beforeFunc) befores+ , [curFunc current]+ , map (uncurry afterFunc) afters+ ]) verticalMapCursorWidget :: (k -> v -> Widget n)@@ -47,7 +49,11 @@ 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@@ -60,7 +66,11 @@ mapCursorWidgetM $ \befores current afters -> vBox <$> sequenceA- (concat [map (uncurry beforeFunc) befores, [curFunc current], map (uncurry afterFunc) afters])+ (concat+ [ map (uncurry beforeFunc) befores+ , [curFunc current]+ , map (uncurry afterFunc) afters+ ]) mapCursorWidget :: ([(k, v)] -> KeyValueCursor kc vc k v -> [(k, v)] -> Widget n)
src/Cursor/Brick/Map/KeyValue.hs view
@@ -3,18 +3,15 @@ module Cursor.Brick.Map.KeyValue where -import Control.Monad--import Cursor.List.NonEmpty import Cursor.Map import Brick.Types-import Brick.Widgets.Core -import Cursor.Brick.List.NonEmpty- 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 ::
+ src/Cursor/Brick/Text.hs view
@@ -0,0 +1,69 @@+{-# LANGUAGE OverloadedStrings #-}++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++-- | Make a text cursor widget with a blink-y box.+--+-- This function does not wrap the given text.+--+-- Otherwise, because of the way indexes work, there would be rendering errors for text that crosses the side of the terminal.+selectedTextCursorWidget :: n -> TextCursor -> Widget n+selectedTextCursorWidget n tc =+ Brick.showCursor n (Brick.Location (textCursorIndex tc, 0)) $+ textCursorWidget tc++-- | Make a text cursor widget without a blink-y box.+--+-- This function does not wrap the given text.+textCursorWidget :: TextCursor -> Widget n+textCursorWidget tc =+ txt $+ 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+textWidget = txt . nonNullLinesText . sanitiseText++-- | Draw an arbitrary Text (with wrapping), it will be sanitised.+textWidgetWrap :: Text -> Widget n+textWidgetWrap = txtWrap . nonNullLinesText . sanitiseText++-- | Draw an arbitrary single-line Text, it will be sanitised.+textLineWidget :: Text -> Widget n+textLineWidget = txt . nonNullText . sanitiseText++-- | Draw an arbitrary single-line Text (with wrapping), it will be sanitised.+textLineWidgetWrap :: Text -> Widget n+textLineWidgetWrap = txtWrap . nonNullText . sanitiseText++-- | Makes every line of a Text non-empty using `nonNullText`+nonNullLinesText :: Text -> Text+nonNullLinesText = T.intercalate "\n" . map nonNullText . T.splitOn "\n"++-- | Makes a text non-empty.+--+-- This turns the empty text into " " and leaves other text as-is.+nonNullText :: Text -> Text+nonNullText "" = " "+nonNullText t = t++-- | Replace tabs by spaces so that brick doesn't render nonsense.+--+-- See https://hackage.haskell.org/package/brick/docs/Brick-Widgets-Core.html#v:txt+sanitiseText :: Text -> Text+sanitiseText =+ T.map $ \c ->+ case c of+ '\t' -> ' '+ _ -> c
+ src/Cursor/Brick/TextField.hs view
@@ -0,0 +1,36 @@+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++-- | Make a textfield cursor widget with a blink-y box.+--+-- This function does not wrap lines.+-- Otherwise, because of the way indexes work, there would be rendering errors for text that crosses the side of the terminal.+selectedTextFieldCursorWidget :: n -> TextFieldCursor -> Widget n+selectedTextFieldCursorWidget n (TextFieldCursor tfc) =+ flip foldNonEmptyCursor tfc $ \befores current afters ->+ vBox $+ concat+ [ map textWidget befores+ , [selectedTextCursorWidget n current]+ , map textWidget afters+ ]++-- | Make a textfield cursor widget without a blink-y box.+--+-- This function does not wrap lines .+textFieldCursorWidget :: TextFieldCursor -> Widget n+textFieldCursorWidget (TextFieldCursor tfc) =+ flip foldNonEmptyCursor tfc $ \befores current afters ->+ vBox $+ concat+ [ map textWidget befores+ , [textCursorWidget current]+ , map textWidget afters+ ]
src/Cursor/Brick/Tree.hs view
@@ -3,12 +3,9 @@ module Cursor.Brick.Tree where -import Control.Monad- import Cursor.Tree import Brick.Types-import Brick.Widgets.Core treeCursorWidgetM :: forall a b n m. Monad m