-
Notifications
You must be signed in to change notification settings - Fork 4
/
state_p.hh
47 lines (35 loc) · 1.24 KB
/
state_p.hh
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
#ifndef PUTTY_STATE_P_HH_INCLUDE
#define PUTTY_STATE_P_HH_INCLUDE
#include <putty/state.hh>
namespace Putty
{
static inline bool is_valid_row(const State &state, size_t row)
{
size_t row_index = row + state.buffer_size;
return row_index < state.rows.size();
}
static inline const Row *get_row(const State &state, size_t row)
{
if (!is_valid_row(state, row))
return nullptr;
return &state.rows[row + state.buffer_size];
}
static inline bool is_valid_cell(const State &state, size_t row, size_t col)
{
return is_valid_row(state, row) && (col < state.rows[row + state.buffer_size].cells.size());
}
static inline const Cell *get_cell(const State &state, size_t row, size_t col)
{
if (!is_valid_cell(state, row, col))
return nullptr;
return &state.rows[row + state.buffer_size].cells[col];
}
static inline bool set_cell(State &state, size_t row, size_t col, const std::wstring &characters, uint64_t attributes)
{
if (!is_valid_cell(state, row, col))
return false;
state.rows[row + state.buffer_size].cells[col] = Cell{characters, attributes & CellHelpers::ValidMask};
return true;
}
}
#endif // PUTTY_STATE_P_HH_INCLUDE