ENH warn user if deps are missing

This commit is contained in:
Nathan Dwarshuis 2021-06-19 15:32:43 -04:00
parent 461fc783c7
commit a04150657e
2 changed files with 19 additions and 8 deletions

View File

@ -74,10 +74,11 @@ main = do
, childPIDs = [p] , childPIDs = [p]
, childHandles = [h] , childHandles = [h]
} }
ekbs <- evalExternal $ externalBindings ts (ekbs, missing) <- fmap filterExternal $ evalExternal $ externalBindings ts
mapM_ warnMissing missing
launch launch
$ ewmh $ ewmh
$ addKeymap (filterExternal ekbs) $ addKeymap ekbs
$ def { terminal = myTerm $ def { terminal = myTerm
, modMask = myModMask , modMask = myModMask
, layoutHook = myLayouts , layoutHook = myLayouts
@ -463,13 +464,15 @@ evalExternal = mapM go
evalKeyBinding :: Monad m => KeyBinding (m a) -> m (KeyBinding a) evalKeyBinding :: Monad m => KeyBinding (m a) -> m (KeyBinding a)
evalKeyBinding k@KeyBinding { kbAction = a } = (\b -> k { kbAction = b }) <$> a evalKeyBinding k@KeyBinding { kbAction = a } = (\b -> k { kbAction = b }) <$> a
filterExternal :: [KeyGroup MaybeX] -> [KeyGroup (X ())] filterExternal :: [KeyGroup MaybeX] -> ([KeyGroup (X ())], [Dependency])
filterExternal = fmap go filterExternal kgs = let kgs' = fmap go kgs in (fst <$> kgs', concatMap snd kgs')
where where
go k@KeyGroup { kgBindings = bs } = go k@KeyGroup { kgBindings = bs } = let bs' = go' <$> bs in
k { kgBindings = mapMaybe go' bs } (k { kgBindings = mapMaybe fst bs' }, concatMap snd bs')
go' k@KeyBinding { kbAction = Installed x _ } = Just $ k { kbAction = x } go' k@KeyBinding { kbAction = a } = case a of
go' _ = Nothing Installed x ds -> (Just $ k { kbAction = x }, fmap Optional ds)
Missing ds -> (Nothing, ds)
Ignore -> (Nothing, [])
externalBindings :: ThreadState -> [KeyGroup (IO MaybeX)] externalBindings :: ThreadState -> [KeyGroup (IO MaybeX)]
externalBindings ts = externalBindings ts =

View File

@ -7,6 +7,7 @@ module XMonad.Internal.Shell
, MaybeX , MaybeX
, IOMaybeX , IOMaybeX
, runIfInstalled , runIfInstalled
, warnMissing
, whenInstalled , whenInstalled
, spawnIfInstalled , spawnIfInstalled
, spawnCmdIfInstalled , spawnCmdIfInstalled
@ -45,6 +46,13 @@ type MaybeX = MaybeExe X
type IOMaybeX = IO MaybeX type IOMaybeX = IO MaybeX
warnMissing :: Dependency -> IO ()
warnMissing d = case d of
Required d' -> warn "required" d'
Optional d' -> warn "optional" d'
where
warn t n = putStrLn $ "WARNING: " ++ t ++ " executable not found: " ++ n
exeInstalled :: String -> IO Bool exeInstalled :: String -> IO Bool
exeInstalled x = isJust <$> findExecutable x exeInstalled x = isJust <$> findExecutable x