----------------------------------------------------------------------------- -- | -- Module : XMonad.Prompt.ConfirmPrompt -- Description : A prompt for setting up simple confirmation prompts for keybindings. -- Copyright : (C) 2015 Antoine Beaupré -- License : BSD3 -- -- Maintainer : Antoine Beaupré <anarcat@debian.org> -- Stability : unstable -- Portability : unportable -- -- A module for setting up simple confirmation prompts for keybindings. -- ----------------------------------------------------------------------------- module XMonad.Prompt.ConfirmPrompt (confirmPrompt -- * Usage -- $usage , module XMonad.Prompt -- * Use case: confirming exit -- $tip , EnterPrompt ) where import XMonad (X) import XMonad.Prompt (XPConfig, XPrompt, showXPrompt, mkXPrompt, mkComplFunFromList) {- $usage This module makes it easy to add a confirmation prompt for specific actions. Instead of just running the action, a simple confirmation prompt will be created using 'XMonad.Prompt' primitives. The action will then run normally if the user confirms. -} {- $tip This should be used something like this: > ... > , ((modm , xK_l), confirmPrompt def "exit" $ io (exitWith ExitSuccess)) > ... -} {- | Customized 'XPrompt' prompt that will ask to confirm the given string -} newtype EnterPrompt = EnterPrompt String instance XPrompt EnterPrompt where showXPrompt :: EnterPrompt -> String showXPrompt (EnterPrompt String n) = String "Confirm " String -> String -> String forall a. [a] -> [a] -> [a] ++ String n String -> String -> String forall a. [a] -> [a] -> [a] ++ String " (esc/ENTER)" {- | Prompt the user to confirm a given action. We offer no completion and simply ask to confirm (ENTER) or cancel (ESCAPE). The actual key handling is done by mkXPrompt.-} confirmPrompt :: XPConfig -> String -> X() -> X() confirmPrompt :: XPConfig -> String -> X () -> X () confirmPrompt XPConfig config String app X () func = EnterPrompt -> XPConfig -> ComplFunction -> (String -> X ()) -> X () forall p. XPrompt p => p -> XPConfig -> ComplFunction -> (String -> X ()) -> X () mkXPrompt (String -> EnterPrompt EnterPrompt String app) XPConfig config (XPConfig -> [String] -> ComplFunction mkComplFunFromList XPConfig config []) ((String -> X ()) -> X ()) -> (String -> X ()) -> X () forall a b. (a -> b) -> a -> b $ X () -> String -> X () forall a b. a -> b -> a const X () func