Make the tracker state change function re-useable

This commit is contained in:
Kovid Goyal 2016-11-11 22:07:40 +05:30
parent a8616f8598
commit 1ad4d52659
2 changed files with 40 additions and 31 deletions

View File

@ -6,6 +6,7 @@
*/
#include "data-types.h"
#include "tracker.h"
#include <structmember.h>
#define RESET_STATE_VARS(self) \
@ -60,37 +61,6 @@ reset(ChangeTracker *self) {
Py_RETURN_NONE;
}
static inline void tracker_cursor_changed(ChangeTracker *self) {
self->cursor_changed = true;
self->dirty = true;
}
static inline void tracker_line_added_to_history(ChangeTracker *self) {
self->history_line_added_count++;
self->dirty = true;
}
static inline void tracker_update_screen(ChangeTracker *self) {
self->screen_changed = true;
self->dirty = true;
}
static inline void tracker_update_line_range(ChangeTracker *self, unsigned int first_line, unsigned int last_line) {
if (!self->screen_changed) {
for (unsigned int i = first_line; i <= MIN(self->ynum - 1, last_line); i++) self->changed_lines[i] = true;
self->dirty = true;
}
}
static inline void tracker_update_cell_range(ChangeTracker *self, unsigned int line, unsigned int first_cell, unsigned int last_cell) {
if (!self->screen_changed && line < self->ynum && !self->changed_lines[line]) {
self->lines_with_changed_cells[line] = true;
unsigned int base = line * self->xnum;
for (unsigned int i = first_cell; i <= MIN(self->xnum - 1, last_cell); i++) self->changed_cells[base + i] = true;
self->dirty = true;
}
}
static PyObject*
cursor_changed(ChangeTracker *self) {
#define cursor_changed_doc ""

39
kitty/tracker.h Normal file
View File

@ -0,0 +1,39 @@
/*
* tracker.h
* Copyright (C) 2016 Kovid Goyal <kovid at kovidgoyal.net>
*
* Distributed under terms of the GPL3 license.
*/
#pragma once
static inline void tracker_cursor_changed(ChangeTracker *self) {
self->cursor_changed = true;
self->dirty = true;
}
static inline void tracker_line_added_to_history(ChangeTracker *self) {
self->history_line_added_count++;
self->dirty = true;
}
static inline void tracker_update_screen(ChangeTracker *self) {
self->screen_changed = true;
self->dirty = true;
}
static inline void tracker_update_line_range(ChangeTracker *self, unsigned int first_line, unsigned int last_line) {
if (!self->screen_changed) {
for (unsigned int i = first_line; i <= MIN(self->ynum - 1, last_line); i++) self->changed_lines[i] = true;
self->dirty = true;
}
}
static inline void tracker_update_cell_range(ChangeTracker *self, unsigned int line, unsigned int first_cell, unsigned int last_cell) {
if (!self->screen_changed && line < self->ynum && !self->changed_lines[line]) {
self->lines_with_changed_cells[line] = true;
unsigned int base = line * self->xnum;
for (unsigned int i = first_cell; i <= MIN(self->xnum - 1, last_cell); i++) self->changed_cells[base + i] = true;
self->dirty = true;
}
}