1 TinyCon - A tiny console library, written for C++
2 --------------------------------------------------------------------------------
4 Author: Unix-Ninja | chris (at) unix-ninja (dot) com
6 Released: March 20, 2013
7 --------------------------------------------------------------------------------
9 Perhaps you are writing an application that requires user input to a console on
10 the commandline. There is the readline library from GNU, but it's license may
11 be a bit restrictive for your type of application. Instead, TinyCon is meant to
12 be a fairly light-weight and cross-platform input console library written in
13 C++, that is released under a less restrictive license. It is available for
14 Windows, OS X, and Linux. To use this library, simply include the tinycon.cpp
15 source file into your project. Then you can create an instance of the
20 Optionally, you can also specify a custom command prompt when you delcare your
23 tinyConsole tc("prompt> ");
25 To run tinycon, just use the run() method.
29 Tinycon will then sit and collect input from the user until the class registers
30 a quit state, (by default this occurs when the user types "exit");
32 To compile the demo with GCC, you can run the following:
33 $ g++ -o demo demo.cpp tinycon.cpp
39 Tinycon becomes most useful when inheriting it in a custom class. Here, you have
40 the option to over-ride the trigger() and hotkeys() methods. By doing so, you
41 can define your own custom behaviour to how tinycon handles user input.
47 getLine([int mode] [, string mask])
48 This method will collect user input until the return key is pressed. Once
49 collected, it will return the input as a string.
50 Optionally, you can specify the mode of operation as either M_LINE (default)
51 or M_PASSWORD. Setting this to M_PASSWORD will supress echoing of the input
52 characters as they are typed.
53 A mask can also be supplied when using M_PASSWORD mode. If given, the mask
54 will be echoed to the screen instead of the characters being typed.
57 This method will trigger each time a key is pressed. You can override this
58 method in an inherited class, and use it to evaluate the value of "c" in
59 order to perform some action that matches your criteria.
60 (Please note, the enter key does NOT trigger the hotkeys method).
63 This method starts collecting input from the user in an infinite loop. It
64 will terminate when a "quit" state is registered.
67 This method will copy the contents of the current line buffer with the
68 contents of the given string "s".
70 setMaxHistory(int size)
71 This method setst the size of the history buffer. You can use this to
72 control the total number of commands that tinycon can remember. A user can
73 use the up and down arrow keys to scroll through history on the commandline.
76 When a user presses the enter key, their input is passed as a string to this
77 method. You can override this method in an inherited class to process a
81 This method registered the quit state of the console. It can be set to true