|Maintainer||Stefan Schmidt (firstname.lastname@example.org)|
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:
If you don't use the -threaded option, then the runtime does not make use of multiple OS threads. Foreign calls will block all other running Haskell threads until the call returns. The System.IO library still does multiplexing, so there can be multiple threads doing IO, and this is handled internally by the runtime using select.
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 ()
Map which contains all commands that the user can execute
gets the next option from the command line as string
Simple parser for the commandline...
command string (the word the user has to enter when he wants to execute the command)
|-> ConsoleFunction a|
the function which should be executed
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