Explaination of the demo code
The demo code delivered with the CIH source files shows an example of the usage of the Dust Signs CIH. It mainly demonstrates the commands "echo", "recho" (reverse echo), "exit", "about" and "cd".
var
console_handler: TCustomizeablePrintableConsoleHandler;
parser: TAdvancedConsoleInputParser;
input_handler: TConsoleInputHandler;
[..]
parser := TAdvancedConsoleInputParser.Create;
input_handler := TConsoleInputHandler.Create;
console_handler := TCustomizeablePrintableConsoleHandler.Create(parser, input_handler, GetCurrentDirectory);
The declaration of 3 important objects is necessary: first of all, we need a Console Handler (in this case a TCustomizeablePrintableConsoleHandler to let the printing of the status etc. be done by the class. The Console Handler needs a parser and an Input Handler (the Input Handler manages a number of Command Handlers). It also needs a status, which will be set to the current directory to assure that the "cd" and the "dir" command work properly.
input_handler.RegisterCommandHandler(EchoCommandHandler); //Register command handlers
The next thing we have to do is to register the Command Handlers we want to be available in our Input Handler. EchoCommandHandler in this example is a pre-defined Command Handler which can be found in coninph2.pas.
Now comes the most important thing: the infinite loop where we read what the user typed and handle it over to the Console Handler:
while true do begin //Endless loop
ReadLn(input);
if not console_handler.Execute(input) then
break; //Break if Execute returns false (HR_REQUIRES_EXIT)
end;
The input will just be executed with the Execute function of the Console Handler and returns true. If it returns false, the HR_REQUIRES_EXIT return code was used by the called function (p.e. "exit") and the loop has to be quit using the break command to terminate the whole process (if you prefer, you can handle this case differently, of course).