mirror of
https://github.com/tmux/tmux.git
synced 2024-12-12 17:38:48 +00:00
Sync OpenBSD patchset 227:
Add a flags member to the grid_line struct and use it to differentiate lines wrapped at the screen edge from those terminated by a newline. Then use this when copying to combine wrapped lines together into one.
This commit is contained in:
parent
37b0bcd7c1
commit
97eb537f38
10
input.c
10
input.c
@ -1,4 +1,4 @@
|
|||||||
/* $Id: input.c,v 1.89 2009-08-09 16:57:49 tcunha Exp $ */
|
/* $Id: input.c,v 1.90 2009-08-09 17:32:06 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -635,7 +635,7 @@ input_handle_c0_control(u_char ch, struct input_ctx *ictx)
|
|||||||
case '\0': /* NUL */
|
case '\0': /* NUL */
|
||||||
break;
|
break;
|
||||||
case '\n': /* LF */
|
case '\n': /* LF */
|
||||||
screen_write_linefeed(&ictx->ctx);
|
screen_write_linefeed(&ictx->ctx, 0);
|
||||||
break;
|
break;
|
||||||
case '\r': /* CR */
|
case '\r': /* CR */
|
||||||
screen_write_carriagereturn(&ictx->ctx);
|
screen_write_carriagereturn(&ictx->ctx);
|
||||||
@ -659,7 +659,7 @@ input_handle_c0_control(u_char ch, struct input_ctx *ictx)
|
|||||||
} while (s->cx < screen_size_x(s) - 1);
|
} while (s->cx < screen_size_x(s) - 1);
|
||||||
break;
|
break;
|
||||||
case '\013': /* VT */
|
case '\013': /* VT */
|
||||||
screen_write_linefeed(&ictx->ctx);
|
screen_write_linefeed(&ictx->ctx, 0);
|
||||||
break;
|
break;
|
||||||
case '\016': /* SO */
|
case '\016': /* SO */
|
||||||
ictx->cell.attr |= GRID_ATTR_CHARSET;
|
ictx->cell.attr |= GRID_ATTR_CHARSET;
|
||||||
@ -682,11 +682,11 @@ input_handle_c1_control(u_char ch, struct input_ctx *ictx)
|
|||||||
|
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'D': /* IND */
|
case 'D': /* IND */
|
||||||
screen_write_linefeed(&ictx->ctx);
|
screen_write_linefeed(&ictx->ctx, 0);
|
||||||
break;
|
break;
|
||||||
case 'E': /* NEL */
|
case 'E': /* NEL */
|
||||||
screen_write_carriagereturn(&ictx->ctx);
|
screen_write_carriagereturn(&ictx->ctx);
|
||||||
screen_write_linefeed(&ictx->ctx);
|
screen_write_linefeed(&ictx->ctx, 0);
|
||||||
break;
|
break;
|
||||||
case 'H': /* HTS */
|
case 'H': /* HTS */
|
||||||
if (s->cx < screen_size_x(s))
|
if (s->cx < screen_size_x(s))
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $Id: screen-write.c,v 1.66 2009-07-30 21:14:04 tcunha Exp $ */
|
/* $Id: screen-write.c,v 1.67 2009-08-09 17:32:06 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -610,13 +610,20 @@ screen_write_mousemode(struct screen_write_ctx *ctx, int state)
|
|||||||
|
|
||||||
/* Line feed (down with scroll). */
|
/* Line feed (down with scroll). */
|
||||||
void
|
void
|
||||||
screen_write_linefeed(struct screen_write_ctx *ctx)
|
screen_write_linefeed(struct screen_write_ctx *ctx, int wrapped)
|
||||||
{
|
{
|
||||||
struct screen *s = ctx->s;
|
struct screen *s = ctx->s;
|
||||||
struct tty_ctx ttyctx;
|
struct grid_line *gl;
|
||||||
|
struct tty_ctx ttyctx;
|
||||||
|
|
||||||
screen_write_initctx(ctx, &ttyctx);
|
screen_write_initctx(ctx, &ttyctx);
|
||||||
|
|
||||||
|
gl = &s->grid->linedata[s->grid->hsize + s->cy];
|
||||||
|
if (wrapped)
|
||||||
|
gl->flags |= GRID_LINE_WRAPPED;
|
||||||
|
else
|
||||||
|
gl->flags &= ~GRID_LINE_WRAPPED;
|
||||||
|
|
||||||
if (s->cy == s->rlower)
|
if (s->cy == s->rlower)
|
||||||
grid_view_scroll_region_up(s->grid, s->rupper, s->rlower);
|
grid_view_scroll_region_up(s->grid, s->rupper, s->rlower);
|
||||||
else if (s->cy < screen_size_y(s) - 1)
|
else if (s->cy < screen_size_y(s) - 1)
|
||||||
@ -782,10 +789,10 @@ screen_write_cell(
|
|||||||
insert = 1;
|
insert = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check this will fit on the current line; scroll if not. */
|
/* Check this will fit on the current line and wrap if not. */
|
||||||
if (s->cx > screen_size_x(s) - width) {
|
if (s->cx > screen_size_x(s) - width) {
|
||||||
screen_write_carriagereturn(ctx);
|
screen_write_carriagereturn(ctx);
|
||||||
screen_write_linefeed(ctx);
|
screen_write_linefeed(ctx, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sanity checks. */
|
/* Sanity checks. */
|
||||||
|
9
tmux.h
9
tmux.h
@ -1,4 +1,4 @@
|
|||||||
/* $Id: tmux.h,v 1.406 2009-08-09 17:28:23 tcunha Exp $ */
|
/* $Id: tmux.h,v 1.407 2009-08-09 17:32:06 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -483,6 +483,9 @@ struct mode_key_table {
|
|||||||
#define GRID_FLAG_PADDING 0x4
|
#define GRID_FLAG_PADDING 0x4
|
||||||
#define GRID_FLAG_UTF8 0x8
|
#define GRID_FLAG_UTF8 0x8
|
||||||
|
|
||||||
|
/* Grid line flags. */
|
||||||
|
#define GRID_LINE_WRAPPED 0x1
|
||||||
|
|
||||||
/* Grid cell data. */
|
/* Grid cell data. */
|
||||||
struct grid_cell {
|
struct grid_cell {
|
||||||
u_char attr;
|
u_char attr;
|
||||||
@ -506,6 +509,8 @@ struct grid_line {
|
|||||||
|
|
||||||
u_int utf8size;
|
u_int utf8size;
|
||||||
struct grid_utf8 *utf8data;
|
struct grid_utf8 *utf8data;
|
||||||
|
|
||||||
|
int flags;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/* Entire grid of cells. */
|
/* Entire grid of cells. */
|
||||||
@ -1503,7 +1508,7 @@ void screen_write_reverseindex(struct screen_write_ctx *);
|
|||||||
void screen_write_scrollregion(struct screen_write_ctx *, u_int, u_int);
|
void screen_write_scrollregion(struct screen_write_ctx *, u_int, u_int);
|
||||||
void screen_write_insertmode(struct screen_write_ctx *, int);
|
void screen_write_insertmode(struct screen_write_ctx *, int);
|
||||||
void screen_write_mousemode(struct screen_write_ctx *, int);
|
void screen_write_mousemode(struct screen_write_ctx *, int);
|
||||||
void screen_write_linefeed(struct screen_write_ctx *);
|
void screen_write_linefeed(struct screen_write_ctx *, int);
|
||||||
void screen_write_carriagereturn(struct screen_write_ctx *);
|
void screen_write_carriagereturn(struct screen_write_ctx *);
|
||||||
void screen_write_kcursormode(struct screen_write_ctx *, int);
|
void screen_write_kcursormode(struct screen_write_ctx *, int);
|
||||||
void screen_write_kkeypadmode(struct screen_write_ctx *, int);
|
void screen_write_kkeypadmode(struct screen_write_ctx *, int);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $Id: window-copy.c,v 1.74 2009-08-09 17:28:24 tcunha Exp $ */
|
/* $Id: window-copy.c,v 1.75 2009-08-09 17:32:06 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -449,13 +449,11 @@ window_copy_copy_selection(struct window_pane *wp, struct client *c)
|
|||||||
if (sy == ey)
|
if (sy == ey)
|
||||||
window_copy_copy_line(wp, &buf, &off, sy, sx, ex);
|
window_copy_copy_line(wp, &buf, &off, sy, sx, ex);
|
||||||
else {
|
else {
|
||||||
xx = window_copy_find_length(wp, sy);
|
xx = screen_size_x(s);
|
||||||
window_copy_copy_line(wp, &buf, &off, sy, sx, xx);
|
window_copy_copy_line(wp, &buf, &off, sy, sx, xx);
|
||||||
if (ey - sy > 1) {
|
if (ey - sy > 1) {
|
||||||
for (i = sy + 1; i < ey; i++) {
|
for (i = sy + 1; i < ey; i++)
|
||||||
xx = window_copy_find_length(wp, i);
|
|
||||||
window_copy_copy_line(wp, &buf, &off, i, 0, xx);
|
window_copy_copy_line(wp, &buf, &off, i, 0, xx);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
window_copy_copy_line(wp, &buf, &off, ey, 0, ex);
|
window_copy_copy_line(wp, &buf, &off, ey, 0, ex);
|
||||||
}
|
}
|
||||||
@ -473,14 +471,28 @@ void
|
|||||||
window_copy_copy_line(struct window_pane *wp,
|
window_copy_copy_line(struct window_pane *wp,
|
||||||
char **buf, size_t *off, u_int sy, u_int sx, u_int ex)
|
char **buf, size_t *off, u_int sy, u_int sx, u_int ex)
|
||||||
{
|
{
|
||||||
|
struct grid *gd = wp->base.grid;
|
||||||
const struct grid_cell *gc;
|
const struct grid_cell *gc;
|
||||||
const struct grid_utf8 *gu;
|
const struct grid_utf8 *gu;
|
||||||
u_int i, j, xx;
|
struct grid_line *gl;
|
||||||
|
u_int i, j, xx, wrapped = 0;
|
||||||
|
|
||||||
if (sx > ex)
|
if (sx > ex)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
xx = window_copy_find_length(wp, sy);
|
/*
|
||||||
|
* Work out if the line was wrapped at the screen edge and all of it is
|
||||||
|
* on screen.
|
||||||
|
*/
|
||||||
|
gl = &gd->linedata[sy];
|
||||||
|
if (gl->flags & GRID_LINE_WRAPPED && gl->cellsize <= gd->sx)
|
||||||
|
wrapped = 1;
|
||||||
|
|
||||||
|
/* If the line was wrapped, don't strip spaces (use the full length). */
|
||||||
|
if (wrapped)
|
||||||
|
xx = gl->cellsize;
|
||||||
|
else
|
||||||
|
xx = window_copy_find_length(wp, sy);
|
||||||
if (ex > xx)
|
if (ex > xx)
|
||||||
ex = xx;
|
ex = xx;
|
||||||
if (sx > xx)
|
if (sx > xx)
|
||||||
@ -488,14 +500,14 @@ window_copy_copy_line(struct window_pane *wp,
|
|||||||
|
|
||||||
if (sx < ex) {
|
if (sx < ex) {
|
||||||
for (i = sx; i < ex; i++) {
|
for (i = sx; i < ex; i++) {
|
||||||
gc = grid_peek_cell(wp->base.grid, i, sy);
|
gc = grid_peek_cell(gd, i, sy);
|
||||||
if (gc->flags & GRID_FLAG_PADDING)
|
if (gc->flags & GRID_FLAG_PADDING)
|
||||||
continue;
|
continue;
|
||||||
if (!(gc->flags & GRID_FLAG_UTF8)) {
|
if (!(gc->flags & GRID_FLAG_UTF8)) {
|
||||||
*buf = xrealloc(*buf, 1, (*off) + 1);
|
*buf = xrealloc(*buf, 1, (*off) + 1);
|
||||||
(*buf)[(*off)++] = gc->data;
|
(*buf)[(*off)++] = gc->data;
|
||||||
} else {
|
} else {
|
||||||
gu = grid_peek_utf8(wp->base.grid, i, sy);
|
gu = grid_peek_utf8(gd, i, sy);
|
||||||
*buf = xrealloc(*buf, 1, (*off) + UTF8_SIZE);
|
*buf = xrealloc(*buf, 1, (*off) + UTF8_SIZE);
|
||||||
for (j = 0; j < UTF8_SIZE; j++) {
|
for (j = 0; j < UTF8_SIZE; j++) {
|
||||||
if (gu->data[j] == 0xff)
|
if (gu->data[j] == 0xff)
|
||||||
@ -506,9 +518,11 @@ window_copy_copy_line(struct window_pane *wp,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*buf = xrealloc(*buf, 1, (*off) + 1);
|
/* Only add a newline if the line wasn't wrapped. */
|
||||||
(*buf)[*off] = '\n';
|
if (!wrapped) {
|
||||||
(*off)++;
|
*buf = xrealloc(*buf, 1, (*off) + 1);
|
||||||
|
(*buf)[(*off)++] = '\n';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
Reference in New Issue
Block a user