Changeset 4027 for neercs


Ignore:
Timestamp:
Nov 23, 2009, 5:39:33 PM (10 years ago)
Author:
Jean-Yves Lamoureux
Message:
  • Python mini-command input box (no evaluation yet)
Location:
neercs/trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • neercs/trunk/src/input.c

    r4026 r4027  
    182182    case 'e':
    183183        screen_list->python_command = 1;
     184        screen_list->command_props.x = 0;
     185        screen_list->command_props.y = 0;
    184186        break;
    185187#endif
  • neercs/trunk/src/neercs.h

    r4026 r4027  
    144144};
    145145
     146struct command_props
     147{
     148        int x, y;
     149    int size;
     150    char *command;
     151};
     152
    146153struct screen_list
    147154{
     
    185192    struct cube_props cube;      /* Cube */
    186193    long long unsigned int last_switch; /* Cube */
     194    struct command_props command_props;
    187195
    188196    /* ScreenSaver stuff */
     
    309317int help_handle_key(struct screen_list *screen_list, unsigned int c);
    310318#ifdef USE_PYTHON
    311 int python_command_handle_key(struct screen_list *screen_list, unsigned int c);
     319int  python_command_handle_key(struct screen_list *screen_list, unsigned int c);
    312320void draw_python_command(struct screen_list *screen_list);
    313321#endif
  • neercs/trunk/src/python.c

    r4026 r4027  
    3131#include "neercs.h"
    3232
     33void add_char(struct screen_list *sl, unsigned int c);
     34void del_char(struct screen_list *sl);
     35void python_execute(struct screen_list *sl);
     36
     37void 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
     62void 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
    3382int python_command_handle_key(struct screen_list *screen_list, unsigned int c)
    3483{
     
    3988        return 1;
    4089    }
     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    }   
    41104    else
    42105    {
     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;
    43113        return 0;
    44114    }
     115    return 0;
    45116}
    46117
    47118void draw_python_command(struct screen_list *screen_list)
    48119{
     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;
    49123
     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    }
    50139}
     140
     141
     142void 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
    51157#endif
  • neercs/trunk/src/screen_list.c

    r4026 r4027  
    5858    screen_list->mini = 1;
    5959    screen_list->help = 0;
    60     screen_list->python_command = 0;
    6160    screen_list->status = 1;
    6261    screen_list->eyecandy = 1;
     
    9897    screen_list->cube.duration = 1000000;
    9998   
     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;
    100104   
    101105    screen_list->recurrent_list = NULL;
Note: See TracChangeset for help on using the changeset viewer.