kentry.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /** @file kentry.h
  2. *
  3. * @brief Klish scheme's "ENTRY" entry
  4. */
  5. #ifndef _klish_kentry_h
  6. #define _klish_kentry_h
  7. #include <faux/list.h>
  8. #include <klish/kaction.h>
  9. #include <klish/khotkey.h>
  10. typedef struct kentry_s kentry_t;
  11. typedef faux_list_node_t kentry_entrys_node_t;
  12. typedef faux_list_node_t kentry_actions_node_t;
  13. typedef faux_list_node_t kentry_hotkeys_node_t;
  14. // Mode of nested entrys list
  15. typedef enum {
  16. KENTRY_MODE_NONE, // Illegal
  17. KENTRY_MODE_SEQUENCE, // Sequence of entrys
  18. KENTRY_MODE_SWITCH, // Switch of entrys
  19. KENTRY_MODE_EMPTY, // Entry must not have a nested entrys
  20. } kentry_mode_e;
  21. // Purpose of ENTRY
  22. typedef enum {
  23. KENTRY_PURPOSE_NONE,
  24. KENTRY_PURPOSE_COMMON, // Common entry like view/command/param
  25. KENTRY_PURPOSE_PTYPE,
  26. KENTRY_PURPOSE_PROMPT, // Prompt for view
  27. KENTRY_PURPOSE_COND, // Conditional expression
  28. KENTRY_PURPOSE_COMPLETION, // Engine to generate completions
  29. KENTRY_PURPOSE_HELP,
  30. KENTRY_PURPOSE_MAX,
  31. } kentry_purpose_e;
  32. // Number of max occurs
  33. typedef enum {
  34. KENTRY_OCCURS_UNBOUNDED = (size_t)(-1),
  35. } kentry_occurs_e;
  36. typedef bool_t (*kentry_udata_free_fn)(void *data);
  37. C_DECL_BEGIN
  38. kentry_t *kentry_new(const char *name);
  39. void kentry_free(kentry_t *entry);
  40. bool_t kentry_link(kentry_t *dst, const kentry_t *src);
  41. // Name
  42. const char *kentry_name(const kentry_t *entry);
  43. // Help
  44. const char *kentry_help(const kentry_t *entry);
  45. bool_t kentry_set_help(kentry_t *entry, const char *help);
  46. // Parent
  47. kentry_t *kentry_parent(const kentry_t *entry);
  48. bool_t kentry_set_parent(kentry_t *entry, kentry_t *parent);
  49. // Container
  50. bool_t kentry_container(const kentry_t *entry);
  51. bool_t kentry_set_container(kentry_t *entry, bool_t container);
  52. // Mode
  53. kentry_mode_e kentry_mode(const kentry_t *entry);
  54. bool_t kentry_set_mode(kentry_t *entry, kentry_mode_e mode);
  55. // Purpose
  56. kentry_purpose_e kentry_purpose(const kentry_t *entry);
  57. bool_t kentry_set_purpose(kentry_t *entry, kentry_purpose_e purpose);
  58. // Min occurs
  59. size_t kentry_min(const kentry_t *entry);
  60. bool_t kentry_set_min(kentry_t *entry, size_t min);
  61. // Max occurs
  62. size_t kentry_max(const kentry_t *entry);
  63. bool_t kentry_set_max(kentry_t *entry, size_t max);
  64. // Ref
  65. const char *kentry_ref_str(const kentry_t *entry);
  66. bool_t kentry_set_ref_str(kentry_t *entry, const char *ref_str);
  67. // Value
  68. const char *kentry_value(const kentry_t *entry);
  69. bool_t kentry_set_value(kentry_t *entry, const char *value);
  70. // Restore
  71. bool_t kentry_restore(const kentry_t *entry);
  72. bool_t kentry_set_restore(kentry_t *entry, bool_t restore);
  73. // Order
  74. bool_t kentry_order(const kentry_t *entry);
  75. bool_t kentry_set_order(kentry_t *entry, bool_t order);
  76. // Filter
  77. bool_t kentry_filter(const kentry_t *entry);
  78. bool_t kentry_set_filter(kentry_t *entry, bool_t filter);
  79. // User data
  80. void *kentry_udata(const kentry_t *entry);
  81. bool_t kentry_set_udata(kentry_t *entry, void *data, kentry_udata_free_fn udata_free_fn);
  82. // Nested ENTRY list
  83. faux_list_t *kentry_entrys(const kentry_t *entry);
  84. bool_t kentry_add_entrys(kentry_t *entry, kentry_t *nested_entry);
  85. kentry_t *kentry_find_entry(const kentry_t *entry, const char *name);
  86. ssize_t kentry_entrys_len(const kentry_t *entry);
  87. bool_t kentry_entrys_is_empty(const kentry_t *entry);
  88. kentry_entrys_node_t *kentry_entrys_iter(const kentry_t *entry);
  89. kentry_t *kentry_entrys_each(kentry_entrys_node_t **iter);
  90. // ACTIONs
  91. faux_list_t *kentry_actions(const kentry_t *entry);
  92. bool_t kentry_add_actions(kentry_t *entry, kaction_t *action);
  93. ssize_t kentry_actions_len(const kentry_t *entry);
  94. kentry_actions_node_t *kentry_actions_iter(const kentry_t *entry);
  95. kaction_t *kentry_actions_each(kentry_actions_node_t **iter);
  96. bool_t kentry_interactive(const kentry_t *entry);
  97. // HOTKEYs
  98. faux_list_t *kentry_hotkeys(const kentry_t *entry);
  99. bool_t kentry_add_hotkeys(kentry_t *entry, khotkey_t *hotkey);
  100. ssize_t kentry_hotkeys_len(const kentry_t *entry);
  101. kentry_hotkeys_node_t *kentry_hotkeys_iter(const kentry_t *entry);
  102. khotkey_t *kentry_hotkeys_each(kentry_hotkeys_node_t **iter);
  103. int kentry_hotkey_compare(const void *first, const void *second);
  104. // Fast access for nested entries with special purposes
  105. kentry_t *kentry_nested_by_purpose(const kentry_t *entry, kentry_purpose_e purpose);
  106. bool_t kentry_set_nested_by_purpose(kentry_t *entry, kentry_purpose_e purpose,
  107. kentry_t *nested);
  108. C_DECL_END
  109. #endif // _klish_kentry_h