diff options
| author | Joel Martin <github@martintribe.org> | 2014-12-23 22:37:43 -0700 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2015-01-09 16:16:52 -0600 |
| commit | fa9a9758e0d15abe670fbbfd8efa1fce013b1414 (patch) | |
| tree | 7ee5dceceaa79cf0269ae74d10aa297504c69da3 /haskell/Readline.hs | |
| parent | b76aa73bc76a28d7c6bb3c5a43acc9afd9ec42c8 (diff) | |
| download | mal-fa9a9758e0d15abe670fbbfd8efa1fce013b1414.tar.gz mal-fa9a9758e0d15abe670fbbfd8efa1fce013b1414.zip | |
Haskell: steps 4-6. Line editing. Simpler fn calls.
Diffstat (limited to 'haskell/Readline.hs')
| -rw-r--r-- | haskell/Readline.hs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/haskell/Readline.hs b/haskell/Readline.hs new file mode 100644 index 0000000..483c827 --- /dev/null +++ b/haskell/Readline.hs @@ -0,0 +1,30 @@ +module Readline +( readline, load_history ) +where + +-- Pick one of these: +-- GPL license +import qualified System.Console.Readline as RL +-- BSD license +--import qualified System.Console.Editline.Readline as RL + +import System.Directory (getHomeDirectory) + +history_file = do + home <- getHomeDirectory + return $ home ++ "/.mal-history" + +load_history = do + hfile <- history_file + content <- readFile hfile + mapM RL.addHistory (lines content) + +readline prompt = do + hfile <- history_file + maybeLine <- RL.readline prompt + case maybeLine of + Just line -> do + appendFile hfile (line ++ "\n") + RL.addHistory line + return maybeLine + _ -> return maybeLine |
