diff options
author | bfredl <bjorn.linse@gmail.com> | 2022-05-09 00:44:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-09 00:44:33 +0200 |
commit | f6be28c61a66df1bd88e5aac3d2c20792c541e18 (patch) | |
tree | 4b90720ec4c2b365db3d49c0a9b3c0d74ad1df96 /src/nvim/grid.h | |
parent | 6cfb1d4c280a90bcce4e793f56d791b68c66c264 (diff) | |
parent | df41d884a7b788bb38060e732f1a7abb08de7b1b (diff) | |
download | rneovim-f6be28c61a66df1bd88e5aac3d2c20792c541e18.tar.gz rneovim-f6be28c61a66df1bd88e5aac3d2c20792c541e18.tar.bz2 rneovim-f6be28c61a66df1bd88e5aac3d2c20792c541e18.zip |
Merge pull request #18478 from bfredl/gridfile
refactor(grid): move out grid_* functions from screen.c
Diffstat (limited to 'src/nvim/grid.h')
-rw-r--r-- | src/nvim/grid.h | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/nvim/grid.h b/src/nvim/grid.h new file mode 100644 index 0000000000..12a5bf95bb --- /dev/null +++ b/src/nvim/grid.h @@ -0,0 +1,57 @@ +#ifndef NVIM_GRID_H +#define NVIM_GRID_H + +#include <stdbool.h> + +#include "nvim/ascii.h" +#include "nvim/grid_defs.h" +#include "nvim/buffer_defs.h" + +/// By default, all windows are drawn on a single rectangular grid, represented by +/// this ScreenGrid instance. In multigrid mode each window will have its own +/// grid, then this is only used for global screen elements that hasn't been +/// externalized. +/// +/// Note: before the screen is initialized and when out of memory these can be +/// NULL. +EXTERN ScreenGrid default_grid INIT(= SCREEN_GRID_INIT); + +#define DEFAULT_GRID_HANDLE 1 // handle for the default_grid + +EXTERN schar_T *linebuf_char INIT(= NULL); +EXTERN sattr_T *linebuf_attr INIT(= NULL); + +// Low-level functions to manipulate individual character cells on the +// screen grid. + +/// Put a ASCII character in a screen cell. +static inline void schar_from_ascii(char_u *p, const char c) +{ + p[0] = (char_u)c; + p[1] = 0; +} + +/// Put a unicode character in a screen cell. +static inline int schar_from_char(char_u *p, int c) +{ + int len = utf_char2bytes(c, p); + p[len] = NUL; + return len; +} + +/// compare the contents of two screen cells. +static inline int schar_cmp(char_u *sc1, char_u *sc2) +{ + return strncmp((char *)sc1, (char *)sc2, sizeof(schar_T)); +} + +/// copy the contents of screen cell `sc2` into cell `sc1` +static inline void schar_copy(char_u *sc1, char_u *sc2) +{ + xstrlcpy((char *)sc1, (char *)sc2, sizeof(schar_T)); +} + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "grid.h.generated.h" +#endif +#endif // NVIM_GRID_H |