|
3 | 3 | How it works |
4 | 4 | ============ |
5 | 5 |
|
6 | | -To be added... |
| 6 | +This section describes how library works from the basic perspective. |
| 7 | + |
| 8 | +LwSHELL is designed to accept *computer-command-like* input, in format of ``cmdname param1 "param 2 with space"``, |
| 9 | +parse it properly and search for function callback that is assigned for specific ``cmdname``. |
| 10 | + |
| 11 | +Library starts processing input line on *line-feed* or *carriage-return* characters. |
| 12 | +It splits tokens by space character: |
| 13 | + |
| 14 | +* Tokens must not include ``space`` character or it will be considered as multi-token input |
| 15 | +* To use *space* character as token input, encapsulate character in *double-quotes* |
| 16 | + |
| 17 | +Command structure |
| 18 | +^^^^^^^^^^^^^^^^^ |
| 19 | + |
| 20 | +Every command has assigned dedicated name and must start with it. |
| 21 | +Application must take care to input exact command name since commands are case-sensitive, ``mycmd`` is a different command than ``Mycmd``. |
| 22 | + |
| 23 | +Command structure looks like: |
| 24 | + |
| 25 | +* It must start with command name and has at least one (``1``) parameter, eg. ``mycommand``. Command name is counted as first parameter |
| 26 | +* It may have additional parameters split with *space* character |
| 27 | +* Every input is parsed as string, even if parameter is string |
| 28 | + |
| 29 | +.. tip:: |
| 30 | + To use space as an input, encapsulate it with *double quotes*, eg. ``mycmd param1 "param 1 has spaces"`` |
| 31 | + |
| 32 | +Register command |
| 33 | +^^^^^^^^^^^^^^^^ |
| 34 | + |
| 35 | +Application must register command(s) to be used by the system. |
| 36 | +This can be done using :cpp:func:`lwshell_register_cmd` function which accepts |
| 37 | +*command name*, *command function* and optional *command description* |
| 38 | + |
| 39 | +Command description |
| 40 | +^^^^^^^^^^^^^^^^^^^ |
| 41 | + |
| 42 | +Every command can have assigned its very simple description text, know as *help text*. |
| 43 | +Description is later accessible with special command input that has ``2`` parameters in total and second is ``-h``, ``cmdname -h``. |
| 44 | + |
| 45 | +Data output |
| 46 | +^^^^^^^^^^^ |
| 47 | + |
| 48 | +To properly work with the library, application must input data to process by using :cpp:func:`lwshell_input` function. |
| 49 | +Thanks to the library implementation, it is possible to get data feedback and be able to implement OS-like console. |
| 50 | + |
| 51 | +To enable data-output feature, define your output callback function and assign it with :cpp:func:`lwshell_set_output_fn` function. |
| 52 | + |
| 53 | +Data outputs works on: |
| 54 | + |
| 55 | +* Special characters for *carriage return* and *line-feed* |
| 56 | +* Special character *backspace* that returns set of characters to implement backspace-like event on your output |
| 57 | +* Actual input character printed back for user feedback |
| 58 | +* ``cmdname -h`` feature works to print simple help text |
7 | 59 |
|
8 | 60 | .. toctree:: |
9 | 61 | :maxdepth: 2 |
0 commit comments