reading lines with history from bash terminal in OS X

I wrote a program first in Windows, where it works as expected, and now I'm using it in OS X and getting undesired behavior. It reads lines from the terminal using the getLine function. In Windows (DOS, actually) the up and down arrows can be used to choose previously entered lines. However, this does not work in bash in OS X. What do I need to get the history available via the arrow keys? D

You will have to use the haskeline library. FYI that is the library that
makes ghci work.
On Thu, Jul 28, 2016 at 6:09 PM, Dennis Raddle
I wrote a program first in Windows, where it works as expected, and now I'm using it in OS X and getting undesired behavior.
It reads lines from the terminal using the getLine function. In Windows (DOS, actually) the up and down arrows can be used to choose previously entered lines. However, this does not work in bash in OS X.
What do I need to get the history available via the arrow keys?
D
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

Thanks. I'll install haskeline
On Thu, Jul 28, 2016 at 5:05 PM, David McBride
You will have to use the haskeline library. FYI that is the library that makes ghci work.
On Thu, Jul 28, 2016 at 6:09 PM, Dennis Raddle
wrote: I wrote a program first in Windows, where it works as expected, and now I'm using it in OS X and getting undesired behavior.
It reads lines from the terminal using the getLine function. In Windows (DOS, actually) the up and down arrows can be used to choose previously entered lines. However, this does not work in bash in OS X.
What do I need to get the history available via the arrow keys?
D
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

I'm looking over haskeline. It looks like I have to modify some of my code
that is in the IO monad right now. I use 'evaluate' in several places, and
also 'evaluate $ force', to make sure that IO exceptions are encountered
where I can catch them. Can I use 'evaluate' with InputT? I'm muddled
headed about what to do. I guess I would lift 'evaluate' into the inner
monad? I am not sure what those words mean. How would I catch IO exceptions?
On Thu, Jul 28, 2016 at 5:35 PM, Dennis Raddle
Thanks. I'll install haskeline
On Thu, Jul 28, 2016 at 5:05 PM, David McBride
wrote: You will have to use the haskeline library. FYI that is the library that makes ghci work.
On Thu, Jul 28, 2016 at 6:09 PM, Dennis Raddle
wrote: I wrote a program first in Windows, where it works as expected, and now I'm using it in OS X and getting undesired behavior.
It reads lines from the terminal using the getLine function. In Windows (DOS, actually) the up and down arrows can be used to choose previously entered lines. However, this does not work in bash in OS X.
What do I need to get the history available via the arrow keys?
D
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

MonadIO m => MonadIO (InputT m) MonadException m => MonadException (InputT m) MonadIO means you have access to liftIO. liftIO . evaluate . force $ mycode. MonadException means that you have access to haskeline's exception catching mechanisms. In System.Console.Haskeline.MonadException, you have the catch, catches, and handle functions which will allow you to catch IO exceptions (in combination with liftIO), and also a bracket which will just let you do arbitrary IO actions and clean up when you are done (or hit an exception).
let mycode = undefined :: Handle -> IO () -- example code
runInputT _ (bracket (liftIO $ openFile "blah" ReadMode) (liftIO . hClose)
(\fp -> liftIO . mycode $ fp))
Another way to use it might be
runInputT _ (liftIO $ mycode _) `catches` [Handler iohandler, Handler
anotherhandler]
where
iohandler :: IOException -> IO ()
iohandler e = putStrLn "got io exception" >> return ()
Exceptions are always a pain, and so are transformers, but you get used to
them.
On Mon, Aug 1, 2016 at 4:06 AM, Dennis Raddle
I'm looking over haskeline. It looks like I have to modify some of my code that is in the IO monad right now. I use 'evaluate' in several places, and also 'evaluate $ force', to make sure that IO exceptions are encountered where I can catch them. Can I use 'evaluate' with InputT? I'm muddled headed about what to do. I guess I would lift 'evaluate' into the inner monad? I am not sure what those words mean. How would I catch IO exceptions?
On Thu, Jul 28, 2016 at 5:35 PM, Dennis Raddle
wrote: Thanks. I'll install haskeline
On Thu, Jul 28, 2016 at 5:05 PM, David McBride
wrote: You will have to use the haskeline library. FYI that is the library that makes ghci work.
On Thu, Jul 28, 2016 at 6:09 PM, Dennis Raddle
wrote: I wrote a program first in Windows, where it works as expected, and now I'm using it in OS X and getting undesired behavior.
It reads lines from the terminal using the getLine function. In Windows (DOS, actually) the up and down arrows can be used to choose previously entered lines. However, this does not work in bash in OS X.
What do I need to get the history available via the arrow keys?
D
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

