--- tingle-0.9.5.hs	2012-06-10 19:35:18.000000000 +0200
+++ tingle-0.9.5-editline.hs	2012-06-10 20:08:42.000000000 +0200
@@ -18,6 +18,7 @@
 import System.Environment
 import System.IO
 import System.Random
+import System.Console.Editline.Readline
 
 -- basic types
 
@@ -1197,16 +1198,6 @@
       Right (White, _) -> return EmptyLine
       Right (parse, state) -> liftM Done $ exec True state parse
 
-readline prompt = do
-   isterm <- hIsTerminalDevice stdin
-   when isterm $ do
-      putStr prompt
-      hFlush stdout
-   eof <- isEOF
-   if eof
-      then return Nothing
-      else liftM Just getLine
-
 prompter histline state = do
    line <- readline "> "
    case line of
@@ -1218,7 +1209,10 @@
          case res of
             EmptyLine -> prompter histline state
             Incomplete -> extraline line
-            Done state' -> prompter line state'
+            Done state' -> do
+               isterm <- hIsTerminalDevice stdin
+               when (isterm && line /= histline) $ addHistory line
+               prompter line state'
       extraline previouslines = do
          line <- readline "  "
          case line of
@@ -1228,11 +1222,16 @@
                   Left err -> putStrLn $ errshow err
 
 main = do
+   home <- getEnv "HOME"
+   readHistory (home ++ "/.tingle_history")
+   setInhibitCompletion True
+   stifleHistory 500
    lobby <- liftM2 Obj (newIORef IM.empty) (newIORef lobbySym)
    let state = ST IM.empty IM.empty
                   (IM.singleton lobbySym []) (IM.singleton lobbySym [])
                   lobby initialSymbolTable initialLocationTable
                   "main" [] [] []
    getArgs >>= foldM processfile state >>= prompter ""
+   writeHistory (home ++ "/.tingle_history")
    isterm <- hIsTerminalDevice stdin
    when isterm $ putStrLn ""
