Simple status line.

This commit is contained in:
Nicholas Marriott 2007-10-01 14:53:29 +00:00
parent 872696f781
commit bfccbc67d1
7 changed files with 139 additions and 9 deletions

View File

@ -1,3 +1,7 @@
01 October 2007
* (nicm) Simple uncustomisable status line with window list.
30 September 2007
* (nicm) Window info command for debugging, C-b I.
@ -80,5 +84,5 @@
(including mutt, emacs). No status bar yet and no key remapping or other
customisation.
$Id: CHANGES,v 1.18 2007-09-30 13:02:14 nicm Exp $
$Id: CHANGES,v 1.19 2007-10-01 14:53:29 nicm Exp $

View File

@ -1,4 +1,4 @@
# $Id: Makefile,v 1.8 2007-09-29 21:05:21 nicm Exp $
# $Id: Makefile,v 1.9 2007-10-01 14:53:29 nicm Exp $
.SUFFIXES: .c .o .y .h
.PHONY: clean
@ -16,7 +16,7 @@ DEBUG=
# Command prefix. This will go when we get a configuration file...
META?= \002 # C-b
SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c \
SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \
xmalloc.c xmalloc-debug.c input.c input-keys.c screen.c window.c \
session.c local.c log.c client.c client-msg.c client-cmd.c op.c op-list.c

View File

@ -1,4 +1,4 @@
/* $Id: server-fn.c,v 1.9 2007-10-01 14:18:42 nicm Exp $ */
/* $Id: server-fn.c,v 1.10 2007-10-01 14:53:29 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -23,6 +23,8 @@
#include "tmux.h"
void server_draw_status(struct client *);
/* Find session from sessid. */
struct session *
server_find_sessid(struct sessid *sid, char **cause)
@ -170,6 +172,30 @@ server_draw_client(struct client *c, u_int py_upper, u_int py_lower)
BUFFER_IN(c->out) - size - sizeof hdr, &hdr, sizeof hdr);
} else
buffer_reverse_add(c->out, sizeof hdr);
server_draw_status(c);
}
/* Draw status line. */
void
server_draw_status(struct client *c)
{
struct hdr hdr;
size_t size;
if (status_lines == 0)
return;
buffer_ensure(c->out, sizeof hdr);
buffer_add(c->out, sizeof hdr);
size = BUFFER_USED(c->out);
status_write(c);
size = BUFFER_USED(c->out) - size;
hdr.type = MSG_OUTPUT;
hdr.size = size;
memcpy(BUFFER_IN(c->out) - size - sizeof hdr, &hdr, sizeof hdr);
}
/* Send error message command to client. */
@ -202,7 +228,7 @@ server_write_message(struct client *c, const char *fmt, ...)
size = BUFFER_USED(c->out);
input_store_zero(c->out, CODE_CURSOROFF);
input_store_two(c->out, CODE_CURSORMOVE, c->sy, 1);
input_store_two(c->out, CODE_CURSORMOVE, c->sy + status_lines, 1);
input_store_two(c->out, CODE_ATTRIBUTES, ATTR_REVERSE, 0x88);
va_start(ap, fmt);
xvasprintf(&msg, fmt, ap);
@ -225,7 +251,11 @@ server_write_message(struct client *c, const char *fmt, ...)
buffer_add(c->out, sizeof hdr);
size = BUFFER_USED(c->out);
screen_draw(&c->session->window->screen, c->out, c->sy - 1, c->sy - 1);
if (status_lines == 0) {
screen_draw(
&c->session->window->screen, c->out, c->sy - 1, c->sy - 1);
} else
status_write(c);
size = BUFFER_USED(c->out) - size;
hdr.type = MSG_OUTPUT;

View File

