formatting

This commit is contained in:
pingu 2023-10-16 16:27:20 +02:00
parent 934145980b
commit 7f9eaf5621

View File

@ -52,10 +52,10 @@ data ScrollDirection where
data AppS = AppS data AppS = AppS
{ {
_appCWD :: FilePath appCWD :: FilePath
, _appCursor :: Int , appCursor :: Int
, _appFocus :: Maybe FilePath , appFocus :: Maybe FilePath
, _appSubFiles :: [(FilePath, Integer)] , appSubFiles :: [(FilePath, Integer)]
} }
app :: App AppS e () app :: App AppS e ()
@ -79,11 +79,11 @@ select = withAttr (attrName "selected")
browse :: AppS -> Widget () browse :: AppS -> Widget ()
browse s = browse s =
str "Path" <+> padLeft Max (str "Size") <=> str "Path" <+> padLeft Max (str "Size") <=>
viewport () Vertical (foldr (widgetCons s) emptyWidget (_appSubFiles s)) viewport () Vertical (foldr (widgetCons s) emptyWidget (appSubFiles s))
widgetCons :: AppS -> (FilePath, Integer) -> Widget () -> Widget () widgetCons :: AppS -> (FilePath, Integer) -> Widget () -> Widget ()
widgetCons s w@(f,_) ws = widgetCons s w@(f,_) ws =
(<=> ws) if Just f == _appFocus s then (<=> ws) if Just f == appFocus s then
select . visible $ pathWidget w else select . visible $ pathWidget w else
pathWidget w pathWidget w
@ -92,29 +92,29 @@ pathWidget (f, s) = str (show f) <+> padLeft Max (str (show s))
sizeDir :: AppS -> IO AppS sizeDir :: AppS -> IO AppS
sizeDir s = do sizeDir s = do
subFiles <- getSizeSubpaths $ _appCWD s subFiles <- getSizeSubpaths $ appCWD s
pure $ pure $
s { s {
_appCursor = 0 appCursor = 0
, _appFocus = map fst subFiles !? 0 , appFocus = map fst subFiles !? 0
, _appSubFiles = subFiles , appSubFiles = subFiles
} }
changeDir :: AppS -> IO AppS changeDir :: AppS -> IO AppS
changeDir so changeDir so
| isJust $ _appFocus so = do | isJust $ appFocus so = do
allowed <- doesDirectoryExist path allowed <- doesDirectoryExist path
if allowed then do if allowed then do
changeWorkingDirectory path changeWorkingDirectory path
let s = let s =
so { so {
_appCWD = path appCWD = path
, _appSubFiles = [] , appSubFiles = []
} in } in
sizeDir s else sizeDir s else
pure so pure so
| otherwise = pure so | otherwise = pure so
where path = fromJust $ _appFocus so where path = fromJust $ appFocus so
overDir :: IO AppS overDir :: IO AppS
overDir = do overDir = do
@ -124,16 +124,16 @@ overDir = do
scroll :: ScrollDirection -> AppS -> AppS scroll :: ScrollDirection -> AppS -> AppS
scroll d s = s { scroll d s = s {
_appCursor = newCursor appCursor = newCursor
, _appFocus = maybeNewPath , appFocus = maybeNewPath
} }
where cursor = where cursor =
_appCursor s + appCursor s +
case d of case d of
SUp -> (-1) SUp -> (-1)
SDown -> 1 SDown -> 1
newCursor = max 0 (min (subtract 1 . length $ _appSubFiles s) cursor) newCursor = max 0 (min (subtract 1 . length $ appSubFiles s) cursor)
maybeNewPath = fst <$> _appSubFiles s !? newCursor maybeNewPath = fst <$> appSubFiles s !? newCursor
eventHandler :: BrickEvent () e -> EventM () AppS () eventHandler :: BrickEvent () e -> EventM () AppS ()
eventHandler (VtyEvent (EvKey k _)) = do eventHandler (VtyEvent (EvKey k _)) = do
@ -143,8 +143,8 @@ eventHandler (VtyEvent (EvKey k _)) = do
KEsc -> halt KEsc -> halt
(KChar 'j') -> put $ scroll SDown s (KChar 'j') -> put $ scroll SDown s
(KChar 'k') -> put $ scroll SUp s
KDown -> put $ scroll SDown s KDown -> put $ scroll SDown s
(KChar 'k') -> put $ scroll SUp s
KUp -> put $ scroll SUp s KUp -> put $ scroll SUp s
(KChar 'h') -> put =<< liftIO overDir (KChar 'h') -> put =<< liftIO overDir
@ -162,10 +162,10 @@ eventHandler _ = undefined
initialState :: FilePath -> AppS initialState :: FilePath -> AppS
initialState f = initialState f =
AppS { AppS {
_appCWD = f appCWD = f
, _appCursor = 0 , appCursor = 0
, _appFocus = pure f , appFocus = pure f
, _appSubFiles = [] , appSubFiles = []
} }
main :: IO () main :: IO ()