-- |Used to make shell-like command, however with graphical interface. -- In the Future it should gracefully use console mode, when no -- graphical display is available. module Graphics.UI.AF.PolyCommand ( polyCommand , module Graphics.UI.AF.WxFormAll ) where import Graphics.UI.AF.WxFormAll import Graphics.UI.AF.CForm.CFormAll import System polyCommand :: (ECCreator a, GCForm a) => a -> (a -> IO String) -> IO () polyCommand input action = do available <- isDisplayAvailable let command' proxy = command proxy (mkCom input) action if available then command' wxParentProxy else command' consoleParentProxy -- We can also use System.Info.os, which returns the OS name, but -- just returns linux. I would rather have a functions like isPosix and isMSWindows. -- -- We could also use some compile flags to destinguish OS'es. -- getEnv throws isDoesNotExistError -- -- WARNING: This function has only been tested on Linux. isDisplayAvailable :: IO Bool isDisplayAvailable = do isWindows <- isSet "SystemDrive" if isWindows then return True else isSet "DISPLAY" -- We are geussing it's an Posix-OS. where isSet environmentVariable = catch (do getEnv environmentVariable return True ) (\_ -> return False)