struct selection_pos sel_end;
};
+static void inc_age(struct tsm_screen *con)
+{
+ if (!++con->age_cnt) {
+ con->age_reset = 1;
+ ++con->age_cnt;
+ }
+}
+
+static struct cell *get_cursor_cell(struct tsm_screen *con)
+{
+ unsigned int cur_x, cur_y;
+
+ cur_x = con->cursor_x;
+ if (cur_x >= con->size_x)
+ cur_x = con->size_x - 1;
+
+ cur_y = con->cursor_y;
+ if (cur_y >= con->size_y)
+ cur_y = con->size_y - 1;
+
+ return &con->lines[cur_y]->cells[cur_x];
+}
+
+static void move_cursor(struct tsm_screen *con, unsigned int x, unsigned int y)
+{
+ struct cell *c;
+
+ if (con->cursor_x == x && con->cursor_y == y)
+ return;
+
+ c = get_cursor_cell(con);
+ c->age = con->age_cnt;
+
+ con->cursor_x = x;
+ con->cursor_y = y;
+
+ c = get_cursor_cell(con);
+ c->age = con->age_cnt;
+}
+
static void cell_init(struct tsm_screen *con, struct cell *cell)
{
cell->ch = 0;
{
struct line *tmp;
+ /* TODO: more sophisticated ageing */
+ con->age = con->age_cnt;
+
if (con->sb_max == 0) {
if (con->sel_active) {
if (con->sel_start.line == line) {
if (!num)
return;
+ /* TODO: more sophisticated ageing */
+ con->age = con->age_cnt;
+
max = con->margin_bottom + 1 - con->margin_top;
if (num > max)
num = max;
if (!num)
return;
+ /* TODO: more sophisticated ageing */
+ con->age = con->age_cnt;
+
max = con->margin_bottom + 1 - con->margin_top;
if (num > max)
num = max;
return;
}
+ /* TODO: more sophisticated ageing */
+ con->age = con->age_cnt;
+
line = con->lines[y];
if ((con->flags & TSM_SCREEN_INSERT_MODE) &&
unsigned int to;
struct line *line;
+ /* TODO: more sophisticated ageing */
+ con->age = con->age_cnt;
+
if (y_to >= con->size_y)
y_to = con->size_y - 1;
if (x_to >= con->size_x)
}
}
+ inc_age(con);
+ /* TODO: more sophisticated ageing */
+ con->age = con->age_cnt;
+
/* clear expansion/padding area */
for (j = 0; j < con->line_num; ++j) {
i = 0;
if (!con)
return;
+ inc_age(con);
+ /* TODO: more sophisticated ageing */
+ con->age = con->age_cnt;
+
while (con->sb_count > max) {
line = con->sb_first;
con->sb_first = line->next;
if (!con)
return;
+ inc_age(con);
+ /* TODO: more sophisticated ageing */
+ con->age = con->age_cnt;
+
for (iter = con->sb_first; iter; ) {
tmp = iter;
iter = iter->next;
if (!con || !num)
return;
+ inc_age(con);
+ /* TODO: more sophisticated ageing */
+ con->age = con->age_cnt;
+
while (num--) {
if (con->sb_pos) {
if (!con->sb_pos->prev)
if (!con || !num)
return;
+ inc_age(con);
+ /* TODO: more sophisticated ageing */
+ con->age = con->age_cnt;
+
while (num--) {
if (con->sb_pos)
con->sb_pos = con->sb_pos->next;
if (!con || !num)
return;
+ inc_age(con);
tsm_screen_sb_up(con, num * con->size_y);
}
if (!con || !num)
return;
+ inc_age(con);
tsm_screen_sb_down(con, num * con->size_y);
}
if (!con)
return;
+ inc_age(con);
+ /* TODO: more sophisticated ageing */
+ con->age = con->age_cnt;
+
con->sb_pos = NULL;
}
if (!con)
return;
+ inc_age(con);
+ con->age = con->age_cnt;
+
con->flags = 0;
con->margin_top = 0;
con->margin_bottom = con->size_y - 1;
void tsm_screen_set_flags(struct tsm_screen *con, unsigned int flags)
{
unsigned int old;
+ struct cell *c;
if (!con || !flags)
return;
+ inc_age(con);
+
old = con->flags;
con->flags |= flags;
- if (!(old & TSM_SCREEN_ALTERNATE) && (flags & TSM_SCREEN_ALTERNATE))
+ if (!(old & TSM_SCREEN_ALTERNATE) && (flags & TSM_SCREEN_ALTERNATE)) {
+ con->age = con->age_cnt;
con->lines = con->alt_lines;
+ }
+
+ if (!(old & TSM_SCREEN_HIDE_CURSOR) &&
+ (flags & TSM_SCREEN_HIDE_CURSOR)) {
+ c = get_cursor_cell(con);
+ c->age = con->age_cnt;
+ }
+
+ if (!(old & TSM_SCREEN_INVERSE) && (flags & TSM_SCREEN_INVERSE))
+ con->age = con->age_cnt;
}
SHL_EXPORT
void tsm_screen_reset_flags(struct tsm_screen *con, unsigned int flags)
{
unsigned int old;
+ struct cell *c;
if (!con || !flags)
return;
+ inc_age(con);
+
old = con->flags;
con->flags &= ~flags;
- if ((old & TSM_SCREEN_ALTERNATE) && (flags & TSM_SCREEN_ALTERNATE))
+ if ((old & TSM_SCREEN_ALTERNATE) && (flags & TSM_SCREEN_ALTERNATE)) {
+ con->age = con->age_cnt;
con->lines = con->main_lines;
+ }
+
+ if ((old & TSM_SCREEN_HIDE_CURSOR) &&
+ (flags & TSM_SCREEN_HIDE_CURSOR)) {
+ c = get_cursor_cell(con);
+ c->age = con->age_cnt;
+ }
+
+ if ((old & TSM_SCREEN_INVERSE) && (flags & TSM_SCREEN_INVERSE))
+ con->age = con->age_cnt;
}
SHL_EXPORT
if (!len)
return;
+ inc_age(con);
+ /* TODO: more sophisticated ageing */
+ con->age = con->age_cnt;
+
if (con->cursor_y <= con->margin_bottom ||
con->cursor_y >= con->size_y)
last = con->margin_bottom;
if (!con)
return;
+ inc_age(con);
+
tsm_screen_move_down(con, 1, true);
tsm_screen_move_line_home(con);
}
if (!con || !num)
return;
+ inc_age(con);
+
screen_scroll_up(con, num);
}
if (!con || !num)
return;
+ inc_age(con);
+
screen_scroll_down(con, num);
}
if (!con)
return;
+ inc_age(con);
+
if (con->flags & TSM_SCREEN_REL_ORIGIN)
last = con->margin_bottom;
else
last = con->size_y - 1;
- con->cursor_x = to_abs_x(con, x);
- if (con->cursor_x >= con->size_x)
- con->cursor_x = con->size_x - 1;
+ x = to_abs_x(con, x);
+ if (x >= con->size_x)
+ x = con->size_x - 1;
- con->cursor_y = to_abs_y(con, y);
- if (con->cursor_y > last)
- con->cursor_y = last;
+ y = to_abs_y(con, y);
+ if (y > last)
+ y = last;
+
+ move_cursor(con, x, y);
}
SHL_EXPORT
if (!con || !num)
return;
+ inc_age(con);
+
if (con->cursor_y >= con->margin_top)
size = con->margin_top;
else
num -= diff;
if (scroll)
screen_scroll_down(con, num);
- con->cursor_y = size;
+ move_cursor(con, con->cursor_x, size);
} else {
- con->cursor_y -= num;
+ move_cursor(con, con->cursor_x, con->cursor_y - num);
}
}
if (!con || !num)
return;
+ inc_age(con);
+
if (con->cursor_y <= con->margin_bottom)
size = con->margin_bottom + 1;
else
num -= diff;
if (scroll)
screen_scroll_up(con, num);
- con->cursor_y = size - 1;
+ move_cursor(con, con->cursor_x, size - 1);
} else {
- con->cursor_y += num;
+ move_cursor(con, con->cursor_x, con->cursor_y + num);
}
}
SHL_EXPORT
void tsm_screen_move_left(struct tsm_screen *con, unsigned int num)
{
+ unsigned int x;
+
if (!con || !num)
return;
+ inc_age(con);
+
if (num > con->size_x)
num = con->size_x;
- if (con->cursor_x >= con->size_x)
- con->cursor_x = con->size_x - 1;
+ x = con->cursor_x;
+ if (x >= con->size_x)
+ x = con->size_x - 1;
- if (num > con->cursor_x)
- con->cursor_x = 0;
+ if (num > x)
+ move_cursor(con, 0, con->cursor_y);
else
- con->cursor_x -= num;
+ move_cursor(con, x - num, con->cursor_y);
}
SHL_EXPORT
if (!con || !num)
return;
+ inc_age(con);
+
if (num > con->size_x)
num = con->size_x;
if (num + con->cursor_x >= con->size_x)
- con->cursor_x = con->size_x - 1;
+ move_cursor(con, con->size_x - 1, con->cursor_y);
else
- con->cursor_x += num;
+ move_cursor(con, con->cursor_x + num, con->cursor_y);
}
SHL_EXPORT
if (!con)
return;
- con->cursor_x = con->size_x - 1;
+ inc_age(con);
+
+ move_cursor(con, con->size_x - 1, con->cursor_y);
}
SHL_EXPORT
if (!con)
return;
- con->cursor_x = 0;
+ inc_age(con);
+
+ move_cursor(con, 0, con->cursor_y);
}
SHL_EXPORT
void tsm_screen_tab_right(struct tsm_screen *con, unsigned int num)
{
- unsigned int i, j;
+ unsigned int i, j, x;
if (!con || !num)
return;
+ inc_age(con);
+
+ x = con->cursor_x;
for (i = 0; i < num; ++i) {
- for (j = con->cursor_x + 1; j < con->size_x; ++j) {
+ for (j = x + 1; j < con->size_x; ++j) {
if (con->tab_ruler[j])
break;
}
- con->cursor_x = j;
- if (con->cursor_x + 1 >= con->size_x)
+ x = j;
+ if (x + 1 >= con->size_x)
break;
}
/* tabs never cause pending new-lines */
- if (con->cursor_x >= con->size_x)
- con->cursor_x = con->size_x - 1;
+ if (x >= con->size_x)
+ x = con->size_x - 1;
+
+ move_cursor(con, x, con->cursor_y);
}
SHL_EXPORT
void tsm_screen_tab_left(struct tsm_screen *con, unsigned int num)
{
- unsigned int i;
+ unsigned int i, x;
int j;
if (!con || !num)
return;
+ inc_age(con);
+
+ x = con->cursor_x;
for (i = 0; i < num; ++i) {
- for (j = con->cursor_x - 1; j > 0; --j) {
+ for (j = x - 1; j > 0; --j) {
if (con->tab_ruler[j])
break;
}
if (j <= 0) {
- con->cursor_x = 0;
+ x = 0;
break;
}
- con->cursor_x = j;
+ x = j;
}
+
+ move_cursor(con, x, con->cursor_y);
}
SHL_EXPORT
con->cursor_y > con->margin_bottom)
return;
+ inc_age(con);
+ /* TODO: more sophisticated ageing */
+ con->age = con->age_cnt;
+
max = con->margin_bottom - con->cursor_y + 1;
if (num > max)
num = max;
con->cursor_y > con->margin_bottom)
return;
+ inc_age(con);
+ /* TODO: more sophisticated ageing */
+ con->age = con->age_cnt;
+
max = con->margin_bottom - con->cursor_y + 1;
if (num > max)
num = max;
if (!con || !num || !con->size_y || !con->size_x)
return;
+ inc_age(con);
+ /* TODO: more sophisticated ageing */
+ con->age = con->age_cnt;
+
if (con->cursor_x >= con->size_x)
con->cursor_x = con->size_x - 1;
if (con->cursor_y >= con->size_y)
if (!con || !num || !con->size_y || !con->size_x)
return;
+ inc_age(con);
+ /* TODO: more sophisticated ageing */
+ con->age = con->age_cnt;
+
if (con->cursor_x >= con->size_x)
con->cursor_x = con->size_x - 1;
if (con->cursor_y >= con->size_y)
if (!con)
return;
+ inc_age(con);
+
if (con->cursor_x >= con->size_x)
x = con->size_x - 1;
else
if (!con || !num)
return;
+ inc_age(con);
+
if (con->cursor_x >= con->size_x)
x = con->size_x - 1;
else
if (!con)
return;
+ inc_age(con);
+
if (con->cursor_x >= con->size_x)
x = con->size_x - 1;
else
if (!con)
return;
+ inc_age(con);
+
screen_erase_region(con, 0, con->cursor_y, con->cursor_x,
con->cursor_y, protect);
}
if (!con)
return;
+ inc_age(con);
+
screen_erase_region(con, 0, con->cursor_y, con->size_x - 1,
con->cursor_y, protect);
}
if (!con)
return;
+ inc_age(con);
+
screen_erase_region(con, 0, 0, con->cursor_x, con->cursor_y, protect);
}
if (!con)
return;
+ inc_age(con);
+
if (con->cursor_x >= con->size_x)
x = con->size_x - 1;
else
if (!con)
return;
+ inc_age(con);
+
screen_erase_region(con, 0, 0, con->size_x - 1, con->size_y - 1,
protect);
}
if (!con)
return;
+ inc_age(con);
+ /* TODO: more sophisticated ageing */
+ con->age = con->age_cnt;
+
con->sel_active = false;
}
if (!con)
return;
+ inc_age(con);
+ /* TODO: more sophisticated ageing */
+ con->age = con->age_cnt;
+
con->sel_active = true;
selection_set(con, &con->sel_start, posx, posy);
memcpy(&con->sel_end, &con->sel_start, sizeof(con->sel_end));
if (!con || !con->sel_active)
return;
+ inc_age(con);
+ /* TODO: more sophisticated ageing */
+ con->age = con->age_cnt;
+
selection_set(con, &con->sel_end, posx, posy);
}