input.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /** \file input.h
  2. * \brief Header: WInput widget
  3. */
  4. #ifndef MC__WIDGET_INPUT_H
  5. #define MC__WIDGET_INPUT_H
  6. #include <limits.h> /* MB_LEN_MAX */
  7. /*** typedefs(not structures) and defined constants **********************************************/
  8. #define INPUT(x) ((WInput *)(x))
  9. /* For history load-save functions */
  10. #define INPUT_LAST_TEXT ((char *) 2)
  11. /*** enums ***************************************************************************************/
  12. typedef enum
  13. {
  14. WINPUTC_MAIN, /* color used */
  15. WINPUTC_MARK, /* color for marked text */
  16. WINPUTC_UNCHANGED, /* color for inactive text (Is first keystroke) */
  17. WINPUTC_HISTORY, /* color for history list */
  18. WINPUTC_COUNT_COLORS /* count of used colors */
  19. } input_colors_enum_t;
  20. /* completion flags */
  21. typedef enum
  22. {
  23. INPUT_COMPLETE_NONE = 0,
  24. INPUT_COMPLETE_FILENAMES = 1 << 0,
  25. INPUT_COMPLETE_HOSTNAMES = 1 << 1,
  26. INPUT_COMPLETE_COMMANDS = 1 << 2,
  27. INPUT_COMPLETE_VARIABLES = 1 << 3,
  28. INPUT_COMPLETE_USERNAMES = 1 << 4,
  29. INPUT_COMPLETE_CD = 1 << 5,
  30. INPUT_COMPLETE_SHELL_ESC = 1 << 6,
  31. } input_complete_t;
  32. /*** structures declarations (and typedefs of structures)*****************************************/
  33. typedef int input_colors_t[WINPUTC_COUNT_COLORS];
  34. typedef struct
  35. {
  36. Widget widget;
  37. GString *buffer;
  38. const int *color;
  39. int point; /* cursor position in the input line in characters */
  40. int mark; /* the mark position in characters; negative value means no marked text */
  41. int term_first_shown; /* column of the first shown character */
  42. gboolean first; /* is first keystroke? */
  43. int disable_update; /* do we want to skip updates? */
  44. gboolean is_password; /* is this a password input line? */
  45. gboolean init_from_history; /* init text will be get from history */
  46. gboolean need_push; /* need to push the current Input on hist? */
  47. gboolean strip_password; /* need to strip password before placing string to history */
  48. GPtrArray *completions; /* possible completions array */
  49. input_complete_t completion_flags;
  50. char charbuf[MB_LEN_MAX]; /* buffer for multibytes characters */
  51. size_t charpoint; /* point to end of mulibyte sequence in charbuf */
  52. WLabel *label; /* label associated with this input line */
  53. struct input_history_t
  54. {
  55. char *name; /* name of history for loading and saving */
  56. GList *list; /* the history */
  57. GList *current; /* current history item */
  58. gboolean changed; /* the history has changed */
  59. } history;
  60. } WInput;
  61. /*** global variables defined in .c file *********************************************************/
  62. extern int quote;
  63. extern const global_keymap_t *input_map;
  64. /* Color styles for normal and command line input widgets */
  65. extern input_colors_t input_colors;
  66. /*** declarations of public functions ************************************************************/
  67. WInput *input_new (int y, int x, const int *colors,
  68. int len, const char *text, const char *histname,
  69. input_complete_t completion_flags);
  70. /* callback is public; needed for command line */
  71. cb_ret_t input_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data);
  72. void input_set_default_colors (void);
  73. cb_ret_t input_handle_char (WInput * in, int key);
  74. void input_assign_text (WInput * in, const char *text);
  75. void input_insert (WInput * in, const char *text, gboolean insert_extra_space);
  76. void input_set_point (WInput * in, int pos);
  77. void input_update (WInput * in, gboolean clear_first);
  78. void input_enable_update (WInput * in);
  79. void input_disable_update (WInput * in);
  80. void input_clean (WInput * in);
  81. /* input_complete.c */
  82. void input_complete (WInput * in);
  83. void input_complete_free (WInput * in);
  84. /* --------------------------------------------------------------------------------------------- */
  85. /*** inline functions ****************************************************************************/
  86. /* --------------------------------------------------------------------------------------------- */
  87. /**
  88. * Get text of input line.
  89. *
  90. * @param in input line
  91. *
  92. * @return newly allocated string that contains a copy of @in's text.
  93. */
  94. static inline char *
  95. input_get_text (const WInput *in)
  96. {
  97. return g_strndup (in->buffer->str, in->buffer->len);
  98. }
  99. /* --------------------------------------------------------------------------------------------- */
  100. /**
  101. * Get pointer to input line buffer.
  102. *
  103. * @param in input line
  104. *
  105. * @return pointer to @in->buffer->str.
  106. */
  107. static inline const char *
  108. input_get_ctext (const WInput *in)
  109. {
  110. return in->buffer->str;
  111. }
  112. /* --------------------------------------------------------------------------------------------- */
  113. /**
  114. * Is input line empty or not.
  115. *
  116. * @param in input line
  117. *
  118. * @return TRUE if buffer of @in is empty, FALSE otherwise.
  119. */
  120. static inline gboolean
  121. input_is_empty (const WInput *in)
  122. {
  123. return (in->buffer->len == 0);
  124. }
  125. /* --------------------------------------------------------------------------------------------- */
  126. #endif /* MC__WIDGET_INPUT_H */