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)的功能建议也很有帮助。