annotate libmenu/menu_console.c @ 16862:931bdbc37ee0

Unify include paths, -I.. is in CFLAGS.
author diego
date Wed, 26 Oct 2005 00:07:43 +0000
parents 26937d8c5c9e
children 98eb966a4024
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
1
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 14087
diff changeset
2 #include "config.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
3
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
4 #include <stdlib.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
5 #include <stdio.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
6 #include <string.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
7 #include <ctype.h>
8229
rfelker
parents: 8227
diff changeset
8 #include <sys/time.h>
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
9 #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
10 #ifndef __MINGW32__
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
11 #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
12 #endif
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
13 #include <unistd.h>
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
14 #include <errno.h>
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
15
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
16 #include "img_format.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
17 #include "mp_image.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
18
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 14087
diff changeset
19 #include "m_struct.h"
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 14087
diff changeset
20 #include "m_option.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
21 #include "menu.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
22
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 14087
diff changeset
23 #include "libvo/font_load.h"
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 14087
diff changeset
24 #include "osdep/keycodes.h"
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 14087
diff changeset
25 #include "input/input.h"
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 14087
diff changeset
26 #include "osdep/timer.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
27
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
28 typedef struct history_st history_t;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
29
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
30 struct history_st {
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
31 char* buffer;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
32 int size;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
33 history_t* next;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
34 history_t* prev;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
35 };
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
36
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
37 struct menu_priv_s {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
38 char** lines; // Our buffer
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
39 int last_line;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
40 int num_lines;
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
41 int add_line;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
42 unsigned int hide_ts;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
43 unsigned int show_ts;
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
44 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
45 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
46 char* prompt;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
47 //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
48 history_t* history;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
49 history_t* cur_history;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
50 int history_size;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
51
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
52 char* mp_prompt;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
53 char* child_prompt;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
54 int buf_lines; // Buffer size (in line)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
55 int height; // Display size in %
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
56 int minb;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
57 int vspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
58 unsigned int hide_time;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
59 unsigned int show_time;
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
60 int history_max;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
61 int raw_child;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
62 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
63
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
64 static struct menu_priv_s cfg_dflt = {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
65 NULL,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
66 0,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
67 0,
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
68 1,
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
69 0,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
70 0,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
71 0,
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
72 { 0 , 0, 0 },
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
73 NULL,
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
74 NULL,
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
75 NULL,
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
76 0,
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
77
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
78 "# ",
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
79 "$ ",
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
80 50, // lines
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
81 33, // %
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
82 3,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
83 3,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
84 500,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
85 500,
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
86 10,
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
87 0
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
88 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
89
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
90 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s,m)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
91
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
92 static m_option_t cfg_fields[] = {
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
93 { "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
94 { "child-prompt", ST_OFF(child_prompt), CONF_TYPE_STRING, M_OPT_MIN, 1, 0, NULL },
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
95 { "buffer-lines", ST_OFF(buf_lines), CONF_TYPE_INT, M_OPT_MIN, 5, 0, NULL },
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
96 { "height", ST_OFF(height), CONF_TYPE_INT, M_OPT_RANGE, 1, 100, NULL },
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
97 { "minbor", ST_OFF(minb), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL },
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
98 { "vspace", ST_OFF(vspace), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL },
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
99 { "show-time",ST_OFF(show_time), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL },
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
100 { "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
101 { "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
102 { "raw-child", ST_OFF(raw_child), CONF_TYPE_FLAG, 0, 0, 1, NULL },
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
103 { NULL, NULL, NULL, 0,0,0,NULL }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
104 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
105
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
106 #define mpriv (menu->priv)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
107
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
108 static void check_child(menu_t* menu);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
109
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
110 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
111 char* eol = strchr(l,'\n');
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
112
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
113 if(eol) {
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
114 if(eol != l) {
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
115 eol[0] = '\0';
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
116 add_line(priv,l);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
117 }
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
118 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
119 return;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
120 }
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
121
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
122 if(priv->num_lines >= priv->buf_lines && priv->lines[priv->last_line])
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
123 free(priv->lines[priv->last_line]);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
124 else
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
125 priv->num_lines++;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
126
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
127 priv->lines[priv->last_line] = strdup(l);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
128 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
129 priv->add_line = 1;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
130 }
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
131
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
132 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
133 char* eol = strchr(l,'\n');
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
134 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
135
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
136 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
137 add_line(priv,l);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
138 priv->add_line = 0;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
139 return;
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
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
142 if(eol) {
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
143 eol[0] = '\0';
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
144 add_string(priv,l);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
145 if(eol[1]) {
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
146 add_line(priv,eol+1);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
147 priv->add_line = 0;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
148 } else
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
149 priv->add_line = 1;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
150 return;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
151 }
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
152 priv->lines[ll] = realloc(priv->lines[ll],strlen(priv->lines[ll]) + strlen(l) + 1);
12646
9a495bdc3a1e string handling security fixes
diego
parents: 10864
diff changeset
153 if ( priv->lines[ll] != NULL )
9a495bdc3a1e string handling security fixes
diego
parents: 10864
diff changeset
154 {
9a495bdc3a1e string handling security fixes
diego
parents: 10864
diff changeset
155 strcat(priv->lines[ll],l);
9a495bdc3a1e string handling security fixes
diego
parents: 10864
diff changeset
156 }
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
157 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
158
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
159 static void draw(menu_t* menu, mp_image_t* mpi) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
160 int h = mpi->h*mpriv->height/100;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
161 int w = mpi->w - 2* mpriv->minb;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
162 int x = mpriv->minb, y;
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
163 int lw,lh,i, ll;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
164
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
165 if(mpriv->child) check_child(menu);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
166
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
167 ll = mpriv->last_line - 1;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
168
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
169 if(mpriv->hide_ts) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
170 unsigned int t = GetTimerMS() - mpriv->hide_ts;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
171 if(t >= mpriv->hide_time) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
172 mpriv->hide_ts = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
173 menu->show = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
174 return;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
175 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
176 h = mpi->h*(mpriv->height - (mpriv->height * t /mpriv->hide_time))/100;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
177 } else if(mpriv->show_time && mpriv->show_ts == 0) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
178 mpriv->show_ts = GetTimerMS();
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
179 return;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
180 } else if(mpriv->show_ts > 0) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
181 unsigned int t = GetTimerMS() - mpriv->show_ts;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
182 if(t > mpriv->show_time)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
183 mpriv->show_ts = -1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
184 else
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
185 h = mpi->h*(mpriv->height * t /mpriv->hide_time)/100;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
186 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
187
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
188 y = h - mpriv->vspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
189
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
190 if(x < 0 || y < 0 || w <= 0 || h <= 0 )
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
191 return;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
192
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
193 if(!mpriv->child || !mpriv->raw_child){
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
194 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
195 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
196 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
197 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
198 MENU_TEXT_BOT|MENU_TEXT_LEFT,
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
199 MENU_TEXT_BOT|MENU_TEXT_LEFT);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
200 y -= lh + mpriv->vspace;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
201 }
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
202
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
203
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
204 for( i = 0 ; y > mpriv->minb && i < mpriv->num_lines ; i++){
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
205 int c = (ll - i) >= 0 ? ll - i : mpriv->buf_lines + ll - i;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
206 menu_text_size(mpriv->lines[c],w,mpriv->vspace,1,&lw,&lh);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
207 menu_draw_text_full(mpi,mpriv->lines[c],x,y,w,h,mpriv->vspace,1,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
208 MENU_TEXT_BOT|MENU_TEXT_LEFT,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
209 MENU_TEXT_BOT|MENU_TEXT_LEFT);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
210 y -= lh + mpriv->vspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
211 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
212 return;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
213 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
214
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
215 static void read_cmd(menu_t* menu,int cmd) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
216 switch(cmd) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
217 case MENU_CMD_UP:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
218 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
219 case MENU_CMD_DOWN:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
220 case MENU_CMD_OK:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
221 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
222 case MENU_CMD_CANCEL:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
223 menu->show = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
224 menu->cl = 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
225 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
226 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
227 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
228
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
229 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
230 #ifndef __MINGW32__
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
231 fd_set rfd;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
232 struct timeval tv;
8297
879f88c3212e fix 100l typo :)
colin
parents: 8229
diff changeset
233 int max_fd = mpriv->child_fd[2] > mpriv->child_fd[1] ? mpriv->child_fd[2] :
879f88c3212e fix 100l typo :)
colin
parents: 8229
diff changeset
234 mpriv->child_fd[1];
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
235 int i,r,child_status,w;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
236 char buffer[256];
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
237
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
238 if(!mpriv->child) return;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
239
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
240 memset(&tv,0,sizeof(struct timeval));
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
241 FD_ZERO(&rfd);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
242 FD_SET(mpriv->child_fd[1],&rfd);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
243 FD_SET(mpriv->child_fd[2],&rfd);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
244
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
245 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
246 if(r == 0) {
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
247 r = waitpid(mpriv->child,&child_status,WNOHANG);
13391
b6c3752d9544 handle sigchld in mplayer.c
faust3
parents: 12874
diff changeset
248 if(r < 0){
b6c3752d9544 handle sigchld in mplayer.c
faust3
parents: 12874
diff changeset
249 if(errno==ECHILD){ ///exiting childs get handled in mplayer.c
b6c3752d9544 handle sigchld in mplayer.c
faust3
parents: 12874
diff changeset
250 for(i = 0 ; i < 3 ; i++)
b6c3752d9544 handle sigchld in mplayer.c
faust3
parents: 12874
diff changeset
251 close(mpriv->child_fd[i]);
b6c3752d9544 handle sigchld in mplayer.c
faust3
parents: 12874
diff changeset
252 mpriv->child = 0;
b6c3752d9544 handle sigchld in mplayer.c
faust3
parents: 12874
diff changeset
253 mpriv->prompt = mpriv->mp_prompt;
b6c3752d9544 handle sigchld in mplayer.c
faust3
parents: 12874
diff changeset
254 //add_line(mpriv,"Child process exited");
b6c3752d9544 handle sigchld in mplayer.c
faust3
parents: 12874
diff changeset
255 }
b6c3752d9544 handle sigchld in mplayer.c
faust3
parents: 12874
diff changeset
256 else printf("waitpid error: %s\n",strerror(errno));
b6c3752d9544 handle sigchld in mplayer.c
faust3
parents: 12874
diff changeset
257 }
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
258 } else if(r < 0) {
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
259 printf("select error\n");
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
260 return;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
261 }
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
262
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
263 w = 0;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
264 for(i = 1 ; i < 3 ; i++) {
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
265 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
266 if(w) mpriv->add_line = 1;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
267 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
268 if(r < 0)
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
269 printf("Read error on child's %s \n", i == 1 ? "stdout":"stderr");
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
270 else if(r>0) {
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
271 buffer[r] = '\0';
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
272 add_string(mpriv,buffer);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
273 }
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
274 w = 1;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
275 }
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
276 }
10864
a2537e7d2d76 make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents: 10333
diff changeset
277 #endif
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
278
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
279 }
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
280
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
281 #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
282
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
283 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
284 #ifndef __MINGW32__
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
285 int in[2],out[2],err[2];
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
286
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
287 printf("Console run %s ...\n",cmd);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
288 if(mpriv->child) {
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
289 printf("A child is alredy running\n");
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
290 return 0;
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 pipe(in);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
294 pipe(out);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
295 pipe(err);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
296
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
297 mpriv->child = fork();
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
298 if(mpriv->child < 0) {
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
299 printf("Fork failed !!!\n");
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
300 close_pipe(in);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
301 close_pipe(out);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
302 close_pipe(err);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
303 return 0;
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 if(!mpriv->child) { // Chlid process
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
306 int err_fd = dup(2);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
307 FILE* errf = fdopen(err_fd,"w");
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
308 // Bind the std fd to our pipes
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
309 dup2(in[0],0);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
310 dup2(out[1],1);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
311 dup2(err[1],2);
10333
7b8a3f2101b6 64bit support
alex
parents: 9380
diff changeset
312 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
313 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
314 exit(1);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
315 }
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
316 // MPlayer
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
317 mpriv->child_fd[0] = in[1];
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
318 mpriv->child_fd[1] = out[0];
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
319 mpriv->child_fd[2] = err[0];
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
320 mpriv->prompt = mpriv->child_prompt;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
321 //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
322 #endif
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
323 return 1;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
324 }
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
325
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
326 static void enter_cmd(menu_t* menu) {
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
327 history_t* h;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
328 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
329
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
330 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
331 add_line(mpriv,input);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
332
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
333 if(mpriv->history == mpriv->cur_history) {
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
334 if(mpriv->history_size >= mpriv->history_max) {
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
335 history_t* i;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
336 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
337 /**/;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
338 i->next->prev = NULL;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
339 free(i->buffer);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
340 free(i);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
341 } else
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
342 mpriv->history_size++;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
343 h = calloc(1,sizeof(history_t));
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
344 h->size = 255;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
345 h->buffer = calloc(h->size,1);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
346 h->prev = mpriv->history;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
347 mpriv->history->next = h;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
348 mpriv->history = h;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
349 } else
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
350 mpriv->history->buffer[0] = '\0';
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
351
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
352 mpriv->cur_history = mpriv->history;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
353 //mpriv->input = mpriv->cur_history->buffer;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
354 }
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
355
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
356 static void read_key(menu_t* menu,int c) {
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
357 if(!mpriv->child || !mpriv->raw_child) switch(c) {
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
358 case KEY_ESC:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
359 if(mpriv->hide_time)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
360 mpriv->hide_ts = GetTimerMS();
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
361 else
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
362 menu->show = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
363 mpriv->show_ts = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
364 return;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
365 case KEY_ENTER: {
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
366 mp_cmd_t* c;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
367 if(mpriv->child) {
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
368 char *str = mpriv->cur_history->buffer;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
369 int l = strlen(str);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
370 while(l > 0) {
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
371 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
372 if(w < 0) {
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
373 printf("Write error\n");
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
374 break;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
375 }
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
376 l -= w;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
377 str += w;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
378 }
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
379 if(write(mpriv->child_fd[0],"\n",1) < 0)
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
380 printf("Write error\n");
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
381 enter_cmd(menu);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
382 return;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
383 }
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
384 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
385 enter_cmd(menu);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
386 if(!c)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
387 add_line(mpriv,"Invalid command try help");
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
388 else {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
389 switch(c->id) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
390 case MP_CMD_CHELP:
12874
4e8887e99fef Fix typos and better explanatory text.
diego
parents: 12646
diff changeset
391 add_line(mpriv,"MPlayer console 0.01");
4e8887e99fef Fix typos and better explanatory text.
diego
parents: 12646
diff changeset
392 add_line(mpriv,"TODO: meaningful help message ;)");
4e8887e99fef Fix typos and better explanatory text.
diego
parents: 12646
diff changeset
393 add_line(mpriv,"Enter any slave command");
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
394 add_line(mpriv,"exit close this console");
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
395 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
396 case MP_CMD_CEXIT:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
397 menu->show = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
398 menu->cl = 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
399 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
400 case MP_CMD_CHIDE:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
401 if(mpriv->hide_time)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
402 mpriv->hide_ts = GetTimerMS();
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
403 else
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
404 menu->show = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
405 mpriv->show_ts = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
406 break;
14087
26937d8c5c9e enable the run slave commande even without libmenu
aurel
parents: 13391
diff changeset
407 case MP_CMD_RUN:
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
408 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
409 break;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
410 default: // Send the other commands to mplayer
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
411 mp_input_queue_cmd(c);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
412 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
413 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
414 return;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
415 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
416 case KEY_DELETE:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
417 case KEY_BS: {
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
418 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
419 if(i > 0)
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
420 mpriv->cur_history->buffer[i-1] = '\0';
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
421 return;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
422 }
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
423 case KEY_UP:
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
424 if(mpriv->cur_history->prev)
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
425 mpriv->cur_history = mpriv->cur_history->prev;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
426 break;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
427 case KEY_DOWN:
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
428 if(mpriv->cur_history->next)
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
429 mpriv->cur_history = mpriv->cur_history->next;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
430 break;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
431 }
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
432
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
433 if(mpriv->child && mpriv->raw_child) {
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
434 write(mpriv->child_fd[0],&c,sizeof(int));
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
435 return;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
436 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
437
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
438 if(isascii(c)) {
8227
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
439 int l = strlen(mpriv->cur_history->buffer);
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
440 if(l >= mpriv->cur_history->size) {
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
441 mpriv->cur_history->size += 255;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
442 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
443 }
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
444 mpriv->cur_history->buffer[l] = (char)c;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
445 mpriv->cur_history->buffer[l+1] = '\0';
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
446 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
447
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
448 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
449
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
450
10864
a2537e7d2d76 make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents: 10333
diff changeset
451 static int openMenu(menu_t* menu, char* args) {
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
452
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
453
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
454 menu->draw = draw;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
455 menu->read_cmd = read_cmd;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
456 menu->read_key = read_key;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
457
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
458 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
459 mpriv->prompt = mpriv->mp_prompt;
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
460 mpriv->cur_history = mpriv->history = calloc(1,sizeof(history_t));
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
461 mpriv->cur_history->buffer = calloc(255,sizeof(char));
3050cfda3c61 A new command to run shell process and a command history.
albeu
parents: 8197
diff changeset
462 mpriv->cur_history->size = 255;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
463
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
464 if(args)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
465 add_line(mpriv,args);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
466
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
467 return 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
468 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
469
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
470 const menu_info_t menu_info_console = {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
471 "MPlayer console",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
472 "console",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
473 "Albeu",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
474 "",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
475 {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
476 "console_cfg",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
477 sizeof(struct menu_priv_s),
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
478 &cfg_dflt,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
479 cfg_fields
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
480 },
10864
a2537e7d2d76 make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents: 10333
diff changeset
481 openMenu,
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
482 };