diff --git a/src-3.0/GF/System/NoReadline.hs b/src-3.0/GF/System/NoReadline.hs index 138ba4e28..564200a3e 100644 --- a/src-3.0/GF/System/NoReadline.hs +++ b/src-3.0/GF/System/NoReadline.hs @@ -12,7 +12,7 @@ -- Do not use readline. ----------------------------------------------------------------------------- -module GF.System.NoReadline (fetchCommand) where +module GF.System.NoReadline (fetchCommand, setCompletionFunction) where import System.IO.Error (try) import System.IO (stdout,hFlush) @@ -25,3 +25,6 @@ fetchCommand s = do case res of Left e -> return "q" Right l -> return l + +setCompletionFunction :: Maybe (String -> String -> Int -> IO [String]) -> IO () +setCompletionFunction _ = return () diff --git a/src-3.0/GF/System/Readline.hs b/src-3.0/GF/System/Readline.hs index c12493f98..94fca89bd 100644 --- a/src-3.0/GF/System/Readline.hs +++ b/src-3.0/GF/System/Readline.hs @@ -14,14 +14,14 @@ -- Uses the right readline library to read user input. ----------------------------------------------------------------------------- -module GF.System.Readline (fetchCommand) where +module GF.System.Readline (fetchCommand, setCompletionFunction) where #ifdef USE_READLINE -import GF.System.UseReadline (fetchCommand) +import GF.System.UseReadline (fetchCommand, setCompletionFunction) #else -import GF.System.NoReadline (fetchCommand) +import GF.System.NoReadline (fetchCommand, setCompletionFunction) #endif diff --git a/src-3.0/GF/System/UseReadline.hs b/src-3.0/GF/System/UseReadline.hs index c84b9d7f4..c4a8f9239 100644 --- a/src-3.0/GF/System/UseReadline.hs +++ b/src-3.0/GF/System/UseReadline.hs @@ -12,9 +12,9 @@ -- Use GNU readline ----------------------------------------------------------------------------- -module GF.System.UseReadline (fetchCommand) where +module GF.System.UseReadline (fetchCommand, setCompletionFunction) where -import System.Console.Readline (readline, addHistory) +import System.Console.Readline fetchCommand :: String -> IO (String) fetchCommand s = do @@ -23,3 +23,12 @@ fetchCommand s = do Nothing -> return "q" Just s -> do addHistory s return s + +setCompletionFunction :: Maybe (String -> String -> Int -> IO [String]) -> IO () +setCompletionFunction Nothing = setCompletionEntryFunction Nothing +setCompletionFunction (Just fn) = setCompletionEntryFunction (Just my_fn) + where + my_fn prefix = do + s <- getLineBuffer + p <- getPoint + fn s prefix p