Mercurial > mplayer.hg
annotate libmenu/menu_console.c @ 36298:353055b6213d
Remove remaining XFlush() calls.
These should have been already removed in r36386,
but they were mistakenly considered necessary.
We can rely on the implicit flushes of the output buffer.
author | ib |
---|---|
date | Fri, 02 Aug 2013 22:40:25 +0000 |
parents | caa2267e0cc6 |
children |
rev | line source |
---|---|
28113 | 1 /* |
2 * This file is part of MPlayer. | |
3 * | |
4 * MPlayer is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; either version 2 of the License, or | |
7 * (at your option) any later version. | |
8 * | |
9 * MPlayer is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License along | |
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
17 */ | |
8197 | 18 |
16862 | 19 #include "config.h" |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
20 #include "mp_msg.h" |
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
21 #include "help_mp.h" |
8197 | 22 |
23 #include <stdlib.h> | |
24 #include <stdio.h> | |
25 #include <string.h> | |
26 #include <ctype.h> | |
8229 | 27 #include <sys/time.h> |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
28 #include <sys/types.h> |
10864
a2537e7d2d76
make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents:
10333
diff
changeset
|
29 #ifndef __MINGW32__ |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
30 #include <sys/wait.h> |
10864
a2537e7d2d76
make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents:
10333
diff
changeset
|
31 #endif |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
32 #include <unistd.h> |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
33 #include <errno.h> |
8197 | 34 |
19431
ac69ba536915
Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents:
18858
diff
changeset
|
35 #include "libmpcodecs/img_format.h" |
ac69ba536915
Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents:
18858
diff
changeset
|
36 #include "libmpcodecs/mp_image.h" |
8197 | 37 |
16862 | 38 #include "m_struct.h" |
39 #include "m_option.h" | |
8197 | 40 #include "menu.h" |
41 | |
32466
9e627a1793b1
Move font_load.[ch], font_load_ft.c and osd_font.h from libvo to sub.
cigaes
parents:
30957
diff
changeset
|
42 #include "sub/font_load.h" |
16862 | 43 #include "osdep/keycodes.h" |
44 #include "input/input.h" | |
45 #include "osdep/timer.h" | |
8197 | 46 |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
47 typedef struct history_st history_t; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
48 |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
49 struct history_st { |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
50 char* buffer; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
51 int size; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
52 history_t* next; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
53 history_t* prev; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
54 }; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
55 |
8197 | 56 struct menu_priv_s { |
57 char** lines; // Our buffer | |
58 int last_line; | |
59 int num_lines; | |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
60 int add_line; |
8197 | 61 unsigned int hide_ts; |
62 unsigned int show_ts; | |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
63 pid_t child; // Child process if we are running a shell cmd |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
64 int child_fd[3]; // The 3 default fd |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
65 char* prompt; |
8197 | 66 //int max_lines; // Max number of lines with the last mpi |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
67 history_t* history; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
68 history_t* cur_history; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
69 int history_size; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
70 |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
71 char* mp_prompt; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
72 char* child_prompt; |
8197 | 73 int buf_lines; // Buffer size (in line) |
74 int height; // Display size in % | |
75 int minb; | |
76 int vspace; | |
17993
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
16862
diff
changeset
|
77 int bg,bg_alpha; |
8197 | 78 unsigned int hide_time; |
79 unsigned int show_time; | |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
80 int history_max; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
81 int raw_child; |
8197 | 82 }; |
83 | |
84 static struct menu_priv_s cfg_dflt = { | |
85 NULL, | |
86 0, | |
87 0, | |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
88 1, |
8197 | 89 0, |
90 0, | |
91 0, | |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
92 { 0 , 0, 0 }, |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
93 NULL, |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
94 NULL, |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
95 NULL, |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
96 0, |
8197 | 97 |
98 "# ", | |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
99 "$ ", |
8197 | 100 50, // lines |
101 33, // % | |
102 3, | |
103 3, | |
17993
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
16862
diff
changeset
|
104 0x80,0x40, |
8197 | 105 500, |
106 500, | |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
107 10, |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
108 0 |
8197 | 109 }; |
110 | |
111 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s,m) | |
112 | |
30957 | 113 static const m_option_t cfg_fields[] = { |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
114 { "prompt", ST_OFF(mp_prompt), CONF_TYPE_STRING, M_OPT_MIN, 1, 0, NULL }, |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
115 { "child-prompt", ST_OFF(child_prompt), CONF_TYPE_STRING, M_OPT_MIN, 1, 0, NULL }, |
8197 | 116 { "buffer-lines", ST_OFF(buf_lines), CONF_TYPE_INT, M_OPT_MIN, 5, 0, NULL }, |
117 { "height", ST_OFF(height), CONF_TYPE_INT, M_OPT_RANGE, 1, 100, NULL }, | |
118 { "minbor", ST_OFF(minb), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL }, | |
119 { "vspace", ST_OFF(vspace), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL }, | |
17993
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
16862
diff
changeset
|
120 { "bg", ST_OFF(bg), CONF_TYPE_INT, M_OPT_RANGE, -1, 255, NULL }, |
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
16862
diff
changeset
|
121 { "bg-alpha", ST_OFF(bg_alpha), CONF_TYPE_INT, M_OPT_RANGE, 0, 255, NULL }, |
8197 | 122 { "show-time",ST_OFF(show_time), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL }, |
123 { "hide-time",ST_OFF(hide_time), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL }, | |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
124 { "history-size",ST_OFF(history_max), CONF_TYPE_INT, M_OPT_MIN, 1, 0, NULL }, |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
125 { "raw-child", ST_OFF(raw_child), CONF_TYPE_FLAG, 0, 0, 1, NULL }, |
8197 | 126 { NULL, NULL, NULL, 0,0,0,NULL } |
127 }; | |
128 | |
129 #define mpriv (menu->priv) | |
130 | |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
131 static void check_child(menu_t* menu); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
132 |
8197 | 133 static void add_line(struct menu_priv_s* priv, char* l) { |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
134 char* eol = strchr(l,'\n'); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
135 |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
136 if(eol) { |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
137 if(eol != l) { |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
138 eol[0] = '\0'; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
139 add_line(priv,l); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
140 } |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
141 if(eol[1]) add_line(priv,eol+1); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
142 return; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
143 } |
8197 | 144 |
32537
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
32466
diff
changeset
|
145 if(priv->num_lines >= priv->buf_lines) |
8197 | 146 free(priv->lines[priv->last_line]); |
147 else | |
148 priv->num_lines++; | |
149 | |
150 priv->lines[priv->last_line] = strdup(l); | |
151 priv->last_line = (priv->last_line + 1) % priv->buf_lines; | |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
152 priv->add_line = 1; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
153 } |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
154 |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
155 static void add_string(struct menu_priv_s* priv, char* l) { |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
156 char* eol = strchr(l,'\n'); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
157 int ll = priv->last_line > 0 ? priv->last_line - 1 : priv->buf_lines-1; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
158 |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
159 if(priv->num_lines <= 0 || priv->add_line || eol == l) { |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
160 add_line(priv,l); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
161 priv->add_line = 0; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
162 return; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
163 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
164 |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
165 if(eol) { |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
166 eol[0] = '\0'; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
167 add_string(priv,l); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
168 if(eol[1]) { |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
169 add_line(priv,eol+1); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
170 priv->add_line = 0; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
171 } else |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
172 priv->add_line = 1; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
173 return; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
174 } |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
175 priv->lines[ll] = realloc(priv->lines[ll],strlen(priv->lines[ll]) + strlen(l) + 1); |
12646 | 176 if ( priv->lines[ll] != NULL ) |
177 { | |
178 strcat(priv->lines[ll],l); | |
179 } | |
8197 | 180 } |
181 | |
182 static void draw(menu_t* menu, mp_image_t* mpi) { | |
183 int h = mpi->h*mpriv->height/100; | |
184 int w = mpi->w - 2* mpriv->minb; | |
185 int x = mpriv->minb, y; | |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
186 int lw,lh,i, ll; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
187 |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
188 if(mpriv->child) check_child(menu); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
189 |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
190 ll = mpriv->last_line - 1; |
8197 | 191 |
192 if(mpriv->hide_ts) { | |
193 unsigned int t = GetTimerMS() - mpriv->hide_ts; | |
194 if(t >= mpriv->hide_time) { | |
195 mpriv->hide_ts = 0; | |
196 menu->show = 0; | |
197 return; | |
198 } | |
199 h = mpi->h*(mpriv->height - (mpriv->height * t /mpriv->hide_time))/100; | |
200 } else if(mpriv->show_time && mpriv->show_ts == 0) { | |
201 mpriv->show_ts = GetTimerMS(); | |
202 return; | |
203 } else if(mpriv->show_ts > 0) { | |
204 unsigned int t = GetTimerMS() - mpriv->show_ts; | |
205 if(t > mpriv->show_time) | |
206 mpriv->show_ts = -1; | |
207 else | |
208 h = mpi->h*(mpriv->height * t /mpriv->hide_time)/100; | |
209 } | |
210 | |
211 y = h - mpriv->vspace; | |
212 | |
213 if(x < 0 || y < 0 || w <= 0 || h <= 0 ) | |
214 return; | |
215 | |
17993
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
16862
diff
changeset
|
216 if(mpriv->bg >= 0) |
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
16862
diff
changeset
|
217 menu_draw_box(mpi,mpriv->bg,mpriv->bg_alpha,0,0,mpi->w,h); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
218 |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
219 if(!mpriv->child || !mpriv->raw_child){ |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
220 char input[strlen(mpriv->cur_history->buffer) + strlen(mpriv->prompt) + 1]; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
221 sprintf(input,"%s%s",mpriv->prompt,mpriv->cur_history->buffer); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
222 menu_text_size(input,w,mpriv->vspace,1,&lw,&lh); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
223 menu_draw_text_full(mpi,input,x,y,w,h,mpriv->vspace,1, |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
224 MENU_TEXT_BOT|MENU_TEXT_LEFT, |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
225 MENU_TEXT_BOT|MENU_TEXT_LEFT); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
226 y -= lh + mpriv->vspace; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
227 } |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
228 |
8197 | 229 |
230 for( i = 0 ; y > mpriv->minb && i < mpriv->num_lines ; i++){ | |
231 int c = (ll - i) >= 0 ? ll - i : mpriv->buf_lines + ll - i; | |
232 menu_text_size(mpriv->lines[c],w,mpriv->vspace,1,&lw,&lh); | |
233 menu_draw_text_full(mpi,mpriv->lines[c],x,y,w,h,mpriv->vspace,1, | |
234 MENU_TEXT_BOT|MENU_TEXT_LEFT, | |
235 MENU_TEXT_BOT|MENU_TEXT_LEFT); | |
236 y -= lh + mpriv->vspace; | |
237 } | |
238 return; | |
239 } | |
240 | |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
241 static void check_child(menu_t* menu) { |
10864
a2537e7d2d76
make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents:
10333
diff
changeset
|
242 #ifndef __MINGW32__ |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
243 fd_set rfd; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
244 struct timeval tv; |
8297 | 245 int max_fd = mpriv->child_fd[2] > mpriv->child_fd[1] ? mpriv->child_fd[2] : |
246 mpriv->child_fd[1]; | |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
247 int i,r,child_status,w; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
248 char buffer[256]; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
249 |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
250 if(!mpriv->child) return; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
251 |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
252 memset(&tv,0,sizeof(struct timeval)); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
253 FD_ZERO(&rfd); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
254 FD_SET(mpriv->child_fd[1],&rfd); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
255 FD_SET(mpriv->child_fd[2],&rfd); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
256 |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
257 r = select(max_fd+1,&rfd, NULL, NULL, &tv); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
258 if(r == 0) { |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
259 r = waitpid(mpriv->child,&child_status,WNOHANG); |
13391 | 260 if(r < 0){ |
23871 | 261 if(errno==ECHILD){ ///exiting children get handled in mplayer.c |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
262 for(i = 0 ; i < 3 ; i++) |
13391 | 263 close(mpriv->child_fd[i]); |
264 mpriv->child = 0; | |
265 mpriv->prompt = mpriv->mp_prompt; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
266 //add_line(mpriv,"Child process exited"); |
13391 | 267 } |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
268 else mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_WaitPidError,strerror(errno)); |
13391 | 269 } |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
270 } else if(r < 0) { |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
271 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_SelectError); |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
272 return; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
273 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
274 |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
275 w = 0; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
276 for(i = 1 ; i < 3 ; i++) { |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
277 if(FD_ISSET(mpriv->child_fd[i],&rfd)){ |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
278 if(w) mpriv->add_line = 1; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
279 r = read(mpriv->child_fd[i],buffer,255); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
280 if(r < 0) |
23874 | 281 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_ReadErrorOnChildFD, i == 1 ? "stdout":"stderr"); |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
282 else if(r>0) { |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
283 buffer[r] = '\0'; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
284 add_string(mpriv,buffer); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
285 } |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
286 w = 1; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
287 } |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
288 } |
10864
a2537e7d2d76
make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents:
10333
diff
changeset
|
289 #endif |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
290 |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
291 } |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
292 |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
293 #define close_pipe(pipe) close(pipe[0]); close(pipe[1]) |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
294 |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
295 static int run_shell_cmd(menu_t* menu, char* cmd) { |
10864
a2537e7d2d76
make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents:
10333
diff
changeset
|
296 #ifndef __MINGW32__ |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
297 int in[2],out[2],err[2]; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
298 |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
299 mp_msg(MSGT_GLOBAL,MSGL_INFO,MSGTR_LIBMENU_ConsoleRun,cmd); |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
300 if(mpriv->child) { |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
301 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_AChildIsAlreadyRunning); |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
302 return 0; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
303 } |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
304 |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
305 pipe(in); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
306 pipe(out); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
307 pipe(err); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
308 |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
309 mpriv->child = fork(); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
310 if(mpriv->child < 0) { |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
311 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_ForkFailed); |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
312 close_pipe(in); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
313 close_pipe(out); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
314 close_pipe(err); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
315 return 0; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
316 } |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
317 if(!mpriv->child) { // Chlid process |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
318 int err_fd = dup(2); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
319 FILE* errf = fdopen(err_fd,"w"); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
320 // Bind the std fd to our pipes |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
321 dup2(in[0],0); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
322 dup2(out[1],1); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
323 dup2(err[1],2); |
10333 | 324 execl("/bin/sh","sh","-c",cmd,(void*)NULL); |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
325 fprintf(errf,"exec failed : %s\n",strerror(errno)); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
326 exit(1); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
327 } |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
328 // MPlayer |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
329 mpriv->child_fd[0] = in[1]; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
330 mpriv->child_fd[1] = out[0]; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
331 mpriv->child_fd[2] = err[0]; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
332 mpriv->prompt = mpriv->child_prompt; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
333 //add_line(mpriv,"Child process started"); |
10864
a2537e7d2d76
make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents:
10333
diff
changeset
|
334 #endif |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
335 return 1; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
336 } |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
337 |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
338 static void enter_cmd(menu_t* menu) { |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
339 history_t* h; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
340 char input[strlen(mpriv->cur_history->buffer) + strlen(mpriv->prompt) + 1]; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
341 |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
342 sprintf(input,"%s%s",mpriv->prompt,mpriv->cur_history->buffer); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
343 add_line(mpriv,input); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
344 |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
345 if(mpriv->history == mpriv->cur_history) { |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
346 if(mpriv->history_size >= mpriv->history_max) { |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
347 history_t* i; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
348 for(i = mpriv->history ; i->prev ; i = i->prev) |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
349 /**/; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
350 i->next->prev = NULL; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
351 free(i->buffer); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
352 free(i); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
353 } else |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
354 mpriv->history_size++; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
355 h = calloc(1,sizeof(history_t)); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
356 h->size = 255; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
357 h->buffer = calloc(h->size,1); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
358 h->prev = mpriv->history; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
359 mpriv->history->next = h; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
360 mpriv->history = h; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
361 } else |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
362 mpriv->history->buffer[0] = '\0'; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
363 |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
364 mpriv->cur_history = mpriv->history; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
365 //mpriv->input = mpriv->cur_history->buffer; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
366 } |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
367 |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23874
diff
changeset
|
368 static void read_cmd(menu_t* menu,int cmd) { |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23874
diff
changeset
|
369 switch(cmd) { |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23874
diff
changeset
|
370 case MENU_CMD_CANCEL: |
8197 | 371 if(mpriv->hide_time) |
372 mpriv->hide_ts = GetTimerMS(); | |
373 else | |
374 menu->show = 0; | |
375 mpriv->show_ts = 0; | |
376 return; | |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23874
diff
changeset
|
377 case MENU_CMD_OK: { |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
378 mp_cmd_t* c; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
379 if(mpriv->child) { |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
380 char *str = mpriv->cur_history->buffer; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
381 int l = strlen(str); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
382 while(l > 0) { |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
383 int w = write(mpriv->child_fd[0],str,l); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
384 if(w < 0) { |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
385 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_WriteError); |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
386 break; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
387 } |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
388 l -= w; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
389 str += w; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
390 } |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
391 if(write(mpriv->child_fd[0],"\n",1) < 0) |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
392 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_WriteError); |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
393 enter_cmd(menu); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
394 return; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
395 } |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
396 c = mp_input_parse_cmd(mpriv->cur_history->buffer); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
397 enter_cmd(menu); |
8197 | 398 if(!c) |
399 add_line(mpriv,"Invalid command try help"); | |
400 else { | |
401 switch(c->id) { | |
402 case MP_CMD_CHELP: | |
12874 | 403 add_line(mpriv,"MPlayer console 0.01"); |
404 add_line(mpriv,"TODO: meaningful help message ;)"); | |
405 add_line(mpriv,"Enter any slave command"); | |
8197 | 406 add_line(mpriv,"exit close this console"); |
407 break; | |
408 case MP_CMD_CEXIT: | |
409 menu->show = 0; | |
410 menu->cl = 1; | |
411 break; | |
412 case MP_CMD_CHIDE: | |
413 if(mpriv->hide_time) | |
414 mpriv->hide_ts = GetTimerMS(); | |
415 else | |
416 menu->show = 0; | |
417 mpriv->show_ts = 0; | |
418 break; | |
14087 | 419 case MP_CMD_RUN: |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
420 run_shell_cmd(menu,c->args[0].v.s); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
421 break; |
8197 | 422 default: // Send the other commands to mplayer |
423 mp_input_queue_cmd(c); | |
35305 | 424 c = NULL; |
8197 | 425 } |
35305 | 426 if (c) mp_cmd_free(c); |
8197 | 427 } |
428 return; | |
429 } | |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23874
diff
changeset
|
430 case MENU_CMD_UP: |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23874
diff
changeset
|
431 if(mpriv->cur_history->prev) |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23874
diff
changeset
|
432 mpriv->cur_history = mpriv->cur_history->prev; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23874
diff
changeset
|
433 break; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23874
diff
changeset
|
434 case MENU_CMD_DOWN: |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23874
diff
changeset
|
435 if(mpriv->cur_history->next) |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23874
diff
changeset
|
436 mpriv->cur_history = mpriv->cur_history->next; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23874
diff
changeset
|
437 break; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23874
diff
changeset
|
438 } |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23874
diff
changeset
|
439 } |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23874
diff
changeset
|
440 |
25502
605d4e3e403f
From now on, libmenu does not steal all input keys from input modules.
ulion
parents:
25263
diff
changeset
|
441 static int read_key(menu_t* menu,int c) { |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23874
diff
changeset
|
442 if(mpriv->child && mpriv->raw_child) { |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23874
diff
changeset
|
443 write(mpriv->child_fd[0],&c,sizeof(int)); |
25502
605d4e3e403f
From now on, libmenu does not steal all input keys from input modules.
ulion
parents:
25263
diff
changeset
|
444 return 1; |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23874
diff
changeset
|
445 } |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23874
diff
changeset
|
446 |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23874
diff
changeset
|
447 if (c == KEY_DELETE || c == KEY_BS) { |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
448 unsigned int i = strlen(mpriv->cur_history->buffer); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
449 if(i > 0) |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
450 mpriv->cur_history->buffer[i-1] = '\0'; |
25502
605d4e3e403f
From now on, libmenu does not steal all input keys from input modules.
ulion
parents:
25263
diff
changeset
|
451 return 1; |
8197 | 452 } |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23874
diff
changeset
|
453 if (menu_dflt_read_key(menu, c)) |
25502
605d4e3e403f
From now on, libmenu does not steal all input keys from input modules.
ulion
parents:
25263
diff
changeset
|
454 return 1; |
8197 | 455 |
456 if(isascii(c)) { | |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
457 int l = strlen(mpriv->cur_history->buffer); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
458 if(l >= mpriv->cur_history->size) { |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
459 mpriv->cur_history->size += 255; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
460 mpriv->cur_history->buffer = realloc(mpriv->cur_history,mpriv->cur_history->size); |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
461 } |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
462 mpriv->cur_history->buffer[l] = (char)c; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
463 mpriv->cur_history->buffer[l+1] = '\0'; |
25502
605d4e3e403f
From now on, libmenu does not steal all input keys from input modules.
ulion
parents:
25263
diff
changeset
|
464 return 1; |
8197 | 465 } |
25502
605d4e3e403f
From now on, libmenu does not steal all input keys from input modules.
ulion
parents:
25263
diff
changeset
|
466 return 0; |
8197 | 467 } |
468 | |
469 | |
10864
a2537e7d2d76
make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents:
10333
diff
changeset
|
470 static int openMenu(menu_t* menu, char* args) { |
8197 | 471 |
472 | |
473 menu->draw = draw; | |
474 menu->read_cmd = read_cmd; | |
475 menu->read_key = read_key; | |
476 | |
477 mpriv->lines = calloc(mpriv->buf_lines,sizeof(char*)); | |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
478 mpriv->prompt = mpriv->mp_prompt; |
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
479 mpriv->cur_history = mpriv->history = calloc(1,sizeof(history_t)); |
18858 | 480 mpriv->cur_history->buffer = calloc(255,1); |
8227
3050cfda3c61
A new command to run shell process and a command history.
albeu
parents:
8197
diff
changeset
|
481 mpriv->cur_history->size = 255; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
482 |
8197 | 483 if(args) |
484 add_line(mpriv,args); | |
485 | |
486 return 1; | |
487 } | |
488 | |
489 const menu_info_t menu_info_console = { | |
490 "MPlayer console", | |
491 "console", | |
492 "Albeu", | |
493 "", | |
494 { | |
495 "console_cfg", | |
496 sizeof(struct menu_priv_s), | |
497 &cfg_dflt, | |
498 cfg_fields | |
499 }, | |
10864
a2537e7d2d76
make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents:
10333
diff
changeset
|
500 openMenu, |
8197 | 501 }; |