mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-20 01:40:14 -05:00
selection: selections can be made, and are rendered
* Start selection on mouse button down * Update selection on motion * Button release cancels selection if there were no motion after start * Renderer detects cells inside the selection and inverts their colors
This commit is contained in:
parent
decb4503bf
commit
632790d5d8
4 changed files with 57 additions and 1 deletions
28
render.c
28
render.c
|
|
@ -42,6 +42,32 @@ render_cell(struct terminal *term, struct buffer *buf, const struct cell *cell,
|
|||
double x = col * width;
|
||||
double y = row * height;
|
||||
|
||||
bool is_selected = false;
|
||||
if (term->selection.start.col != -1 && term->selection.end.col != -1) {
|
||||
const struct coord *start = &term->selection.start;
|
||||
const struct coord *end = &term->selection.end;
|
||||
|
||||
if (end->row < start->row || (end->row == start->row && end->col < start->col)) {
|
||||
const struct coord *tmp = start;
|
||||
start = end;
|
||||
end = tmp;
|
||||
}
|
||||
|
||||
assert(start->row <= end->row);
|
||||
|
||||
if (start->row == end->row) {
|
||||
is_selected
|
||||
= term->grid->view + row == start->row && col >= start->col && col <= end->col;
|
||||
} else {
|
||||
if (term->grid->view + row == start->row)
|
||||
is_selected = col >= start->col;
|
||||
else if (term->grid->view + row == end->row)
|
||||
is_selected = col <= end->col;
|
||||
else
|
||||
is_selected = term->grid->view + row >= start->row && term->grid->view + row <= end->row;
|
||||
}
|
||||
}
|
||||
|
||||
const struct rgb *foreground = cell->attrs.have_foreground
|
||||
? &cell->attrs.foreground
|
||||
: !term->reverse ? &term->foreground : &term->background;
|
||||
|
|
@ -50,7 +76,7 @@ render_cell(struct terminal *term, struct buffer *buf, const struct cell *cell,
|
|||
: !term->reverse ? &term->background : &term->foreground;
|
||||
|
||||
/* If *one* is set, we reverse */
|
||||
if (has_cursor ^ cell->attrs.reverse) {
|
||||
if (has_cursor ^ cell->attrs.reverse ^ is_selected) {
|
||||
const struct rgb *swap = foreground;
|
||||
foreground = background;
|
||||
background = swap;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue