e16-epplets/epplets/E-Exec.c

91 lines
2.0 KiB
C
Raw Normal View History

#include "epplet.h"
#define EPPLET_NAME "E-Exec"
#define EPPLET_VERSION "0.1"
#define EPPLET_INFO "Exec a command given by the user"
#define MAX_HIST_LEN 15
Epplet_gadget textbox = NULL;
char* command_history[MAX_HIST_LEN];
int current_command = 0;
int num_commands = 0;
1999-11-10 14:46:14 -08:00
static void cb_close(void *data);
static void run_contents(void *data);
static void
cb_close(void *data)
{
Epplet_cleanup();
exit(0);
1999-11-10 14:46:14 -08:00
data = NULL;
}
1999-11-10 14:46:14 -08:00
static void
run_contents(void *data)
{
char *command = Epplet_textbox_contents(textbox);
int i;
if(num_commands < MAX_HIST_LEN)
command_history[num_commands++] = strdup(command);
else
{
free(command_history[0]);
for(i=0; i < MAX_HIST_LEN; i++)
command_history[i] = command_history[i+1];
command_history[MAX_HIST_LEN] = strdup(command);
}
Epplet_spawn_command(command);
Epplet_reset_textbox(textbox);
1999-11-10 14:46:14 -08:00
return;
data = NULL;
}
static void
hist_last(void *data)
{
//if(current_command >= 0)
//Epplet_change_textbox(textbox, command_history[--current_command]);
}
static void
hist_next(void *data)
{
//if(current_command < num_commands)
//Epplet_change_textbox(textbox, command_history[++current_command]);
}
int
main(int argc, char *argv[])
{
atexit(Epplet_cleanup);
Epplet_Init(EPPLET_NAME, EPPLET_VERSION, EPPLET_INFO, 5, 2, argc, argv, 0);
Epplet_gadget_show(Epplet_create_button(NULL, NULL, 2, 2,
12, 12, "CLOSE", 0, NULL, cb_close, NULL));
Epplet_gadget_show(Epplet_create_button(NULL, NULL, 16, 2,
12, 12, "ARROW_UP", 0, NULL, hist_last, NULL));
Epplet_gadget_show(Epplet_create_button(NULL, NULL, 30, 2,
12, 12, "ARROW_DOWN", 0, NULL, hist_next, NULL));
Epplet_gadget_show(Epplet_create_button(NULL, NULL, 44, 2,
12, 12, "PLAY", 0, NULL, run_contents, NULL));
textbox =
Epplet_create_textbox(NULL, NULL, 2, 15, 76, 16, 1, run_contents, NULL);
Epplet_gadget_show(textbox);
Epplet_show();
Epplet_Loop();
return 0;
}