-----------------------------------------------------------------------------
-- |
-- Module      :  XMonad.Prompt.Theme
-- Description :  A prompt for changing the theme of the current workspace.
-- Copyright   :  (C) 2007 Andrea Rossato
-- License     :  BSD3
--
-- Maintainer  :  andrea.rossato@unibz.it
-- Stability   :  unstable
-- Portability :  unportable
--
-- A prompt for changing the theme of the current workspace
-----------------------------------------------------------------------------

module XMonad.Prompt.Theme
    ( -- * Usage
      -- $usage
      themePrompt,
      ThemePrompt,
    ) where

import Control.Arrow ( (&&&) )
import qualified Data.Map as M
import XMonad.Prelude ( fromMaybe )
import XMonad
import XMonad.Prompt
import XMonad.Layout.Decoration
import XMonad.Util.Themes

-- $usage
-- You can use this module with the following in your
-- @xmonad.hs@:
--
-- > import XMonad.Prompt
-- > import XMonad.Prompt.Theme
--
-- in your keybindings add:
--
-- >   , ((modm .|. controlMask, xK_t), themePrompt def)
--
-- For detailed instruction on editing the key binding see
-- <https://xmonad.org/TUTORIAL.html#customizing-xmonad the tutorial>.

data ThemePrompt = ThemePrompt

instance XPrompt ThemePrompt where
    showXPrompt :: ThemePrompt -> String
showXPrompt ThemePrompt
ThemePrompt = String
"Select a theme: "
    commandToComplete :: ThemePrompt -> String -> String
commandToComplete ThemePrompt
_ String
c = String
c
    nextCompletion :: ThemePrompt -> String -> [String] -> String
nextCompletion      ThemePrompt
_ = String -> [String] -> String
getNextCompletion

themePrompt :: XPConfig -> X ()
themePrompt :: XPConfig -> X ()
themePrompt XPConfig
c = forall p.
XPrompt p =>
p -> XPConfig -> ComplFunction -> (String -> X ()) -> X ()
mkXPrompt ThemePrompt
ThemePrompt XPConfig
c (XPConfig -> [String] -> ComplFunction
mkComplFunFromList' XPConfig
c forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map ThemeInfo -> String
ppThemeInfo forall a b. (a -> b) -> a -> b
$ [ThemeInfo]
listOfThemes) String -> X ()
changeTheme
    where changeTheme :: String -> X ()
changeTheme String
t = forall a. Message a => a -> X ()
sendMessage forall b c a. (b -> c) -> (a -> b) -> a -> c
. Theme -> DecorationMsg
SetTheme forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a -> a
fromMaybe forall a. Default a => a
def forall a b. (a -> b) -> a -> b
$ forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup String
t Map String Theme
mapOfThemes

mapOfThemes :: M.Map String Theme
mapOfThemes :: Map String Theme
mapOfThemes = forall k a. Ord k => [(k, a)] -> Map k a
M.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a b. [a] -> [b] -> [(a, b)]
zip forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. (a -> b) -> [a] -> [b]
map ThemeInfo -> String
ppThemeInfo forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& forall a b. (a -> b) -> [a] -> [b]
map ThemeInfo -> Theme
theme) forall a b. (a -> b) -> a -> b
$ [ThemeInfo]
listOfThemes