mirror of
https://github.com/tmux/tmux.git
synced 2024-12-12 17:38:48 +00:00
Redo mode keys slightly more cleanly and apply them to command prompt editing. vi or emacs mode is controlled by the session option status-keys.
This commit is contained in:
parent
47e6b2725d
commit
95c8c049f5
7
CHANGES
7
CHANGES
@ -1,5 +1,10 @@
|
||||
13 February 2009
|
||||
|
||||
* Redo mode keys slightly more cleanly and apply them to command prompt
|
||||
editing. vi or emacs mode is controlled by the session option status-keys.
|
||||
|
||||
12 February 2009
|
||||
|
||||
* Looking up argv[0] is expensive, so just use p_comm for the window name which
|
||||
is good enough. Also increase name update time to 500 ms.
|
||||
|
||||
@ -1109,7 +1114,7 @@
|
||||
(including mutt, emacs). No status bar yet and no key remapping or other
|
||||
customisation.
|
||||
|
||||
$Id: CHANGES,v 1.254 2009-02-13 00:43:04 nicm Exp $
|
||||
$Id: CHANGES,v 1.255 2009-02-13 21:39:45 nicm Exp $
|
||||
|
||||
LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
|
||||
LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms
|
||||
|
1
TODO
1
TODO
@ -99,3 +99,4 @@
|
||||
for stuff like mode keys?
|
||||
- bug: copy mode gets the start of the selection wrong
|
||||
- ncmpc scroll up doesn't redraw properly
|
||||
- document status-keys
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-set-option.c,v 1.58 2009-01-30 00:24:49 nicm Exp $ */
|
||||
/* $Id: cmd-set-option.c,v 1.59 2009-02-13 21:39:45 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -42,6 +42,9 @@ const struct cmd_entry cmd_set_option_entry = {
|
||||
cmd_option_print
|
||||
};
|
||||
|
||||
const char *set_option_status_keys_list[] = {
|
||||
"emacs", "vi", NULL
|
||||
};
|
||||
const char *set_option_bell_action_list[] = {
|
||||
"none", "any", "current", NULL
|
||||
};
|
||||
@ -64,6 +67,7 @@ const struct set_option_entry set_option_table[NSETOPTION] = {
|
||||
{ "status-bg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||
{ "status-fg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||
{ "status-interval", SET_OPTION_NUMBER, 0, INT_MAX, NULL },
|
||||
{ "status-keys", SET_OPTION_CHOICE, 0, 0, set_option_status_keys_list },
|
||||
{ "status-left", SET_OPTION_STRING, 0, 0, NULL },
|
||||
{ "status-left-length", SET_OPTION_NUMBER, 0, SHRT_MAX, NULL },
|
||||
{ "status-right", SET_OPTION_STRING, 0, 0, NULL },
|
||||
|
247
mode-key.c
247
mode-key.c
@ -1,4 +1,4 @@
|
||||
/* $Id: mode-key.c,v 1.8 2009-02-13 16:40:04 nicm Exp $ */
|
||||
/* $Id: mode-key.c,v 1.9 2009-02-13 21:39:45 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -20,79 +20,180 @@
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
struct mode_key_entry {
|
||||
enum mode_key mkey;
|
||||
int key;
|
||||
};
|
||||
enum mode_key_cmd mode_key_lookup_vi(struct mode_key_data *, int);
|
||||
enum mode_key_cmd mode_key_lookup_emacs(struct mode_key_data *, int);
|
||||
|
||||
const struct mode_key_entry mode_key_table_vi[] = {
|
||||
{ MODEKEY_ENTER, '\r' }, /* must come first */
|
||||
{ MODEKEY_BOL, '0' },
|
||||
{ MODEKEY_BOL, '^' },
|
||||
{ MODEKEY_CLEARSEL, '\033' },
|
||||
{ MODEKEY_COPYSEL, '\r' },
|
||||
{ MODEKEY_DOWN, 'j' },
|
||||
{ MODEKEY_DOWN, KEYC_DOWN },
|
||||
{ MODEKEY_EOL, '$' },
|
||||
{ MODEKEY_LEFT, 'h' },
|
||||
{ MODEKEY_LEFT, KEYC_LEFT },
|
||||
{ MODEKEY_NPAGE, '\006' },
|
||||
{ MODEKEY_NPAGE, KEYC_NPAGE },
|
||||
{ MODEKEY_NWORD, 'w' },
|
||||
{ MODEKEY_PPAGE, '\025' },
|
||||
{ MODEKEY_PPAGE, KEYC_PPAGE },
|
||||
{ MODEKEY_PWORD, 'b' },
|
||||
{ MODEKEY_QUIT, 'q' },
|
||||
{ MODEKEY_RIGHT, 'l' },
|
||||
{ MODEKEY_RIGHT, KEYC_RIGHT },
|
||||
{ MODEKEY_STARTSEL, ' ' },
|
||||
{ MODEKEY_UP, 'k' },
|
||||
{ MODEKEY_UP, KEYC_UP },
|
||||
};
|
||||
|
||||
const struct mode_key_entry mode_key_table_emacs[] = {
|
||||
{ MODEKEY_ENTER, '\r' }, /* must come first */
|
||||
{ MODEKEY_BOL, '\001' },
|
||||
{ MODEKEY_CLEARSEL, '\007' },
|
||||
{ MODEKEY_COPYSEL, '\027' },
|
||||
{ MODEKEY_COPYSEL, KEYC_ADDESC('w') },
|
||||
{ MODEKEY_DOWN, '\016' },
|
||||
{ MODEKEY_DOWN, KEYC_DOWN },
|
||||
{ MODEKEY_EOL, '\005' },
|
||||
{ MODEKEY_LEFT, '\002' },
|
||||
{ MODEKEY_LEFT, KEYC_LEFT },
|
||||
{ MODEKEY_NPAGE, '\026' },
|
||||
{ MODEKEY_NPAGE, KEYC_NPAGE },
|
||||
{ MODEKEY_NWORD, KEYC_ADDESC('f') },
|
||||
{ MODEKEY_PPAGE, KEYC_ADDESC('v') },
|
||||
{ MODEKEY_PPAGE, KEYC_PPAGE },
|
||||
{ MODEKEY_PWORD, KEYC_ADDESC('b') },
|
||||
{ MODEKEY_QUIT, 'q' },
|
||||
{ MODEKEY_RIGHT, '\006' },
|
||||
{ MODEKEY_RIGHT, KEYC_RIGHT },
|
||||
{ MODEKEY_STARTSEL, '\000' },
|
||||
{ MODEKEY_UP, '\020' },
|
||||
{ MODEKEY_UP, KEYC_UP },
|
||||
};
|
||||
|
||||
enum mode_key
|
||||
mode_key_lookup(int table, int key)
|
||||
void
|
||||
mode_key_init(struct mode_key_data *mdata, int type, int flags)
|
||||
{
|
||||
const struct mode_key_entry *ptr;
|
||||
u_int i, n;
|
||||
mdata->type = type;
|
||||
|
||||
if (table == MODEKEY_EMACS) {
|
||||
ptr = mode_key_table_emacs;
|
||||
n = nitems(mode_key_table_emacs);
|
||||
} else if (table == MODEKEY_VI) {
|
||||
ptr = mode_key_table_vi;
|
||||
n = nitems(mode_key_table_vi);
|
||||
} else
|
||||
return (MODEKEY_NONE);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
if (ptr[i].key == key)
|
||||
return (ptr[i].mkey);
|
||||
}
|
||||
return (MODEKEY_NONE);
|
||||
if (flags & MODEKEY_CANEDIT)
|
||||
flags |= MODEKEY_EDITMODE;
|
||||
mdata->flags = flags;
|
||||
}
|
||||
|
||||
void
|
||||
mode_key_free(unused struct mode_key_data *mdata)
|
||||
{
|
||||
}
|
||||
|
||||
enum mode_key_cmd
|
||||
mode_key_lookup(struct mode_key_data *mdata, int key)
|
||||
{
|
||||
switch (mdata->type) {
|
||||
case MODEKEY_VI:
|
||||
return (mode_key_lookup_vi(mdata, key));
|
||||
case MODEKEY_EMACS:
|
||||
return (mode_key_lookup_emacs(mdata, key));
|
||||
default:
|
||||
fatalx("unknown mode key type");
|
||||
}
|
||||
}
|
||||
|
||||
enum mode_key_cmd
|
||||
mode_key_lookup_vi(struct mode_key_data *mdata, int key)
|
||||
{
|
||||
if (mdata->flags & MODEKEY_EDITMODE) {
|
||||
switch (key) {
|
||||
case '\003':
|
||||
return (MODEKEYCMD_QUIT);
|
||||
case '\033':
|
||||
if (mdata->flags & MODEKEY_CANEDIT)
|
||||
mdata->flags &= ~MODEKEY_EDITMODE;
|
||||
return (MODEKEYCMD_NONE);
|
||||
case '\010':
|
||||
case '\177':
|
||||
return (MODEKEYCMD_BACKSPACE);
|
||||
case '\011':
|
||||
return (MODEKEYCMD_COMPLETE);
|
||||
case KEYC_DC:
|
||||
return (MODEKEYCMD_DELETE);
|
||||
case '\r':
|
||||
return (MODEKEYCMD_CHOOSE);
|
||||
}
|
||||
return (MODEKEYCMD_OTHERKEY);
|
||||
}
|
||||
|
||||
switch (key) {
|
||||
case '\010':
|
||||
case '\177':
|
||||
return (MODEKEYCMD_LEFT);
|
||||
case KEYC_DC:
|
||||
return (MODEKEYCMD_DELETE);
|
||||
case '\011':
|
||||
return (MODEKEYCMD_COMPLETE);
|
||||
case 'i':
|
||||
if (mdata->flags & MODEKEY_CANEDIT)
|
||||
mdata->flags |= MODEKEY_EDITMODE;
|
||||
break;
|
||||
case 'a':
|
||||
if (mdata->flags & MODEKEY_CANEDIT) {
|
||||
mdata->flags |= MODEKEY_EDITMODE;
|
||||
return (MODEKEYCMD_RIGHT);
|
||||
}
|
||||
break;
|
||||
case '\r':
|
||||
if (mdata->flags & MODEKEY_CANEDIT)
|
||||
return (MODEKEYCMD_CHOOSE);
|
||||
return (MODEKEYCMD_COPYSELECTION);
|
||||
case '0':
|
||||
case '^':
|
||||
return (MODEKEYCMD_STARTOFLINE);
|
||||
case '\033':
|
||||
return (MODEKEYCMD_CLEARSELECTION);
|
||||
case 'j':
|
||||
case KEYC_DOWN:
|
||||
return (MODEKEYCMD_DOWN);
|
||||
case '$':
|
||||
return (MODEKEYCMD_ENDOFLINE);
|
||||
case 'h':
|
||||
case KEYC_LEFT:
|
||||
return (MODEKEYCMD_LEFT);
|
||||
case '\006':
|
||||
case KEYC_NPAGE:
|
||||
return (MODEKEYCMD_NEXTPAGE);
|
||||
case 'w':
|
||||
return (MODEKEYCMD_NEXTWORD);
|
||||
case '\025':
|
||||
case KEYC_PPAGE:
|
||||
return (MODEKEYCMD_PREVIOUSPAGE);
|
||||
case 'b':
|
||||
return (MODEKEYCMD_PREVIOUSWORD);
|
||||
case 'q':
|
||||
case '\003':
|
||||
return (MODEKEYCMD_QUIT);
|
||||
case 'l':
|
||||
case KEYC_RIGHT:
|
||||
return (MODEKEYCMD_RIGHT);
|
||||
case ' ':
|
||||
return (MODEKEYCMD_STARTSELECTION);
|
||||
case 'k':
|
||||
case KEYC_UP:
|
||||
return (MODEKEYCMD_UP);
|
||||
}
|
||||
|
||||
return (MODEKEYCMD_NONE);
|
||||
}
|
||||
|
||||
enum mode_key_cmd
|
||||
mode_key_lookup_emacs(struct mode_key_data *mdata, int key)
|
||||
{
|
||||
switch (key) {
|
||||
case '\010':
|
||||
case '\177':
|
||||
return (MODEKEYCMD_BACKSPACE);
|
||||
case KEYC_DC:
|
||||
return (MODEKEYCMD_DELETE);
|
||||
case '\011':
|
||||
return (MODEKEYCMD_COMPLETE);
|
||||
case '\r':
|
||||
return (MODEKEYCMD_CHOOSE);
|
||||
case '\001':
|
||||
return (MODEKEYCMD_STARTOFLINE);
|
||||
case '\007':
|
||||
return (MODEKEYCMD_CLEARSELECTION);
|
||||
case '\027':
|
||||
case KEYC_ADDESC('w'):
|
||||
return (MODEKEYCMD_COPYSELECTION);
|
||||
case '\016':
|
||||
case KEYC_DOWN:
|
||||
return (MODEKEYCMD_DOWN);
|
||||
case '\005':
|
||||
return (MODEKEYCMD_ENDOFLINE);
|
||||
case '\002':
|
||||
case KEYC_LEFT:
|
||||
return (MODEKEYCMD_LEFT);
|
||||
case ' ':
|
||||
if (mdata->flags & MODEKEY_CANEDIT)
|
||||
break;
|
||||
/* FALLTHROUGH */
|
||||
case '\026':
|
||||
case KEYC_NPAGE:
|
||||
return (MODEKEYCMD_NEXTPAGE);
|
||||
case KEYC_ADDESC('f'):
|
||||
return (MODEKEYCMD_NEXTWORD);
|
||||
case KEYC_ADDESC('v'):
|
||||
case KEYC_PPAGE:
|
||||
return (MODEKEYCMD_PREVIOUSPAGE);
|
||||
case KEYC_ADDESC('b'):
|
||||
return (MODEKEYCMD_PREVIOUSWORD);
|
||||
case '\006':
|
||||
case KEYC_RIGHT:
|
||||
return (MODEKEYCMD_RIGHT);
|
||||
case '\000':
|
||||
return (MODEKEYCMD_STARTSELECTION);
|
||||
case '\020':
|
||||
case KEYC_UP:
|
||||
return (MODEKEYCMD_UP);
|
||||
case 'q':
|
||||
if (mdata->flags & MODEKEY_CANEDIT)
|
||||
break;
|
||||
/* FALLTHROUGH */
|
||||
case '\003':
|
||||
case '\033':
|
||||
return (MODEKEYCMD_QUIT);
|
||||
}
|
||||
|
||||
return (MODEKEYCMD_OTHERKEY);
|
||||
}
|
||||
|
41
status.c
41
status.c
@ -1,4 +1,4 @@
|
||||
/* $Id: status.c,v 1.74 2009-02-13 18:57:55 nicm Exp $ */
|
||||
/* $Id: status.c,v 1.75 2009-02-13 21:39:45 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -577,6 +577,10 @@ status_prompt_set(struct client *c,
|
||||
|
||||
c->prompt_hidden = hide;
|
||||
|
||||
mode_key_init(&c->prompt_mdata,
|
||||
options_get_number(&c->session->options, "status-keys"),
|
||||
MODEKEY_CANEDIT);
|
||||
|
||||
c->tty.flags |= (TTY_NOCURSOR|TTY_FREEZE);
|
||||
c->flags |= CLIENT_STATUS;
|
||||
}
|
||||
@ -587,6 +591,8 @@ status_prompt_clear(struct client *c)
|
||||
if (c->prompt_string == NULL)
|
||||
return;
|
||||
|
||||
mode_key_free(&c->prompt_mdata);
|
||||
|
||||
xfree(c->prompt_string);
|
||||
c->prompt_string = NULL;
|
||||
|
||||
@ -682,35 +688,33 @@ status_prompt_key(struct client *c, int key)
|
||||
size_t size, n, off, idx;
|
||||
char word[64];
|
||||
|
||||
/* XXX This function needs some tidying... */
|
||||
|
||||
size = strlen(c->prompt_buffer);
|
||||
switch (key) {
|
||||
case KEYC_LEFT:
|
||||
switch (mode_key_lookup(&c->prompt_mdata, key)) {
|
||||
case MODEKEYCMD_LEFT:
|
||||
if (c->prompt_index > 0) {
|
||||
c->prompt_index--;
|
||||
c->flags |= CLIENT_STATUS;
|
||||
}
|
||||
break;
|
||||
case KEYC_RIGHT:
|
||||
case MODEKEYCMD_RIGHT:
|
||||
if (c->prompt_index < size) {
|
||||
c->prompt_index++;
|
||||
c->flags |= CLIENT_STATUS;
|
||||
}
|
||||
break;
|
||||
case '\001': /* C-a */
|
||||
case MODEKEYCMD_STARTOFLINE:
|
||||
if (c->prompt_index != 0) {
|
||||
c->prompt_index = 0;
|
||||
c->flags |= CLIENT_STATUS;
|
||||
}
|
||||
break;
|
||||
case '\005': /* C-e */
|
||||
case MODEKEYCMD_ENDOFLINE:
|
||||
if (c->prompt_index != size) {
|
||||
c->prompt_index = size;
|
||||
c->flags |= CLIENT_STATUS;
|
||||
}
|
||||
break;
|
||||
case '\011':
|
||||
case MODEKEYCMD_COMPLETE:
|
||||
if (*c->prompt_buffer == '\0')
|
||||
break;
|
||||
|
||||
@ -758,8 +762,7 @@ status_prompt_key(struct client *c, int key)
|
||||
|
||||
c->flags |= CLIENT_STATUS;
|
||||
break;
|
||||
case '\010':
|
||||
case '\177':
|
||||
case MODEKEYCMD_BACKSPACE:
|
||||
if (c->prompt_index != 0) {
|
||||
if (c->prompt_index == size)
|
||||
c->prompt_buffer[--c->prompt_index] = '\0';
|
||||
@ -772,7 +775,7 @@ status_prompt_key(struct client *c, int key)
|
||||
c->flags |= CLIENT_STATUS;
|
||||
}
|
||||
break;
|
||||
case KEYC_DC:
|
||||
case MODEKEYCMD_DELETE:
|
||||
if (c->prompt_index != size) {
|
||||
memmove(c->prompt_buffer + c->prompt_index,
|
||||
c->prompt_buffer + c->prompt_index + 1,
|
||||
@ -780,7 +783,7 @@ status_prompt_key(struct client *c, int key)
|
||||
c->flags |= CLIENT_STATUS;
|
||||
}
|
||||
break;
|
||||
case KEYC_UP:
|
||||
case MODEKEYCMD_UP:
|
||||
if (ARRAY_LENGTH(&c->prompt_hdata) == 0)
|
||||
break;
|
||||
xfree(c->prompt_buffer);
|
||||
@ -793,7 +796,7 @@ status_prompt_key(struct client *c, int key)
|
||||
c->prompt_index = strlen(c->prompt_buffer);
|
||||
c->flags |= CLIENT_STATUS;
|
||||
break;
|
||||
case KEYC_DOWN:
|
||||
case MODEKEYCMD_DOWN:
|
||||
xfree(c->prompt_buffer);
|
||||
|
||||
if (c->prompt_hindex != 0) {
|
||||
@ -807,7 +810,7 @@ status_prompt_key(struct client *c, int key)
|
||||
c->prompt_index = strlen(c->prompt_buffer);
|
||||
c->flags |= CLIENT_STATUS;
|
||||
break;
|
||||
case '\r': /* enter */
|
||||
case MODEKEYCMD_CHOOSE:
|
||||
if (*c->prompt_buffer != '\0') {
|
||||
status_prompt_add_history(c);
|
||||
if (c->prompt_callback(
|
||||
@ -816,12 +819,12 @@ status_prompt_key(struct client *c, int key)
|
||||
break;
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
case '\033': /* escape */
|
||||
case MODEKEYCMD_QUIT:
|
||||
if (c->prompt_callback(c->prompt_data, NULL) == 0)
|
||||
status_prompt_clear(c);
|
||||
break;
|
||||
default:
|
||||
if (key < 32)
|
||||
case MODEKEYCMD_OTHERKEY:
|
||||
if (key < 32 || key > 126)
|
||||
break;
|
||||
c->prompt_buffer = xrealloc(c->prompt_buffer, 1, size + 2);
|
||||
|
||||
@ -837,6 +840,8 @@ status_prompt_key(struct client *c, int key)
|
||||
|
||||
c->flags |= CLIENT_STATUS;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
3
tmux.c
3
tmux.c
@ -1,4 +1,4 @@
|
||||
/* $Id: tmux.c,v 1.106 2009-02-08 16:26:43 nicm Exp $ */
|
||||
/* $Id: tmux.c,v 1.107 2009-02-13 21:39:45 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -252,6 +252,7 @@ main(int argc, char **argv)
|
||||
options_set_string(&global_options, "status-left", "[#S]");
|
||||
options_set_string(
|
||||
&global_options, "status-right", "\"#24T\" %%H:%%M %%d-%%b-%%y");
|
||||
options_set_number(&global_options, "status-keys", MODEKEY_EMACS);
|
||||
options_init(&global_window_options, NULL);
|
||||
options_set_number(&global_window_options, "aggressive-resize", 0);
|
||||
options_set_number(&global_window_options, "clock-mode-colour", 4);
|
||||
|
66
tmux.h
66
tmux.h
@ -1,4 +1,4 @@
|
||||
/* $Id: tmux.h,v 1.272 2009-02-13 18:57:55 nicm Exp $ */
|
||||
/* $Id: tmux.h,v 1.273 2009-02-13 21:39:45 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -398,6 +398,41 @@ struct msg_resize_data {
|
||||
u_int sy;
|
||||
};
|
||||
|
||||
/* Editing keys. */
|
||||
enum mode_key_cmd {
|
||||
MODEKEYCMD_BACKSPACE,
|
||||
MODEKEYCMD_CHOOSE,
|
||||
MODEKEYCMD_CLEARSELECTION,
|
||||
MODEKEYCMD_COMPLETE,
|
||||
MODEKEYCMD_COPYSELECTION,
|
||||
MODEKEYCMD_DELETE,
|
||||
MODEKEYCMD_DOWN,
|
||||
MODEKEYCMD_ENDOFLINE,
|
||||
MODEKEYCMD_LEFT,
|
||||
MODEKEYCMD_NEXTPAGE,
|
||||
MODEKEYCMD_NEXTWORD,
|
||||
MODEKEYCMD_NONE,
|
||||
MODEKEYCMD_OTHERKEY,
|
||||
MODEKEYCMD_PREVIOUSPAGE,
|
||||
MODEKEYCMD_PREVIOUSWORD,
|
||||
MODEKEYCMD_QUIT,
|
||||
MODEKEYCMD_RIGHT,
|
||||
MODEKEYCMD_STARTOFLINE,
|
||||
MODEKEYCMD_STARTSELECTION,
|
||||
MODEKEYCMD_UP,
|
||||
};
|
||||
|
||||
struct mode_key_data {
|
||||
int type;
|
||||
|
||||
int flags;
|
||||
#define MODEKEY_EDITMODE 0x1
|
||||
#define MODEKEY_CANEDIT 0x2
|
||||
};
|
||||
|
||||
#define MODEKEY_EMACS 0
|
||||
#define MODEKEY_VI 1
|
||||
|
||||
/* Modes. */
|
||||
#define MODE_CURSOR 0x1
|
||||
#define MODE_INSERT 0x2
|
||||
@ -786,6 +821,7 @@ struct client {
|
||||
int prompt_hidden;
|
||||
u_int prompt_hindex;
|
||||
ARRAY_DECL(, char *) prompt_hdata;
|
||||
struct mode_key_data prompt_mdata;
|
||||
|
||||
struct session *session;
|
||||
};
|
||||
@ -914,31 +950,9 @@ struct set_option_entry {
|
||||
};
|
||||
extern const struct set_option_entry set_option_table[];
|
||||
extern const struct set_option_entry set_window_option_table[];
|
||||
#define NSETOPTION 22
|
||||
#define NSETOPTION 23
|
||||
#define NSETWINDOWOPTION 17
|
||||
|
||||
/* Edit keys. */
|
||||
enum mode_key {
|
||||
MODEKEY_BOL,
|
||||
MODEKEY_CLEARSEL,
|
||||
MODEKEY_COPYSEL,
|
||||
MODEKEY_DOWN,
|
||||
MODEKEY_ENTER,
|
||||
MODEKEY_EOL,
|
||||
MODEKEY_LEFT,
|
||||
MODEKEY_NONE,
|
||||
MODEKEY_NPAGE,
|
||||
MODEKEY_NWORD,
|
||||
MODEKEY_PPAGE,
|
||||
MODEKEY_PWORD,
|
||||
MODEKEY_QUIT,
|
||||
MODEKEY_RIGHT,
|
||||
MODEKEY_STARTSEL,
|
||||
MODEKEY_UP,
|
||||
};
|
||||
#define MODEKEY_EMACS 0
|
||||
#define MODEKEY_VI 1
|
||||
|
||||
#ifdef NO_STRTONUM
|
||||
/* strtonum.c */
|
||||
long long strtonum(const char *, long long, long long, const char **);
|
||||
@ -999,7 +1013,9 @@ void sighandler(int);
|
||||
int load_cfg(const char *, char **x);
|
||||
|
||||
/* mode-key.c */
|
||||
enum mode_key mode_key_lookup(int, int);
|
||||
void mode_key_init(struct mode_key_data *, int, int);
|
||||
void mode_key_free(struct mode_key_data *);
|
||||
enum mode_key_cmd mode_key_lookup(struct mode_key_data *, int);
|
||||
|
||||
/* options.c */
|
||||
int options_cmp(struct options_entry *, struct options_entry *);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: window-choose.c,v 1.10 2009-01-29 20:02:33 nicm Exp $ */
|
||||
/* $Id: window-choose.c,v 1.11 2009-02-13 21:39:45 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -53,6 +53,8 @@ struct window_choose_mode_item {
|
||||
struct window_choose_mode_data {
|
||||
struct screen screen;
|
||||
|
||||
struct mode_key_data mdata;
|
||||
|
||||
ARRAY_DECL(, struct window_choose_mode_item) list;
|
||||
u_int top;
|
||||
u_int selected;
|
||||
@ -115,6 +117,9 @@ window_choose_init(struct window_pane *wp)
|
||||
screen_init(s, screen_size_x(&wp->base), screen_size_y(&wp->base), 0);
|
||||
s->mode &= ~MODE_CURSOR;
|
||||
s->mode |= MODE_MOUSE;
|
||||
|
||||
mode_key_init(&data->mdata,
|
||||
options_get_number(&wp->window->options, "mode-keys"), 0);
|
||||
|
||||
return (s);
|
||||
}
|
||||
@ -124,6 +129,8 @@ window_choose_free(struct window_pane *wp)
|
||||
{
|
||||
struct window_choose_mode_data *data = wp->modedata;
|
||||
u_int i;
|
||||
|
||||
mode_key_free(&data->mdata);
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(&data->list); i++)
|
||||
xfree(ARRAY_ITEM(&data->list, i).name);
|
||||
@ -154,23 +161,21 @@ window_choose_key(struct window_pane *wp, unused struct client *c, int key)
|
||||
struct screen *s = &data->screen;
|
||||
struct screen_write_ctx ctx;
|
||||
struct window_choose_mode_item *item;
|
||||
int table;
|
||||
u_int items;
|
||||
|
||||
items = ARRAY_LENGTH(&data->list);
|
||||
|
||||
table = options_get_number(&wp->window->options, "mode-keys");
|
||||
switch (mode_key_lookup(table, key)) {
|
||||
case MODEKEY_QUIT:
|
||||
switch (mode_key_lookup(&data->mdata, key)) {
|
||||
case MODEKEYCMD_QUIT:
|
||||
data->callback(data->data, -1);
|
||||
window_pane_reset_mode(wp);
|
||||
break;
|
||||
case MODEKEY_ENTER:
|
||||
case MODEKEYCMD_CHOOSE:
|
||||
item = &ARRAY_ITEM(&data->list, data->selected);
|
||||
data->callback(data->data, item->idx);
|
||||
window_pane_reset_mode(wp);
|
||||
break;
|
||||
case MODEKEY_UP:
|
||||
case MODEKEYCMD_UP:
|
||||
if (items == 0)
|
||||
break;
|
||||
if (data->selected == 0) {
|
||||
@ -192,7 +197,7 @@ window_choose_key(struct window_pane *wp, unused struct client *c, int key)
|
||||
screen_write_stop(&ctx);
|
||||
}
|
||||
break;
|
||||
case MODEKEY_DOWN:
|
||||
case MODEKEYCMD_DOWN:
|
||||
if (items == 0)
|
||||
break;
|
||||
if (data->selected == items - 1) {
|
||||
@ -213,7 +218,7 @@ window_choose_key(struct window_pane *wp, unused struct client *c, int key)
|
||||
screen_write_stop(&ctx);
|
||||
}
|
||||
break;
|
||||
case MODEKEY_PPAGE:
|
||||
case MODEKEYCMD_PREVIOUSPAGE:
|
||||
if (data->selected < screen_size_y(s)) {
|
||||
data->selected = 0;
|
||||
data->top = 0;
|
||||
@ -226,11 +231,7 @@ window_choose_key(struct window_pane *wp, unused struct client *c, int key)
|
||||
}
|
||||
window_choose_redraw_screen(wp);
|
||||
break;
|
||||
case MODEKEY_NONE:
|
||||
if (key != ' ')
|
||||
break;
|
||||
/* FALLTHROUGH */
|
||||
case MODEKEY_NPAGE:
|
||||
case MODEKEYCMD_NEXTPAGE:
|
||||
data->selected += screen_size_y(s);
|
||||
if (data->selected > items - 1)
|
||||
data->selected = items - 1;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: window-copy.c,v 1.49 2009-01-28 22:00:22 nicm Exp $ */
|
||||
/* $Id: window-copy.c,v 1.50 2009-02-13 21:39:45 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -73,6 +73,8 @@ const struct window_mode window_copy_mode = {
|
||||
struct window_copy_mode_data {
|
||||
struct screen screen;
|
||||
|
||||
struct mode_key_data mdata;
|
||||
|
||||
u_int ox;
|
||||
u_int oy;
|
||||
|
||||
@ -101,6 +103,9 @@ window_copy_init(struct window_pane *wp)
|
||||
screen_init(s, screen_size_x(&wp->base), screen_size_y(&wp->base), 0);
|
||||
s->mode |= MODE_MOUSE;
|
||||
|
||||
mode_key_init(&data->mdata,
|
||||
options_get_number(&wp->window->options, "mode-keys"), 0);
|
||||
|
||||
s->cx = data->cx;
|
||||
s->cy = data->cy;
|
||||
|
||||
@ -118,6 +123,8 @@ window_copy_free(struct window_pane *wp)
|
||||
{
|
||||
struct window_copy_mode_data *data = wp->modedata;
|
||||
|
||||
mode_key_free(&data->mdata);
|
||||
|
||||
screen_free(&data->screen);
|
||||
xfree(data);
|
||||
}
|
||||
@ -155,29 +162,27 @@ window_copy_key(struct window_pane *wp, struct client *c, int key)
|
||||
{
|
||||
struct window_copy_mode_data *data = wp->modedata;
|
||||
struct screen *s = &data->screen;
|
||||
int table;
|
||||
|
||||
table = options_get_number(&wp->window->options, "mode-keys");
|
||||
switch (mode_key_lookup(table, key)) {
|
||||
case MODEKEY_QUIT:
|
||||
switch (mode_key_lookup(&data->mdata, key)) {
|
||||
case MODEKEYCMD_QUIT:
|
||||
window_pane_reset_mode(wp);
|
||||
break;
|
||||
case MODEKEY_LEFT:
|
||||
case MODEKEYCMD_LEFT:
|
||||
window_copy_cursor_left(wp);
|
||||
return;
|
||||
case MODEKEY_RIGHT:
|
||||
case MODEKEYCMD_RIGHT:
|
||||
window_copy_cursor_right(wp);
|
||||
return;
|
||||
case MODEKEY_UP:
|
||||
case MODEKEYCMD_UP:
|
||||
window_copy_cursor_up(wp);
|
||||
return;
|
||||
case MODEKEY_DOWN:
|
||||
case MODEKEYCMD_DOWN:
|
||||
window_copy_cursor_down(wp);
|
||||
return;
|
||||
case MODEKEY_PPAGE:
|
||||
case MODEKEYCMD_PREVIOUSPAGE:
|
||||
window_copy_pageup(wp);
|
||||
break;
|
||||
case MODEKEY_NPAGE:
|
||||
case MODEKEYCMD_NEXTPAGE:
|
||||
if (data->oy < screen_size_y(s))
|
||||
data->oy = 0;
|
||||
else
|
||||
@ -185,30 +190,29 @@ window_copy_key(struct window_pane *wp, struct client *c, int key)
|
||||
window_copy_update_selection(wp);
|
||||
window_copy_redraw_screen(wp);
|
||||
break;
|
||||
case MODEKEY_STARTSEL:
|
||||
case MODEKEYCMD_STARTSELECTION:
|
||||
window_copy_start_selection(wp);
|
||||
break;
|
||||
case MODEKEY_CLEARSEL:
|
||||
case MODEKEYCMD_CLEARSELECTION:
|
||||
screen_clear_selection(&data->screen);
|
||||
window_copy_redraw_screen(wp);
|
||||
break;
|
||||
case MODEKEY_COPYSEL:
|
||||
case MODEKEY_ENTER:
|
||||
case MODEKEYCMD_COPYSELECTION:
|
||||
if (c != NULL && c->session != NULL) {
|
||||
window_copy_copy_selection(wp, c);
|
||||
window_pane_reset_mode(wp);
|
||||
}
|
||||
break;
|
||||
case MODEKEY_BOL:
|
||||
case MODEKEYCMD_STARTOFLINE:
|
||||
window_copy_cursor_start_of_line(wp);
|
||||
break;
|
||||
case MODEKEY_EOL:
|
||||
case MODEKEYCMD_ENDOFLINE:
|
||||
window_copy_cursor_end_of_line(wp);
|
||||
break;
|
||||
case MODEKEY_NWORD:
|
||||
case MODEKEYCMD_NEXTWORD:
|
||||
window_copy_cursor_next_word(wp);
|
||||
break;
|
||||
case MODEKEY_PWORD:
|
||||
case MODEKEYCMD_PREVIOUSWORD:
|
||||
window_copy_cursor_previous_word(wp);
|
||||
break;
|
||||
default:
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: window-more.c,v 1.28 2009-01-28 19:52:21 nicm Exp $ */
|
||||
/* $Id: window-more.c,v 1.29 2009-02-13 21:39:45 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -46,6 +46,8 @@ const struct window_mode window_more_mode = {
|
||||
struct window_more_mode_data {
|
||||
struct screen screen;
|
||||
|
||||
struct mode_key_data mdata;
|
||||
|
||||
ARRAY_DECL(, char *) list;
|
||||
u_int top;
|
||||
};
|
||||
@ -97,6 +99,9 @@ window_more_init(struct window_pane *wp)
|
||||
screen_init(s, screen_size_x(&wp->base), screen_size_y(&wp->base), 0);
|
||||
s->mode &= ~MODE_CURSOR;
|
||||
|
||||
mode_key_init(&data->mdata,
|
||||
options_get_number(&wp->window->options, "mode-keys"), 0);
|
||||
|
||||
return (s);
|
||||
}
|
||||
|
||||
@ -106,6 +111,8 @@ window_more_free(struct window_pane *wp)
|
||||
struct window_more_mode_data *data = wp->modedata;
|
||||
u_int i;
|
||||
|
||||
mode_key_free(&data->mdata);
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(&data->list); i++)
|
||||
xfree(ARRAY_ITEM(&data->list, i));
|
||||
ARRAY_FREE(&data->list);
|
||||
@ -129,31 +136,25 @@ window_more_key(struct window_pane *wp, unused struct client *c, int key)
|
||||
{
|
||||
struct window_more_mode_data *data = wp->modedata;
|
||||
struct screen *s = &data->screen;
|
||||
int table;
|
||||
|
||||
table = options_get_number(&wp->window->options, "mode-keys");
|
||||
switch (mode_key_lookup(table, key)) {
|
||||
case MODEKEY_QUIT:
|
||||
switch (mode_key_lookup(&data->mdata, key)) {
|
||||
case MODEKEYCMD_QUIT:
|
||||
window_pane_reset_mode(wp);
|
||||
break;
|
||||
case MODEKEY_UP:
|
||||
case MODEKEYCMD_UP:
|
||||
window_more_scroll_up(wp);
|
||||
break;
|
||||
case MODEKEY_DOWN:
|
||||
case MODEKEYCMD_DOWN:
|
||||
window_more_scroll_down(wp);
|
||||
break;
|
||||
case MODEKEY_PPAGE:
|
||||
case MODEKEYCMD_PREVIOUSPAGE:
|
||||
if (data->top < screen_size_y(s))
|
||||
data->top = 0;
|
||||
else
|
||||
data->top -= screen_size_y(s);
|
||||
window_more_redraw_screen(wp);
|
||||
break;
|
||||
case MODEKEY_NONE:
|
||||
if (key != ' ')
|
||||
break;
|
||||
/* FALLTHROUGH */
|
||||
case MODEKEY_NPAGE:
|
||||
case MODEKEYCMD_NEXTPAGE:
|
||||
if (data->top + screen_size_y(s) > ARRAY_LENGTH(&data->list))
|
||||
data->top = ARRAY_LENGTH(&data->list);
|
||||
else
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: window-scroll.c,v 1.31 2009-01-28 19:52:21 nicm Exp $ */
|
||||
/* $Id: window-scroll.c,v 1.32 2009-02-13 21:39:45 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -50,6 +50,8 @@ const struct window_mode window_scroll_mode = {
|
||||
struct window_scroll_mode_data {
|
||||
struct screen screen;
|
||||
|
||||
struct mode_key_data mdata;
|
||||
|
||||
u_int ox;
|
||||
u_int oy;
|
||||
};
|
||||
@ -70,6 +72,9 @@ window_scroll_init(struct window_pane *wp)
|
||||
screen_init(s, screen_size_x(&wp->base), screen_size_y(&wp->base), 0);
|
||||
s->mode &= ~MODE_CURSOR;
|
||||
|
||||
mode_key_init(&data->mdata,
|
||||
options_get_number(&wp->window->options, "mode-keys"), 0);
|
||||
|
||||
screen_write_start(&ctx, NULL, s);
|
||||
for (i = 0; i < screen_size_y(s); i++)
|
||||
window_scroll_write_line(wp, &ctx, i);
|
||||
@ -83,6 +88,8 @@ window_scroll_free(struct window_pane *wp)
|
||||
{
|
||||
struct window_scroll_mode_data *data = wp->modedata;
|
||||
|
||||
mode_key_free(&data->mdata);
|
||||
|
||||
screen_free(&data->screen);
|
||||
xfree(data);
|
||||
}
|
||||
@ -121,29 +128,27 @@ window_scroll_key(struct window_pane *wp, unused struct client *c, int key)
|
||||
{
|
||||
struct window_scroll_mode_data *data = wp->modedata;
|
||||
struct screen *s = &data->screen;
|
||||
int table;
|
||||
|
||||
table = options_get_number(&wp->window->options, "mode-keys");
|
||||
switch (mode_key_lookup(table, key)) {
|
||||
case MODEKEY_QUIT:
|
||||
switch (mode_key_lookup(&data->mdata, key)) {
|
||||
case MODEKEYCMD_QUIT:
|
||||
window_pane_reset_mode(wp);
|
||||
break;
|
||||
case MODEKEY_LEFT:
|
||||
case MODEKEYCMD_LEFT:
|
||||
window_scroll_scroll_left(wp);
|
||||
break;
|
||||
case MODEKEY_RIGHT:
|
||||
case MODEKEYCMD_RIGHT:
|
||||
window_scroll_scroll_right(wp);
|
||||
break;
|
||||
case MODEKEY_UP:
|
||||
case MODEKEYCMD_UP:
|
||||
window_scroll_scroll_up(wp);
|
||||
break;
|
||||
case MODEKEY_DOWN:
|
||||
case MODEKEYCMD_DOWN:
|
||||
window_scroll_scroll_down(wp);
|
||||
break;
|
||||
case MODEKEY_PPAGE:
|
||||
case MODEKEYCMD_PREVIOUSPAGE:
|
||||
window_scroll_pageup(wp);
|
||||
break;
|
||||
case MODEKEY_NPAGE:
|
||||
case MODEKEYCMD_NEXTPAGE:
|
||||
if (data->oy < screen_size_y(s))
|
||||
data->oy = 0;
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user