REF use text in few more places

This commit is contained in:
Nathan Dwarshuis 2022-12-26 15:18:50 -05:00
parent 3dd2536f0f
commit ec42f34905
4 changed files with 16 additions and 8 deletions

View File

@ -60,7 +60,7 @@ vmPID :: String -> IO (Maybe Int)
vmPID vid = do vmPID vid = do
(rc, out, _) <- readCreateProcessWithExitCode' cmd "" (rc, out, _) <- readCreateProcessWithExitCode' cmd ""
return $ case rc of return $ case rc of
ExitSuccess -> readMaybe out ExitSuccess -> readMaybe $ T.unpack out
_ -> Nothing _ -> Nothing
where where
cmd = proc "pgrep" ["-f", "VirtualBoxVM.*" ++ vid] cmd = proc "pgrep" ["-f", "VirtualBoxVM.*" ++ vid]

View File

@ -425,11 +425,13 @@ vpnPresent =
go <$> tryIOError (readCreateProcessWithExitCode' (proc' "nmcli" args) "") go <$> tryIOError (readCreateProcessWithExitCode' (proc' "nmcli" args) "")
where where
args = ["-c", "no", "-t", "-f", "TYPE", "c", "show"] args = ["-c", "no", "-t", "-f", "TYPE", "c", "show"]
go (Right (ExitSuccess, out, _)) = if "vpn" `elem` lines out then Nothing go (Right (ExitSuccess, out, _)) = if "vpn" `elem` T.lines out then Nothing
else Just $ Msg Error "vpn not found" else Just $ Msg Error "vpn not found"
go (Right (ExitFailure c, _, err)) = Just $ Msg Error go (Right (ExitFailure c, _, err)) = Just $ Msg Error
$ T.concat ["vpn search exited with code " $ T.concat ["vpn search exited with code "
, T.pack $ show c, ": ", T.pack err] , T.pack $ show c
, ": "
, err]
go (Left e) = Just $ Msg Error $ T.pack $ show e go (Left e) = Just $ Msg Error $ T.pack $ show e
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View File

@ -15,6 +15,7 @@ import Data.Internal.Dependency
import Data.List import Data.List
import Data.Maybe import Data.Maybe
import Data.Monoid import Data.Monoid
import Data.Text.IO (hPutStrLn)
import Graphics.X11.Types import Graphics.X11.Types
import Graphics.X11.Xlib.Atom import Graphics.X11.Xlib.Atom
@ -25,7 +26,9 @@ import qualified RIO.Text as T
import System.Directory import System.Directory
import System.Environment import System.Environment
import System.IO import System.IO hiding
( hPutStrLn
)
import System.IO.Error import System.IO.Error
import System.Process import System.Process
@ -437,7 +440,6 @@ whenChanged v action = do
logXinerama :: Handle -> X () logXinerama :: Handle -> X ()
logXinerama h = withWindowSet $ \ws -> io logXinerama h = withWindowSet $ \ws -> io
$ hPutStrLn h $ hPutStrLn h
$ T.unpack
$ T.unwords $ T.unwords
$ filter (not . T.null) [onScreen ws, offScreen ws, sep, layout ws, nWindows ws] $ filter (not . T.null) [onScreen ws, offScreen ws, sep, layout ws, nWindows ws]
where where

View File

@ -23,6 +23,8 @@ import Control.Monad.IO.Class
import Data.Maybe import Data.Maybe
import qualified RIO.Text as T
import System.Directory import System.Directory
import System.Exit import System.Exit
import System.IO import System.IO
@ -62,9 +64,11 @@ addGroupSession cp = cp { create_group = True, new_session = True }
createProcess' :: CreateProcess -> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) createProcess' :: CreateProcess -> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
createProcess' = withDefaultSignalHandlers . createProcess createProcess' = withDefaultSignalHandlers . createProcess
readCreateProcessWithExitCode' :: CreateProcess -> String -> IO (ExitCode, String, String) readCreateProcessWithExitCode' :: CreateProcess -> String
readCreateProcessWithExitCode' c i = withDefaultSignalHandlers -> IO (ExitCode, T.Text, T.Text)
$ readCreateProcessWithExitCode c i readCreateProcessWithExitCode' c i = withDefaultSignalHandlers $ do
(r, e, p) <- readCreateProcessWithExitCode c i
return (r, T.pack e, T.pack p)
shell' :: String -> CreateProcess shell' :: String -> CreateProcess
shell' = addGroupSession . shell shell' = addGroupSession . shell