Portability | portable |
---|---|
Stability | experimental |
Maintainer | Stefan Schmidt (stefanschmidt@web.de) |
Version : 0.1
This module provides a tiny and nice implementation of a little command shell. It can be feed with individual commands and provides a simple but powerful way to interact with your program. The following functions are implemented by default: exit - exit the console loop help - print a nice help
There was a little bug with the System.Console.Readline package. When we use this option, we make a foreign call... and the Haskell library documentation say this about concurrency and GHC:
We make a foreign call, which is not in the System.IO library, so we have to work with -threaded when we want a fancy command history.
- type ConsoleData a = Map String (ConsoleCommand a)
- nextOption :: [String] -> IO (Maybe String, [String])
- parseOption :: Read a => [String] -> IO (Maybe a, [String])
- initializeConsole :: ConsoleData a
- addConsoleCommand :: String -> ConsoleFunction a -> String -> ConsoleData a -> ConsoleData a
- handleUserInput :: ConsoleData a -> a -> IO ()
Console datatype
type ConsoleData a = Map String (ConsoleCommand a)Source
Map which contains all commands that the user can execute
Operations
nextOption :: [String] -> IO (Maybe String, [String])Source
gets the next option from the command line as string
parseOption :: Read a => [String] -> IO (Maybe a, [String])Source
Simple parser for the commandline...
initializeConsole :: ConsoleData aSource
Creates a new console datatype
:: String | command string (the word the user has to enter when he wants to execute the command) |
-> ConsoleFunction a | the function which should be executed |
-> String | the function description |
-> ConsoleData a | the old console data |
-> ConsoleData a |
Adds a new console command to the function, an existing command with the same name will be overwritten
handleUserInput :: ConsoleData a -> a -> IO ()Source
The main loop. You know... read stdin, parse the input, execute command. You can quit it by the exit-command.