Thanks. I will study this.
On Mon, Aug 1, 2016 at 5:43 AM, David McBride
MonadIO m => MonadIO (InputT m) MonadException m => MonadException (InputT m)
MonadIO means you have access to liftIO. liftIO . evaluate . force $ mycode. MonadException means that you have access to haskeline's exception catching mechanisms.
In System.Console.Haskeline.MonadException, you have the catch, catches, and handle functions which will allow you to catch IO exceptions (in combination with liftIO), and also a bracket which will just let you do arbitrary IO actions and clean up when you are done (or hit an exception).
let mycode = undefined :: Handle -> IO () -- example code
runInputT _ (bracket (liftIO $ openFile "blah" ReadMode) (liftIO . hClose) (\fp -> liftIO . mycode $ fp))
Another way to use it might be
runInputT _ (liftIO $ mycode _) `catches` [Handler iohandler, Handler anotherhandler] where iohandler :: IOException -> IO () iohandler e = putStrLn "got io exception" >> return ()
Exceptions are always a pain, and so are transformers, but you get used to them.
On Mon, Aug 1, 2016 at 4:06 AM, Dennis Raddle
wrote: I'm looking over haskeline. It looks like I have to modify some of my code that is in the IO monad right now. I use 'evaluate' in several places, and also 'evaluate $ force', to make sure that IO exceptions are encountered where I can catch them. Can I use 'evaluate' with InputT? I'm muddled headed about what to do. I guess I would lift 'evaluate' into the inner monad? I am not sure what those words mean. How would I catch IO exceptions?
On Thu, Jul 28, 2016 at 5:35 PM, Dennis Raddle
wrote: Thanks. I'll install haskeline
On Thu, Jul 28, 2016 at 5:05 PM, David McBride
wrote: You will have to use the haskeline library. FYI that is the library that makes ghci work.
On Thu, Jul 28, 2016 at 6:09 PM, Dennis Raddle
wrote:
I wrote a program first in Windows, where it works as expected, and now I'm using it in OS X and getting undesired behavior.
It reads lines from the terminal using the getLine function. In Windows (DOS, actually) the up and down arrows can be used to choose previously entered lines. However, this does not work in bash in OS X.
What do I need to get the history available via the arrow keys?
D
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 You can just run your program via the GNU readline wrapper. - -- Alexander alexander@plaimi.net https://secure.plaimi.net/~alexander -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCgAGBQJXqFKTAAoJENQqWdRUGk8Bw9kQAJt69W6tx5nAuBLEBN3Dxbgn ywd2vnlHxAjM5mwhO5fesjHVQrn7KmMNnKCwAZoheN5CzQ+FTloph5b1N5vz8+PW ScbOXkO0DllsEEGm+xVbizMtNBd/jQcTZCfne88L+pN17iB8Tq38BO/Z0wGdHBa6 9wc5zVA8WYIp3Rz6JenCbMMNdkvlJkGPLtFj4Dc4HpjUUf0shkYBD2FLY/+KdJmy TS8rpa8pmUf7iLJtjx08/aq3mlOnUneV1MLMU48YAHSxIirumiN1FqZob9xsJxGy 13oxevngEBfNCfNNHoHFCWxh7ouxvpLKszmwTb25Ts7aOyqPMXifTTrZhL7ZYTad emy/cmbIZu430JbeNTti0gZiqD6ZxjEDXxlFIrAIr/lqoIUghqabKcu2ddq/8pqD VSwymoxTCvJ0sZgpxnCRFwoilZh47W9wPISrIdAjgJTSpGpInzVteXfJi0t49B/G wKUruCO2uZjeznU5iBTPRKBKUab4WhbvF9bJeSPk+tHlNHlqFd3uEFymyB8lHFAu +d/89LUFz+wZXplHgDX4Qd/4SBhUILOdMUr60tCszWuI/HpxoZrLWVtIbZJ5Exvn k6L803FPU6/M1Z2GgB5lRSNOUDm2zJdNK/hpUxXaBQpFVVc/6hK+1WLMS7jZ/hiH eaVanrvlJ6m/kdRRMF0L =0Z0J -----END PGP SIGNATURE-----
participants (3)
-
Alexander Berntsen
-
David McBride
-
Dennis Raddle