Keep stack of previous windows.

Check for op (orig_pair) for default colours.
This commit is contained in:
Nicholas Marriott 2008-11-16 10:10:26 +00:00
parent 1425738790
commit 46f5e42145
9 changed files with 72 additions and 23 deletions

12
CHANGES
View File

@ -1,3 +1,13 @@
16 November 2008
* Enable default colours if op contains \033[39;49m, based on a report from
fulvio ciriaco.
12 November 2008
* Keep stack of last windows rather than just most recent; based on a diff from
joshe.
04 November 2008 04 November 2008
* Don't try to redraw status line when showing a prompt or message; if it does, * Don't try to redraw status line when showing a prompt or message; if it does,
@ -687,4 +697,4 @@
(including mutt, emacs). No status bar yet and no key remapping or other (including mutt, emacs). No status bar yet and no key remapping or other
customisation. customisation.
$Id: CHANGES,v 1.165 2008-11-04 20:55:58 nicm Exp $ $Id: CHANGES,v 1.166 2008-11-16 10:10:26 nicm Exp $

3
TODO
View File

@ -33,7 +33,7 @@
- flags to centre screen in window - flags to centre screen in window
- better terminal emulation (identify, insert mode, some other bits) - better terminal emulation (identify, insert mode, some other bits)
- save stack for last window - save stack for last window
- paste stack should be an SLIST. also key bindings? others? - when resizing, use history
-- For 0.5 -------------------------------------------------------------------- -- For 0.5 --------------------------------------------------------------------
@ -54,3 +54,4 @@
- many more info() displays for various things - many more info() displays for various things
- document mode-keys - document mode-keys
- vi half page scroll - vi half page scroll
- document new flags

View File

@ -1,4 +1,4 @@
/* $Id: cmd-link-window.c,v 1.24 2008-06-25 20:33:20 nicm Exp $ */ /* $Id: cmd-link-window.c,v 1.25 2008-11-16 10:10:26 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -79,6 +79,7 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
* if this makes it empty. * if this makes it empty.
*/ */
session_alert_cancel(dst, wl_dst); session_alert_cancel(dst, wl_dst);
winlink_stack_remove(&dst->lastw, wl_dst);
winlink_remove(&dst->windows, wl_dst); winlink_remove(&dst->windows, wl_dst);
/* Force select/redraw if current. */ /* Force select/redraw if current. */
@ -86,8 +87,6 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
data->flags &= ~CMD_DFLAG; data->flags &= ~CMD_DFLAG;
dst->curw = NULL; dst->curw = NULL;
} }
if (wl_dst == dst->lastw)
dst->lastw = NULL;
} }
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-move-window.c,v 1.1 2008-06-25 20:43:13 nicm Exp $ */ /* $Id: cmd-move-window.c,v 1.2 2008-11-16 10:10:26 nicm Exp $ */
/* /*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@ -81,6 +81,7 @@ cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
* if this makes it empty. * if this makes it empty.
*/ */
session_alert_cancel(dst, wl_dst); session_alert_cancel(dst, wl_dst);
winlink_stack_remove(&dst->lastw, wl_dst);
winlink_remove(&dst->windows, wl_dst); winlink_remove(&dst->windows, wl_dst);
/* Force select/redraw if current. */ /* Force select/redraw if current. */
@ -88,8 +89,6 @@ cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
data->flags &= ~CMD_DFLAG; data->flags &= ~CMD_DFLAG;
dst->curw = NULL; dst->curw = NULL;
} }
if (wl_dst == dst->lastw)
dst->lastw = NULL;
} }
} }

View File

