Put the non-boilerplate functions in their proper place
This commit is contained in:
parent
e37ee422b6
commit
14a33dbd94
@ -2183,6 +2183,49 @@ screen_request_capabilities(Screen *self, char c, PyObject *q) {
|
||||
// }}}
|
||||
|
||||
// Rendering {{{
|
||||
static color_type
|
||||
effective_cell_edge_color(char_type ch, color_type fg, color_type bg, bool is_left_edge) {
|
||||
START_ALLOW_CASE_RANGE
|
||||
if (ch == 0x2588) return fg; // full block
|
||||
if (is_left_edge) {
|
||||
switch (ch) {
|
||||
case 0x2589 ... 0x258f: // left eighth blocks
|
||||
case 0xe0b0: case 0xe0b4: case 0xe0b8: case 0xe0bc: // powerline blocks
|
||||
case 0x1fb6a: // 🭪
|
||||
return fg;
|
||||
}
|
||||
} else {
|
||||
switch (ch) {
|
||||
case 0x2590: // right half block
|
||||
case 0x1fb87 ... 0x1fb8b: // eighth right blocks
|
||||
case 0xe0b2: case 0xe0b6: case 0xe0ba: case 0xe0be:
|
||||
case 0x1fb68: // 🭨
|
||||
return fg;
|
||||
}
|
||||
}
|
||||
return bg;
|
||||
END_ALLOW_CASE_RANGE
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
get_line_edge_colors(Screen *self, color_type *left, color_type *right) {
|
||||
// Return the color at the left and right edges of the line with the cursor on it
|
||||
Line *line = range_line_(self, self->cursor->y);
|
||||
if (!line) return false;
|
||||
color_type left_cell_fg = OPT(foreground), left_cell_bg = OPT(background), right_cell_bg = OPT(background), right_cell_fg = OPT(foreground);
|
||||
index_type cell_color_x = 0;
|
||||
char_type left_char = line_get_char(line, cell_color_x);
|
||||
colors_for_cell(line, self->color_profile, &cell_color_x, &left_cell_fg, &left_cell_bg);
|
||||
if (line->xnum > 0) cell_color_x = line->xnum - 1;
|
||||
char_type right_char = line_get_char(line, cell_color_x);
|
||||
colors_for_cell(line, self->color_profile, &cell_color_x, &right_cell_fg, &right_cell_bg);
|
||||
*left = effective_cell_edge_color(left_char, left_cell_fg, left_cell_bg, true);
|
||||
*right = effective_cell_edge_color(right_char, right_cell_fg, right_cell_bg, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
update_line_data(Line *line, unsigned int dest_y, uint8_t *data) {
|
||||
size_t base = sizeof(GPUCell) * dest_y * line->xnum;
|
||||
@ -3948,47 +3991,6 @@ cursor_at_prompt(Screen *self, PyObject *args UNUSED) {
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static color_type
|
||||
effective_cell_edge_color(char_type ch, color_type fg, color_type bg, bool is_left_edge) {
|
||||
START_ALLOW_CASE_RANGE
|
||||
if (ch == 0x2588) return fg; // full block
|
||||
if (is_left_edge) {
|
||||
switch (ch) {
|
||||
case 0x2589 ... 0x258f: // left eighth blocks
|
||||
case 0xe0b0: case 0xe0b4: case 0xe0b8: case 0xe0bc: // powerline blocks
|
||||
case 0x1fb6a: // 🭪
|
||||
return fg;
|
||||
}
|
||||
} else {
|
||||
switch (ch) {
|
||||
case 0x2590: // right half block
|
||||
case 0x1fb87 ... 0x1fb8b: // eighth right blocks
|
||||
case 0xe0b2: case 0xe0b6: case 0xe0ba: case 0xe0be:
|
||||
case 0x1fb68: // 🭨
|
||||
return fg;
|
||||
}
|
||||
}
|
||||
return bg;
|
||||
END_ALLOW_CASE_RANGE
|
||||
}
|
||||
|
||||
bool
|
||||
get_line_edge_colors(Screen *self, color_type *left, color_type *right) {
|
||||
// Return the color at the left and right edges of the line with the cursor on it
|
||||
Line *line = range_line_(self, self->cursor->y);
|
||||
if (!line) return false;
|
||||
color_type left_cell_fg = OPT(foreground), left_cell_bg = OPT(background), right_cell_bg = OPT(background), right_cell_fg = OPT(foreground);
|
||||
index_type cell_color_x = 0;
|
||||
char_type left_char = line_get_char(line, cell_color_x);
|
||||
colors_for_cell(line, self->color_profile, &cell_color_x, &left_cell_fg, &left_cell_bg);
|
||||
if (line->xnum > 0) cell_color_x = line->xnum - 1;
|
||||
char_type right_char = line_get_char(line, cell_color_x);
|
||||
colors_for_cell(line, self->color_profile, &cell_color_x, &right_cell_fg, &right_cell_bg);
|
||||
*left = effective_cell_edge_color(left_char, left_cell_fg, left_cell_bg, true);
|
||||
*right = effective_cell_edge_color(right_char, right_cell_fg, right_cell_bg, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
line_edge_colors(Screen *self, PyObject *a UNUSED) {
|
||||
color_type left, right;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user