Changeset 4027 for neercs/trunk
- Timestamp:
- Nov 23, 2009, 5:39:33 PM (13 years ago)
- Location:
- neercs/trunk/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
neercs/trunk/src/input.c
r4026 r4027 182 182 case 'e': 183 183 screen_list->python_command = 1; 184 screen_list->command_props.x = 0; 185 screen_list->command_props.y = 0; 184 186 break; 185 187 #endif -
neercs/trunk/src/neercs.h
r4026 r4027 144 144 }; 145 145 146 struct command_props 147 { 148 int x, y; 149 int size; 150 char *command; 151 }; 152 146 153 struct screen_list 147 154 { … … 185 192 struct cube_props cube; /* Cube */ 186 193 long long unsigned int last_switch; /* Cube */ 194 struct command_props command_props; 187 195 188 196 /* ScreenSaver stuff */ … … 309 317 int help_handle_key(struct screen_list *screen_list, unsigned int c); 310 318 #ifdef USE_PYTHON 311 int python_command_handle_key(struct screen_list *screen_list, unsigned int c);319 int python_command_handle_key(struct screen_list *screen_list, unsigned int c); 312 320 void draw_python_command(struct screen_list *screen_list); 313 321 #endif -
neercs/trunk/src/python.c
r4026 r4027 31 31 #include "neercs.h" 32 32 33 void add_char(struct screen_list *sl, unsigned int c); 34 void del_char(struct screen_list *sl); 35 void python_execute(struct screen_list *sl); 36 37 void add_char(struct screen_list *sl, unsigned int c) 38 { 39 /* FIXME handle return values */ 40 if (!sl->command_props.command) 41 { 42 sl->command_props.size = 1; 43 sl->command_props.x = 0; 44 sl->command_props.command = (char *)malloc(2); 45 sl->command_props.command[0] = 0; 46 } 47 else 48 { 49 sl->command_props.command = 50 (char *)realloc(sl->command_props.command, 51 sl->command_props.size + 1); 52 } 53 memmove(&sl->command_props.command[sl->command_props.x + 1], 54 &sl->command_props.command[sl->command_props.x], 55 (sl->command_props.size - sl->command_props.x)); 56 57 sl->command_props.command[sl->command_props.x] = c; 58 sl->command_props.x++; 59 sl->command_props.size++; 60 } 61 62 void del_char(struct screen_list *sl) 63 { 64 if(sl->command_props.x<1) return; 65 if (sl->command_props.size > 1) 66 sl->command_props.size--; 67 else 68 return; 69 70 memcpy(&sl->command_props.command[sl->command_props.x - 1], 71 &sl->command_props.command[sl->command_props.x], 72 sl->command_props.size - sl->command_props.x); 73 74 sl->command_props.command = 75 (char *)realloc(sl->command_props.command, sl->command_props.size); 76 77 if (sl->command_props.x) 78 sl->command_props.x--; 79 sl->command_props.command[sl->command_props.size-1] = 0; 80 } 81 33 82 int python_command_handle_key(struct screen_list *screen_list, unsigned int c) 34 83 { … … 39 88 return 1; 40 89 } 90 else if(c == CACA_KEY_LEFT) 91 { 92 if(screen_list->command_props.x) 93 screen_list->command_props.x--; 94 } 95 else if(c == CACA_KEY_RIGHT) 96 { 97 if(screen_list->command_props.x < screen_list->command_props.size-1) 98 screen_list->command_props.x++; 99 } 100 else if(c == CACA_KEY_RETURN) 101 { 102 python_execute(screen_list); 103 } 41 104 else 42 105 { 106 if (c >= ' ' && c < 127) 107 add_char(screen_list, c); 108 else if (c == 8) 109 { 110 del_char(screen_list); 111 } 112 screen_list->changed = 1; 43 113 return 0; 44 114 } 115 return 0; 45 116 } 46 117 47 118 void draw_python_command(struct screen_list *screen_list) 48 119 { 120 int w = 65, h = 5; 121 int x = (caca_get_canvas_width(screen_list->cv) - w) / 2; 122 int y = (caca_get_canvas_height(screen_list->cv) - h) / 2; 49 123 124 caca_set_color_ansi(screen_list->cv, CACA_BLUE, CACA_BLUE); 125 caca_fill_box(screen_list->cv, x, y, w, h, '#'); 126 caca_set_color_ansi(screen_list->cv, CACA_DEFAULT, CACA_BLUE); 127 caca_draw_cp437_box(screen_list->cv, x, y, w, h); 128 caca_printf(screen_list->cv, x, y, "Execute command"); 129 130 caca_printf(screen_list->cv, x + 2, y + 2, 131 "[___________________________________________________________]"); 132 if (screen_list->command_props.command) 133 { 134 caca_printf(screen_list->cv, x + 3, y + 2, 135 "%s", screen_list->command_props.command); 136 caca_gotoxy(screen_list->cv, 137 x + 3 + screen_list->command_props.x, y + 2); 138 } 50 139 } 140 141 142 void python_execute(struct screen_list *sl) 143 { 144 debug("Executing '%s'\n", sl->command_props.command); 145 146 if(sl->command_props.command); 147 free(sl->command_props.command); 148 sl->command_props.command = NULL; 149 sl->command_props.size = 0; 150 sl->command_props.x = 0; 151 sl->python_command = 0; 152 sl->changed = 1; 153 } 154 155 156 51 157 #endif -
neercs/trunk/src/screen_list.c
r4026 r4027 58 58 screen_list->mini = 1; 59 59 screen_list->help = 0; 60 screen_list->python_command = 0;61 60 screen_list->status = 1; 62 61 screen_list->eyecandy = 1; … … 98 97 screen_list->cube.duration = 1000000; 99 98 99 screen_list->python_command = 0; 100 screen_list->command_props.x = 0; 101 screen_list->command_props.y = 0; 102 screen_list->command_props.command = NULL; 103 screen_list->command_props.size = 0; 100 104 101 105 screen_list->recurrent_list = NULL;
Note: See TracChangeset
for help on using the changeset viewer.