X.A.Commands: Parameterize runCommand to accept dmenu-like launchers.

The X.U.Dmenu library has support to run dmenu-like launchers, but X.A.Commands
has the use of dmenu hardcoded. This commit makes it possible to use other
launchers without duplicating existing code.
This commit is contained in:
Xander Rémon van der Goot 2017-07-03 19:41:11 +02:00
parent 12227d37ca
commit d5dd9329b5

View File

@ -19,6 +19,7 @@ module XMonad.Actions.Commands (
-- $usage -- $usage
commandMap, commandMap,
runCommand, runCommand,
runCommandConfig,
runCommand', runCommand',
workspaceCommands, workspaceCommands,
screenCommands, screenCommands,
@ -103,11 +104,18 @@ defaultCommands = do
] ]
-- | Given a list of command\/action pairs, prompt the user to choose a -- | Given a list of command\/action pairs, prompt the user to choose a
-- command and return the corresponding action. -- command using dmenu and return the corresponding action.
runCommand :: [(String, X ())] -> X () runCommand :: [(String, X ())] -> X ()
runCommand cl = do runCommand = runCommandConfig dmenu
-- | Given a list of command\/action pairs, prompt the user to choose a
-- command using dmenu-compatible launcher and return the corresponding action.
-- See X.U.Dmenu for compatible launchers.
runCommandConfig :: ([String] -> X String) -> [(String, X ())] -> X()
runCommandConfig f cl = do
let m = commandMap cl let m = commandMap cl
choice <- dmenu (M.keys m) choice <- f (M.keys m)
fromMaybe (return ()) (M.lookup choice m) fromMaybe (return ()) (M.lookup choice m)
-- | Given the name of a command from 'defaultCommands', return the -- | Given the name of a command from 'defaultCommands', return the