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