forked from GitHub/gf-core
add setCompletionFunction in GF.System.Readline
This commit is contained in:
@@ -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 ()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user