-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected behaviour when feeding getLine input to a process #85
Comments
@AliceRixte this looks like because of IO buffering occurring in the pipeChunks API. Let me check and update. |
Try out this fix: #86 . If this works we can add a config option to enable different types of buffering optionally. |
Yes it works great ! This is awesome ! I'm amazed at how concise this is :-) |
I've been playing a bit more with this and I think it would be great to also have the possibility to use line buffers in the output as well. For instance, what I'm currently trying to achieve is to make a REPL for an EDSL I made in Haskell, and I'd like to be able to replace the Another example of why this would be useful is the (admitedly not great) hack I came up with to quit as soon as GHCi quit using Fold.takeEndBy ( == stringToByteArray "Leaving GHCi.") Stdio.writeChunks This does not work for now because the buffering splits "Leaving GHCi." into 2 chunks. |
If we do line buffering then you cannot output a line until newline is encountered, since ghci prompt does not end with a newline you wont be able to display the prompt correctly. Not very efficient, but you can output character-by-character for now like this.
We can do it more efficiently in chunks as well, but that will require a bit more complicated code. BTW, using "Leaving GHCi" to detect the end is hacky, if the ghci output has this string elsewhere e.g. the user types it that will end the session. |
The simplest is to not detect the end by a string, just use end-of-stream to end the session, something like this should work:
|
Thank you for your insights ! The second code doesn't end the stream on quitting GHC, but it really nice ! However I will process the input line by line before feeding it to GHCi so I think I'll stick to getLine. For quitting, I think I will use something in the flavor of your AcidRain example, and hijack the ":q" command to change the program state, send ":q" to GHCi and then quit. This will be less hacky. I will need a state anyway for other purposes. Thanks again for all the support ! |
Line by line processing is easy. You can split the input into lines using the stream APIs. In the following example each chunk being sent to pipeChunks is a line:
|
Oh this is really cool. I tried to use the same idea to process the output of GHCi line by line, the idea being that I can put my own prompt "myLanguage>", and delete "ghci>" at the begining of every line of the output of GHCi. I suppose I'll use the Parser functionalities to do so. However if I try to convert back the output of
the output is a bit all over the place :
Notice how GHCi's errors are displayed in the right place and how everything else is flushed only when quitting the program. |
First of all, thank you for this library and the great work !
I've posted this question on stackoverflow, and it looks like nobody there knows the answer, so I'll post it here as an issue. Here is a copy/paste from stack overflow :
I'm trying to use
streamly-process
to communicate with some REPL in background. It could be Python or anything but here I try to run GHCi. I came up with the following code :When I use
fromList
, it works as expected and returns :However, when I'm using
getNewLn
this is what I get :What did I get wrong ?
The text was updated successfully, but these errors were encountered: