summaryrefslogtreecommitdiff
path: root/src-3.0
diff options
context:
space:
mode:
authorkr.angelov <kr.angelov@chalmers.se>2008-06-03 16:54:59 +0000
committerkr.angelov <kr.angelov@chalmers.se>2008-06-03 16:54:59 +0000
commitea145ddf5289c1f12d01a39ceb2935ddce8b31a0 (patch)
treec1ebce2e9aa46883d9471502a279239f1952c341 /src-3.0
parentbd1fd9569634240c26c9961298b7a4b503cc2c59 (diff)
add setCompletionFunction in GF.System.Readline
Diffstat (limited to 'src-3.0')
-rw-r--r--src-3.0/GF/System/NoReadline.hs5
-rw-r--r--src-3.0/GF/System/Readline.hs6
-rw-r--r--src-3.0/GF/System/UseReadline.hs13
3 files changed, 18 insertions, 6 deletions
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