Haskeline使得获取文件名制表符完成功能变得非常容易:
module Main where
import System.Console.Haskeline
import System.Environment
mySettings :: Settings IO
mySettings = defaultSettings {historyFile = Just "myhist"}
main :: IO ()
main = do
args <- getArgs
let inputFunc = getInputLine
runInputT mySettings $ withInterrupt $ loop inputFunc 0
where
loop inputFunc n = do
minput <- handleInterrupt (return (Just "Caught interrupted"))
$ inputFunc (show n ++ ":")
case minput of
Nothing -> return ()
Just s -> do
outputStrLn ("line " ++ show n ++ ":" ++ s)
loop inputFunc (n+1)它还提供了像completeWord和completeQuotedWord这样的函数,应该能够像使用completeFilename一样使用这些函数来实现上述功能。
(换句话说,根据单词列表(比如函数名)进行制表符补全,而不是基于文件夹的内容)
有人能提供这方面的工作示例或工作代码吗?
对其他包(如HCL)中的函数的推荐也很有帮助。
发布于 2011-05-29 12:15:18
这就是你要找的东西吗?
import Data.List
wordList = [ "Apple", "Pear", "Peach", "Grape", "Grapefruit", "Slime Mold"]
searchFunc :: String -> [Completion]
searchFunc str = map simpleCompletion $ filter (str `isPrefixOf`) wordList
mySettings :: Settings IO
mySettings = Settings { historyFile = Just "myhist"
, complete = completeWord Nothing " \t" $ return . searchFunc
, autoAddHistory = True
}将代码片段中的mySettings定义替换为该定义,它应该可以工作。
https://stackoverflow.com/questions/6147201
复制相似问题