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