diff options
author | Utkarsh Maheshwari <utkarshme96@gmail.com> | 2018-08-17 17:40:04 +0530 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2018-12-31 12:44:22 +0100 |
commit | 911b731378954dd0fa0448cc02b95d576cdfc3c5 (patch) | |
tree | 9239d05596e32f53d9075c5a95cc676e521b86a8 /src | |
parent | 0432e1586ef0f9dd5e473cee07787ed5bb880570 (diff) | |
download | rneovim-911b731378954dd0fa0448cc02b95d576cdfc3c5.tar.gz rneovim-911b731378954dd0fa0448cc02b95d576cdfc3c5.tar.bz2 rneovim-911b731378954dd0fa0448cc02b95d576cdfc3c5.zip |
multigrid: Get rid of global ScreenLines and set_screengrid
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/vim.c | 10 | ||||
-rw-r--r-- | src/nvim/edit.c | 2 | ||||
-rw-r--r-- | src/nvim/eval.c | 14 | ||||
-rw-r--r-- | src/nvim/globals.h | 17 | ||||
-rw-r--r-- | src/nvim/highlight.c | 6 | ||||
-rw-r--r-- | src/nvim/mbyte.c | 11 | ||||
-rw-r--r-- | src/nvim/mouse.c | 5 | ||||
-rw-r--r-- | src/nvim/screen.c | 37 |
8 files changed, 43 insertions, 59 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index ecfff1ea8f..82a61b43bd 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1920,13 +1920,13 @@ Object nvim_get_proc(Integer pid, Error *err) Array nvim__inspect_cell(Integer row, Integer col, Error *err) { Array ret = ARRAY_DICT_INIT; - if (row < 0 || row >= screen_Rows - || col < 0 || col >= screen_Columns) { + if (row < 0 || row >= default_grid.Rows + || col < 0 || col >= default_grid.Columns) { return ret; } - size_t off = LineOffset[(size_t)row] + (size_t)col; - ADD(ret, STRING_OBJ(cstr_to_string((char *)ScreenLines[off]))); - int attr = ScreenAttrs[off]; + size_t off = default_grid.LineOffset[(size_t)row] + (size_t)col; + ADD(ret, STRING_OBJ(cstr_to_string((char *)default_grid.ScreenLines[off]))); + int attr = default_grid.ScreenAttrs[off]; ADD(ret, DICTIONARY_OBJ(hl_get_attr_by_id(attr, true, err))); // will not work first time if (!highlight_use_hlstate()) { diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 14577d5abb..0cc64f6965 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -1494,7 +1494,7 @@ void edit_putchar(int c, int highlight) { int attr; - if (ScreenLines != NULL) { + if (default_grid.ScreenLines != NULL) { update_topline(); /* just in case w_topline isn't valid */ validate_cursor(); if (highlight) { diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 6fe62f1a87..957a8c4ef1 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -14023,11 +14023,11 @@ static void f_screenattr(typval_T *argvars, typval_T *rettv, FunPtr fptr) const int row = (int)tv_get_number_chk(&argvars[0], NULL) - 1; const int col = (int)tv_get_number_chk(&argvars[1], NULL) - 1; - if (row < 0 || row >= screen_Rows - || col < 0 || col >= screen_Columns) { + if (row < 0 || row >= default_grid.Rows + || col < 0 || col >= default_grid.Columns) { c = -1; } else { - c = ScreenAttrs[LineOffset[row] + col]; + c = default_grid.ScreenAttrs[default_grid.LineOffset[row] + col]; } rettv->vval.v_number = c; } @@ -14042,12 +14042,12 @@ static void f_screenchar(typval_T *argvars, typval_T *rettv, FunPtr fptr) const int row = tv_get_number_chk(&argvars[0], NULL) - 1; const int col = tv_get_number_chk(&argvars[1], NULL) - 1; - if (row < 0 || row >= screen_Rows - || col < 0 || col >= screen_Columns) { + if (row < 0 || row >= default_grid.Rows + || col < 0 || col >= default_grid.Columns) { c = -1; } else { - off = LineOffset[row] + col; - c = utf_ptr2char(ScreenLines[off]); + off = default_grid.LineOffset[row] + col; + c = utf_ptr2char(default_grid.ScreenLines[off]); } rettv->vval.v_number = c; } diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 7e17136528..317ae8f41a 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -91,9 +91,10 @@ EXTERN struct nvim_stats_s { /* * Number of Rows and Columns in the screen. * Must be long to be able to use them as options in option.c. - * Note: Use screen_Rows and screen_Columns to access items in ScreenLines[]. - * They may have different values when the screen wasn't (re)allocated yet - * after setting Rows or Columns (e.g., when starting up). + * Note: Use default_grid.Rows and default_grid.Columns to access items in + * default_grid.ScreenLines[]. They may have different values when the screen + * wasn't (re)allocated yet after setting Rows or Columns (e.g., when starting + * up). */ #define DFLT_COLS 80 // default value for 'columns' #define DFLT_ROWS 24 // default value for 'lines' @@ -150,17 +151,11 @@ typedef off_t off_T; /// to the next line. It can only be true if a window occupies the entire screen /// width. /// +/// These, with other related attributes, are stored in a "ScreenGrid" +/// datastructure. /// /// Note: before the screen is initialized and when out of memory these can be /// NULL. -EXTERN schar_T *ScreenLines INIT(= NULL); -EXTERN sattr_T *ScreenAttrs INIT(= NULL); -EXTERN unsigned *LineOffset INIT(= NULL); -EXTERN char_u *LineWraps INIT(= NULL); /* line wraps to next line */ - -EXTERN int screen_Rows INIT(= 0); /* actual size of ScreenLines[] */ -EXTERN int screen_Columns INIT(= 0); /* actual size of ScreenLines[] */ - EXTERN ScreenGrid default_grid INIT(= { 0, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0 }); diff --git a/src/nvim/highlight.c b/src/nvim/highlight.c index 5a9727f46e..cbc230b65a 100644 --- a/src/nvim/highlight.c +++ b/src/nvim/highlight.c @@ -213,11 +213,11 @@ void clear_hl_tables(bool reinit) highlight_attr_set_all(); highlight_changed(); redraw_all_later(NOT_VALID); - if (ScreenAttrs) { + if (default_grid.ScreenAttrs) { // the meaning of 0 doesn't change anyway // but the rest must be retransmitted - memset(ScreenAttrs, 0, - sizeof(*ScreenAttrs) * (size_t)(screen_Rows * screen_Columns)); + memset(default_grid.ScreenAttrs, 0, sizeof(*default_grid.ScreenAttrs) + * (size_t)(default_grid.Rows * default_grid.Columns)); } } else { kv_destroy(attr_entries); diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index 0ee8e2bd85..c0c36717e2 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -560,7 +560,8 @@ size_t mb_string2cells(const char_u *str) /// We make sure that the offset used is less than "max_off". int utf_off2cells(unsigned off, unsigned max_off) { - return (off + 1 < max_off && ScreenLines[off + 1][0] == 0) ? 2 : 1; + return (off + 1 < max_off + && default_grid.ScreenLines[off + 1][0] == 0) ? 2 : 1; } /// Convert a UTF-8 byte sequence to a wide character @@ -1829,8 +1830,8 @@ const char *mb_unescape(const char **const pp) */ bool mb_lefthalve(int row, int col) { - return utf_off2cells(LineOffset[row] + col, - LineOffset[row] + screen_Columns) > 1; + return utf_off2cells(default_grid.LineOffset[row] + col, + default_grid.LineOffset[row] + screen_Columns) > 1; } /* @@ -1841,8 +1842,8 @@ int mb_fix_col(int col, int row) { col = check_col(col); row = check_row(row); - if (ScreenLines != NULL && col > 0 - && ScreenLines[LineOffset[row] + col][0] == 0) { + if (default_grid.ScreenLines != NULL && col > 0 + && default_grid.ScreenLines[default_grid.LineOffset[row] + col][0] == 0) { return col - 1; } return col; diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c index 3c792326a4..bd19f54b3d 100644 --- a/src/nvim/mouse.c +++ b/src/nvim/mouse.c @@ -110,8 +110,9 @@ retnomove: // Remember the character under the mouse, it might be a '-' or '+' in the // fold column. NB: only works for ASCII chars! if (row >= 0 && row < Rows && col >= 0 && col <= Columns - && ScreenLines != NULL) { - mouse_char = ScreenLines[LineOffset[row] + (unsigned)col][0]; + && default_grid.ScreenLines != NULL) { + mouse_char = default_grid.ScreenLines[default_grid.LineOffset[row] + + (unsigned)col][0]; } else { mouse_char = ' '; } diff --git a/src/nvim/screen.c b/src/nvim/screen.c index c248977df5..f00fe5d338 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -2021,8 +2021,8 @@ static void copy_text_attr(int off, char_u *buf, int len, int attr) int i; for (i = 0; i < len; i++) { - schar_from_ascii(ScreenLines[off + i], buf[i]); - ScreenAttrs[off + i] = attr; + schar_from_ascii(default_grid.ScreenLines[off + i], buf[i]); + default_grid.ScreenAttrs[off + i] = attr; } } @@ -5967,13 +5967,14 @@ void grid_assign_handle(ScreenGrid *grid) /* * Resize the shell to Rows and Columns. - * Allocate ScreenLines[] and associated items. + * Allocate default_grid.ScreenLines[] and associated items. * * There may be some time between setting Rows and Columns and (re)allocating - * ScreenLines[]. This happens when starting up and when (manually) changing - * the shell size. Always use screen_Rows and screen_Columns to access items - * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the - * final size of the shell is needed. + * default_grid.ScreenLines[]. This happens when starting up and when + * (manually) changing the shell size. Always use default_grid.Rows and + * default_grid.Columns to access items in default_grid.ScreenLines[]. Use Rows + * and Columns for positioning text etc. where the final size of the shell is + * needed. */ void screenalloc(bool doclear) { @@ -6044,16 +6045,9 @@ retry: clear_tab_page_click_defs(tab_page_click_defs, tab_page_click_defs_size); xfree(tab_page_click_defs); - set_screengrid(&default_grid); - tab_page_click_defs = new_tab_page_click_defs; tab_page_click_defs_size = default_grid.Columns; - /* It's important that screen_Rows and screen_Columns reflect the actual - * size of ScreenLines[]. Set them before calling anything. */ - screen_Rows = default_grid.Rows; - screen_Columns = default_grid.Columns; - default_grid.OffsetRow = 0; default_grid.OffsetColumn = 0; default_grid.handle = DEFAULT_GRID_HANDLE; @@ -6129,14 +6123,6 @@ void free_screengrid(ScreenGrid *grid) xfree(grid->LineWraps); } -void set_screengrid(ScreenGrid *grid) -{ - ScreenLines = grid->ScreenLines; - ScreenAttrs = grid->ScreenAttrs; - LineOffset = grid->LineOffset; - LineWraps = grid->LineWraps; -} - /// Clear tab_page_click_defs table /// /// @param[out] tpcd Table to clear. @@ -6165,14 +6151,15 @@ static void screenclear2(void) { int i; - if (starting == NO_SCREEN || ScreenLines == NULL) { + if (starting == NO_SCREEN || default_grid.ScreenLines == NULL) { return; } /* blank out ScreenLines */ for (i = 0; i < default_grid.Rows; ++i) { - grid_clear_line(&default_grid, LineOffset[i], (int)default_grid.Columns, true); - LineWraps[i] = FALSE; + grid_clear_line(&default_grid, default_grid.LineOffset[i], + (int)default_grid.Columns, true); + default_grid.LineWraps[i] = FALSE; } ui_call_grid_clear(1); // clear the display |