input.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /** \file input.h
  2. * \brief Header: WInput widget
  3. */
  4. #ifndef MC__WIDGET_INPUT_H
  5. #define MC__WIDGET_INPUT_H
  6. #include "lib/keybind.h" /* global_keymap_t */
  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. const int *color;
  38. int point; /* cursor position in the input line in characters */
  39. int mark; /* the mark position in characters; negative value means no marked text */
  40. int term_first_shown; /* column of the first shown character */
  41. size_t current_max_size; /* maximum length of input line (bytes) */
  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. char *buffer; /* pointer to editing buffer */
  47. gboolean need_push; /* need to push the current Input on hist? */
  48. gboolean strip_password; /* need to strip password before placing string to history */
  49. char **completions; /* possible completions array */
  50. input_complete_t completion_flags;
  51. char charbuf[MB_LEN_MAX]; /* buffer for multibytes characters */
  52. size_t charpoint; /* point to end of mulibyte sequence in charbuf */
  53. WLabel *label; /* label associated with this input line */
  54. struct input_history_t
  55. {
  56. char *name; /* name of history for loading and saving */
  57. GList *list; /* the history */
  58. GList *current; /* current history item */
  59. gboolean changed; /* the history has changed */
  60. } history;
  61. } WInput;
  62. /*** global variables defined in .c file *********************************************************/
  63. extern int quote;
  64. extern const global_keymap_t *input_map;
  65. /* Color styles for normal and command line input widgets */
  66. extern input_colors_t input_colors;
  67. /*** declarations of public functions ************************************************************/
  68. WInput *input_new (int y, int x, const int *colors,
  69. int len, const char *text, const char *histname,
  70. input_complete_t completion_flags);
  71. /* callbac is public; needed for command line */
  72. cb_ret_t input_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data);
  73. void input_set_default_colors (void);
  74. cb_ret_t input_handle_char (WInput * in, int key);
  75. int input_key_is_in_map (WInput * in, int key);
  76. void input_assign_text (WInput * in, const char *text);
  77. void input_insert (WInput * in, const char *text, gboolean insert_extra_space);
  78. void input_set_point (WInput * in, int pos);
  79. void input_update (WInput * in, gboolean clear_first);
  80. void input_enable_update (WInput * in);
  81. void input_disable_update (WInput * in);
  82. void input_clean (WInput * in);
  83. void input_free_completions (WInput * in);
  84. /*** inline functions ****************************************************************************/
  85. #endif /* MC__WIDGET_INPUT_H */