multigrid: Get rid of global ScreenLines and set_screengrid

This commit is contained in:
Utkarsh Maheshwari
2018-08-17 17:40:04 +05:30
committed by Björn Linse
parent 0432e1586e
commit 911b731378
8 changed files with 43 additions and 59 deletions

View File

@@ -1920,13 +1920,13 @@ Object nvim_get_proc(Integer pid, Error *err)
Array nvim__inspect_cell(Integer row, Integer col, Error *err) Array nvim__inspect_cell(Integer row, Integer col, Error *err)
{ {
Array ret = ARRAY_DICT_INIT; Array ret = ARRAY_DICT_INIT;
if (row < 0 || row >= screen_Rows if (row < 0 || row >= default_grid.Rows
|| col < 0 || col >= screen_Columns) { || col < 0 || col >= default_grid.Columns) {
return ret; return ret;
} }
size_t off = LineOffset[(size_t)row] + (size_t)col; size_t off = default_grid.LineOffset[(size_t)row] + (size_t)col;
ADD(ret, STRING_OBJ(cstr_to_string((char *)ScreenLines[off]))); ADD(ret, STRING_OBJ(cstr_to_string((char *)default_grid.ScreenLines[off])));
int attr = ScreenAttrs[off]; int attr = default_grid.ScreenAttrs[off];
ADD(ret, DICTIONARY_OBJ(hl_get_attr_by_id(attr, true, err))); ADD(ret, DICTIONARY_OBJ(hl_get_attr_by_id(attr, true, err)));
// will not work first time // will not work first time
if (!highlight_use_hlstate()) { if (!highlight_use_hlstate()) {

View File

@@ -1494,7 +1494,7 @@ void edit_putchar(int c, int highlight)
{ {
int attr; int attr;
if (ScreenLines != NULL) { if (default_grid.ScreenLines != NULL) {
update_topline(); /* just in case w_topline isn't valid */ update_topline(); /* just in case w_topline isn't valid */
validate_cursor(); validate_cursor();
if (highlight) { if (highlight) {

View File

@@ -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 row = (int)tv_get_number_chk(&argvars[0], NULL) - 1;
const int col = (int)tv_get_number_chk(&argvars[1], NULL) - 1; const int col = (int)tv_get_number_chk(&argvars[1], NULL) - 1;
if (row < 0 || row >= screen_Rows if (row < 0 || row >= default_grid.Rows
|| col < 0 || col >= screen_Columns) { || col < 0 || col >= default_grid.Columns) {
c = -1; c = -1;
} else { } else {
c = ScreenAttrs[LineOffset[row] + col]; c = default_grid.ScreenAttrs[default_grid.LineOffset[row] + col];
} }
rettv->vval.v_number = c; 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 row = tv_get_number_chk(&argvars[0], NULL) - 1;
const int col = tv_get_number_chk(&argvars[1], NULL) - 1; const int col = tv_get_number_chk(&argvars[1], NULL) - 1;
if (row < 0 || row >= screen_Rows if (row < 0 || row >= default_grid.Rows
|| col < 0 || col >= screen_Columns) { || col < 0 || col >= default_grid.Columns) {
c = -1; c = -1;
} else { } else {
off = LineOffset[row] + col; off = default_grid.LineOffset[row] + col;
c = utf_ptr2char(ScreenLines[off]); c = utf_ptr2char(default_grid.ScreenLines[off]);
} }
rettv->vval.v_number = c; rettv->vval.v_number = c;
} }

View File

@@ -91,9 +91,10 @@ EXTERN struct nvim_stats_s {
/* /*
* Number of Rows and Columns in the screen. * Number of Rows and Columns in the screen.
* Must be long to be able to use them as options in option.c. * 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[]. * Note: Use default_grid.Rows and default_grid.Columns to access items in
* They may have different values when the screen wasn't (re)allocated yet * default_grid.ScreenLines[]. They may have different values when the screen
* after setting Rows or Columns (e.g., when starting up). * 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_COLS 80 // default value for 'columns'
#define DFLT_ROWS 24 // default value for 'lines' #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 /// to the next line. It can only be true if a window occupies the entire screen
/// width. /// 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 /// Note: before the screen is initialized and when out of memory these can be
/// NULL. /// 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, EXTERN ScreenGrid default_grid INIT(= { 0, NULL, NULL, NULL, NULL, 0, 0, 0, 0,
0, 0 }); 0, 0 });

View File

@@ -213,11 +213,11 @@ void clear_hl_tables(bool reinit)
highlight_attr_set_all(); highlight_attr_set_all();
highlight_changed(); highlight_changed();
redraw_all_later(NOT_VALID); redraw_all_later(NOT_VALID);
if (ScreenAttrs) { if (default_grid.ScreenAttrs) {
// the meaning of 0 doesn't change anyway // the meaning of 0 doesn't change anyway
// but the rest must be retransmitted // but the rest must be retransmitted
memset(ScreenAttrs, 0, memset(default_grid.ScreenAttrs, 0, sizeof(*default_grid.ScreenAttrs)
sizeof(*ScreenAttrs) * (size_t)(screen_Rows * screen_Columns)); * (size_t)(default_grid.Rows * default_grid.Columns));
} }
} else { } else {
kv_destroy(attr_entries); kv_destroy(attr_entries);

View File

@@ -560,7 +560,8 @@ size_t mb_string2cells(const char_u *str)
/// We make sure that the offset used is less than "max_off". /// We make sure that the offset used is less than "max_off".
int utf_off2cells(unsigned off, unsigned 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 /// 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) bool mb_lefthalve(int row, int col)
{ {
return utf_off2cells(LineOffset[row] + col, return utf_off2cells(default_grid.LineOffset[row] + col,
LineOffset[row] + screen_Columns) > 1; default_grid.LineOffset[row] + screen_Columns) > 1;
} }
/* /*
@@ -1841,8 +1842,8 @@ int mb_fix_col(int col, int row)
{ {
col = check_col(col); col = check_col(col);
row = check_row(row); row = check_row(row);
if (ScreenLines != NULL && col > 0 if (default_grid.ScreenLines != NULL && col > 0
&& ScreenLines[LineOffset[row] + col][0] == 0) { && default_grid.ScreenLines[default_grid.LineOffset[row] + col][0] == 0) {
return col - 1; return col - 1;
} }
return col; return col;

View File

@@ -110,8 +110,9 @@ retnomove:
// Remember the character under the mouse, it might be a '-' or '+' in the // Remember the character under the mouse, it might be a '-' or '+' in the
// fold column. NB: only works for ASCII chars! // fold column. NB: only works for ASCII chars!
if (row >= 0 && row < Rows && col >= 0 && col <= Columns if (row >= 0 && row < Rows && col >= 0 && col <= Columns
&& ScreenLines != NULL) { && default_grid.ScreenLines != NULL) {
mouse_char = ScreenLines[LineOffset[row] + (unsigned)col][0]; mouse_char = default_grid.ScreenLines[default_grid.LineOffset[row]
+ (unsigned)col][0];
} else { } else {
mouse_char = ' '; mouse_char = ' ';
} }

View File

@@ -2021,8 +2021,8 @@ static void copy_text_attr(int off, char_u *buf, int len, int attr)
int i; int i;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
schar_from_ascii(ScreenLines[off + i], buf[i]); schar_from_ascii(default_grid.ScreenLines[off + i], buf[i]);
ScreenAttrs[off + i] = attr; default_grid.ScreenAttrs[off + i] = attr;
} }
} }
@@ -5967,13 +5967,14 @@ void grid_assign_handle(ScreenGrid *grid)
/* /*
* Resize the shell to Rows and Columns. * 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 * There may be some time between setting Rows and Columns and (re)allocating
* ScreenLines[]. This happens when starting up and when (manually) changing * default_grid.ScreenLines[]. This happens when starting up and when
* the shell size. Always use screen_Rows and screen_Columns to access items * (manually) changing the shell size. Always use default_grid.Rows and
* in ScreenLines[]. Use Rows and Columns for positioning text etc. where the * default_grid.Columns to access items in default_grid.ScreenLines[]. Use Rows
* final size of the shell is needed. * and Columns for positioning text etc. where the final size of the shell is
* needed.
*/ */
void screenalloc(bool doclear) void screenalloc(bool doclear)
{ {
@@ -6044,16 +6045,9 @@ retry:
clear_tab_page_click_defs(tab_page_click_defs, tab_page_click_defs_size); clear_tab_page_click_defs(tab_page_click_defs, tab_page_click_defs_size);
xfree(tab_page_click_defs); xfree(tab_page_click_defs);
set_screengrid(&default_grid);
tab_page_click_defs = new_tab_page_click_defs; tab_page_click_defs = new_tab_page_click_defs;
tab_page_click_defs_size = default_grid.Columns; 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.OffsetRow = 0;
default_grid.OffsetColumn = 0; default_grid.OffsetColumn = 0;
default_grid.handle = DEFAULT_GRID_HANDLE; default_grid.handle = DEFAULT_GRID_HANDLE;
@@ -6129,14 +6123,6 @@ void free_screengrid(ScreenGrid *grid)
xfree(grid->LineWraps); 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 /// Clear tab_page_click_defs table
/// ///
/// @param[out] tpcd Table to clear. /// @param[out] tpcd Table to clear.
@@ -6165,14 +6151,15 @@ static void screenclear2(void)
{ {
int i; int i;
if (starting == NO_SCREEN || ScreenLines == NULL) { if (starting == NO_SCREEN || default_grid.ScreenLines == NULL) {
return; return;
} }
/* blank out ScreenLines */ /* blank out ScreenLines */
for (i = 0; i < default_grid.Rows; ++i) { for (i = 0; i < default_grid.Rows; ++i) {
grid_clear_line(&default_grid, LineOffset[i], (int)default_grid.Columns, true); grid_clear_line(&default_grid, default_grid.LineOffset[i],
LineWraps[i] = FALSE; (int)default_grid.Columns, true);
default_grid.LineWraps[i] = FALSE;
} }
ui_call_grid_clear(1); // clear the display ui_call_grid_clear(1); // clear the display