cli.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #pragma once
  2. #ifdef __cplusplus
  3. extern "C" {
  4. #endif
  5. #include <m-string.h>
  6. /* Cli type
  7. * Anonymous structure. Use cli_i.h if you need to go deeper.
  8. */
  9. typedef struct Cli Cli;
  10. /* Cli callback function pointer.
  11. * Implement this interface and use add_cli_command
  12. * @param args - string with what was passed after command
  13. * @param context - pointer to whatever you gave us on cli_add_command
  14. */
  15. typedef void (*CliCallback)(string_t args, void* context);
  16. /* Add cli command
  17. * Registers you command callback
  18. * @param cli - pointer to cli instance
  19. * @param name - command name
  20. * @param callback - callback function
  21. * @param context - pointer to whatever we need to pass to callback
  22. */
  23. void cli_add_command(Cli* cli, const char* name, CliCallback callback, void* context);
  24. /* Read terminal input.
  25. * Do it only from inside of callback.
  26. * @param buffer - buffer pointer to char buffer
  27. * @param size - size of buffer in bytes
  28. */
  29. void cli_read(char* buffer, size_t size);
  30. /* Print to terminal
  31. * Do it only from inside of callback.
  32. * @param buffer - pointer to null terminated string to print.
  33. */
  34. void cli_print(const char* buffer);
  35. /* New line
  36. * Send new ine sequence
  37. */
  38. void cli_nl();
  39. #ifdef __cplusplus
  40. }
  41. #endif