mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 11:42:49 -06:00
add setCompletionFunction in GF.System.Readline
This commit is contained in:
@@ -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 ()
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user