diff --git a/app/rofi-dev.hs b/app/rofi-dev.hs index 8c62a4f..531efb8 100644 --- a/app/rofi-dev.hs +++ b/app/rofi-dev.hs @@ -121,10 +121,10 @@ runMounts opts = do parseStaticConfig :: FilePath -> IO (Maybe StaticConfig) parseStaticConfig p = do - res <- try $ inputFile auto p + res <- tryIO $ inputFile auto p case res of - Left e -> TI.putStrLn (T.pack $ show (e :: SomeException)) >> return Nothing - Right c -> return $ Just (c :: StaticConfig) + Left e -> TI.putStrLn (T.pack $ show e) >> return Nothing + Right c -> return $ Just c runPrompt :: HasRofiConf c => [RofiGroup c] -> RIO c () runPrompt gs = @@ -163,9 +163,9 @@ mountByAlias unmountFlag alias = do mapM_ (`mountMaybe` unmountFlag) $ configToTree static <$> M.lookup alias static mkGroup :: NE.NonEmpty (Header, ProtoAction) -> RofiGroup MountConf -mkGroup as = - let (h, _) = NE.head as - in titledGroup (T.pack $ show h) $ toRofiActions $ NE.toList $ alignEntries $ fmap snd as +mkGroup as = titledGroup h $ toRofiActions $ NE.toList $ alignEntries $ snd <$> as + where + h = (T.pack $ show $ fst $ NE.head as) alignSep :: T.Text alignSep = " | " @@ -178,23 +178,14 @@ alignEntries ps = NE.zip (align es) as fmap (T.intercalate alignSep . NE.toList) . NE.transpose . fmap padAll - -- . mapToLast pad . NE.transpose - -- padAll xs = let padAll xs = let m = maxNE $ fmap T.length xs in fmap (rpad m ' ') xs maxNE (x :| []) = x maxNE (x :| (y : ys)) = maxNE $ (max x y) :| ys --- pad xs = let m = getMax xs in fmap (\x -> T.append x (T.replicate (m - T.length x) " ")) xs --- getMax = LP.maximum . fmap T.length - rpad :: Int -> Char -> T.Text -> T.Text rpad n c s = T.append s $ T.replicate (n - T.length s) $ T.singleton c --- mapToLast _ [] = [] --- mapToLast _ [x] = [x] --- mapToLast f (x : xs) = f x : mapToLast f xs - -------------------------------------------------------------------------------- -- Global config used in the reader monad stack @@ -227,13 +218,17 @@ class Mountable a where mountMaybe :: a -> Bool -> RofiMountIO () mountMaybe dev mountFlag = do + let lab = getLabel dev mounted <- isMounted dev verbose <- asks mountconfVerbose - if mountFlag == mounted - then (io . notifyMountResult mounted (getLabel dev)) =<< mount dev mountFlag - else when verbose notify' - where - notify' = io $ notify IconInfo (T.append (getLabel dev) " already mounted") Nothing + if + | mountFlag == mounted -> do + r <- mount dev mountFlag + io $ notifyMountResult mounted lab r + | verbose -> + io $ notify IconInfo (T.append lab " already mounted") Nothing + | otherwise -> + return () -- | Check if the mounting utilities are present allInstalled :: a -> RofiMountIO Bool @@ -295,7 +290,7 @@ data Header | VeracryptHeader | RemovableHeader | MTPFSHeader - deriving (Enum, Eq) + deriving (Ord, Enum, Eq) instance Show Header where show h = case h of @@ -307,9 +302,6 @@ instance Show Header where where suffix = (++ " Devices") -instance Ord Header where - compare x y = compare (fromEnum x) (fromEnum y) - data ProtoAction = ProtoAction (NE.NonEmpty T.Text) (RofiMountIO ()) --------------------------------------------------------------------------------