diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-10-12 16:59:56 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-10-12 16:59:56 +0000 |
commit | bd76886db84b43b503db1aa901bffc4107fa3003 (patch) | |
tree | 4bd3b85b9d5cfcc310798ca2510a2f4ec8a9d632 | |
parent | d75b9e3cb93538cdb6e59d5bfea958937d2c7428 (diff) |
When backspace is received at the beginning of a line and the previous line was
wrapped, move the cursor back up to the end of the previous line.
Another one of the forgotten persons requested this quite a while ago (I need
to start noting names on todo items...) when it was quite hard to
implement. Now it is easy and I don't see it can do any harm, so hey presto...
-rw-r--r-- | usr.bin/tmux/input.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/screen-write.c | 22 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 3 |
3 files changed, 25 insertions, 4 deletions
diff --git a/usr.bin/tmux/input.c b/usr.bin/tmux/input.c index 1ce61c7704f..b34cb6554eb 100644 --- a/usr.bin/tmux/input.c +++ b/usr.bin/tmux/input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: input.c,v 1.15 2009/08/20 10:48:25 nicm Exp $ */ +/* $OpenBSD: input.c,v 1.16 2009/10/12 16:59:55 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -646,7 +646,7 @@ input_handle_c0_control(u_char ch, struct input_ctx *ictx) ictx->wp->window->flags |= WINDOW_BELL; break; case '\010': /* BS */ - screen_write_cursorleft(&ictx->ctx, 1); + screen_write_backspace(&ictx->ctx); break; case '\011': /* TAB */ /* Don't tab beyond the end of the line. */ diff --git a/usr.bin/tmux/screen-write.c b/usr.bin/tmux/screen-write.c index e3a420ff57d..e66a350afa6 100644 --- a/usr.bin/tmux/screen-write.c +++ b/usr.bin/tmux/screen-write.c @@ -1,4 +1,4 @@ -/* $OpenBSD: screen-write.c,v 1.28 2009/10/12 16:33:39 nicm Exp $ */ +/* $OpenBSD: screen-write.c,v 1.29 2009/10/12 16:59:55 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -513,6 +513,25 @@ screen_write_cursorleft(struct screen_write_ctx *ctx, u_int nx) s->cx -= nx; } +/* Backspace; cursor left unless at start of wrapped line when can move up. */ +void +screen_write_backspace(struct screen_write_ctx *ctx) +{ + struct screen *s = ctx->s; + struct grid_line *gl; + + if (s->cx == 0) { + if (s->cy == 0) + return; + gl = &s->grid->linedata[s->grid->hsize + s->cy - 1]; + if (gl->flags & GRID_LINE_WRAPPED) { + s->cy--; + s->cx = screen_size_x(s) - 1; + } + } else + s->cx--; +} + /* VT100 alignment test. */ void screen_write_alignmenttest(struct screen_write_ctx *ctx) @@ -536,6 +555,7 @@ screen_write_alignmenttest(struct screen_write_ctx *ctx) s->cy = 0; s->rupper = 0; + s->rlower = screen_size_y(s) - 1; tty_write(tty_cmd_alignmenttest, &ttyctx); diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index c1fee7094d1..e77ef5d52a0 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.135 2009/10/12 13:01:18 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.136 2009/10/12 16:59:55 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -1646,6 +1646,7 @@ void screen_write_putc( struct screen_write_ctx *, struct grid_cell *, u_char); void screen_write_copy(struct screen_write_ctx *, struct screen *, u_int, u_int, u_int, u_int); +void screen_write_backspace(struct screen_write_ctx *); void screen_write_cursorup(struct screen_write_ctx *, u_int); void screen_write_cursordown(struct screen_write_ctx *, u_int); void screen_write_cursorright(struct screen_write_ctx *, u_int); |