This source file includes following definitions.
- enter
- command_callback
- command_new
- command_set_default_colors
- command_insert
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 #include <config.h>
35
36 #include <stdlib.h>
37 #include <string.h>
38
39 #include "lib/global.h"
40 #include "lib/vfs/vfs.h"
41 #include "lib/skin.h"
42 #include "lib/util.h"
43 #include "lib/widget.h"
44
45 #include "src/setup.h"
46 #ifdef ENABLE_SUBSHELL
47 #include "src/subshell/subshell.h"
48 #endif
49 #include "src/execute.h"
50 #include "src/usermenu.h"
51
52 #include "filemanager.h"
53 #include "cd.h"
54
55 #include "command.h"
56
57
58
59
60 WInput *cmdline;
61
62
63
64
65
66
67
68
69
70
71 static input_colors_t command_colors;
72
73
74
75
76
77
78
79
80
81
82
83 static cb_ret_t
84 enter (WInput *lc_cmdline)
85 {
86 const char *cmd;
87
88 if (!command_prompt)
89 return MSG_HANDLED;
90
91 cmd = input_get_ctext (lc_cmdline);
92
93
94 while (whiteness (*cmd))
95 cmd++;
96
97 if (*cmd == '\0')
98 return MSG_HANDLED;
99
100 if (strncmp (cmd, "cd", 2) == 0 && (cmd[2] == '\0' || whitespace (cmd[2])))
101 {
102 cd_to (cmd + 2);
103 input_clean (lc_cmdline);
104 return MSG_HANDLED;
105 }
106 else if (strcmp (cmd, "exit") == 0)
107 {
108 input_assign_text (lc_cmdline, "");
109 if (!quiet_quit_cmd ())
110 return MSG_NOT_HANDLED;
111 }
112 else
113 {
114 GString *command;
115 size_t i;
116
117 if (!vfs_current_is_local ())
118 {
119 message (D_ERROR, MSG_ERROR, _("Cannot execute commands on non-local filesystems"));
120 return MSG_NOT_HANDLED;
121 }
122 #ifdef ENABLE_SUBSHELL
123
124
125 if (mc_global.tty.use_subshell && subshell_state != INACTIVE)
126 {
127 message (D_ERROR, MSG_ERROR, _("The shell is already running a command"));
128 return MSG_NOT_HANDLED;
129 }
130 #endif
131 command = g_string_sized_new (32);
132
133 for (i = 0; cmd[i] != '\0'; i++)
134 {
135 if (cmd[i] != '%')
136 g_string_append_c (command, cmd[i]);
137 else
138 {
139 char *s;
140
141 s = expand_format (NULL, cmd[++i], TRUE);
142 if (s != NULL)
143 {
144 g_string_append (command, s);
145 g_free (s);
146 }
147 }
148 }
149
150 input_clean (lc_cmdline);
151 shell_execute (command->str, 0);
152 g_string_free (command, TRUE);
153
154 #ifdef ENABLE_SUBSHELL
155 if ((quit & SUBSHELL_EXIT) != 0)
156 {
157 if (quiet_quit_cmd ())
158 return MSG_HANDLED;
159
160 quit = 0;
161
162 if (mc_global.tty.use_subshell)
163 init_subshell ();
164 }
165
166 if (mc_global.tty.use_subshell)
167 do_load_prompt ();
168 #endif
169 }
170 return MSG_HANDLED;
171 }
172
173
174
175
176
177
178
179
180
181
182
183
184
185 static cb_ret_t
186 command_callback (Widget *w, Widget *sender, widget_msg_t msg, int parm, void *data)
187 {
188 switch (msg)
189 {
190 case MSG_KEY:
191
192 if (parm == '\n')
193 return enter (INPUT (w));
194 MC_FALLTHROUGH;
195
196 default:
197 return input_callback (w, sender, msg, parm, data);
198 }
199 }
200
201
202
203
204
205 WInput *
206 command_new (int y, int x, int cols)
207 {
208 WInput *cmd;
209 Widget *w;
210
211 cmd = input_new (y, x, command_colors, cols, "", "cmdline",
212 INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_VARIABLES | INPUT_COMPLETE_USERNAMES
213 | INPUT_COMPLETE_HOSTNAMES | INPUT_COMPLETE_CD | INPUT_COMPLETE_COMMANDS |
214 INPUT_COMPLETE_SHELL_ESC);
215 w = WIDGET (cmd);
216
217 widget_set_options (w, WOP_SELECTABLE, FALSE);
218
219 w->callback = command_callback;
220
221 return cmd;
222 }
223
224
225
226
227
228
229 void
230 command_set_default_colors (void)
231 {
232 command_colors[WINPUTC_MAIN] = DEFAULT_COLOR;
233 command_colors[WINPUTC_MARK] = COMMAND_MARK_COLOR;
234 command_colors[WINPUTC_UNCHANGED] = DEFAULT_COLOR;
235 command_colors[WINPUTC_HISTORY] = COMMAND_HISTORY_COLOR;
236 }
237
238
239
240
241
242
243
244
245
246
247
248 void
249 command_insert (WInput *in, const char *text, gboolean insert_extra_space)
250 {
251 char *quoted_text;
252
253 quoted_text = name_quote (text, TRUE);
254 if (quoted_text != NULL)
255 {
256 input_insert (in, quoted_text, insert_extra_space);
257 g_free (quoted_text);
258 }
259 }
260
261