input.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. /* For history load-save functions */
  9. #define INPUT_LAST_TEXT ((char *) 2)
  10. /*** enums ***************************************************************************************/
  11. typedef enum
  12. {
  13. WINPUTC_MAIN, /* color used */
  14. WINPUTC_MARK, /* color for marked text */
  15. WINPUTC_UNCHANGED, /* color for inactive text (Is first keystroke) */
  16. WINPUTC_HISTORY, /* color for history list */
  17. WINPUTC_COUNT_COLORS /* count of used colors */
  18. } input_colors_enum_t;
  19. /* completion flags */
  20. typedef enum
  21. {
  22. INPUT_COMPLETE_FILENAMES = 1 << 0,
  23. INPUT_COMPLETE_HOSTNAMES = 1 << 1,
  24. INPUT_COMPLETE_COMMANDS = 1 << 2,
  25. INPUT_COMPLETE_VARIABLES = 1 << 3,
  26. INPUT_COMPLETE_USERNAMES = 1 << 4,
  27. INPUT_COMPLETE_CD = 1 << 5,
  28. INPUT_COMPLETE_SHELL_ESC = 1 << 6,
  29. INPUT_COMPLETE_DEFAULT = INPUT_COMPLETE_FILENAMES
  30. | INPUT_COMPLETE_HOSTNAMES | INPUT_COMPLETE_VARIABLES | INPUT_COMPLETE_USERNAMES
  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. input_colors_t color;
  38. int point; /* cursor position in the input line in characters */
  39. int mark; /* the mark position in characters */
  40. gboolean highlight; /* there is a selected block */
  41. int term_first_shown; /* column of the first shown character */
  42. size_t current_max_size; /* maximum length of input line (bytes) */
  43. int field_width; /* width of the editing field */
  44. gboolean first; /* is first keystroke? */
  45. int disable_update; /* do we want to skip updates? */
  46. gboolean is_password; /* is this a password input line? */
  47. char *init_text; /* initial text of input line */
  48. char *buffer; /* pointer to editing buffer */
  49. char *history_name; /* name of history for loading and saving */
  50. GList *history; /* the history */
  51. GList *history_current; /* current history item */
  52. gboolean history_changed; /* the history has changed */
  53. gboolean need_push; /* need to push the current Input on hist? */
  54. gboolean strip_password; /* need to strip password before placing string to history */
  55. char **completions; /* possible completions array */
  56. input_complete_t completion_flags;
  57. char charbuf[MB_LEN_MAX]; /* buffer for multibytes characters */
  58. size_t charpoint; /* point to end of mulibyte sequence in charbuf */
  59. } WInput;
  60. /*** global variables defined in .c file *********************************************************/
  61. extern int quote;
  62. extern const global_keymap_t *input_map;
  63. /*** declarations of public functions ************************************************************/
  64. WInput *input_new (int y, int x, const int *input_colors,
  65. int len, const char *text, const char *histname,
  66. input_complete_t completion_flags);
  67. /* callbac is public; needed for command line */
  68. cb_ret_t input_callback (Widget * w, widget_msg_t msg, int parm);
  69. const int *input_get_default_colors (void);
  70. void input_set_origin (WInput * i, int x, int field_width);
  71. cb_ret_t input_handle_char (WInput * in, int key);
  72. int input_key_is_in_map (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. void input_free_completions (WInput * in);
  81. /*** inline functions ****************************************************************************/
  82. #endif /* MC__WIDGET_INPUT_H */