aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/grid.h
blob: deb3d3785daff932c2d6a05bf583ea7a1c9a67e5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef NVIM_GRID_H
#define NVIM_GRID_H

#include <stdbool.h>
#include <string.h>

#include "nvim/ascii.h"
#include "nvim/buffer_defs.h"
#include "nvim/grid_defs.h"
#include "nvim/macros.h"
#include "nvim/mbyte.h"
#include "nvim/memory.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

/// While resizing the screen this flag is set.
EXTERN bool resizing_screen INIT(= 0);

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 *p, const char c)
{
  p[0] = c;
  p[1] = 0;
}

/// Put a unicode character in a screen cell.
static inline int schar_from_char(char *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 *sc1, char *sc2)
{
  return strncmp(sc1, sc2, sizeof(schar_T));
}

/// copy the contents of screen cell `sc2` into cell `sc1`
static inline void schar_copy(char *sc1, char *sc2)
{
  xstrlcpy(sc1, sc2, sizeof(schar_T));
}

#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "grid.h.generated.h"
#endif
#endif  // NVIM_GRID_H