Enlightenment CVS committal Author : sebastid Project : e17 Module : proto
Dir : e17/proto/enterminus/src/bin Modified Files: handlers.c main.c misc.c pty.c smart.c term.c term.h ui.c Log Message: Sorry for the large patch. I may have broke something, but resizeing works now. The use of cur_row and cur_col is not right at the moment. =================================================================== RCS file: /cvsroot/enlightenment/e17/proto/enterminus/src/bin/handlers.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -3 -r1.8 -r1.9 --- handlers.c 24 Feb 2005 12:31:00 -0000 1.8 +++ handlers.c 25 Feb 2005 09:21:26 -0000 1.9 @@ -3,7 +3,6 @@ void term_handler_xterm_seq(int op, Term *term) { char buf[512]; int len; - int buflen; unsigned char c; Term_Event_Title_Change *e; Ecore_Event *event; @@ -32,12 +31,10 @@ int term_handler_escape_seq(Term *term) { - int len; int pos; int args[NPAR]; int narg = 0; int digit; - int rows, cols; int i; int questionmark; unsigned char c; @@ -125,7 +122,7 @@ if(args[0] == 1) { /* erase from start to cursor */ term_clear_area(term, 1, 1, term->tcanvas->cols, - term->tcanvas->cur_row); + term->cur_row); } if(args[0] == 2) { /* erase whole display */ @@ -135,7 +132,7 @@ } else { /* erase from cursor to end of display */ - term_clear_area(term, 1, term->tcanvas->cur_row, + term_clear_area(term, 1, term->cur_row, term->tcanvas->cols, term->tcanvas->rows); } break; @@ -149,20 +146,20 @@ if(narg) { if(args[0] == 1) { /* erase from start of line to cursor */ - term_clear_area(term, 1, term->tcanvas->cur_row, - term->tcanvas->cur_col, term->tcanvas->cur_row); + term_clear_area(term, 1, term->cur_row, + term->cur_col, term->cur_row); } if(args[0] == 2) { /* erase whole line */ - term_clear_area(term, 1, term->tcanvas->cur_row, - term->tcanvas->cols, term->tcanvas->cur_row); + term_clear_area(term, 1, term->cur_row, + term->tcanvas->cols, term->cur_row); } } else { /* erase from cursor to end of line */ - term_clear_area(term, term->tcanvas->cur_col, - term->tcanvas->cur_row, - term->tcanvas->cols, term->tcanvas->cur_row); + term_clear_area(term, term->cur_col, + term->cur_row, + term->tcanvas->cols, term->cur_row); } break; case 'L': @@ -178,10 +175,10 @@ case 'P': /* ESC [ [ n ] P Delete n characters (DCH), default 1 */ DPRINT((stderr, "ESC [ [ n ] P Delete n characters (DCH)\n")); - term_clear_area(term, term->tcanvas->cur_col, - term->tcanvas->cur_row, - term->tcanvas->cur_col + args[0], - term->tcanvas->cur_row); + term_clear_area(term, term->cur_col, + term->cur_row, + term->cur_col + args[0], + term->cur_row); break; case 'W': /* ESC [ [ n ] W Tabulator functions @@ -402,7 +399,7 @@ /* cursor position */ snprintf(buf, sizeof(buf), "\033[%d;%dR", - term->tcanvas->cur_row, term->tcanvas->cur_col); + term->cur_row, term->cur_col); write(term->cmd_fd.sys, buf, strlen(buf)); //cmd_write(buf, strlen(buf)); @@ -418,7 +415,7 @@ * defaults to the full screen */ DPRINT((stderr, "ESC [ [ t ; b ] r Set Scrolling Region (CSR)\n")); - term->tcanvas->scroll_region_start = args[0] ? args[0] : 1; + term->tcanvas->scroll_region_start = args[0] ? args[0] : 0; term->tcanvas->scroll_region_end = args[1] ? args[1] : term->tcanvas->rows; if(!narg) { /* Reset scroll region */ @@ -465,13 +462,13 @@ break; case '7': /* ESC 7 (save cursor position) */ DPRINT((stderr, "ESC 7 (save cursor pos)\n")); - term->tcanvas->saved_cursor_x = term->tcanvas->cur_col; - term->tcanvas->saved_cursor_y = term->tcanvas->cur_row; + term->tcanvas->saved_cursor_x = term->cur_col; + term->tcanvas->saved_cursor_y = term->cur_row; break; case '8': /* ESC 8 (restore cursor position) */ DPRINT((stderr, "ESC 8 (restore cursor pos)\n")); - term->tcanvas->cur_col = term->tcanvas->saved_cursor_x; - term->tcanvas->cur_row = term->tcanvas->saved_cursor_y; + term->cur_col = term->tcanvas->saved_cursor_x; + term->cur_row = term->tcanvas->saved_cursor_y; break; case '=': /* ESC = (set application keypad mode) */ DPRINT((stderr, "ESC = (set application keypad mode)\n")); @@ -483,10 +480,11 @@ break; case 'M': /* ESC M (reverse linefeed) */ DPRINT((stderr, "ESC = (reverse linefeed)\n")); - term->tcanvas->cur_row--; - if(term->tcanvas->cur_row < term->tcanvas->scroll_region_start) { - term->tcanvas->cur_row = term->tcanvas->scroll_region_start; + term->cur_row--; + if (term->cur_row < 0) { + /* We moved over the top! Scroll up! */ term_scroll_down(term, 1); + term->cur_row = 0; } break; default: @@ -570,9 +568,9 @@ return; } /* fixup upper case chars */ +#if 0 else if (key_modifiers & TERM_KEY_MODIFIER_SHIFT) strupper(keyname); -#if 0 if (!strcmp(ev->keyname, "Left")) term_entry_cursor_left_move(evas_object_smart_data_get(data)); else if (!strcmp(ev->keyname, "Right")) @@ -598,7 +596,7 @@ } else if ((ev->keyname && strlen(ev->keyname) == 1) || !strcmp(keyname, " ")) { - char *tmp = ev->string; + //char *tmp = ev->string; //term_key_down(evas_object_smart_data_get(data),tmp[0]); //write(term->cmd_fd.sys, tmp, 1); =================================================================== RCS file: /cvsroot/enlightenment/e17/proto/enterminus/src/bin/main.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -3 -r1.6 -r1.7 --- main.c 19 Feb 2005 12:18:37 -0000 1.6 +++ main.c 25 Feb 2005 09:21:26 -0000 1.7 @@ -1,4 +1,5 @@ #include "term.h" +#include "enterm.h" int main(int argc, char **argv) { =================================================================== RCS file: /cvsroot/enlightenment/e17/proto/enterminus/src/bin/misc.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- misc.c 24 Jan 2005 10:57:27 -0000 1.1 +++ misc.c 25 Feb 2005 09:21:26 -0000 1.2 @@ -1,13 +1,14 @@ +/* + * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>3 + */ #include "term.h" -static void strupper(char *str) +#if 0 +static void +strupper(char *str) { char *i; - for(i = str; *i != '\0'; i++) - *i = toupper(*i); -} - -int term_timers(void *data) { - ecore_job_add(term_redraw, data); - return 1; + for (i = str; *i != '\0'; i++) + *i = toupper(*i); } +#endif =================================================================== RCS file: /cvsroot/enlightenment/e17/proto/enterminus/src/bin/pty.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -3 -r1.6 -r1.7 --- pty.c 19 Feb 2005 12:18:37 -0000 1.6 +++ pty.c 25 Feb 2005 09:21:26 -0000 1.7 @@ -102,7 +102,6 @@ int execute_command(Term *term)//, int argc, const char **argv) { char **args; - int master; struct passwd *pw; pw = find_user(); =================================================================== RCS file: /cvsroot/enlightenment/e17/proto/enterminus/src/bin/smart.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -3 -r1.6 -r1.7 --- smart.c 18 Feb 2005 23:26:40 -0000 1.6 +++ smart.c 25 Feb 2005 09:21:26 -0000 1.7 @@ -1,3 +1,6 @@ +/* + * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>3 + */ #include "term.h" /* Evas Smart Object API Wrapping methods */ @@ -5,7 +8,9 @@ static Evas_Smart *smart; /* instantiate a new terminal */ -Evas_Object *term_new(Evas *evas) { +Evas_Object * +term_new(Evas *evas) +{ Evas_Object *term; term = evas_object_smart_add(evas, term_smart_get()); TERM_EVENT_TITLE_CHANGE = ecore_event_type_new(); @@ -13,39 +18,44 @@ } /* knit smart object with its functions */ -Evas_Smart *term_smart_get() { - if(smart) return smart; - smart = evas_smart_new ("term", - term_smart_add, - term_smart_del, - term_smart_layer_set, - term_smart_raise, - term_smart_lower, - term_smart_stack_above, - term_smart_stack_below, - term_smart_move, - term_smart_resize, - term_smart_show, - term_smart_hide, - term_smart_color_set, - term_smart_clip_set, - term_smart_clip_unset, - NULL - ); +Evas_Smart * +term_smart_get() +{ + if (smart) return smart; + smart = evas_smart_new("term", + term_smart_add, + term_smart_del, + term_smart_layer_set, + term_smart_raise, + term_smart_lower, + term_smart_stack_above, + term_smart_stack_below, + term_smart_move, + term_smart_resize, + term_smart_show, + term_smart_hide, + term_smart_color_set, + term_smart_clip_set, + term_smart_clip_unset, + NULL); return smart; } /* add the term object */ -void term_smart_add(Evas_Object *o) { +void +term_smart_add(Evas_Object *o) +{ Term *data; - + data = term_init(o); - if(!data) return; + if (!data) return; evas_object_smart_data_set(o, data); } /* delete the term object */ -void term_smart_del(Evas_Object *o) { +void +term_smart_del(Evas_Object *o) +{ } /* we have 3 layers to deal with: @@ -53,83 +63,115 @@ * 2- bg for evas text objects * 3- bg for entire termnal */ -void term_smart_layer_set(Evas_Object *o, int l) { +void +term_smart_layer_set(Evas_Object *o, int l) +{ Term *t; - int i; + int i, j; Term_EGlyph *gl; - + t = evas_object_smart_data_get(o); - evas_object_layer_set(t->bg, l-2); - for(i = 0; i < t->tcanvas->cols * t->tcanvas->rows; i++) { - gl = &t->grid[i]; - evas_object_layer_set(gl->text, l); - evas_object_layer_set(gl->bg, l-1); - } + evas_object_layer_set(t->bg, l - 2); + for (i = 0; i < t->tcanvas->rows; i++) { + for (j = 0; j < t->tcanvas->cols; j++) { + gl = &t->grid[i][j]; + evas_object_layer_set(gl->text, l); + /* + evas_object_layer_set(gl->bg, l - 1); + */ + } + } } -void term_smart_raise(Evas_Object *o) { +void +term_smart_raise(Evas_Object *o) +{ Term *t; - int i; + int i, j; Term_EGlyph *gl; - + t = evas_object_smart_data_get(o); evas_object_raise(t->bg); - for(i = 0; i < t->tcanvas->cols * t->tcanvas->rows; i++) { - gl = &t->grid[i]; - evas_object_raise(gl->text); - evas_object_raise(gl->bg); - } + for (i = 0; i < t->tcanvas->rows; i++) { + for (j = 0; j < t->tcanvas->cols; j++) { + gl = &t->grid[i][j]; + evas_object_raise(gl->text); + /* + evas_object_raise(gl->bg); + */ + } + } } -void term_smart_lower(Evas_Object *o) { +void +term_smart_lower(Evas_Object *o) +{ Term *t; - int i; + int i, j; Term_EGlyph *gl; - + t = evas_object_smart_data_get(o); evas_object_lower(t->bg); - for(i = 0; i < t->tcanvas->cols * t->tcanvas->rows; i++) { - gl = &t->grid[i]; - evas_object_lower(gl->text); - evas_object_lower(gl->bg); - } + for (i = 0; i < t->tcanvas->rows; i++) { + for (j = 0; j < t->tcanvas->cols; j++) { + gl = &t->grid[i][j]; + evas_object_lower(gl->text); + /* + evas_object_lower(gl->bg); + */ + } + } } -void term_smart_stack_above(Evas_Object *o, Evas_Object *above) { +void +term_smart_stack_above(Evas_Object *o, Evas_Object *above) +{ Term *t; - int i; + int i, j; Term_EGlyph *gl; - + t = evas_object_smart_data_get(o); evas_object_stack_above(t->bg, above); - for(i = 0; i < t->tcanvas->cols * t->tcanvas->rows; i++) { - gl = &t->grid[i]; - evas_object_stack_above(gl->text, above); - evas_object_stack_above(gl->bg, above); + for (i = 0; i < t->tcanvas->rows; i++) { + for (j = 0; j < t->tcanvas->cols; j++) { + gl = &t->grid[i][j]; + evas_object_stack_above(gl->text, above); + /* + evas_object_stack_above(gl->bg, above); + */ + } } } -void term_smart_stack_below(Evas_Object *o, Evas_Object *below) { +void +term_smart_stack_below(Evas_Object *o, Evas_Object *below) +{ Term *t; - int i; + int i, j; Term_EGlyph *gl; - + t = evas_object_smart_data_get(o); evas_object_stack_below(t->bg, below); - for(i = 0; i < t->tcanvas->cols * t->tcanvas->rows; i++) { - gl = &t->grid[i]; - evas_object_stack_below(gl->text, below); - evas_object_stack_below(gl->bg, below); - } + for (i = 0; i < t->tcanvas->rows; i++) { + for (j = 0; j < t->tcanvas->cols; j++) { + gl = &t->grid[i][j]; + evas_object_stack_below(gl->text, below); + /* + evas_object_stack_below(gl->bg, below); + */ + } + } } /* implement some sort of offset which will make moving easy */ -void term_smart_move(Evas_Object *o, Evas_Coord x, Evas_Coord y) { +void +term_smart_move(Evas_Object *o, Evas_Coord x, Evas_Coord y) +{ } /* TODO: * We need to show evas objects and set their layers after a resize - * + * * When we resize, if we dont clear the text (which is what we should * do, not clear the text) and we just call a normal redraw, then all * of out text will get shifted and we get a distorted looking term. @@ -137,131 +179,178 @@ * as it were without any distortions. We dont get that now because we * set all the area to '\0' in our current method, hence, clearing it. */ -void term_smart_resize(Evas_Object *o, Evas_Coord w, Evas_Coord h) { - int x, y, old_size; +void +term_smart_resize(Evas_Object *o, Evas_Coord w, Evas_Coord h) +{ + int x, y, size; int num_chars_w, num_chars_h; Term *term; Term_EGlyph *gl; Term_TGlyph *gt; - + /* check for w = 0 or h = 0 */ - if(w == 0)w = 1; - if(h == 0)h = 1; - + if (w == 0) w = 1; + if (h == 0) h = 1; + term = evas_object_smart_data_get(o); - term->w = w; - term->h = h; - num_chars_w = w/term->font.width; - num_chars_h = h/term->font.height; - - if(term->tcanvas->cols == num_chars_w && term->tcanvas->rows == num_chars_h) - return; - - /* TODO: Check if we're increasing or decreasing window size */ - - old_size = term->tcanvas->cols * term->tcanvas->rows; - - term->tcanvas->cols = num_chars_w; - term->tcanvas->rows = num_chars_h; - - term->tcanvas->scroll_region_start = 0; - term->tcanvas->scroll_region_end = term->tcanvas->rows - 1; - - if((term->tcanvas->grid = realloc(term->tcanvas->grid, - term->tcanvas->cols * term->tcanvas->rows * - term->tcanvas->scroll_size * - sizeof(Term_TGlyph))) == NULL) { - fprintf(stderr,"Fatal: Could not reallocate text grid!\n"); + num_chars_w = w / term->font.width; + num_chars_h = h / term->font.height; + + if ((term->tcanvas->cols == num_chars_w) && (term->tcanvas->rows == num_chars_h)) + return; + + term->tcanvas->scroll_region_start += (term->tcanvas->rows - num_chars_h); + if (term->tcanvas->scroll_region_start < 0) + term->tcanvas->scroll_region_start += term->tcanvas->scroll_size; + else if (term->tcanvas->scroll_region_start >= term->tcanvas->scroll_size) + term->tcanvas->scroll_region_start -= term->tcanvas->scroll_size; + + term->tcanvas->grid[0] = realloc(term->tcanvas->grid[0], + num_chars_w * term->tcanvas->scroll_size + * sizeof(Term_TGlyph)); + for (x = 1; x < term->tcanvas->scroll_size; x++) + term->tcanvas->grid[x] = &term->tcanvas->grid[x - 1][num_chars_w]; + /* FIXME: Initialize new characters if we get bigger */ + + /* Mark all visible characters changed */ + if (term->tcanvas->scroll_region_start < term->tcanvas->scroll_region_end) { + for (x = term->tcanvas->scroll_region_start; x < term->tcanvas->scroll_region_end; x++) { + term->tcanvas->changed_rows[x] = 1; + for (y = 0; y < num_chars_w; y++) { + gt = &term->tcanvas->grid[x][y]; + gt->changed = 1; + } + } + } else { + for (x = term->tcanvas->scroll_region_start; x < term->tcanvas->scroll_size; x++) { + term->tcanvas->changed_rows[x] = 1; + for (y = 0; y < num_chars_w; y++) { + gt = &term->tcanvas->grid[x][y]; + gt->changed = 1; + } + } + + for (x = 0; x < term->tcanvas->scroll_region_end; x++) { + term->tcanvas->changed_rows[x] = 1; + for (y = 0; y < num_chars_w; y++) { + gt = &term->tcanvas->grid[x][y]; + gt->changed = 1; + } + } + } + + size = (num_chars_h * num_chars_w) - (term->tcanvas->cols * term->tcanvas->rows); + /* Free grid */ + if (size < 0) { + int start, end; + start = (num_chars_h * num_chars_w); + end = (term->tcanvas->cols * term->tcanvas->rows); + for (x = start; x < end; x++) { + gl = &term->grid[0][x]; + if (gl->text) evas_object_del(gl->text); + /* + if (gl->bg) evas_object_del(gl->bg); + */ + } + } + if ((term->grid = realloc(term->grid, + num_chars_h + * sizeof(Term_EGlyph *))) == NULL) { + fprintf(stderr, "Fatal: Couldn't not reallocate evas grid!\n"); exit(-1); } - - /* review this, do we need to subtract: - * We know that we need to subtract, but its segging when we do, fix. - * (term->tcanvas->cols * term->tcanvas->rows * term->tcanvas->scroll_size) - */ - y = (term->tcanvas->cols * term->tcanvas->rows * term->tcanvas->scroll_size) - - (old_size * term->tcanvas->scroll_size); - - for(x = y ; - x <= term->tcanvas->cols * term->tcanvas->rows * term->tcanvas->scroll_size; - x++) { - gt = &term->tcanvas->grid[x]; - gt->c = '\0'; - } - - if((term->tcanvas->changed_rows = realloc(term->tcanvas->changed_rows, - term->tcanvas->rows * - term->tcanvas->scroll_size * - sizeof(int))) == NULL) { - fprintf(stderr,"Fatal: Could not reallocate changed rows buffer!\n"); - exit(-1); - } - - for(x = 0; x <= term->tcanvas->rows * term->tcanvas->scroll_size; x++) - term->tcanvas->changed_rows[x] = 0; - - if((term->grid = realloc(term->grid, term->tcanvas->cols * - term->tcanvas->rows * - sizeof(Term_EGlyph))) == NULL) { - fprintf(stderr,"Fatal: Couldnt not reallocate evas grid!\n"); + + if ((term->grid[0] = realloc(term->grid[0], + num_chars_h * num_chars_w + * sizeof(Term_EGlyph))) == NULL) { + fprintf(stderr, "Fatal: Couldn't not reallocate evas grid!\n"); exit(-1); } - - y = term->tcanvas->cols * term->tcanvas->rows - - (term->tcanvas->cols * term->tcanvas->rows - (old_size)); - - for(x = y ; x <= term->tcanvas->cols * term->tcanvas->rows; x++) { - gl = &term->grid[x]; - gl->text = evas_object_text_add(term->evas); - evas_object_layer_set(gl->text, 2); - evas_object_show(gl->text); - //gl->bg = evas_object_rectangle_add(term->evas); - //evas_object_resize(gl->bg, term->font.width, term->font.height); - //evas_object_color_set(gl->bg, 100, 50, 50, 150); - //evas_object_layer_set(gl->bg, 1); + for (x = 1; x < num_chars_h; x++) + term->grid[x] = &term->grid[x - 1][num_chars_w]; + + /* Init grid */ + if (size > 0) { + int start, end; + start = (term->tcanvas->cols * term->tcanvas->rows); + end = (num_chars_h * num_chars_w); + for (x = start; x < end; x++) { + gl = &term->grid[0][x]; + gl->text = evas_object_text_add(term->evas); + evas_object_layer_set(gl->text, 2); + evas_object_show(gl->text); + } } - - if(ioctl(term->cmd_fd.sys, TIOCSWINSZ, get_font_dim(term)) < 0) { + +#if 0 + gl->bg = evas_object_rectangle_add(term->evas); + evas_object_resize(gl->bg, term->font.width, term->font.height); + evas_object_color_set(gl->bg, 100, 50, 50, 150); + evas_object_layer_set(gl->bg, 1); +#endif + + if (ioctl(term->cmd_fd.sys, TIOCSWINSZ, get_font_dim(term)) < 0) { fprintf(stderr, "Couldn't set window size: %m\n"); } - + + term->tcanvas->cols = num_chars_w; + term->tcanvas->rows = num_chars_h; + + term->w = term->font.width * term->tcanvas->cols; + term->h = term->font.height * term->tcanvas->rows; + term_term_bg_set(term, DATADIR"black.png"); } -void term_smart_show(Evas_Object *o) { +void +term_smart_show(Evas_Object *o) +{ Term *t; - int i; + int i, j; Term_EGlyph *gl; - + t = evas_object_smart_data_get(o); evas_object_show(t->bg); - for(i = 0; i < t->tcanvas->cols * t->tcanvas->rows; i++) { - gl = &t->grid[i]; - evas_object_show(gl->text); - /* Enabling this isnt really wise at this point, uber slowness */ - //evas_object_show(gl->bg); + for (i = 0; i < t->tcanvas->rows; i++) { + for (j = 0; j < t->tcanvas->cols; j++) { + gl = &t->grid[i][j]; + evas_object_show(gl->text); + /* Enabling this isnt really wise at this point, uber slowness */ + //evas_object_show(gl->bg); + } } } -void term_smart_hide(Evas_Object *o) { +void +term_smart_hide(Evas_Object *o) +{ Term *t; - int i; + int i, j; Term_EGlyph *gl; - + t = evas_object_smart_data_get(o); evas_object_hide(t->bg); - for(i = 0; i < t->tcanvas->cols * t->tcanvas->rows; i++) { - gl = &t->grid[i]; - evas_object_hide(gl->text); - evas_object_hide(gl->bg); - } + for (i = 0; i < t->tcanvas->rows; i++) { + for (j = 0; j < t->tcanvas->cols; j++) { + gl = &t->grid[i][j]; + evas_object_hide(gl->text); + /* + evas_object_hide(gl->bg); + */ + } + } } -void term_smart_color_set(Evas_Object *o, int r, int g, int b, int a) { +void +term_smart_color_set(Evas_Object *o, int r, int g, int b, int a) +{ } -void term_smart_clip_set(Evas_Object *o, Evas_Object *clip) { +void +term_smart_clip_set(Evas_Object *o, Evas_Object *clip) +{ } -void term_smart_clip_unset(Evas_Object *o) { +void term_smart_clip_unset(Evas_Object *o) +{ } =================================================================== RCS file: /cvsroot/enlightenment/e17/proto/enterminus/src/bin/term.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -3 -r1.13 -r1.14 --- term.c 24 Feb 2005 00:27:54 -0000 1.13 +++ term.c 25 Feb 2005 09:21:26 -0000 1.14 @@ -1,113 +1,140 @@ +/* + * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>3 + */ #include "term.h" -void term_tcanvas_fg_color_set(Term *term, int c) { +void +term_tcanvas_fg_color_set(Term *term, int c) +{ Term_TGlyph *gl; - gl = &term->tcanvas->grid[term->tcanvas->cur_col + (term->tcanvas->cur_row * term->tcanvas->cols)]; + int pos; + + pos = term->tcanvas->scroll_region_start + term->cur_row; + if (pos >= term->tcanvas->scroll_size) + pos -= term->tcanvas->scroll_size; + + gl = &term->tcanvas->grid[pos][term->cur_col]; gl->changed = 1; gl->fg = c; - term->tcanvas->cur_fg = c; - term->tcanvas->changed_rows[term->tcanvas->cur_row] = 1; + term->tcanvas->cur_fg = c; + term->tcanvas->changed_rows[pos] = 1; } -void term_tcanvas_bg_color_set(Term *term, int c) { +void +term_tcanvas_bg_color_set(Term *term, int c) +{ Term_TGlyph *gl; - gl = &term->tcanvas->grid[term->tcanvas->cur_col + (term->tcanvas->cur_row * term->tcanvas->cols)]; + int pos; + + pos = term->tcanvas->scroll_region_start + term->cur_row; + if (pos >= term->tcanvas->scroll_size) + pos -= term->tcanvas->scroll_size; + + gl = &term->tcanvas->grid[pos][term->cur_col]; gl->changed = 1; gl->bg = c; term->tcanvas->cur_bg = c; - term->tcanvas->changed_rows[term->tcanvas->cur_row] = 1; + term->tcanvas->changed_rows[pos] = 1; } -void term_tcanvas_glyph_push(Term *term, char c) { - +void +term_tcanvas_glyph_push(Term *term, char c) +{ Term_TGlyph *gl; int j; - gl = &term->tcanvas->grid[term->tcanvas->cur_col + (term->tcanvas->cur_row * term->tcanvas->cols)]; + int pos; + + pos = term->tcanvas->scroll_region_start + term->cur_row; + if (pos >= term->tcanvas->scroll_size) + pos -= term->tcanvas->scroll_size; + + gl = &term->tcanvas->grid[pos][term->cur_col]; gl->changed = 1; gl->c = c; gl->fg = term->tcanvas->cur_fg; - gl->bg = term->tcanvas->cur_bg; - term->tcanvas->changed_rows[term->tcanvas->cur_row] = 1; - term->tcanvas->cur_col++; - - if(term->tcanvas->cur_col > term->tcanvas->cols) { - term->tcanvas->cur_col = 0; - term->tcanvas->cur_row++; - + gl->bg = term->tcanvas->cur_bg; + term->tcanvas->changed_rows[pos] = 1; + term->cur_col++; + + if (term->cur_col > term->tcanvas->cols) { + term->cur_col = 0; term->cur_row++; - if(term->cur_row > term->tcanvas->rows-1) - term->cur_row = term->tcanvas->rows-1; - - for(j = 0; j <= term->tcanvas->cols; j++) { - gl = & term->tcanvas->grid[j + (term->tcanvas->cols * term->tcanvas->cur_row)]; + if (term->cur_row >= term->tcanvas->rows) { + term_scroll_up(term, 1); + term->cur_row = term->tcanvas->rows - 1; + } + for (j = 0; j < term->tcanvas->cols; j++) { + gl = &term->tcanvas->grid[pos][j]; gl->c = ' '; gl->changed = 1; } } - - return; + + return; } -char term_tcanvas_data_pop(Term *term) { - if(term->data_ptr >= term->data_len) - return 0; +char +term_tcanvas_data_pop(Term *term) +{ + if (term->data_ptr >= term->data_len) + return 0; return term->data[term->data_ptr++]; } /* look for new characters on the terminal device */ -int term_tcanvas_data(void *data) { +int +term_tcanvas_data(void *data, Ecore_Fd_Handler *fd_handler) +{ char c; - Term *term = data; + Term *term; + + term = data; term->data_ptr = 0; /* THIS | WAS NOT HERE */ term->data_len = read(term->cmd_fd.sys, &term->data[0], sizeof(term->data)); - if( term->data_len > 0 ) { - while ( (c = term_tcanvas_data_pop(term)) ) { + if (term->data_len > 0) { + while ((c = term_tcanvas_data_pop(term))) { //printf("%c",c); switch(c) { - case '\007': /* Bell */ - - break; - case '\010': /* backspace */ - term->tcanvas->cur_col--; - //term_tcanvas_glyph_push(term, ' '); - - break; - case '\011': /* tab */ - - break; - case '\033': /* escape */ - term_handler_escape_seq(term); - break; - case '\n': /* newline */ - term->tcanvas->cur_col = 0; - term->tcanvas->cur_row++; - term->cur_row++; - if(term->cur_row > term->tcanvas->rows-1) - term->cur_row = term->tcanvas->rows-1; - - /* TODO: Remember to scroll */ - - { - int j; - Term_TGlyph *gl; - for(j = 0; j <= term->tcanvas->cols; j++) { - gl = & term->tcanvas->grid[j + (term->tcanvas->cols * term->tcanvas->cur_row)]; - gl->c = ' '; - gl->changed = 1; - } - } - - if(term->tcanvas->cur_row >= term->tcanvas->scroll_region_end) { - term_scroll_up(term, term->tcanvas->cur_row - term->tcanvas->scroll_region_end); - term->tcanvas->cur_row = term->tcanvas->scroll_region_end; - } - break; - case '\r': /* carriage return */ - term->tcanvas->cur_col = 0; - break; - default: - term_tcanvas_glyph_push(term, c); - break; + case '\007': /* Bell */ + break; + case '\010': /* backspace */ + term->cur_col--; + //term_tcanvas_glyph_push(term, ' '); + break; + case '\011': /* tab */ + break; + case '\033': /* escape */ + term_handler_escape_seq(term); + break; + case '\n': /* newline */ + term->cur_col = 0; + term->cur_row++; + if (term->cur_row >= term->tcanvas->rows) { + term_scroll_up(term, 1); + term->cur_row = term->tcanvas->rows - 1; + } + { + Term_TGlyph *gl; + int j; + int pos; + + pos = term->tcanvas->scroll_region_start + term->cur_row; + if (pos >= term->tcanvas->scroll_size) + pos -= term->tcanvas->scroll_size; + + for (j = 0; j < term->tcanvas->cols; j++) { + gl = &term->tcanvas->grid[pos][j]; + gl->c = ' '; + gl->changed = 1; + } + } + break; + case '\r': /* carriage return */ + term->cur_col = 0; + break; + default: + term_tcanvas_glyph_push(term, c); + break; } } } @@ -116,55 +143,56 @@ } /* Create a new text canvas */ -Term_TCanvas *term_tcanvas_new() { +Term_TCanvas +*term_tcanvas_new() +{ - int i; + int i, j; Term_TGlyph *gl; Term_TCanvas *canvas = malloc(sizeof(Term_TCanvas)); canvas->canvas_id = 1; /* change later */ - canvas->rows = 24; /* multiply by a number or scrollback */ + canvas->rows = 24; /* number of rows to show */ canvas->cols = 80; - canvas->scroll_size = 30; /* this means rows * 3 total rows */ - canvas->cur_row = 0; /* between 0 and rows-1 */ - canvas->cur_col = 0; - canvas->grid = calloc(canvas->cols * - canvas->rows * - canvas->scroll_size, sizeof(Term_TGlyph)); - canvas->changed_rows = malloc(canvas->rows * canvas->scroll_size * - sizeof(int)); - + canvas->scroll_size = 500; /* number of rows to keep */ + canvas->grid = calloc(canvas->scroll_size, sizeof(Term_TGlyph *)); + canvas->grid[0] = calloc(canvas->scroll_size * canvas->cols, sizeof(Term_TGlyph)); + canvas->changed_rows = calloc(canvas->scroll_size, sizeof(int)); + + for (i = 0; i < canvas->scroll_size; i++) { + if (i > 0) + canvas->grid[i] = &canvas->grid[i - 1][canvas->cols]; + for (j = 0; j < canvas->cols; j++) { + gl = &canvas->grid[i][j]; + gl->c = '\0'; + gl->changed = 0; + } + } + canvas->scroll_region_start = 0; - canvas->scroll_region_end = canvas->rows -1; - - for(i = 0; i < canvas->rows * canvas->scroll_size; i++) - canvas->changed_rows[i] = 0; - - if(canvas->grid == NULL || canvas->changed_rows == NULL) { + canvas->scroll_region_end = canvas->rows; + + if (canvas->grid == NULL || canvas->changed_rows == NULL) { fprintf(stderr, "Could not allocate memory for grid!"); exit(-1); } - - for(i = 0; i < canvas->cols * canvas->rows * canvas->scroll_size; i++) { - gl = &canvas->grid[i]; - gl->c = '\0'; - gl->changed = 0; - } - + return canvas; } /* * get the max width this font at this size could have */ -int term_font_get_width(Term *term) { +int +term_font_get_width(Term *term) +{ int x, y, w, h; Evas_Object *ob; ob = evas_object_text_add(term->evas); evas_font_path_append(term->evas, term->font.path); evas_object_text_font_set(ob, term->font.face, term->font.size); evas_object_text_text_set(ob, "W"); - evas_object_geometry_get(ob,&x,&y,&w,&h); + evas_object_geometry_get(ob, &x, &y, &w, &h); evas_object_del(ob); return w; } @@ -172,52 +200,65 @@ /* * get the max height this font at this size could have */ -int term_font_get_height(Term *term) { +int +term_font_get_height(Term *term) +{ int x, y, w, h; Evas_Object *ob; ob = evas_object_text_add(term->evas); evas_font_path_append(term->evas, term->font.path); evas_object_text_font_set(ob, term->font.face, term->font.size); evas_object_text_text_set(ob, "W"); - evas_object_geometry_get(ob,&x,&y,&w,&h); + evas_object_geometry_get(ob, &x, &y, &w, &h); evas_object_del(ob); return h; } -Term *term_init(Evas_Object *o) { - int i, j; +Term +*term_init(Evas_Object *o) +{ + int x, y; Evas *evas; - Term_EGlyph *gl; + Term_EGlyph *gl; Term *term; - + term = malloc(sizeof(Term)); evas = evas_object_evas_get(o); term->term_id = 0; term->evas = evas; term->tcanvas = term_tcanvas_new(); - term->grid = calloc(term->tcanvas->cols * term->tcanvas->rows, - sizeof(Term_EGlyph)); - - for(i = 0; - i < term->tcanvas->cols * term->tcanvas->rows; i++) { - gl = &term->grid[i]; - gl->text = evas_object_text_add(term->evas); - gl->bg = evas_object_rectangle_add(term->evas); - evas_object_layer_set(gl->text,2); - evas_object_layer_set(gl->bg,1); - } - + term->cur_row = 0; + term->cur_col = 0; + + term->grid = calloc(term->tcanvas->rows, sizeof(Term_EGlyph *)); + term->grid[0] = calloc(term->tcanvas->rows * term->tcanvas->cols, sizeof(Term_EGlyph)); + for (x = 0; x < term->tcanvas->rows; x++) { + if (x > 0) + term->grid[x] = &term->grid[x - 1][term->tcanvas->cols]; + for (y = 0; y < term->tcanvas->cols; y++) { + gl = &term->grid[x][y]; + gl->text = evas_object_text_add(term->evas); + /* + gl->bg = evas_object_rectangle_add(term->evas); + */ + evas_object_layer_set(gl->text, 2); + /* + evas_object_layer_set(gl->bg, 1); + */ + } + } + term->bg = NULL; strcpy(term->font.path, DATADIR); strcpy(term->font.face, "VeraMono"); term->font.size = 11; - term->data_ptr = 0; + term->data_ptr = 0; term->font.width = term_font_get_width(term); term->font.height = term_font_get_height(term); term->title = NULL; evas_font_path_append(term->evas, term->font.path); - ecore_timer_add(0.01, term_timers, term); + ecore_timer_add(0.01, term_redraw, term); ecore_timer_add(0.095, term_cursor_anim, term); execute_command(term);//, argc, argv); term->cursor.shape = evas_object_rectangle_add(term->evas); @@ -233,6 +274,6 @@ term->w = term->font.width * term->tcanvas->cols; term->h = term->font.height * term->tcanvas->rows; term_term_bg_set(term, DATADIR"black.png"); - + return term; } =================================================================== RCS file: /cvsroot/enlightenment/e17/proto/enterminus/src/bin/term.h,v retrieving revision 1.11 retrieving revision 1.12 diff -u -3 -r1.11 -r1.12 --- term.h 24 Feb 2005 12:31:00 -0000 1.11 +++ term.h 25 Feb 2005 09:21:26 -0000 1.12 @@ -1,3 +1,7 @@ +#define _GNU_SOURCE +#include <stdlib.h> +#include <stdio.h> +#include <ctype.h> #include <assert.h> #include <signal.h> #include <pwd.h> @@ -5,8 +9,6 @@ #include <sys/time.h> #include <sys/wait.h> #include <unistd.h> -#include <stdio.h> -#include <stdlib.h> #include <limits.h> #include <sys/types.h> #include <sys/stat.h> @@ -19,13 +21,13 @@ #include <Ecore_X.h> #include "config.h" -#define DEBUG 1 +#define DEBUG 0 #define NPAR 16 #define DATADIR PACKAGE_DATA_DIR"/" #ifdef DEBUG -#define DPRINT(stuff) fprintf stuff; +#define DPRINT(stuff) fprintf stuff #else #define DPRINT(stuff) #endif @@ -54,7 +56,6 @@ int sys; Ecore_Fd_Handler *ecore; }; - typedef struct _Term_Fd Term_Fd; struct _Term_TGlyph { @@ -63,28 +64,24 @@ int fg; int changed; }; - typedef struct _Term_TGlyph Term_TGlyph; struct _Term_TCanvas { - int canvas_id; - int rows; - int cols; - int cur_row; - int cur_col; - int cur_fg; - int cur_bg; - int *changed_rows; - int saved_cursor_x; - int saved_cursor_y; - int app_keypad_mode; - int scroll_region_start; - int scroll_region_end; - int scroll_in_region; - int scroll_size; - Term_TGlyph *grid; + int canvas_id; + int rows; + int cols; + int cur_fg; + int cur_bg; + int *changed_rows; + int saved_cursor_x; + int saved_cursor_y; + int app_keypad_mode; + int scroll_region_start; + int scroll_region_end; + int scroll_in_region; + int scroll_size; + Term_TGlyph **grid; }; - typedef struct _Term_TCanvas Term_TCanvas; struct _Term_Font { @@ -94,14 +91,14 @@ int width; int height; }; - typedef struct _Term_Font Term_Font; struct _Term_EGlyph { Evas_Object *text; +#if 0 Evas_Object *bg; +#endif }; - typedef struct _Term_EGlyph Term_EGlyph; struct _Term_Cursor { @@ -111,37 +108,38 @@ typedef struct _Term_Cursor Term_Cursor; struct _Term { - int term_id; - pid_t pid; - Ecore_Evas *ee; - Term_TCanvas *tcanvas; - Term_EGlyph *grid; - Evas_Object *bg; - Term_Cursor cursor; - Term_Font font; - Evas *evas; - Term_Fd cmd_fd; - Term_Fd slave; - char data[512]; - int data_ptr; - int data_len; - int font_width; - int font_height; - char *title; - int w; - int h; - int cur_col; - int cur_row; + int term_id; + pid_t pid; + Ecore_Evas *ee; + Term_TCanvas *tcanvas; + Term_EGlyph **grid; + Evas_Object *bg; + Term_Cursor cursor; + Term_Font font; + Evas *evas; + Term_Fd cmd_fd; + Term_Fd slave; + char data[512]; + int data_ptr; + int data_len; + int font_width; + int font_height; + char *title; + int w; + int h; + int cur_col; + int cur_row; }; - typedef struct _Term Term; +Evas_Object *term_new(Evas *evas); Term *term_init(Evas_Object *o); Term_TCanvas *term_tcanvas_new(); -int term_tcanvas_data(void *data); +int term_tcanvas_data(void *data, Ecore_Fd_Handler *fd_handler); void term_tcanvas_glyph_push(Term *term, char c); void term_tcanvas_fg_color_set(Term *term, int c); void term_tcanvas_bg_color_set(Term *term, int c); +char term_tcanvas_data_pop(Term *term); int term_font_get_width(Term *term); int term_font_get_height(Term *term); @@ -151,9 +149,6 @@ void term_cb_key_down(void *data, Evas *e, Evas_Object *obj, void *event_info); void term_cb_resize(Ecore_Evas *ee); -static void strupper(char *str); -int term_timers(void *data); - struct winsize *get_font_dim(Term *term); int get_pty(Term *term); int get_tty(Term *term); @@ -163,7 +158,7 @@ void term_window_init(Ecore_Evas *ee, Evas *evas); void term_term_bg_set(Term *term, char *img); -void term_redraw(void *data); +int term_redraw(void *data); int term_cursor_move_up(Term *term, int n); int term_cursor_move_down(Term *term, int n); =================================================================== RCS file: /cvsroot/enlightenment/e17/proto/enterminus/src/bin/ui.c,v retrieving revision 1.20 retrieving revision 1.21 diff -u -3 -r1.20 -r1.21 --- ui.c 24 Feb 2005 12:31:01 -0000 1.20 +++ ui.c 25 Feb 2005 09:21:26 -0000 1.21 @@ -1,7 +1,8 @@ +/* + * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>3 + */ #include "term.h" -/* TODO: check replace all term->tcanvas->cur* with term->cur* */ - #define COLOR0 255, 255, 255 #define COLOR1 200, 20, 20 #define COLOR2 20, 200, 20 @@ -17,15 +18,17 @@ * that will simply capture keys. This should be set by the application * that uses the smart object */ -void term_term_bg_set(Term *term, char *img) { +void +term_term_bg_set(Term *term, char *img) +{ - if(!term->bg) { + if (!term->bg) { term->bg = evas_object_image_add(term->evas); - evas_object_event_callback_add(term->bg, EVAS_CALLBACK_KEY_DOWN, + evas_object_event_callback_add(term->bg, EVAS_CALLBACK_KEY_DOWN, term_cb_key_down, - term); + term); } - + evas_object_resize(term->bg, term->w, term->h); evas_object_image_file_set(term->bg, img, NULL); evas_object_layer_set(term->bg, 0); @@ -34,17 +37,60 @@ evas_object_show(term->bg); } -/* see what changed chars we have, redraw */ -void term_redraw(void *data) { - int i,i2,j; - int ig = 0; +void +term_update_glyph(Term *term, Term_TGlyph *tgl, Term_EGlyph *gl, int i, int j) +{ char c[2]; - Term *term = data; - Evas_Object *ob; + + c[0] = tgl->c; + c[1] = '\0'; + evas_object_text_font_set(gl->text, term->font.face, term->font.size); + evas_object_text_text_set(gl->text, c); + + /* this is just temp, move it into its own function later */ + switch (tgl->fg) { + case 0: + evas_object_color_set(gl->text, COLOR0, 255); + break; + case 1: + evas_object_color_set(gl->text, COLOR1, 255); + break; + case 2: + evas_object_color_set(gl->text, COLOR2, 255); + break; + case 3: + evas_object_color_set(gl->text, COLOR3, 255); + break; + case 4: + evas_object_color_set(gl->text, COLOR4, 255); + break; + case 5: + evas_object_color_set(gl->text, COLOR5, 255); + break; + case 6: + evas_object_color_set(gl->text, COLOR6, 255); + break; + case 7: + evas_object_color_set(gl->text, COLOR7, 255); + break; + case 8: + evas_object_color_set(gl->text, COLOR8, 255); + break; + } + /* The Layer setting and showing functions need to go away */ + evas_object_move(gl->text, j * term->font.width, i * term->font.height); + tgl->changed = 0; +} + +/* see what changed chars we have, redraw */ +int +term_redraw(void *data) { + int i1, i2, j; + Term *term; Term_EGlyph *gl; - Term_TGlyph *tgl; - - i2 = term->tcanvas->scroll_region_start; + Term_TGlyph *tgl; + + term = data; /* loop over all rows, see what has changed */ /* the general idea is to only inspect as many rows from the tcanvas @@ -53,303 +99,259 @@ * Since i (0 -> rows) cant be used to subscript the current rows, we * start it from scroll_region_start. */ - for(i = 0; i < term->tcanvas->rows; i++) { - if(term->tcanvas->changed_rows[i2] != 1) { - /* unchanged row, increment i2 and continue */ - i2++; + for (i1 = term->tcanvas->scroll_region_start, i2 = 0; + i2 < term->tcanvas->rows; i1++, i2++) { + if (term->tcanvas->changed_rows[i1] != 1) continue; - } - + + if (i1 >= term->tcanvas->scroll_size) + i1 = 0; + /* fetch the text glyph */ - for(j = 0; j < term->tcanvas->cols; j++) { - tgl = &term->tcanvas->grid[j + (term->tcanvas->cols * i2)]; - if(tgl->changed != 1) { - /* unchanged glyph, continue */ + for (j = 0; j < term->tcanvas->cols; j++) { + tgl = &term->tcanvas->grid[i1][j]; + gl = &term->grid[i2][j]; + if (tgl->changed != 1) continue; - } + /* unsure as to why this is here, I dont think we need it */ - if(tgl->c == '\033') { + if (tgl->c == '\033') { printf("Got escape in term_redraw()!\n"); continue; } - - /* check if start pointer has gone past virtual scroll buffer */ - /* when we overflow, we store row numbers in ig */ - if(i + term->tcanvas->scroll_region_start <= (term->tcanvas->rows - 1)*term->tcanvas->scroll_size) { - gl = &term->grid[j + (term->tcanvas->cols * i)]; - } else { - DPRINT((stderr,"Overflowing: [cur_row=%d] [start: %d, end: %d] [ig=%d]\n",term->tcanvas->cur_row,term->tcanvas->scroll_region_start,term->tcanvas->scroll_region_end,ig)); - gl = &term->grid[j + (term->tcanvas->cols * ig)]; - } - - evas_object_text_font_set(gl->text, term->font.face, term->font.size); - c[0] = tgl->c; - c[1] = '\0'; - evas_object_text_text_set(gl->text, c); - - /* this is just temp, move it into its own function later */ - switch(tgl->fg) { - case 0: - evas_object_color_set(gl->text, COLOR0, 255); - break; - case 1: - evas_object_color_set(gl->text, COLOR1, 255); - break; - case 2: - evas_object_color_set(gl->text, COLOR2, 255); - break; - case 3: - evas_object_color_set(gl->text, COLOR3, 255); - break; - case 4: - evas_object_color_set(gl->text, COLOR4, 255); - break; - case 5: - evas_object_color_set(gl->text, COLOR5, 255); - break; - case 6: - evas_object_color_set(gl->text, COLOR6, 255); - break; - case 7: - evas_object_color_set(gl->text, COLOR7, 255); - break; - case 8: - evas_object_color_set(gl->text, COLOR8, 255); - break; - } - /* The Layer setting and showing functions need to go away */ - //evas_object_layer_set(gl->text,2); - evas_object_move(gl->text, j*term->font.width, i*term->font.height); - //evas_object_show(gl->text); - //evas_object_layer_set(gl->bg,1); - //evas_object_move(gl->bg, j*term->font.width, i*term->font.height); - //evas_object_show(gl->bg); - tgl->changed = 0; - + term_update_glyph(term, tgl, gl, i2, j); } - if(i + term->tcanvas->scroll_region_start > (term->tcanvas->rows - 1)*term->tcanvas->scroll_size) { - ig++; - } - - i2++; - term->tcanvas->changed_rows[i] = 0; - } - - /* display cursor, note: this is still sort of a hack */ - evas_object_move(term->cursor.shape, - term->tcanvas->cur_col*term->font.width, - term->cur_row*term->font.height); + term->tcanvas->changed_rows[i1] = 0; + } + return 1; } /* Move cursor up n rows*/ -int term_cursor_move_up(Term *term, int n) { - DPRINT((stderr,"Moving cursor up %d rows\n",n)); - term->tcanvas->cur_row -= n-1; - if(term->tcanvas->cur_row < 0) - term->tcanvas->cur_row = 0; - return term->tcanvas->cur_row; +int +term_cursor_move_up(Term *term, int n) +{ + term->cur_row -= n - 1; + if (term->cur_row < 0) + term->cur_row = 0; + return term->cur_row; } /* Move cursor down n rows */ -int term_cursor_move_down(Term *term, int n) { - DPRINT((stderr,"Moving cursor down %d rows\n",n)); - term->tcanvas->cur_row += n-1; - if(term->tcanvas->cur_row >= term->tcanvas->rows) - term->tcanvas->cur_row = term->tcanvas->rows-1; - return term->tcanvas->cur_row; +int +term_cursor_move_down(Term *term, int n) +{ + term->cur_row += n - 1; + if (term->cur_row >= term->tcanvas->rows) + term->cur_row = term->tcanvas->rows - 1; + return term->cur_row; } /* Move cursor left n cols */ -int term_cursor_move_left(Term *term, int n) { - DPRINT((stderr,"Moving cursor left by %d cols\n",n)); - term->tcanvas->cur_col -= n-1; - if(term->tcanvas->cur_col < 0) - term->tcanvas->cur_col = 0; - return term->tcanvas->cur_col; +int +term_cursor_move_left(Term *term, int n) +{ + term->cur_col -= n - 1; + if (term->cur_col < 0) + term->cur_col = 0; + return term->cur_col; } -/* Move cursor right n cols */ -int term_cursor_move_right(Term *term, int n) { - DPRINT((stderr,"Moving cursor right %d cols\n",n)); - term->tcanvas->cur_col += n-1; - if(term->tcanvas->cur_col >= term->tcanvas->cols) - term->tcanvas->cur_col = term->tcanvas->cols-1; - return term->tcanvas->cur_col; +/* Move cursor right n cols */ +int +term_cursor_move_right(Term *term, int n) +{ + term->cur_col += n - 1; + if(term->cur_col >= term->tcanvas->cols) + term->cur_col = term->tcanvas->cols - 1; + return term->cur_col; } /* Move to a certain col */ -int term_cursor_move_col(Term *term, int n) { - DPRINT((stderr,"Moving cursor to col %d\n",n)); - term->tcanvas->cur_col = n-1; - if(term->tcanvas->cur_col < 0) - term->tcanvas->cur_col = 0; - if(term->tcanvas->cur_col >= term->tcanvas->cols) - term->tcanvas->cur_col = term->tcanvas->cols-1; - return term->tcanvas->cur_col; +int +term_cursor_move_col(Term *term, int n) +{ + term->cur_col = n - 1; + if (term->cur_col < 0) + term->cur_col = 0; + if (term->cur_col >= term->tcanvas->cols) + term->cur_col = term->tcanvas->cols - 1; + return term->cur_col; } /* Move to a certain row */ -int term_cursor_move_row(Term *term, int n) { - DPRINT((stderr,"Moving cursor to row %d\n",n)); - term->tcanvas->cur_row = n-1; - if(term->tcanvas->cur_row < 0) - term->tcanvas->cur_row = 0; - if(term->tcanvas->cur_row >= term->tcanvas->rows) - term->tcanvas->cur_row = term->tcanvas->rows-1; - return term->tcanvas->cur_row; +int +term_cursor_move_row(Term *term, int n) +{ + term->cur_row = n - 1; + if (term->cur_row < 0) + term->cur_row = 0; + if (term->cur_row >= term->tcanvas->rows) + term->cur_row = term->tcanvas->rows - 1; + return term->cur_row; } /* Move cursor to [x,y] */ -void term_cursor_goto(Term *term, int x, int y) { - DPRINT((stderr,"Moving cursor to [%d,%d]\n",x,y)); - term->cur_col = x-1; - term->cur_row = y-1; - if(term->cur_col < 0) - term->cur_col = 0; - if(term->cur_col >= term->tcanvas->cols) - term->cur_col = term->tcanvas->cols-1; - if(term->cur_row < 0) - term->cur_row = 0; - if(term->cur_row >= term->tcanvas->rows) - term->cur_row = term->tcanvas->rows-1; - term->tcanvas->cur_col = term->cur_col; - term->tcanvas->cur_row = term->tcanvas->scroll_region_start +term->cur_row; +void +term_cursor_goto(Term *term, int x, int y) +{ + term->cur_col = x - 1; + term->cur_row = y - 1; + if (term->cur_col < 0) + term->cur_col = 0; + if (term->cur_col >= term->tcanvas->cols) + term->cur_col = term->tcanvas->cols - 1; + if (term->cur_row < 0) + term->cur_row = 0; + if (term->cur_row >= term->tcanvas->rows) + term->cur_row = term->tcanvas->rows - 1; } /* Move cursor again to last saved [x,y] */ -void term_cursor_rego(Term *term) { - DPRINT((stderr,"Re-going cursor to last saved position\n")); - term_cursor_goto(term, term->tcanvas->cur_col, term->tcanvas->cur_row); +void +term_cursor_rego(Term *term) +{ + term_cursor_goto(term, term->cur_col, term->cur_row); } /* Delete n rows starting from start */ -void term_delete_rows(Term *term, int start, int n) { - int i; - DPRINT((stderr,"Deleting %d rows from %d\n",n,start)); +void +term_delete_rows(Term *term, int start, int n) +{ } /* Add n rows starting from pos */ -void term_add_rows(Term *term, int pos, int n) { - DPRINT((stderr,"Adding %d rows from %d\n",n,pos)); +void +term_add_rows(Term *term, int pos, int n) +{ } /* Save the current screen */ -void term_tcanvas_save(Term *term) { - DPRINT((stderr,"Saving current screen\n")); +void +term_tcanvas_save(Term *term) +{ } /* Restore the last saved screen */ -void term_tcanvas_restore(Term *term) { - DPRINT((stderr,"Restoring current screen\n")); +void +term_tcanvas_restore(Term *term) +{ } /* clear a certain part of the screen */ -void term_clear_area(Term *term, int x1, int y1, int x2, int y2) { - int i, j; +void +term_clear_area(Term *term, int x1, int y1, int x2, int y2) +{ + int i, j, x; Term_TGlyph *tgl; - /* TODO: Finalize this shit before shipping code out */ - x1--;y1--;x2--;y2--; - if(x1 < 0) x1 = 0; if(x1 > term->tcanvas->cols) x1 = term->tcanvas->cols; - if(y1 < 0) y1 = 0; if(y1 > term->tcanvas->rows) y1 = term->tcanvas->rows; - if(x2 < 0) x2 = 0; if(x2 > term->tcanvas->cols) x2 = term->tcanvas->cols; - if(y2 < 0) y2 = 0; if(y2 > term->tcanvas->rows) y2 = term->tcanvas->rows; - DPRINT((stderr,"Clearing: %d %d, %d %d\n",x1,y1+term->tcanvas->scroll_region_start,x2,y2+term->tcanvas->scroll_region_start)); - for(i = y1; i <= y2; i++) { - for(j = x1; j <= x2; j++) { - tgl = &term->tcanvas->grid[j + (term->tcanvas->cols * (i + term->tcanvas->scroll_region_start))]; - if(tgl->c != ' ' && tgl->c != '\0') { + /* Points are given in 1-indexed numbers, we work with 0-indexed */ + x1--; y1--; x2--; y2--; + + if (x1 < 0) x1 = 0; + if (x1 > term->tcanvas->cols) x1 = term->tcanvas->cols; + if (y1 < 0) y1 = 0; + if (y1 > term->tcanvas->rows) y1 = term->tcanvas->rows; + y1 += term->tcanvas->scroll_region_start; + if (x2 < 0) x2 = 0; + if (x2 > term->tcanvas->cols) x2 = term->tcanvas->cols; + if (y2 < 0) y2 = 0; + if (y2 > term->tcanvas->rows) y2 = term->tcanvas->rows; + y2 += term->tcanvas->scroll_region_start; + + DPRINT((stderr, "Clearing: %d %d, %d %d\n", x1, y1, x2, y2)); + for (i = y1; i < y2; i++) { + for (j = x1; j < x2; j++) { + x = i; + if (x >= term->tcanvas->scroll_size) + x -= term->tcanvas->scroll_size; + tgl = &term->tcanvas->grid[x][j]; + if (tgl->c != ' ' && tgl->c != '\0') { tgl->c = '\0'; tgl->changed = 1; - term->tcanvas->changed_rows[i + term->tcanvas->scroll_region_start] = 1; + term->tcanvas->changed_rows[x] = 1; } - } + } } } /* scroll window / region upwards */ -void term_scroll_up(Term *term, int rows) { - - - int i, i2, j; - int x,y; - Term_TGlyph *gl; +void +term_scroll_up(Term *term, int rows) +{ + int i, j; + Term_TGlyph *gl; - if(term->tcanvas->scroll_in_region) { + if (term->tcanvas->scroll_in_region) { /* TODO: implement this */ DPRINT((stderr,"Scrolling: in region between %d and %d\n", term->tcanvas->scroll_region_start, term->tcanvas->scroll_region_end)); - } else { - DPRINT((stderr,"Scrolling: window\n")); - /* Going past the virtual scroll buffer, we need to wrap */ - if(term->tcanvas->scroll_region_end + rows > - (term->tcanvas->rows-1) * term->tcanvas->scroll_size) { - DPRINT((stderr,"End gone past max scroll buffer, wrapping\n")); - term->tcanvas->scroll_region_end = rows - (((term->tcanvas->rows-1) * - term->tcanvas->scroll_size) - term->tcanvas->scroll_region_end); + DPRINT((stderr, "Scrolling: window\n")); + term->tcanvas->scroll_region_end += rows; + if (term->tcanvas->scroll_region_end >= term->tcanvas->scroll_size) { + /* Going past the virtual scroll buffer, we need to wrap */ + DPRINT((stderr, "End gone past max scroll buffer, wrapping\n")); + term->tcanvas->scroll_region_end -= term->tcanvas->scroll_size; /* we're going back to the top, clear the rows we want to overwrite */ - for(i = 0; i <= term->tcanvas->scroll_region_end; i++) { + for (i = 0; i < term->tcanvas->scroll_region_end; i++) { term->tcanvas->changed_rows[i] = 1; - for(j = 0; j <= term->tcanvas->cols; j++) { - gl = & term->tcanvas->grid[j + (term->tcanvas->cols * i)]; + for (j = 0; j < term->tcanvas->cols; j++) { + gl = &term->tcanvas->grid[i][j]; gl->c = ' '; gl->changed = 1; } } - } else { - /* normal scrolling */ - term->tcanvas->scroll_region_end+=rows; } - - /* Start pointer going past virtual scroll buffer */ - if(term->tcanvas->scroll_region_start + rows > - (term->tcanvas->rows-1) * term->tcanvas->scroll_size) { + + term->tcanvas->scroll_region_start += rows; + if (term->tcanvas->scroll_region_start >= term->tcanvas->scroll_size) { + /* Start pointer going past virtual scroll buffer */ DPRINT((stderr,"Start gone past scroll area max, going back to start\n")); - term->tcanvas->scroll_region_start = rows - (((term->tcanvas->rows-1) * - term->tcanvas->scroll_size) - term->tcanvas->scroll_region_start); - } else { - /* normal scrolling */ - term->tcanvas->scroll_region_start+= rows; + term->tcanvas->scroll_region_start -= term->tcanvas->scroll_size; } - + /* set changed flags on chars */ /* if start and end are havent gone past virtual scroll buffer */ - if(term->tcanvas->scroll_region_start < term->tcanvas->scroll_region_end) - i2 = term->tcanvas->scroll_region_end; - else { + if (term->tcanvas->scroll_region_start < term->tcanvas->scroll_region_end) { + for (i = term->tcanvas->scroll_region_start; i < term->tcanvas->scroll_region_end; i++) { + term->tcanvas->changed_rows[i] = 1; + for (j = 0; j < term->tcanvas->cols; j++) { + gl = &term->tcanvas->grid[i][j]; + gl->changed = 1; + } + } + } else { /* we now have two areas to modify: * the first being at the end of the virtual scroll buffer * the second being at the start */ - for(i = 0; i <= term->tcanvas->scroll_region_end; i++) { + for (i = 0; i < term->tcanvas->scroll_region_end; i++) { term->tcanvas->changed_rows[i] = 1; - for(j = 0; j <= term->tcanvas->cols; j++) { - gl = & term->tcanvas->grid[j + (term->tcanvas->cols * i)]; + for(j = 0; j < term->tcanvas->cols; j++) { + gl = &term->tcanvas->grid[i][j]; gl->changed = 1; - } - } - i2 = (term->tcanvas->rows - 1) * term->tcanvas->scroll_size; - } - - /* set changed flag from start until determined end */ - for(i = term->tcanvas->scroll_region_start; i <= i2; i++) { - term->tcanvas->changed_rows[i] = 1; - for(j = 0; j <= term->tcanvas->cols; j++) { - gl = & term->tcanvas->grid[j + (term->tcanvas->cols * i)]; - gl->changed = 1; + } + for (i = term->tcanvas->scroll_region_start; i < term->tcanvas->scroll_size; i++) { + term->tcanvas->changed_rows[i] = 1; + for(j = 0; j < term->tcanvas->cols; j++) { + gl = &term->tcanvas->grid[i][j]; + gl->changed = 1; + } + } } } } } /* scroll window / region down */ -void term_scroll_down(Term *term, int rows) { - if(term->tcanvas->scroll_in_region) { - DPRINT((stderr,"Scrolling: in region\n")); +void +term_scroll_down(Term *term, int rows) +{ + if (term->tcanvas->scroll_in_region) { + } else { - DPRINT((stderr,"Scrolling: window\n")); + } } @@ -364,7 +366,7 @@ int a, b; a = term->tcanvas->scroll_region_start; b = term->tcanvas->scroll_in_region; - term->tcanvas->scroll_region_start = term->tcanvas->cur_row; + term->tcanvas->scroll_region_start = term->cur_row; term->tcanvas->scroll_in_region = 0; term_scroll_up(term, lines); term->tcanvas->scroll_region_start = a; ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs