diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-07-26 21:13:48 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-07-26 21:13:48 +0000 |
commit | 13052375563c2d37c40c4e7a3f26ef97b0da9ddd (patch) | |
tree | 2bde96edf6e3c72c5975829c0d4aa0a0e7b17eb8 /usr.bin | |
parent | 5932d6e6e2eff29a468cbf532d61611a5fe6dd69 (diff) |
Calculate the space available for the prompt buffer and the cursor position
correctly, and make it work when the screen is not wide enough.
Noticed by Kalle Olavi Niemitalo.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/status.c | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/usr.bin/tmux/status.c b/usr.bin/tmux/status.c index 068958546ea..9be22294cc2 100644 --- a/usr.bin/tmux/status.c +++ b/usr.bin/tmux/status.c @@ -1,4 +1,4 @@ -/* $OpenBSD: status.c,v 1.16 2009/07/21 18:40:30 nicm Exp $ */ +/* $OpenBSD: status.c,v 1.17 2009/07/26 21:13:47 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -645,7 +645,7 @@ status_prompt_redraw(struct client *c) struct screen_write_ctx ctx; struct session *s = c->session; struct screen old_status; - size_t i, size, left, len, offset, n; + size_t i, size, left, len, off, n; char ch; struct grid_cell gc; @@ -653,7 +653,7 @@ status_prompt_redraw(struct client *c) return (0); memcpy(&old_status, &c->status, sizeof old_status); screen_init(&c->status, c->tty.sx, 1, 0); - offset = 0; + off = 0; len = strlen(c->prompt_string); if (len > c->tty.sx) @@ -674,7 +674,7 @@ status_prompt_redraw(struct client *c) if (c->prompt_index < left) size = strlen(c->prompt_buffer); else { - offset = c->prompt_index - left - 1; + off = c->prompt_index - left + 1; if (c->prompt_index == strlen(c->prompt_buffer)) left--; size = left; @@ -687,27 +687,27 @@ status_prompt_redraw(struct client *c) screen_write_putc(&ctx, &gc, '*'); } else { screen_write_puts(&ctx, &gc, - "%.*s", (int) left, c->prompt_buffer + offset); + "%.*s", (int) left, c->prompt_buffer + off); } for (i = len + size; i < c->tty.sx; i++) screen_write_putc(&ctx, &gc, ' '); - } - /* Draw a fake cursor. */ - screen_write_cursormove(&ctx, len + c->prompt_index - offset, 0); - if (c->prompt_index == strlen(c->prompt_buffer)) - ch = ' '; - else { - if (c->prompt_flags & PROMPT_HIDDEN) - ch = '*'; - else - ch = c->prompt_buffer[c->prompt_index]; + /* Draw a fake cursor. */ + screen_write_cursormove(&ctx, len + c->prompt_index - off, 0); + if (c->prompt_index == strlen(c->prompt_buffer)) + ch = ' '; + else { + if (c->prompt_flags & PROMPT_HIDDEN) + ch = '*'; + else + ch = c->prompt_buffer[c->prompt_index]; + } + if (ch == '\0') + ch = ' '; + gc.attr ^= GRID_ATTR_REVERSE; + screen_write_putc(&ctx, &gc, ch); } - if (ch == '\0') - ch = ' '; - gc.attr ^= GRID_ATTR_REVERSE; - screen_write_putc(&ctx, &gc, ch); screen_write_stop(&ctx); |