Holumbus-Distribution-0.0.1: intra- and inter-program communicationSource codeContentsIndex
MaintainerStefan Schmidt (stefanschmidt@web.de)
Console datatype

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 ()
Console datatype
type ConsoleData a = Map String (ConsoleCommand a)Source
Map which contains all commands that the user can execute
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
=> Stringcommand string (the word the user has to enter when he wants to execute the command)
-> ConsoleFunction athe function which should be executed
-> Stringthe function description
-> ConsoleData athe 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.
Produced by Haddock version 2.4.2