21 |
#include <pupa/misc.h> |
#include <pupa/misc.h> |
22 |
#include <pupa/mm.h> |
#include <pupa/mm.h> |
23 |
#include <pupa/err.h> |
#include <pupa/err.h> |
24 |
|
#include <pupa/term.h> |
25 |
|
|
26 |
static pupa_command_t pupa_command_list; |
static pupa_command_t pupa_command_list; |
27 |
|
|
165 |
return 0; |
return 0; |
166 |
} |
} |
167 |
|
|
168 |
|
static int |
169 |
|
terminal_command (int argc, char *argv[]) |
170 |
|
{ |
171 |
|
pupa_term_t term = 0; |
172 |
|
|
173 |
|
auto int print_terminal (pupa_term_t); |
174 |
|
auto int find_terminal (pupa_term_t); |
175 |
|
|
176 |
|
int print_terminal (pupa_term_t t) |
177 |
|
{ |
178 |
|
pupa_printf (" %s", t->name); |
179 |
|
return 0; |
180 |
|
} |
181 |
|
|
182 |
|
int find_terminal (pupa_term_t t) |
183 |
|
{ |
184 |
|
if (pupa_strcmp (t->name, argv[0]) == 0) |
185 |
|
{ |
186 |
|
term = t; |
187 |
|
return 1; |
188 |
|
} |
189 |
|
|
190 |
|
return 0; |
191 |
|
} |
192 |
|
|
193 |
|
if (argc == 0) |
194 |
|
{ |
195 |
|
pupa_printf ("Available terminal(s):"); |
196 |
|
pupa_term_iterate (print_terminal); |
197 |
|
pupa_putchar ('\n'); |
198 |
|
|
199 |
|
pupa_printf ("Current terminal: %s\n", pupa_term_get_current ()->name); |
200 |
|
} |
201 |
|
else |
202 |
|
{ |
203 |
|
pupa_term_iterate (find_terminal); |
204 |
|
if (! term) |
205 |
|
return pupa_error (PUPA_ERR_BAD_ARGUMENT, "no such terminal"); |
206 |
|
|
207 |
|
pupa_term_set_current (term); |
208 |
|
} |
209 |
|
|
210 |
|
return PUPA_ERR_NONE; |
211 |
|
} |
212 |
|
|
213 |
void |
void |
214 |
pupa_command_init (void) |
pupa_command_init (void) |
215 |
{ |
{ |
219 |
pupa_register_command ("rescue", rescue_command, PUPA_COMMAND_FLAG_BOTH, |
pupa_register_command ("rescue", rescue_command, PUPA_COMMAND_FLAG_BOTH, |
220 |
"rescue", |
"rescue", |
221 |
"Enter into the rescue mode."); |
"Enter into the rescue mode."); |
222 |
|
pupa_register_command ("terminal", terminal_command, PUPA_COMMAND_FLAG_BOTH, |
223 |
|
"terminal [TERM...]", |
224 |
|
"Select a terminal."); |
225 |
} |
} |