input.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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, int len, const char *text, const char *histname,
  68. input_complete_t completion_flags);
  69. /* callback is public; needed for command line */
  70. cb_ret_t input_callback (Widget *w, Widget *sender, widget_msg_t msg, int parm, void *data);
  71. void input_set_default_colors (void);
  72. cb_ret_t input_handle_char (WInput *in, int key);
  73. void input_assign_text (WInput *in, const char *text);
  74. void input_insert (WInput *in, const char *text, gboolean insert_extra_space);
  75. void input_set_point (WInput *in, int pos);
  76. void input_update (WInput *in, gboolean clear_first);
  77. void input_enable_update (WInput *in);
  78. void input_disable_update (WInput *in);
  79. void input_clean (WInput *in);
  80. /* input_complete.c */
  81. void input_complete (WInput *in);
  82. void input_complete_free (WInput *in);
  83. /* --------------------------------------------------------------------------------------------- */
  84. /*** inline functions ****************************************************************************/
  85. /* --------------------------------------------------------------------------------------------- */
  86. /**
  87. * Get text of input line.
  88. *
  89. * @param in input line
  90. *
  91. * @return newly allocated string that contains a copy of @in's text.
  92. */
  93. static inline char *
  94. input_get_text (const WInput *in)
  95. {
  96. return g_strndup (in->buffer->str, in->buffer->len);
  97. }
  98. /* --------------------------------------------------------------------------------------------- */
  99. /**
  100. * Get pointer to input line buffer.
  101. *
  102. * @param in input line
  103. *
  104. * @return pointer to @in->buffer->str.
  105. */
  106. static inline const char *
  107. input_get_ctext (const WInput *in)
  108. {
  109. return in->buffer->str;
  110. }
  111. /* --------------------------------------------------------------------------------------------- */
  112. /**
  113. * Is input line empty or not.
  114. *
  115. * @param in input line
  116. *
  117. * @return TRUE if buffer of @in is empty, FALSE otherwise.
  118. */
  119. static inline gboolean
  120. input_is_empty (const WInput *in)
  121. {
  122. return (in->buffer->len == 0);
  123. }
  124. /* --------------------------------------------------------------------------------------------- */
  125. #endif /* MC__WIDGET_INPUT_H */