add setCompletionFunction in GF.System.Readline

This commit is contained in:
kr.angelov
2008-06-03 16:54:59 +00:00
parent bd1fd95696
commit ea145ddf52
3 changed files with 18 additions and 6 deletions

View File

@@ -12,7 +12,7 @@
-- Do not use readline. -- 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.Error (try)
import System.IO (stdout,hFlush) import System.IO (stdout,hFlush)
@@ -25,3 +25,6 @@ fetchCommand s = do
case res of case res of
Left e -> return "q" Left e -> return "q"
Right l -> return l Right l -> return l
setCompletionFunction :: Maybe (String -> String -> Int -> IO [String]) -> IO ()
setCompletionFunction _ = return ()

View File

@@ -14,14 +14,14 @@
-- Uses the right readline library to read user input. -- 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 #ifdef USE_READLINE
import GF.System.UseReadline (fetchCommand) import GF.System.UseReadline (fetchCommand, setCompletionFunction)
#else #else
import GF.System.NoReadline (fetchCommand) import GF.System.NoReadline (fetchCommand, setCompletionFunction)
#endif #endif

View File

@@ -12,9 +12,9 @@
-- Use GNU readline -- 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 :: String -> IO (String)
fetchCommand s = do fetchCommand s = do
@@ -23,3 +23,12 @@ fetchCommand s = do
Nothing -> return "q" Nothing -> return "q"
Just s -> do addHistory s Just s -> do addHistory s
return 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