formatting
This commit is contained in:
parent
934145980b
commit
7f9eaf5621
48
app/Main.hs
48
app/Main.hs
@ -52,10 +52,10 @@ data ScrollDirection where
|
||||
|
||||
data AppS = AppS
|
||||
{
|
||||
_appCWD :: FilePath
|
||||
, _appCursor :: Int
|
||||
, _appFocus :: Maybe FilePath
|
||||
, _appSubFiles :: [(FilePath, Integer)]
|
||||
appCWD :: FilePath
|
||||
, appCursor :: Int
|
||||
, appFocus :: Maybe FilePath
|
||||
, appSubFiles :: [(FilePath, Integer)]
|
||||
}
|
||||
|
||||
app :: App AppS e ()
|
||||
@ -79,11 +79,11 @@ select = withAttr (attrName "selected")
|
||||
browse :: AppS -> Widget ()
|
||||
browse s =
|
||||
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 s w@(f,_) ws =
|
||||
(<=> ws) if Just f == _appFocus s then
|
||||
(<=> ws) if Just f == appFocus s then
|
||||
select . visible $ pathWidget w else
|
||||
pathWidget w
|
||||
|
||||
@ -92,29 +92,29 @@ pathWidget (f, s) = str (show f) <+> padLeft Max (str (show s))
|
||||
|
||||
sizeDir :: AppS -> IO AppS
|
||||
sizeDir s = do
|
||||
subFiles <- getSizeSubpaths $ _appCWD s
|
||||
subFiles <- getSizeSubpaths $ appCWD s
|
||||
pure $
|
||||
s {
|
||||
_appCursor = 0
|
||||
, _appFocus = map fst subFiles !? 0
|
||||
, _appSubFiles = subFiles
|
||||
appCursor = 0
|
||||
, appFocus = map fst subFiles !? 0
|
||||
, appSubFiles = subFiles
|
||||
}
|
||||
|
||||
changeDir :: AppS -> IO AppS
|
||||
changeDir so
|
||||
| isJust $ _appFocus so = do
|
||||
| isJust $ appFocus so = do
|
||||
allowed <- doesDirectoryExist path
|
||||
if allowed then do
|
||||
changeWorkingDirectory path
|
||||
let s =
|
||||
so {
|
||||
_appCWD = path
|
||||
, _appSubFiles = []
|
||||
appCWD = path
|
||||
, appSubFiles = []
|
||||
} in
|
||||
sizeDir s else
|
||||
pure so
|
||||
| otherwise = pure so
|
||||
where path = fromJust $ _appFocus so
|
||||
where path = fromJust $ appFocus so
|
||||
|
||||
overDir :: IO AppS
|
||||
overDir = do
|
||||
@ -124,16 +124,16 @@ overDir = do
|
||||
|
||||
scroll :: ScrollDirection -> AppS -> AppS
|
||||
scroll d s = s {
|
||||
_appCursor = newCursor
|
||||
, _appFocus = maybeNewPath
|
||||
appCursor = newCursor
|
||||
, appFocus = maybeNewPath
|
||||
}
|
||||
where cursor =
|
||||
_appCursor s +
|
||||
appCursor s +
|
||||
case d of
|
||||
SUp -> (-1)
|
||||
SDown -> 1
|
||||
newCursor = max 0 (min (subtract 1 . length $ _appSubFiles s) cursor)
|
||||
maybeNewPath = fst <$> _appSubFiles s !? newCursor
|
||||
newCursor = max 0 (min (subtract 1 . length $ appSubFiles s) cursor)
|
||||
maybeNewPath = fst <$> appSubFiles s !? newCursor
|
||||
|
||||
eventHandler :: BrickEvent () e -> EventM () AppS ()
|
||||
eventHandler (VtyEvent (EvKey k _)) = do
|
||||
@ -143,8 +143,8 @@ eventHandler (VtyEvent (EvKey k _)) = do
|
||||
KEsc -> halt
|
||||
|
||||
(KChar 'j') -> put $ scroll SDown s
|
||||
(KChar 'k') -> put $ scroll SUp s
|
||||
KDown -> put $ scroll SDown s
|
||||
(KChar 'k') -> put $ scroll SUp s
|
||||
KUp -> put $ scroll SUp s
|
||||
|
||||
(KChar 'h') -> put =<< liftIO overDir
|
||||
@ -162,10 +162,10 @@ eventHandler _ = undefined
|
||||
initialState :: FilePath -> AppS
|
||||
initialState f =
|
||||
AppS {
|
||||
_appCWD = f
|
||||
, _appCursor = 0
|
||||
, _appFocus = pure f
|
||||
, _appSubFiles = []
|
||||
appCWD = f
|
||||
, appCursor = 0
|
||||
, appFocus = pure f
|
||||
, appSubFiles = []
|
||||
}
|
||||
|
||||
main :: IO ()
|
||||
|
Loading…
Reference in New Issue
Block a user