summaryrefslogtreecommitdiff
path: root/src/interface.c
diff options
context:
space:
mode:
authorSimon <simon@hardwired.org.uk>2011-01-30 21:38:24 (GMT)
committer Simon <simon@hardwired.org.uk>2011-01-30 21:38:24 (GMT)
commitbcbcb0063b1f3451b4e329b69d275bcabadc788a (patch)
tree1e4f749db875ec2e476dd1f018b408822c33415b /src/interface.c
parentc6db32f829339fe36bfb1059eb2154285b0fd9ee (diff)
downloadpowder-bcbcb0063b1f3451b4e329b69d275bcabadc788a.zip
powder-bcbcb0063b1f3451b4e329b69d275bcabadc788a.tar.gz
Command buffer, limit is 9, I think
Diffstat (limited to 'src/interface.c')
-rw-r--r--src/interface.c66
1 files changed, 65 insertions, 1 deletions
diff --git a/src/interface.c b/src/interface.c
index e83adcb..0d963e0 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -3809,8 +3809,15 @@ void open_link(char *uri) {
printf("Cannot open browser\n");
#endif
}
+struct command_history {
+ void *prev_command;
+ char *command;
+};
+typedef struct command_history command_history;
+command_history *last_command = NULL;
char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show previous commands
- int mx,my,b,bq;
+ int mx,my,b,bq,cc,ci = -1;
+ command_history *currentcommand;
ui_edit ed;
ed.x = 15;
ed.y = 210;
@@ -3840,6 +3847,30 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show
"Reset works with pressure, velocity, sparks, temp (ex. 'reset pressure')\n"
"To load a save use load saveID (ex. load 1337)"
,255, 187, 187, 255);
+
+ cc = 0;
+ currentcommand = last_command;
+ while(cc < 10)
+ {
+ if(currentcommand==NULL)
+ break;
+ drawtext(vid_buf, 15, 175-(cc*12), currentcommand->command, 255, 255, 255, 255);
+ if(currentcommand->prev_command!=NULL)
+ {
+ if(cc<9) {
+ currentcommand = currentcommand->prev_command;
+ } else if(currentcommand->prev_command!=NULL){
+ free(currentcommand->prev_command);
+ currentcommand->prev_command = NULL;
+ }
+ cc++;
+ }
+ else
+ {
+ break;
+ }
+ }
+
if(error)
drawtext(vid_buf, 15, 190, error,255, 187, 187, 255);
ui_edit_draw(vid_buf, &ed);
@@ -3847,6 +3878,11 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show
sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
if (sdl_key==SDLK_RETURN)
{
+ currentcommand = malloc(sizeof(command_history));
+ memset(currentcommand, 0, sizeof(command_history));
+ currentcommand->prev_command = last_command;
+ currentcommand->command = mystrdup(ed.str);
+ last_command = currentcommand;
return ed.str;
}
if (sdl_key==SDLK_ESCAPE || sdl_key==SDLK_BACKQUOTE)
@@ -3854,6 +3890,34 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show
console_mode = 0;
return NULL;
}
+ if(sdl_key==SDLK_UP || sdl_key==SDLK_DOWN)
+ {
+ ci += sdl_key==SDLK_UP?1:-1;
+ if(ci<-1)
+ ci = -1;
+ if(ci==-1)
+ {
+ strcpy(ed.str, "");
+ }
+ else
+ {
+ if(last_command!=NULL){
+ currentcommand = last_command;
+ for (cc = 0; cc<ci; cc++) {
+ if(currentcommand->prev_command==NULL)
+ ci = cc;
+ else
+ currentcommand = currentcommand->prev_command;
+ }
+ strcpy(ed.str, currentcommand->command);
+ }
+ else
+ {
+ ci = -1;
+ strcpy(ed.str, "");
+ }
+ }
+ }
}