input.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #include "lib/keybind.h" /* global_keymap_t */
  8. /*** typedefs(not structures) and defined constants **********************************************/
  9. #define INPUT(x) ((WInput *)(x))
  10. /* For history load-save functions */
  11. #define INPUT_LAST_TEXT ((char *) 2)
  12. /*** enums ***************************************************************************************/
  13. typedef enum
  14. {
  15. WINPUTC_MAIN, /* color used */
  16. WINPUTC_MARK, /* color for marked text */
  17. WINPUTC_UNCHANGED, /* color for inactive text (Is first keystroke) */
  18. WINPUTC_HISTORY, /* color for history list */
  19. WINPUTC_COUNT_COLORS /* count of used colors */
  20. } input_colors_enum_t;
  21. /* completion flags */
  22. typedef enum
  23. {
  24. INPUT_COMPLETE_NONE = 0,
  25. INPUT_COMPLETE_FILENAMES = 1 << 0,
  26. INPUT_COMPLETE_HOSTNAMES = 1 << 1,
  27. INPUT_COMPLETE_COMMANDS = 1 << 2,
  28. INPUT_COMPLETE_VARIABLES = 1 << 3,
  29. INPUT_COMPLETE_USERNAMES = 1 << 4,
  30. INPUT_COMPLETE_CD = 1 << 5,
  31. INPUT_COMPLETE_SHELL_ESC = 1 << 6,
  32. } input_complete_t;
  33. /*** structures declarations (and typedefs of structures)*****************************************/
  34. typedef int input_colors_t[WINPUTC_COUNT_COLORS];
  35. typedef struct
  36. {
  37. Widget widget;
  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. size_t current_max_size; /* maximum length of input line (bytes) */
  43. gboolean first; /* is first keystroke? */
  44. int disable_update; /* do we want to skip updates? */
  45. gboolean is_password; /* is this a password input line? */
  46. gboolean init_from_history; /* init text will be get from history */
  47. char *buffer; /* pointer to editing buffer */
  48. gboolean need_push; /* need to push the current Input on hist? */
  49. gboolean strip_password; /* need to strip password before placing string to history */
  50. char **completions; /* possible completions array */
  51. input_complete_t completion_flags;
  52. char charbuf[MB_LEN_MAX]; /* buffer for multibytes characters */
  53. size_t charpoint; /* point to end of mulibyte sequence in charbuf */
  54. WLabel *label; /* label associated with this input line */
  55. struct input_history_t
  56. {
  57. char *name; /* name of history for loading and saving */
  58. GList *list; /* the history */
  59. GList *current; /* current history item */
  60. gboolean changed; /* the history has changed */
  61. } history;
  62. } WInput;
  63. /*** global variables defined in .c file *********************************************************/
  64. extern int quote;
  65. extern const global_keymap_t *input_map;
  66. /* Color styles for normal and command line input widgets */
  67. extern input_colors_t input_colors;
  68. /*** declarations of public functions ************************************************************/
  69. WInput *input_new (int y, int x, const int *colors,
  70. int len, const char *text, const char *histname,
  71. input_complete_t completion_flags);
  72. /* callbac is public; needed for command line */
  73. cb_ret_t input_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data);
  74. void input_set_default_colors (void);
  75. cb_ret_t input_handle_char (WInput * in, int key);
  76. int input_key_is_in_map (WInput * in, int key);
  77. void input_assign_text (WInput * in, const char *text);
  78. gboolean input_is_empty (const WInput * in);
  79. void input_insert (WInput * in, const char *text, gboolean insert_extra_space);
  80. void input_set_point (WInput * in, int pos);
  81. void input_update (WInput * in, gboolean clear_first);
  82. void input_enable_update (WInput * in);
  83. void input_disable_update (WInput * in);
  84. void input_clean (WInput * in);
  85. void input_free_completions (WInput * in);
  86. /*** inline functions ****************************************************************************/
  87. #endif /* MC__WIDGET_INPUT_H */