You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Apologies in advance, the example is not a minimal amount of code - but there is quite a few things going on so slimming it down might take some time... None the less I thought I'd report this.
I've written some code that works correctly when using ghci within a process. If I switch to use stack ghci I get the following behaviour:
stack exec app
"Stapp: stack ghci: createProcess: runInteractiveProcess: exec: does not exist (No such file or directory)
arted
stack ghci
λ main
"<interactive>: stack ghci: createProcess: runInteractiveProcess: exec: does not exist (No such file or directory)
Started"
{-# LANGUAGE LambdaCase #-}
module Main where
import System.IO (stdin, hSetEcho, hReady, stdout)
import GHC.IO.Handle
import Control.Monad (when)
import System.Process
import Control.Monad.STM
import Control.Concurrent.STM.TMVar
import Control.Concurrent
import Control.Monad
getKey :: IO [Char]
getKey = reverse <$> getKey' ""
where getKey' chars = do
char <- getChar
more <- hReady stdin
(if more then getKey' else return) (char:chars)
type Commands = TMVar [String]
ghci :: Commands -> IO ()
ghci cmds = createProcess ((proc "stack ghci" [])) {std_in=CreatePipe} >>= \case
(Just pin, Nothing, Nothing, ph) -> processCommandsLoop cmds pin
_ -> error "Something went wrong"
processCommandsLoop :: Commands -> Handle -> IO ()
processCommandsLoop cmds input = do
x <- atomically $ takeTMVar cmds
forM x (\x' -> do
print "-- ## Sending command to process:"
print x'
hPutStr input (x' ++ "\n")
hFlush input
)
hFlush stdout
processCommandsLoop cmds input
mainLoop :: TMVar [String] -> IO ()
mainLoop commands = do
key <- getKey
when (key /= "\ESC") $ do
case key of
"i" -> do
putStrLn "-- ## Initializing!"
atomically $ putTMVar commands (
[
":l Tidal"
, "main"
])
"r" -> putStrLn "-- ## Reloading!"
"t" -> do
putStrLn "-- ## Testing!"
atomically $ putTMVar commands ([":t head", ":t tail"])
"h" -> putStrLn "-- ## Hushing!"
"d" -> do
putStrLn "-- ## Debug!"
(atomically $ readTMVar commands) >>= print
_ -> return ()
mainLoop commands
main :: IO ()
main = do
hSetBuffering stdout NoBuffering
hSetBuffering stdin NoBuffering
cmds <- newEmptyTMVarIO
ghciThread <- forkIO $ ghci cmds
print "Started"
hSetEcho stdin False
mainLoop cmds
You're calling proc "stack ghci" [], which means "there's an executable called stack ghci, and I'd like to pass it no arguments." You probably meant proc "stack" ["ghci"].
Apologies in advance, the example is not a minimal amount of code - but there is quite a few things going on so slimming it down might take some time... None the less I thought I'd report this.
I've written some code that works correctly when using
ghci
within a process. If I switch to usestack ghci
I get the following behaviour:It is on line 25. A complete functional project can be found here: https://github.com/chrissound/InteractiveTidalGhci (this would be with
ghci
- so line 25 would have to be changed).Possibly related:
leksah/leksah#472
#2489
The text was updated successfully, but these errors were encountered: