mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-08-01 04:31:52 -07:00
Move runXXX functions to one module
This patch takes runProcessWithInput out of Dmenu, runProcessWithInputAndWait out of Dzen, and runInXTerm out of RunInXTerm and collects them in one central module called Run. This way, other modules may include Run instead of Dmenu to get what they want without giving the impression of making use of dmenu.
This commit is contained in:
@@ -20,7 +20,7 @@ module XMonadContrib.DirectoryPrompt (
|
|||||||
|
|
||||||
import XMonad
|
import XMonad
|
||||||
import XMonadContrib.XPrompt
|
import XMonadContrib.XPrompt
|
||||||
import XMonadContrib.Dmenu ( runProcessWithInput )
|
import XMonadContrib.Run ( runProcessWithInput )
|
||||||
|
|
||||||
-- $usage
|
-- $usage
|
||||||
-- For an example usage see "XMonadContrib.WorkspaceDir"
|
-- For an example usage see "XMonadContrib.WorkspaceDir"
|
||||||
|
20
Dmenu.hs
20
Dmenu.hs
@@ -17,16 +17,14 @@
|
|||||||
module XMonadContrib.Dmenu (
|
module XMonadContrib.Dmenu (
|
||||||
-- * Usage
|
-- * Usage
|
||||||
-- $usage
|
-- $usage
|
||||||
dmenu, dmenuXinerama, dmenuMap,
|
dmenu, dmenuXinerama, dmenuMap
|
||||||
runProcessWithInput
|
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import XMonad
|
import XMonad
|
||||||
import qualified StackSet as W
|
import qualified StackSet as W
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import System.Process
|
|
||||||
import System.IO
|
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
|
import XMonadContrib.Run
|
||||||
|
|
||||||
-- $usage
|
-- $usage
|
||||||
-- You can use this module with the following in your Config.hs file:
|
-- You can use this module with the following in your Config.hs file:
|
||||||
@@ -35,20 +33,6 @@ import Control.Monad.State
|
|||||||
|
|
||||||
-- %import XMonadContrib.Dmenu
|
-- %import XMonadContrib.Dmenu
|
||||||
|
|
||||||
-- | Returns Just output if the command succeeded, and Nothing if it didn't.
|
|
||||||
-- This corresponds to dmenu's notion of exit code 1 for a cancelled invocation.
|
|
||||||
runProcessWithInput :: FilePath -> [String] -> String -> IO String
|
|
||||||
runProcessWithInput cmd args input = do
|
|
||||||
(pin, pout, perr, ph) <- runInteractiveProcess cmd args Nothing Nothing
|
|
||||||
hPutStr pin input
|
|
||||||
hClose pin
|
|
||||||
output <- hGetContents pout
|
|
||||||
when (output==output) $ return ()
|
|
||||||
hClose pout
|
|
||||||
hClose perr
|
|
||||||
waitForProcess ph
|
|
||||||
return output
|
|
||||||
|
|
||||||
-- | Starts dmenu on the current screen. Requires this patch to dmenu:
|
-- | Starts dmenu on the current screen. Requires this patch to dmenu:
|
||||||
-- <http://www.jcreigh.com/dmenu/dmenu-3.2-xinerama.patch>
|
-- <http://www.jcreigh.com/dmenu/dmenu-3.2-xinerama.patch>
|
||||||
dmenuXinerama :: [String] -> X String
|
dmenuXinerama :: [String] -> X String
|
||||||
|
30
Dzen.hs
30
Dzen.hs
@@ -14,38 +14,10 @@
|
|||||||
|
|
||||||
module XMonadContrib.Dzen (dzen, dzenScreen) where
|
module XMonadContrib.Dzen (dzen, dzenScreen) where
|
||||||
|
|
||||||
import System.Posix.Process (forkProcess, getProcessStatus, createSession)
|
|
||||||
import System.IO
|
|
||||||
import System.Process
|
|
||||||
import System.Exit
|
|
||||||
import Control.Concurrent (threadDelay)
|
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
|
|
||||||
import qualified StackSet as W
|
import qualified StackSet as W
|
||||||
import XMonad
|
import XMonad
|
||||||
|
import XMonadContrib.Run
|
||||||
-- wait is in us
|
|
||||||
runProcessWithInputAndWait :: FilePath -> [String] -> String -> Int -> IO ()
|
|
||||||
runProcessWithInputAndWait cmd args input timeout = do
|
|
||||||
pid <- forkProcess $ do
|
|
||||||
forkProcess $ do -- double fork it over to init
|
|
||||||
createSession
|
|
||||||
(pin, pout, perr, ph) <- runInteractiveProcess cmd args Nothing Nothing
|
|
||||||
hPutStr pin input
|
|
||||||
hFlush pin
|
|
||||||
threadDelay timeout
|
|
||||||
hClose pin
|
|
||||||
-- output <- hGetContents pout
|
|
||||||
-- when (output==output) $ return ()
|
|
||||||
hClose pout
|
|
||||||
hClose perr
|
|
||||||
waitForProcess ph
|
|
||||||
return ()
|
|
||||||
exitWith ExitSuccess
|
|
||||||
return ()
|
|
||||||
getProcessStatus True False pid
|
|
||||||
return ()
|
|
||||||
|
|
||||||
|
|
||||||
curScreen :: X ScreenId
|
curScreen :: X ScreenId
|
||||||
curScreen = (W.screen . W.current) `liftM` gets windowset
|
curScreen = (W.screen . W.current) `liftM` gets windowset
|
||||||
|
@@ -60,7 +60,6 @@ import XMonadContrib.ResizableTile ()
|
|||||||
import XMonadContrib.Roledex ()
|
import XMonadContrib.Roledex ()
|
||||||
import XMonadContrib.RotSlaves ()
|
import XMonadContrib.RotSlaves ()
|
||||||
import XMonadContrib.RotView ()
|
import XMonadContrib.RotView ()
|
||||||
import XMonadContrib.RunInXTerm ()
|
|
||||||
import XMonadContrib.SetWMName ()
|
import XMonadContrib.SetWMName ()
|
||||||
import XMonadContrib.ShellPrompt ()
|
import XMonadContrib.ShellPrompt ()
|
||||||
import XMonadContrib.SimpleDate ()
|
import XMonadContrib.SimpleDate ()
|
||||||
|
84
Run.hs
Normal file
84
Run.hs
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
-----------------------------------------------------------------------------
|
||||||
|
-- |
|
||||||
|
-- Module : XMonadContrib.Run
|
||||||
|
-- Copyright : (C) 2007 Spencer Janssen, Andrea Rossato, glasser@mit.edu
|
||||||
|
-- License : BSD-style (see LICENSE)
|
||||||
|
--
|
||||||
|
-- Maintainer : Christian Thiemann <mail@christian-thiemann.de>
|
||||||
|
-- Stability : unstable
|
||||||
|
-- Portability : unportable
|
||||||
|
--
|
||||||
|
-- This modules provides several commands to run an external process.
|
||||||
|
-- It is composed of functions formerly defined in XMonadContrib.Dmenu (by
|
||||||
|
-- Spenver Jannsen), XMonadContrib.Dzen (by glasser@mit.edu) and
|
||||||
|
-- XMonadContrib.RunInXTerm (by Andrea Rossato).
|
||||||
|
--
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
module XMonadContrib.Run (
|
||||||
|
-- * Usage
|
||||||
|
-- $usage
|
||||||
|
runInXTerm,
|
||||||
|
runProcessWithInput,
|
||||||
|
runProcessWithInputAndWait
|
||||||
|
) where
|
||||||
|
|
||||||
|
import XMonad
|
||||||
|
import Control.Concurrent (threadDelay)
|
||||||
|
import Control.Monad.State
|
||||||
|
import System.Environment
|
||||||
|
import System.Exit
|
||||||
|
import System.IO
|
||||||
|
import System.Posix.Process (forkProcess, getProcessStatus, createSession)
|
||||||
|
import System.Process
|
||||||
|
|
||||||
|
|
||||||
|
-- $usage
|
||||||
|
-- For an example usage of runInXTerm see XMonadContrib.SshPrompt
|
||||||
|
--
|
||||||
|
-- For an example usage of runProcessWithInput see
|
||||||
|
-- XMonadContrib.{DirectoryPrompt,Dmenu,ShellPrompt,WmiiActions,WorkspaceDir}
|
||||||
|
--
|
||||||
|
-- For an example usage of runProcessWithInputAndWait see XMonadContrib.Dzen
|
||||||
|
|
||||||
|
-- | Returns Just output if the command succeeded, and Nothing if it didn't.
|
||||||
|
-- This corresponds to dmenu's notion of exit code 1 for a cancelled invocation.
|
||||||
|
runProcessWithInput :: FilePath -> [String] -> String -> IO String
|
||||||
|
runProcessWithInput cmd args input = do
|
||||||
|
(pin, pout, perr, ph) <- runInteractiveProcess cmd args Nothing Nothing
|
||||||
|
hPutStr pin input
|
||||||
|
hClose pin
|
||||||
|
output <- hGetContents pout
|
||||||
|
when (output==output) $ return ()
|
||||||
|
hClose pout
|
||||||
|
hClose perr
|
||||||
|
waitForProcess ph
|
||||||
|
return output
|
||||||
|
|
||||||
|
-- wait is in us
|
||||||
|
runProcessWithInputAndWait :: FilePath -> [String] -> String -> Int -> IO ()
|
||||||
|
runProcessWithInputAndWait cmd args input timeout = do
|
||||||
|
pid <- forkProcess $ do
|
||||||
|
forkProcess $ do -- double fork it over to init
|
||||||
|
createSession
|
||||||
|
(pin, pout, perr, ph) <- runInteractiveProcess cmd args Nothing Nothing
|
||||||
|
hPutStr pin input
|
||||||
|
hFlush pin
|
||||||
|
threadDelay timeout
|
||||||
|
hClose pin
|
||||||
|
-- output <- hGetContents pout
|
||||||
|
-- when (output==output) $ return ()
|
||||||
|
hClose pout
|
||||||
|
hClose perr
|
||||||
|
waitForProcess ph
|
||||||
|
return ()
|
||||||
|
exitWith ExitSuccess
|
||||||
|
return ()
|
||||||
|
getProcessStatus True False pid
|
||||||
|
return ()
|
||||||
|
|
||||||
|
runInXTerm :: String -> X ()
|
||||||
|
runInXTerm com = do
|
||||||
|
c <- io $ catch (getEnv "XTERMCMD") (const $ return "xterm")
|
||||||
|
spawn ("exec " ++ c ++ " -e " ++ com)
|
||||||
|
|
@@ -22,7 +22,7 @@ module XMonadContrib.ShellPrompt (
|
|||||||
|
|
||||||
import XMonad
|
import XMonad
|
||||||
import XMonadContrib.XPrompt
|
import XMonadContrib.XPrompt
|
||||||
import XMonadContrib.Dmenu
|
import XMonadContrib.Run
|
||||||
|
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
import Data.List
|
import Data.List
|
||||||
|
@@ -26,7 +26,8 @@ module XMonadContrib.WmiiActions (
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
import XMonad
|
import XMonad
|
||||||
import XMonadContrib.Dmenu (dmenu, dmenuXinerama, runProcessWithInput)
|
import XMonadContrib.Dmenu (dmenu, dmenuXinerama)
|
||||||
|
import XMonadContrib.Run (runProcessWithInput)
|
||||||
|
|
||||||
import Control.Monad (filterM, liftM, liftM2)
|
import Control.Monad (filterM, liftM, liftM2)
|
||||||
import System.Directory (getDirectoryContents, doesFileExist, getPermissions, executable)
|
import System.Directory (getDirectoryContents, doesFileExist, getPermissions, executable)
|
||||||
|
@@ -33,7 +33,7 @@ import System.Directory ( setCurrentDirectory )
|
|||||||
|
|
||||||
import XMonad
|
import XMonad
|
||||||
import Operations ( sendMessage )
|
import Operations ( sendMessage )
|
||||||
import XMonadContrib.Dmenu ( runProcessWithInput )
|
import XMonadContrib.Run ( runProcessWithInput )
|
||||||
import XMonadContrib.XPrompt ( XPConfig )
|
import XMonadContrib.XPrompt ( XPConfig )
|
||||||
import XMonadContrib.DirectoryPrompt ( directoryPrompt )
|
import XMonadContrib.DirectoryPrompt ( directoryPrompt )
|
||||||
import XMonadContrib.LayoutModifier
|
import XMonadContrib.LayoutModifier
|
||||||
|
Reference in New Issue
Block a user