summaryrefslogtreecommitdiffhomepage
path: root/VirtualTerminal.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2017-04-28 18:23:34 -0400
committerJoey Hess <joeyh@joeyh.name>2017-04-28 18:23:34 -0400
commitb7bc253ca3160578f88d05fd7f2d9dacae7b00dd (patch)
treea762feb4803dd9d4c970a3644b1332371e2452c6 /VirtualTerminal.hs
parent85914371f31952b30b062624feec35706382af95 (diff)
downloaddebug-me-b7bc253ca3160578f88d05fd7f2d9dacae7b00dd.tar.gz
automatically open control window
Diffstat (limited to 'VirtualTerminal.hs')
-rw-r--r--VirtualTerminal.hs41
1 files changed, 41 insertions, 0 deletions
diff --git a/VirtualTerminal.hs b/VirtualTerminal.hs
new file mode 100644
index 0000000..6c7ef75
--- /dev/null
+++ b/VirtualTerminal.hs
@@ -0,0 +1,41 @@
+module VirtualTerminal where
+
+import System.FilePath
+import System.Directory
+import System.Process
+import System.Environment
+
+-- | Finds a virtual termianl program that looks like it will work
+-- to run a command with some parameters.
+--
+-- Note that the parameters are exposed to the shell by some virtual
+-- termianls, but not by others.
+runInVirtualTerminal :: String -> String -> [String] -> IO (Maybe CreateProcess)
+runInVirtualTerminal title cmd params = do
+ path <- getSearchPath
+ mdisplay <- lookupEnv "DISPLAY"
+ possibles <- case mdisplay of
+ Just _ -> return $ do
+ p <- path
+ c <- xtermcmds
+ return (p, c)
+ Nothing -> return []
+ find possibles
+ where
+ find [] = return Nothing
+ find ((d, (c, ps)):rest) = do
+ exists <- doesFileExist (d </> c)
+ if exists
+ then return $ Just $ proc (d </> c) ps
+ else find rest
+
+ -- Ordered list; generally xfce user may have gnome stuff
+ -- installed, and only fall back to the older terminals when
+ -- nothing else is available.
+ xtermcmds =
+ [ ("xfce4-terminal", std)
+ , ("gnome-terminal", ["-e", unwords (cmd:params)])
+ , ("xterm", std)
+ , ("rxvt", ["-T", title, "-e", cmd])
+ ]
+ std = ["-T", title, "-e", unwords (cmd:params)]