Can't go above root

This commit is contained in:
pingu 2023-10-17 13:21:03 +02:00
parent 6f027562b6
commit 262413cc69

View File

@ -16,6 +16,7 @@ import System.IO.Error
import Brick
import Brick.Widgets.Edit
import Graphics.Vty
import Data.List ( isPrefixOf )
import Data.List.Extra ( sortOn
, (!?))
import qualified Data.Ord
@ -35,7 +36,10 @@ listSym dir = filterM pathIsSymbolicLink =<< listContents dir
handlePermissionError :: IOError -> IO Integer
handlePermissionError e = if isPermissionError e then pure 0 else ioError e
getSizeSubpaths :: FilePath -> IORef (IOHashMap FilePath [(FilePath, Integer)]) -> IO [(FilePath, Integer)]
getSizeSubpaths ::
FilePath ->
IORef (IOHashMap FilePath [(FilePath, Integer)]) ->
IO [(FilePath, Integer)]
getSizeSubpaths x i = do
memo <- readIORef i
val <- lookup x memo
@ -64,11 +68,12 @@ data ScrollDirection where
data AppS = AppS
{
appCWD :: FilePath
, appCursor :: Int
, appFocus :: Maybe FilePath
appCWD :: FilePath
, appCursor :: Int
, appFocus :: Maybe FilePath
, appSubFiles :: [(FilePath, Integer)]
, appMemo :: IORef (IOHashMap FilePath [(FilePath, Integer)])
, appMemo :: IORef (IOHashMap FilePath [(FilePath, Integer)])
, appRoot :: FilePath
}
app :: App AppS e ()
@ -150,12 +155,14 @@ overDir :: AppS -> IO AppS
overDir s = do
changeWorkingDirectory ".."
a <- getWorkingDirectory
changeDir $ s {
appCWD = a
, appCursor = 0
, appFocus = pure a
, appSubFiles = []
}
if a `isPrefixOf` appRoot s && a /= appRoot s then
pure s else
changeDir $ s {
appCWD = a
, appCursor = 0
, appFocus = pure a
, appSubFiles = []
}
scroll :: ScrollDirection -> AppS -> AppS
scroll d s = s {
@ -194,7 +201,10 @@ eventHandler (VtyEvent (EvKey k _)) = do
eventHandler (VtyEvent (EvResize _ _)) = pure ()
eventHandler _ = undefined
initialState :: FilePath -> IORef (IOHashMap FilePath [(FilePath, Integer)]) -> AppS
initialState ::
FilePath ->
IORef (IOHashMap FilePath [(FilePath, Integer)]) ->
AppS
initialState f i =
AppS {
appCWD = f
@ -202,6 +212,7 @@ initialState f i =
, appFocus = pure f
, appSubFiles = []
, appMemo = i
, appRoot = f
}
main :: IO ()