cli.h 1.1 KB

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