@ -1,4 +1,4 @@
/* $Id: server-msg.c,v 1.12 2007-09-30 13:02:14 nicm Exp $ */
/* $Id: server-msg.c,v 1.13 2007-10-01 14:53:29 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -114,6 +114,9 @@ server_msg_fn_new(struct hdr *hdr, struct client *c)
if (c->sy == 0)
c->sy = 25;
if (c->sy >= status_lines)
c->sy -= status_lines;
data.name[(sizeof data.name) - 1] = '\0';
if (*data.name != '\0' && session_find(data.name) != NULL) {
xasprintf(&msg, "duplicate session: %s", data.name);
@ -157,6 +160,9 @@ server_msg_fn_attach(struct hdr *hdr, struct client *c)
if (c->sy == 0)
c->sy = 25;
if (c->sy >= status_lines)
c->sy -= status_lines;
if ((c->session = server_find_sessid(&data.sid, &cause)) == NULL) {
server_write_error(c, "%s", cause);
xfree(cause);
@ -246,6 +252,9 @@ server_msg_fn_size(struct hdr *hdr, struct client *c)
if (c->sy == 0)
c->sy = 25;
if (c->sy >= status_lines)
c->sy -= status_lines;
if (window_resize(c->session->window, c->sx, c->sy) != 0)
server_draw_client(c, 0, c->sy - 1);

80
status.c Normal file
View File

@ -0,0 +1,80 @@
/* $Id: status.c,v 1.1 2007-10-01 14:53:29 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
#include <stdarg.h>
#include "tmux.h"
void status_print(struct buffer *, size_t *, const char *, ...);
void
status_write(struct client *c)
{
struct screen *s = &c->session->window->screen;
struct buffer *b = c->out;
struct window *w;
size_t size;
u_int i;
input_store_zero(b, CODE_CURSOROFF);
input_store_two(b, CODE_CURSORMOVE, s->sy + 1, 1);
input_store_two(b, CODE_ATTRIBUTES, ATTR_REVERSE, 0x20);
size = s->sx;
for (i = 0; i < ARRAY_LENGTH(&c->session->windows); i++) {
w = ARRAY_ITEM(&c->session->windows, i);
if (w == NULL)
continue;
status_print(b, &size,
"%u:%s%s ", i, w->name, w == c->session->window ? "*" : "");
if (size == 0)
break;
}
while (size-- > 0)
input_store8(b, ' ');
input_store_two(b, CODE_ATTRIBUTES, s->attr, s->colr);
input_store_two(b, CODE_CURSORMOVE, s->cy + 1, s->cx + 1);
if (s->mode & MODE_CURSOR)
input_store_zero(b, CODE_CURSORON);
}
void
status_print(struct buffer *b, size_t *size, const char *fmt, ...)
{
va_list ap;
char *msg, *ptr;
int n;
va_start(ap, fmt);
n = xvasprintf(&msg, fmt, ap);
va_end(ap);
if ((size_t) n > *size) {
msg[*size] = '\0';
n = *size;
}
for (ptr = msg; *ptr != '\0'; ptr++)
input_store8(b, *ptr);
(*size) -= n;
xfree(msg);
}

5
tmux.c
View File

@ -1,4 +1,4 @@
/* $Id: tmux.c,v 1.17 2007-09-28 21:41:52 mxey Exp $ */
/* $Id: tmux.c,v 1.18 2007-10-01 14:53:29 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -35,6 +35,7 @@ const char *malloc_options = "AFGJPX";
volatile sig_atomic_t sigwinch;
volatile sig_atomic_t sigterm;
int debug_level;
u_int status_lines;
void sighandler(int);
@ -183,6 +184,8 @@ main(int argc, char **argv)
log_open(stderr, LOG_USER, debug_level);
status_lines = 1;
for (i = 0; i < NOP; i++) {
op = op_table + i;
if (strncmp(argv[0], op->cmd, strlen(argv[0])) == 0 ||

6
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.30 2007-10-01 14:18:42 nicm Exp $ */
/* $Id: tmux.h,v 1.31 2007-10-01 14:53:29 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -499,6 +499,7 @@ struct client_ctx {
extern volatile sig_atomic_t sigwinch;
extern volatile sig_atomic_t sigterm;
extern int debug_level;
extern u_int status_lines;
int usage(const char *);
void logfile(const char *);
void siginit(void);
@ -547,6 +548,9 @@ void server_write_clients(
void server_window_changed(struct client *);
void server_draw_client(struct client *, u_int, u_int);
/* status.c */
void status_write(struct client *c);
/* input.c */
void input_init(struct input_ctx *, struct screen *);
void input_free(struct input_ctx *);