@ -1,4 +1,4 @@
/* $Id: session.c,v 1.44 2008-11-05 01:19:24 nicm Exp $ */ /* $Id: session.c,v 1.45 2008-11-16 10:10:26 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -117,7 +117,8 @@ session_create(const char *name, const char *cmd, u_int sx, u_int sy)
s = xmalloc(sizeof *s); s = xmalloc(sizeof *s);
if (gettimeofday(&s->tv, NULL) != 0) if (gettimeofday(&s->tv, NULL) != 0)
fatal("gettimeofday"); fatal("gettimeofday");
s->curw = s->lastw = NULL; s->curw = NULL;
SLIST_INIT(&s->lastw);
RB_INIT(&s->windows); RB_INIT(&s->windows);
SLIST_INIT(&s->alerts); SLIST_INIT(&s->alerts);
paste_init_stack(&s->buffers); paste_init_stack(&s->buffers);
@ -168,6 +169,8 @@ session_destroy(struct session *s)
options_free(&s->options); options_free(&s->options);
paste_free_stack(&s->buffers); paste_free_stack(&s->buffers);
while (!SLIST_EMPTY(&s->lastw))
winlink_stack_remove(&s->lastw, SLIST_FIRST(&s->lastw));
while (!RB_EMPTY(&s->windows)) while (!RB_EMPTY(&s->windows))
winlink_remove(&s->windows, RB_ROOT(&s->windows)); winlink_remove(&s->windows, RB_ROOT(&s->windows));
@ -223,10 +226,9 @@ session_detach(struct session *s, struct winlink *wl)
{ {
if (s->curw == wl && session_last(s) != 0 && session_previous(s) != 0) if (s->curw == wl && session_last(s) != 0 && session_previous(s) != 0)
session_next(s); session_next(s);
if (s->lastw == wl)
s->lastw = NULL;
session_alert_cancel(s, wl); session_alert_cancel(s, wl);
winlink_stack_remove(&s->lastw, wl);
winlink_remove(&s->windows, wl); winlink_remove(&s->windows, wl);
if (RB_EMPTY(&s->windows)) { if (RB_EMPTY(&s->windows)) {
session_destroy(s); session_destroy(s);
@ -262,7 +264,8 @@ session_next(struct session *s)
wl = RB_MIN(winlinks, &s->windows); wl = RB_MIN(winlinks, &s->windows);
if (wl == s->curw) if (wl == s->curw)
return (1); return (1);
s->lastw = s->curw; winlink_stack_remove(&s->lastw, wl);
winlink_stack_push(&s->lastw, s->curw);
s->curw = wl; s->curw = wl;
session_alert_cancel(s, wl); session_alert_cancel(s, wl);
return (0); return (0);
@ -282,7 +285,8 @@ session_previous(struct session *s)
wl = RB_MAX(winlinks, &s->windows); wl = RB_MAX(winlinks, &s->windows);
if (wl == s->curw) if (wl == s->curw)
return (1); return (1);
s->lastw = s->curw; winlink_stack_remove(&s->lastw, wl);
winlink_stack_push(&s->lastw, s->curw);
s->curw = wl; s->curw = wl;
session_alert_cancel(s, wl); session_alert_cancel(s, wl);
return (0); return (0);
@ -299,7 +303,8 @@ session_select(struct session *s, int idx)
return (-1); return (-1);
if (wl == s->curw) if (wl == s->curw)
return (1); return (1);
s->lastw = s->curw; winlink_stack_remove(&s->lastw, wl);
winlink_stack_push(&s->lastw, s->curw);
s->curw = wl; s->curw = wl;
session_alert_cancel(s, wl); session_alert_cancel(s, wl);
return (0); return (0);
@ -311,13 +316,14 @@ session_last(struct session *s)
{ {
struct winlink *wl; struct winlink *wl;
wl = s->lastw; wl = SLIST_FIRST(&s->lastw);
if (wl == NULL) if (wl == NULL)
return (-1); return (-1);
if (wl == s->curw) if (wl == s->curw)
return (1); return (1);
s->lastw = s->curw; winlink_stack_remove(&s->lastw, wl);
winlink_stack_push(&s->lastw, s->curw);
s->curw = wl; s->curw = wl;
session_alert_cancel(s, wl); session_alert_cancel(s, wl);
return (0); return (0);

View File

@ -1,4 +1,4 @@
/* $Id: status.c,v 1.49 2008-09-29 17:47:12 nicm Exp $ */ /* $Id: status.c,v 1.50 2008-11-16 10:10:26 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -277,7 +277,7 @@ status_print(struct session *s, struct winlink *wl, struct grid_cell *gc)
char *text, flag; char *text, flag;
flag = ' '; flag = ' ';
if (wl == s->lastw) if (wl == SLIST_FIRST(&s->lastw))
flag = '-'; flag = '-';
if (wl == s->curw) if (wl == s->curw)
flag = '*'; flag = '*';

8
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.195 2008-11-05 01:19:24 nicm Exp $ */ /* $Id: tmux.h,v 1.196 2008-11-16 10:10:26 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -589,8 +589,10 @@ struct winlink {
struct window *window; struct window *window;
RB_ENTRY(winlink) entry; RB_ENTRY(winlink) entry;
SLIST_ENTRY(winlink) sentry;
}; };
RB_HEAD(winlinks, winlink); RB_HEAD(winlinks, winlink);
SLIST_HEAD(winlink_stack, winlink);
/* Option data structures. */ /* Option data structures. */
struct options_entry { struct options_entry {
@ -640,7 +642,7 @@ struct session {
u_int sy; u_int sy;
struct winlink *curw; struct winlink *curw;
struct winlink *lastw; struct winlink_stack lastw;
struct winlinks windows; struct winlinks windows;
struct options options; struct options options;
@ -1260,6 +1262,8 @@ struct winlink *winlink_add(struct winlinks *, struct window *, int);
void winlink_remove(struct winlinks *, struct winlink *); void winlink_remove(struct winlinks *, struct winlink *);
struct winlink *winlink_next(struct winlinks *, struct winlink *); struct winlink *winlink_next(struct winlinks *, struct winlink *);
struct winlink *winlink_previous(struct winlinks *, struct winlink *); struct winlink *winlink_previous(struct winlinks *, struct winlink *);
void winlink_stack_push(struct winlink_stack *, struct winlink *);
void winlink_stack_remove(struct winlink_stack *, struct winlink *);
struct window *window_create(const char *, struct window *window_create(const char *,
const char *, const char **, u_int, u_int, u_int); const char *, const char **, u_int, u_int, u_int);
int window_spawn(struct window *, const char *, const char **); int window_spawn(struct window *, const char *, const char **);

6
tty.c
View File

@ -1,4 +1,4 @@
/* $Id: tty.c,v 1.49 2008-11-05 01:19:24 nicm Exp $ */ /* $Id: tty.c,v 1.50 2008-11-16 10:10:26 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -255,6 +255,7 @@ tty_find_term(char *name, int fd, char **cause)
{ {
struct tty_term *term; struct tty_term *term;
int error; int error;
char *s;
SLIST_FOREACH(term, &tty_terms, entry) { SLIST_FOREACH(term, &tty_terms, entry) {
if (strcmp(term->name, name) == 0) { if (strcmp(term->name, name) == 0) {
@ -348,6 +349,9 @@ tty_find_term(char *name, int fd, char **cause)
if (tigetflag("AX") == TRUE) if (tigetflag("AX") == TRUE)
term->flags |= TERM_HASDEFAULTS; term->flags |= TERM_HASDEFAULTS;
s = tigetstr("orig_pair");
if (s != NULL && s != (char *) -1 && strcmp(s, "\033[39;49m") == 0)
term->flags |= TERM_HASDEFAULTS;
/* /*
* Try to figure out if we have 256 colours. The standard xterm * Try to figure out if we have 256 colours. The standard xterm

View File

@ -1,4 +1,4 @@
/* $Id: window.c,v 1.50 2008-09-26 06:45:28 nicm Exp $ */ /* $Id: window.c,v 1.51 2008-11-16 10:10:26 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -164,6 +164,32 @@ winlink_previous(unused struct winlinks *wwl, struct winlink *wl)
#endif #endif
} }
void
winlink_stack_push(struct winlink_stack *stack, struct winlink *wl)
{
if (wl == NULL)
return;
winlink_stack_remove(stack, wl);
SLIST_INSERT_HEAD(stack, wl, sentry);
}
void
winlink_stack_remove(struct winlink_stack *stack, struct winlink *wl)
{
struct winlink *wl2;
if (wl == NULL)
return;
SLIST_FOREACH(wl2, stack, sentry) {
if (wl2 == wl) {
SLIST_REMOVE(stack, wl, winlink, sentry);
return;
}
}
}
struct window * struct window *
window_create(const char *name, window_create(const char *name,
const char *cmd, const char **envp, u_int sx, u_int sy, u_int hlimit) const char *cmd, const char **envp, u_int sx, u_int sy, u_int hlimit)