| @@ -196,7 +196,6 @@ static cucul_canvas_t *import_text(void const *data, unsigned int size) | |||||
| } | } | ||||
| #define IS_ALPHA(x) (x>='A' && x<='z') | #define IS_ALPHA(x) (x>='A' && x<='z') | ||||
| void _update_canvas_size(cucul_canvas_t *cv, int x, int y, int *max_x, int *max_y); | |||||
| unsigned char _get_ansi_command(unsigned char const *buffer, int size); | unsigned char _get_ansi_command(unsigned char const *buffer, int size); | ||||
| int _parse_tuple(unsigned int *ret, unsigned char const *buffer, int size); | int _parse_tuple(unsigned int *ret, unsigned char const *buffer, int size); | ||||
| void _manage_modifiers(char c, int *fg, int *bg, int *old_fg, int *old_bg); | void _manage_modifiers(char c, int *fg, int *bg, int *old_fg, int *old_bg); | ||||
| @@ -209,7 +208,7 @@ static cucul_canvas_t *import_ansi(void const *data, unsigned int size) | |||||
| unsigned char c; | unsigned char c; | ||||
| unsigned int count = 0; | unsigned int count = 0; | ||||
| unsigned int tuple[1024]; /* Should be enough. Will it be ? */ | unsigned int tuple[1024]; /* Should be enough. Will it be ? */ | ||||
| int x = 0, y = 0, max_x = 80, max_y = 25; | |||||
| int x = 0, y = 0, width = 80, height = 25; | |||||
| int save_x = 0, save_y = 0; | int save_x = 0, save_y = 0; | ||||
| unsigned int j, add = 0; | unsigned int j, add = 0; | ||||
| int fg, bg, old_fg, old_bg; | int fg, bg, old_fg, old_bg; | ||||
| @@ -217,7 +216,7 @@ static cucul_canvas_t *import_ansi(void const *data, unsigned int size) | |||||
| fg = old_fg = CUCUL_COLOR_LIGHTGRAY; | fg = old_fg = CUCUL_COLOR_LIGHTGRAY; | ||||
| bg = old_bg = CUCUL_COLOR_BLACK; | bg = old_bg = CUCUL_COLOR_BLACK; | ||||
| cv = cucul_create_canvas(max_x, max_y); | |||||
| cv = cucul_create_canvas(width, height); | |||||
| for(i = 0; i < size; i++) | for(i = 0; i < size; i++) | ||||
| { | { | ||||
| @@ -248,7 +247,6 @@ static cucul_canvas_t *import_ansi(void const *data, unsigned int size) | |||||
| x = 0; | x = 0; | ||||
| y = 0; | y = 0; | ||||
| } | } | ||||
| _update_canvas_size(cv, x, y, &max_x, &max_y); | |||||
| break; | break; | ||||
| case 'A': | case 'A': | ||||
| if(tuple[0] == 0x1337) | if(tuple[0] == 0x1337) | ||||
| @@ -256,21 +254,18 @@ static cucul_canvas_t *import_ansi(void const *data, unsigned int size) | |||||
| else | else | ||||
| y -= tuple[0]; | y -= tuple[0]; | ||||
| if(y < 0) y = 0; | if(y < 0) y = 0; | ||||
| _update_canvas_size(cv, x, y, &max_x, &max_y); | |||||
| break; | break; | ||||
| case 'B': | case 'B': | ||||
| if(tuple[0] == 0x1337) | if(tuple[0] == 0x1337) | ||||
| y++; | y++; | ||||
| else | else | ||||
| y += tuple[0]; | y += tuple[0]; | ||||
| _update_canvas_size(cv, x, y, &max_x, &max_y); | |||||
| break; | break; | ||||
| case 'C': | case 'C': | ||||
| if(tuple[0] == 0x1337) | if(tuple[0] == 0x1337) | ||||
| x++; | x++; | ||||
| else | else | ||||
| x += tuple[0]; | x += tuple[0]; | ||||
| _update_canvas_size(cv, x, y, &max_x, &max_y); | |||||
| break; | break; | ||||
| case 'D': | case 'D': | ||||
| if(tuple[0] == 0x1337) | if(tuple[0] == 0x1337) | ||||
| @@ -278,7 +273,6 @@ static cucul_canvas_t *import_ansi(void const *data, unsigned int size) | |||||
| else | else | ||||
| x -= tuple[0]; | x -= tuple[0]; | ||||
| if(x < 0) x = 0; | if(x < 0) x = 0; | ||||
| _update_canvas_size(cv, x, y, &max_x, &max_y); | |||||
| break; | break; | ||||
| case 's': | case 's': | ||||
| save_x = x; | save_x = x; | ||||
| @@ -287,14 +281,12 @@ static cucul_canvas_t *import_ansi(void const *data, unsigned int size) | |||||
| case 'u': | case 'u': | ||||
| x = save_x; | x = save_x; | ||||
| y = save_y; | y = save_y; | ||||
| _update_canvas_size(cv, x, y, &max_x, &max_y); | |||||
| break; | break; | ||||
| case 'J': | case 'J': | ||||
| if(tuple[0] == 2) | if(tuple[0] == 2) | ||||
| { | { | ||||
| x = 0; | x = 0; | ||||
| y = 0; | y = 0; | ||||
| _update_canvas_size(cv, x, y, &max_x, &max_y); | |||||
| } | } | ||||
| break; | break; | ||||
| case 'K': | case 'K': | ||||
| @@ -316,7 +308,6 @@ static cucul_canvas_t *import_ansi(void const *data, unsigned int size) | |||||
| { | { | ||||
| x = 0; | x = 0; | ||||
| y++; | y++; | ||||
| _update_canvas_size(cv, x, y, &max_x, &max_y); | |||||
| } | } | ||||
| else if(buffer[i] == '\r') | else if(buffer[i] == '\r') | ||||
| { | { | ||||
| @@ -333,10 +324,20 @@ static cucul_canvas_t *import_ansi(void const *data, unsigned int size) | |||||
| else | else | ||||
| cucul_putchar(cv, x, y, '?'); | cucul_putchar(cv, x, y, '?'); | ||||
| x++; | x++; | ||||
| _update_canvas_size(cv, x, y, &max_x, &max_y); | |||||
| } | } | ||||
| } | } | ||||
| if(x >= width || y >= height) | |||||
| { | |||||
| if(x >= width) | |||||
| width = x + 1; | |||||
| if(y >= height) | |||||
| height = y + 1; | |||||
| cucul_set_canvas_size(cv, width, height); | |||||
| } | |||||
| i += add; // add is tuple char count, then +[ +command | i += add; // add is tuple char count, then +[ +command | ||||
| add = 0; | add = 0; | ||||
| } | } | ||||
| @@ -469,14 +470,3 @@ void _manage_modifiers(char c, int *fg, int *bg, int *old_fg, int *old_bg) | |||||
| } | } | ||||
| } | } | ||||
| void _update_canvas_size(cucul_canvas_t *cv, int x, int y, int *max_x, int *max_y) | |||||
| { | |||||
| if(x > *max_x) | |||||
| *max_x = x; | |||||
| if(y > *max_y) | |||||
| *max_y = y; | |||||
| cucul_set_canvas_size(cv, *max_x, *max_y); | |||||
| } | |||||