【发布时间】:2011-05-27 02:23:39
【问题描述】:
Haskline 让获取文件名制表符补全功能变得非常容易:
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)中的功能建议也很有帮助。
【问题讨论】:
-
我从未使用过这些函数,但如果您正在寻找具有特定函数或模块的示例代码,您可以随时尝试Google Code Search。它并不总是有帮助,但它通常会在各种情况下为您提供一些很好的示例。
-
我没有找到任何功能参考,但感谢您的建议。
-
提供我 62% 的声誉来回答这个问题 :)
标签: haskell command-line haskeline word-completion