brick 0.48 → 0.49
raw patch · 3 files changed
+46/−3 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Brick.Widgets.FileBrowser: [fileInfoLinkTargetType] :: FileInfo -> Maybe FileType
+ Brick.Widgets.FileBrowser: fileInfoLinkTargetTypeL :: Lens' FileInfo (Maybe FileType)
- Brick.Widgets.FileBrowser: FileInfo :: String -> String -> FilePath -> Either IOException FileStatus -> FileInfo
+ Brick.Widgets.FileBrowser: FileInfo :: String -> String -> FilePath -> Either IOException FileStatus -> Maybe FileType -> FileInfo
- Brick.Widgets.FileBrowser: fileBrowserEntryFilterL :: forall n_a1r6u. Lens' (FileBrowser n_a1r6u) (Maybe (FileInfo -> Bool))
+ Brick.Widgets.FileBrowser: fileBrowserEntryFilterL :: forall n_a1r6v. Lens' (FileBrowser n_a1r6v) (Maybe (FileInfo -> Bool))
- Brick.Widgets.FileBrowser: fileBrowserSelectableL :: forall n_a1r6u. Lens' (FileBrowser n_a1r6u) (FileInfo -> Bool)
+ Brick.Widgets.FileBrowser: fileBrowserSelectableL :: forall n_a1r6v. Lens' (FileBrowser n_a1r6v) (FileInfo -> Bool)
Files
- CHANGELOG.md +10/−0
- brick.cabal +1/−1
- src/Brick/Widgets/FileBrowser.hs +35/−2
CHANGELOG.md view
@@ -2,6 +2,16 @@ Brick changelog --------------- +0.49+----++New features:+ * The `FileBrowser` now supports navigation of directories via+ symlinks, so `Enter` on a symlink will descend into the target path+ of the symlink if that path is a directory. Part of this change is+ that the `FileInfo` type got a new file, `fileInfoLinkTargetType`,+ that indicates the type of file that the link points to, if any.+ 0.48 ----
brick.cabal view
@@ -1,5 +1,5 @@ name: brick-version: 0.48+version: 0.49 synopsis: A declarative terminal user interface library description: Write terminal applications painlessly with 'brick'! You write an
src/Brick/Widgets/FileBrowser.hs view
@@ -102,6 +102,7 @@ , fileInfoSanitizedFilenameL , fileInfoFilePathL , fileInfoFileStatusL+ , fileInfoLinkTargetTypeL , fileStatusSizeL , fileStatusFileTypeL @@ -197,6 +198,9 @@ -- ^ The file status if it could be obtained, or the -- exception that was caught when attempting to read the -- file's status.+ , fileInfoLinkTargetType :: Maybe FileType+ -- ^ If this entry is a symlink, this indicates the type of+ -- file the symlink points to, if it could be obtained. } deriving (Show, Eq) @@ -268,6 +272,10 @@ selectNonDirectories i = case fileInfoFileType i of Just Directory -> False+ Just SymbolicLink ->+ case fileInfoLinkTargetType i of+ Just Directory -> False+ _ -> True _ -> True -- | A file entry selector that permits selection of directories@@ -277,6 +285,10 @@ selectDirectories i = case fileInfoFileType i of Just Directory -> True+ Just SymbolicLink ->+ case fileInfoLinkTargetType i of+ Just Directory -> True+ _ -> False _ -> False -- | Set the filtering function used to determine which entries in@@ -346,10 +358,23 @@ , fileStatusSize = sz } + targetTy <- case fileStatusFileType <$> stat of+ Right (Just SymbolicLink) -> do+ targetPathResult <- E.try $ U.readSymbolicLink filePath+ case targetPathResult of+ Left (_::E.SomeException) -> return Nothing+ Right targetPath -> do+ targetInfo <- liftIO $ getFileInfo "unused" targetPath+ case fileInfoFileStatus targetInfo of+ Right (FileStatus _ targetTy) -> return targetTy+ _ -> return Nothing+ _ -> return Nothing+ return FileInfo { fileInfoFilename = name , fileInfoFilePath = filePath , fileInfoSanitizedFilename = sanitizeFilename name , fileInfoFileStatus = stat+ , fileInfoLinkTargetType = targetTy } -- | Get the file type for this file info entry. If the file type could@@ -574,8 +599,16 @@ if fileBrowserSelectable b entry then return $ b & fileBrowserSelectedFilesL %~ Set.insert (fileInfoFilename entry) else case fileInfoFileType entry of- Just Directory -> liftIO $ setWorkingDirectory (fileInfoFilePath entry) b- _ -> return b+ Just Directory ->+ liftIO $ setWorkingDirectory (fileInfoFilePath entry) b+ Just SymbolicLink ->+ case fileInfoLinkTargetType entry of+ Just Directory -> do+ liftIO $ setWorkingDirectory (fileInfoFilePath entry) b+ _ ->+ return b+ _ ->+ return b selectCurrentEntry :: FileBrowser n -> EventM n (FileBrowser n) selectCurrentEntry b =