# Description: Add readline support
# Author: Arjan Oosting <arjanoosting@home.nl>
Index: helium-1.7~pre20090428/helium/src/texthint/Main.hs
===================================================================
--- helium-1.7~pre20090428.orig/helium/src/texthint/Main.hs	2011-06-02 18:34:20.000000000 +0200
+++ helium-1.7~pre20090428/helium/src/texthint/Main.hs	2011-06-02 18:43:48.000000000 +0200
@@ -23,6 +23,7 @@
 import Data.IORef       ( IORef, readIORef, newIORef, writeIORef )
 import System.IO.Unsafe ( unsafePerformIO )
 import System(system, getEnv, getArgs, exitWith, ExitCode(..))
+import qualified System.Console.Editline.Readline as RL
 import OSSpecific(slash)
 import Directory
 import ConfigFile(Config, readConfig)
@@ -155,6 +156,9 @@
               (initialState{ compOptions = addStandardLVMPath basepath (configOptions ++ (map show options)) })
           Nothing ->
             return initialState{ compOptions = addStandardLVMPath basepath configOptions }
+
+    -- Initialize editline
+    RL.initialize
     
     -- Enter read-eval-print loop
     loop stateAfterLoad
@@ -170,20 +174,22 @@
 
 loop :: State -> IO State
 loop state = do
-    putStr (prompt state)
-    hFlush stdout
-    command' <- getLine
-    let command = trim command'
+    command' <- RL.readline (prompt state)
+    let command = fmap trim command'
     newState <- case command of
-        (':':cmd:rest) -> 
+        Just (':':cmd:rest) -> do
+            RL.addHistory (':':cmd:rest)
             processCommand (toLower cmd) (trim rest) state
-        (':':_) -> do
+        Just (':':_) -> do
             putStrLn "Expecting command after colon. Type :? for help"
             return state
-        expression -> do
+        Just expression -> do
             if null expression 
               then return state
-              else processExpression expression state
+              else do
+                RL.addHistory expression
+                processExpression expression state
+        Nothing -> return state
     loop newState
   where
     prompt :: State -> String
