summaryrefslogtreecommitdiff
path: root/src/compiler/GF/System/UseReadline.hs
blob: a0e0516015d2e94dbedd0b887f69825462f8dd61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
----------------------------------------------------------------------
-- |
-- Module      : GF.System.UseReadline
-- Maintainer  : BB
-- Stability   : (stable)
-- Portability : (portable)
--
-- > CVS $Date: 2005/05/10 15:04:01 $ 
-- > CVS $Author: bringert $
-- > CVS $Revision: 1.1 $
--
-- Use GNU readline
-----------------------------------------------------------------------------

module GF.System.UseReadline (fetchCommand, setCompletionFunction, filenameCompletionFunction) where

import System.Console.Readline

fetchCommand :: String -> IO (String)
fetchCommand s = do
  setCompletionAppendCharacter Nothing
  setBasicQuoteCharacters ""
  res <- readline s
  case res of
   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