ENH use mountmaybe for mount-by-alias

This commit is contained in:
Nathan Dwarshuis 2021-03-23 20:33:05 -04:00
parent 8ae0637978
commit f0b931c29c
1 changed files with 3 additions and 5 deletions

View File

@ -298,7 +298,7 @@ getGroups = do
mountByAlias :: Bool -> String -> RofiIO MountConf () mountByAlias :: Bool -> String -> RofiIO MountConf ()
mountByAlias unmountFlag alias = do mountByAlias unmountFlag alias = do
static <- asks mountconfStaticDevs static <- asks mountconfStaticDevs
mapM_ (`mount` unmountFlag) $ configToTree static <$> M.lookup alias static mapM_ (`mountMaybe` unmountFlag) $ configToTree static <$> M.lookup alias static
mkGroup :: [(Header, ProtoAction [String])] -> Maybe (RofiGroup MountConf) mkGroup :: [(Header, ProtoAction [String])] -> Maybe (RofiGroup MountConf)
mkGroup [] = Nothing mkGroup [] = Nothing
@ -309,15 +309,13 @@ alignSep :: String
alignSep = " | " alignSep = " | "
alignEntries :: [ProtoAction [String]] -> [(String, RofiIO MountConf ())] alignEntries :: [ProtoAction [String]] -> [(String, RofiIO MountConf ())]
alignEntries = withEntries alignEntries ps = zip (align es) as
where where
withEntries as = let entries = fmap (\(ProtoAction e _) -> e) as in (es, as) = unzip $ fmap (\(ProtoAction e a) -> (e, a)) ps
zipWith (\e (ProtoAction _ a) -> (e, a)) (align entries) as
align = fmap (intercalate alignSep) align = fmap (intercalate alignSep)
. transpose . transpose
. mapToLast pad . mapToLast pad
. transpose . transpose
-- . fmap (splitOn alignSepPre)
pad xs = let m = getMax xs in fmap (\x -> take m (x ++ repeat ' ')) xs pad xs = let m = getMax xs in fmap (\x -> take m (x ++ repeat ' ')) xs
getMax = maximum . fmap length getMax = maximum . fmap length
mapToLast _ [] = [] mapToLast _ [] = []