summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2024-04-17 21:35:46 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2024-04-17 21:35:46 +0200
commitfc69cbaf3306bd3840db2cb48cb34996127a20db (patch)
treee82bd772a628822be81978b23776a58cf5a4fd9e /main
parent2bb4415d88073e849c32ad7f67e635f9f69125db (diff)
Command name completion using Haskeline
Changelog: Tab-completion of command name
Diffstat (limited to 'main')
-rw-r--r--main/Main.hs13
1 files changed, 12 insertions, 1 deletions
diff --git a/main/Main.hs b/main/Main.hs
index 90e4079..5dbad60 100644
--- a/main/Main.hs
+++ b/main/Main.hs
@@ -140,8 +140,11 @@ main = do
else interactiveLoop st opts
+inputSettings :: Settings IO
+inputSettings = setComplete commandCompletion $ defaultSettings
+
interactiveLoop :: Storage -> Options -> IO ()
-interactiveLoop st opts = runInputT defaultSettings $ do
+interactiveLoop st opts = runInputT inputSettings $ do
erebosHead <- liftIO $ loadLocalStateHead st
outputStrLn $ T.unpack $ displayIdentity $ headLocalIdentity erebosHead
@@ -322,6 +325,14 @@ commands =
#endif
]
+commandCompletion :: CompletionFunc IO
+commandCompletion = completeWordWithPrev Nothing [ ' ', '\t', '\n', '\r' ] $ curry $ \case
+ ([], '/':pref) -> return . map (simpleCompletion . ('/':)) . filter (pref `isPrefixOf`) $ sortedCommandNames
+ _ -> return []
+ where
+ sortedCommandNames = sort $ map fst commands
+
+
cmdUnknown :: String -> Command
cmdUnknown cmd = liftIO $ putStrLn $ "Unknown command: " ++ cmd