I'm writing a console application that needs to prompt the user for several things. I'm using the turtle library.
My function looks like this:
askInput :: IO (Maybe Text)
askInput = do
echo "Input something: "
s <- readline
return s
But echo is implemented using putStrLn and as a result, will print its argument with a trailing newline.
Is there an input function in the turtle library similar to Python's raw_input, that combines prompting followed by reading the user input?
You can import from the text package and use many functions which aren't exported from turtle. In this case:
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.Text.IO as Text
main = Text.putStr "Input something: " -- doesn't print newline
I also want to mention that turtle has a newly added printf function which outputs a formatted string without the trailing newline, so another solution is:
{-# LANGUAGE OverloadedStrings #-}
import Turtle
main = printf "Input something: "
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With