packages feed

brick-filetree 0.1.0.1 → 0.1.0.2

raw patch · 6 files changed

+64/−19 lines, 6 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Brick.Widgets.FileTree: selectedItemAttr :: AttrName
- Brick.Widgets.FileTree: toggleSelection :: FileTree -> EventM String FileTree
- Brick.Widgets.FileTree: toggleSelectionVisible :: FileTree -> FileTree
- Brick.Widgets.FileTree.Internal.Actions: toggleSelection :: FileTree -> EventM String FileTree
- Brick.Widgets.FileTree.Internal.Actions: toggleSelectionVisible :: FileTree -> FileTree
- Brick.Widgets.FileTree.Internal.Render: selectedItemAttr :: AttrName
+ Brick.Widgets.FileTree: flaggedItemAttr :: AttrName
+ Brick.Widgets.FileTree: toggleFlagged :: FileTree -> EventM String FileTree
+ Brick.Widgets.FileTree: toggleFlaggedVisible :: FileTree -> FileTree
+ Brick.Widgets.FileTree.Internal.Actions: toggleFlagged :: FileTree -> EventM String FileTree
+ Brick.Widgets.FileTree.Internal.Actions: toggleFlaggedVisible :: FileTree -> FileTree
+ Brick.Widgets.FileTree.Internal.Render: flaggedItemAttr :: AttrName

Files

README.md view
@@ -6,3 +6,11 @@ [![Stackageetree Nightly](http://stackage.org/package/brick-fil/badge/nightly)](http://stackage.org/nightly/package/brick-filetree) [![Build status](https://secure.travis-ci.org/ChrisPenner/brick-filetree.svg)](https://travis-ci.org/ChrisPenner/brick-filetree)++---++A brick widget for exploring file trees.++See [Hackage](https://hackage.haskell.org/package/brick-filetree) for docs.++[![asciicast](https://asciinema.org/a/BegqABw8NlGfEJqFfbOIVVozr.svg)](https://asciinema.org/a/BegqABw8NlGfEJqFfbOIVVozr)
brick-filetree.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: a0bf5868308352143c04af5f1c6bd4d529abb23b023af4fe7d6308aba8411bbb+-- hash: a1c35f4807a2c1fe8338398832ea28f66d6766999d7cc199b0f806d2a59daf21  name:           brick-filetree-version:        0.1.0.1+version:        0.1.0.2 description:    Please see the README on GitHub at <https://github.com/ChrisPenner/brick-filetree#readme> homepage:       https://github.com/ChrisPenner/brick-filetree#readme bug-reports:    https://github.com/ChrisPenner/brick-filetree/issues
src/Brick/Widgets/FileTree.hs view
@@ -1,22 +1,34 @@ module Brick.Widgets.FileTree-  ( FileTree+  (+  -- * Types+  FileTree++  -- Initialization   , newFileTree-  , toggleSelection++  -- * Interaction   , moveUp   , moveDown-  , pageDown   , pageUp+  , pageDown   , moveToTop   , moveToBottom   , ascendDir   , descendDir+  , toggleFlagged+  , toggleFlaggedVisible++  -- * Queries   , getCurrentFilePath   , getCurrentDir   , getFlagged-  , toggleSelectionVisible++  -- * Rendering   , renderFileTree   , renderSelection-  , selectedItemAttr++  -- ** Attributes+  , flaggedItemAttr   , titleAttr   , dirAttr   , fileAttr
src/Brick/Widgets/FileTree/Internal/Actions.hs view
@@ -15,9 +15,9 @@   , descendDir   , getCurrentFilePath   , getCurrentDir-  , toggleSelection+  , toggleFlagged   , getFlagged-  , toggleSelectionVisible+  , toggleFlaggedVisible   ) where  import qualified Graphics.Vty.Input as V@@ -45,24 +45,31 @@ pressKey :: V.Key -> (FileTree -> EventM String FileTree) pressKey k = overCurrentList (handleListEvent (V.EvKey k [])) +-- | Move the cursor down one item moveDown :: FileTree -> EventM String FileTree moveDown = pressKey V.KDown +-- | Move the cursor up one item moveUp :: FileTree -> EventM String FileTree moveUp = pressKey V.KUp +-- | Move the cursor down a page pageDown :: FileTree -> EventM String FileTree pageDown = pressKey V.KPageDown +-- | Move the cursor up a page pageUp :: FileTree -> EventM String FileTree pageUp = pressKey V.KPageDown +-- | Move the cursor the the top of the file list moveToTop :: FileTree -> EventM String FileTree moveToTop = pressKey V.KHome +-- | Move the cursor the the bottom of the file list moveToBottom :: FileTree -> EventM String FileTree moveToBottom = pressKey V.KEnd +-- | Move the cursor up a directory in the file tree ascendDir :: FileTree -> EventM String FileTree ascendDir (FZ { parents = Seq.Empty, context = tree@((extract -> path -> p)), selection, ..})   = do@@ -73,6 +80,8 @@   return     $ FZ {parents = ps, context = (f :< listModify (const context) pList), ..} +-- | If the cursor is on a directory then descend the cursor into that dir+-- If the cursor is on a file nothing happens descendDir :: FileTree -> EventM String FileTree descendDir fz@(FZ { parents, context = (f :< children), ..}) = do   invalidateCacheEntry (cacheKey f)@@ -85,6 +94,7 @@       }     Just _ -> fz +-- | Get the absolute path of the object (dir or file) under the cursor  getCurrentFilePath :: FileTree -> Maybe FilePath getCurrentFilePath (FZ { context = unwrap -> children }) =   case listSelectedElement children of@@ -92,11 +102,13 @@     Just (_, FC { kind = Error } :< _) -> Nothing     Just (_, fc :< _                 ) -> Just (path fc) +-- | Get the absolute path of the directory where the cursor currently is. getCurrentDir :: FileTree -> FilePath getCurrentDir (FZ { context = extract -> path -> p }) = p -toggleSelection :: FileTree -> EventM String FileTree-toggleSelection fz@(FZ { context = (fc :< lst), selection, ..}) = do+-- | Flag or unflag the current file or dir+toggleFlagged :: FileTree -> EventM String FileTree+toggleFlagged fz@(FZ { context = (fc :< lst), selection, ..}) = do   invalidateCacheEntry selectionCacheKey   return . fromMaybe fz $ do     ((selectedContext@FC { selected = isSelected, path }) :< rest) <- snd@@ -109,9 +121,11 @@           lst     return $ FZ {context = (fc :< newList), selection = newSelection, ..} +-- | Get all flagged file paths. All paths are absolute getFlagged :: FileTree -> [FilePath] getFlagged = toList . selection -toggleSelectionVisible :: FileTree -> FileTree-toggleSelectionVisible fz@(FZ { config }) =+-- | Hide/Show a list of all flagged files+toggleFlaggedVisible :: FileTree -> FileTree+toggleFlaggedVisible fz@(FZ { config }) =   fz { config = config { showSelection = not $ showSelection config } }
src/Brick/Widgets/FileTree/Internal/Render.hs view
@@ -2,7 +2,7 @@ {-# LANGUAGE ViewPatterns #-} {-# LANGUAGE OverloadedStrings #-} module Brick.Widgets.FileTree.Internal.Render-  ( selectedItemAttr+  ( flaggedItemAttr   , titleAttr   , dirAttr   , fileAttr@@ -28,11 +28,20 @@ import           Data.Bool import qualified Data.Sequence                 as S -selectedItemAttr, titleAttr, dirAttr, fileAttr, errorAttr :: AttrName-selectedItemAttr = "selectedItemAttr"+-- | Flagged items are rendered with this attr+flaggedItemAttr :: AttrName+flaggedItemAttr = "flaggedItemAttr"+-- | UI Titles have this attr+titleAttr :: AttrName titleAttr = "titleAttr"+-- | Directories in the list have this attr+dirAttr :: AttrName dirAttr = "dirAttr"+-- | Files in the list have this attr+fileAttr :: AttrName fileAttr = "fileAttr"+-- | Errors have this attr+errorAttr :: AttrName errorAttr = "errorAttr"  cacheKey :: FileContext -> String@@ -68,7 +77,7 @@   = let selectionsW =           cached selectionCacheKey             . vBox-            . fmap (withAttr selectedItemAttr . str)+            . fmap (withAttr flaggedItemAttr . str)             . toList             $ selection     in  hBorder <=> withAttr titleAttr (str "Selected") <=> selectionsW@@ -94,11 +103,11 @@ renderFileContext :: FileContext -> Widget String renderFileContext (FC { kind = File, name, selected }) =   let (attr', modStr) =-        if selected then (selectedItemAttr, "* ") else (fileAttr, "")+        if selected then (flaggedItemAttr, "* ") else (fileAttr, "")   in  withAttr attr' . str $ modStr <> name renderFileContext (FC { kind = Error, name, path }) =   withAttr errorAttr . str $ "! " <> path <> ": " <> name renderFileContext (FC { kind = Dir, name, selected }) =   let (attr', modStr) =-        if selected then (selectedItemAttr, "* ") else (dirAttr, "")+        if selected then (flaggedItemAttr, "* ") else (dirAttr, "")   in  withAttr attr' . str $ modStr <> name <> "/"
src/Brick/Widgets/FileTree/Internal/Types.hs view
@@ -44,6 +44,7 @@  type SubTree = Cofree (GenericList String V.Vector) FileContext +-- | Represents all the state required to interact with or display a filetree data FileTree = FZ   { parents :: S.Seq SubTree   , selection :: S.Set FilePath@@ -60,6 +61,7 @@   replace pth fc@((path -> pth') :< _) new | pth == pth' = new                                            | otherwise   = fc +-- | Create a new 'FileTree' situated at the given 'FilePath' newFileTree :: FilePath -> IO FileTree newFileTree currentDir = do   absRoot        <- makeAbsolute (normalise currentDir)