Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
/* $OpenBSD$ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@gmail.com>
|
|
|
|
*
|
|
|
|
* 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 <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
|
|
|
static struct screen *window_tree_init(struct window_pane *,
|
|
|
|
struct cmd_find_state *, struct args *);
|
|
|
|
static void window_tree_free(struct window_pane *);
|
|
|
|
static void window_tree_resize(struct window_pane *, u_int, u_int);
|
|
|
|
static void window_tree_key(struct window_pane *,
|
|
|
|
struct client *, struct session *, key_code,
|
|
|
|
struct mouse_event *);
|
|
|
|
|
|
|
|
#define WINDOW_TREE_DEFAULT_COMMAND "switch-client -t '%%'"
|
|
|
|
|
2017-08-09 11:43:45 +00:00
|
|
|
#define WINDOW_TREE_DEFAULT_FORMAT \
|
|
|
|
"#{?pane_format," \
|
|
|
|
"#{pane_current_command} \"#{pane_title}\"" \
|
|
|
|
"," \
|
|
|
|
"#{?window_format," \
|
|
|
|
"#{window_name}#{window_flags} " \
|
|
|
|
"(#{window_panes} panes)" \
|
|
|
|
"#{?#{==:#{window_panes},1}, \"#{pane_title}\",}" \
|
|
|
|
"," \
|
|
|
|
"#{session_windows} windows" \
|
|
|
|
"#{?session_grouped, (group ,}" \
|
|
|
|
"#{session_group}#{?session_grouped,),}" \
|
|
|
|
"#{?session_attached, (attached),}" \
|
|
|
|
"}" \
|
|
|
|
"}"
|
|
|
|
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
const struct window_mode window_tree_mode = {
|
|
|
|
.name = "tree-mode",
|
|
|
|
|
|
|
|
.init = window_tree_init,
|
|
|
|
.free = window_tree_free,
|
|
|
|
.resize = window_tree_resize,
|
|
|
|
.key = window_tree_key,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum window_tree_sort_type {
|
|
|
|
WINDOW_TREE_BY_INDEX,
|
|
|
|
WINDOW_TREE_BY_NAME,
|
|
|
|
WINDOW_TREE_BY_TIME,
|
|
|
|
};
|
|
|
|
static const char *window_tree_sort_list[] = {
|
|
|
|
"index",
|
|
|
|
"name",
|
|
|
|
"time"
|
|
|
|
};
|
|
|
|
|
|
|
|
enum window_tree_type {
|
|
|
|
WINDOW_TREE_NONE,
|
|
|
|
WINDOW_TREE_SESSION,
|
|
|
|
WINDOW_TREE_WINDOW,
|
|
|
|
WINDOW_TREE_PANE,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct window_tree_itemdata {
|
|
|
|
enum window_tree_type type;
|
|
|
|
int session;
|
|
|
|
int winlink;
|
|
|
|
int pane;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct window_tree_modedata {
|
|
|
|
struct window_pane *wp;
|
|
|
|
int dead;
|
|
|
|
int references;
|
|
|
|
|
|
|
|
struct mode_tree_data *data;
|
2017-08-09 11:43:45 +00:00
|
|
|
char *format;
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
char *command;
|
|
|
|
|
|
|
|
struct window_tree_itemdata **item_list;
|
|
|
|
u_int item_size;
|
|
|
|
|
|
|
|
struct client *client;
|
|
|
|
const char *entered;
|
|
|
|
|
|
|
|
struct cmd_find_state fs;
|
|
|
|
enum window_tree_type type;
|
2017-07-04 22:21:31 +00:00
|
|
|
|
|
|
|
int offset;
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
window_tree_pull_item(struct window_tree_itemdata *item, struct session **sp,
|
|
|
|
struct winlink **wlp, struct window_pane **wp)
|
|
|
|
{
|
|
|
|
*wp = NULL;
|
|
|
|
*wlp = NULL;
|
|
|
|
*sp = session_find_by_id(item->session);
|
|
|
|
if (*sp == NULL)
|
|
|
|
return;
|
|
|
|
if (item->type == WINDOW_TREE_SESSION) {
|
|
|
|
*wlp = (*sp)->curw;
|
|
|
|
*wp = (*wlp)->window->active;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
*wlp = winlink_find_by_index(&(*sp)->windows, item->winlink);
|
|
|
|
if (*wlp == NULL) {
|
|
|
|
*sp = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (item->type == WINDOW_TREE_WINDOW) {
|
|
|
|
*wp = (*wlp)->window->active;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
*wp = window_pane_find_by_id(item->pane);
|
|
|
|
if (!window_has_pane((*wlp)->window, *wp))
|
|
|
|
*wp = NULL;
|
|
|
|
if (*wp == NULL) {
|
|
|
|
*sp = NULL;
|
|
|
|
*wlp = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct window_tree_itemdata *
|
|
|
|
window_tree_add_item(struct window_tree_modedata *data)
|
|
|
|
{
|
|
|
|
struct window_tree_itemdata *item;
|
|
|
|
|
|
|
|
data->item_list = xreallocarray(data->item_list, data->item_size + 1,
|
|
|
|
sizeof *data->item_list);
|
|
|
|
item = data->item_list[data->item_size++] = xcalloc(1, sizeof *item);
|
|
|
|
return (item);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
window_tree_free_item(struct window_tree_itemdata *item)
|
|
|
|
{
|
|
|
|
free(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
window_tree_cmp_session_name(const void *a0, const void *b0)
|
|
|
|
{
|
|
|
|
const struct session *const *a = a0;
|
|
|
|
const struct session *const *b = b0;
|
|
|
|
|
|
|
|
return (strcmp((*a)->name, (*b)->name));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
window_tree_cmp_session_time(const void *a0, const void *b0)
|
|
|
|
{
|
|
|
|
const struct session *const *a = a0;
|
|
|
|
const struct session *const *b = b0;
|
|
|
|
|
|
|
|
if (timercmp(&(*a)->activity_time, &(*b)->activity_time, >))
|
|
|
|
return (-1);
|
|
|
|
if (timercmp(&(*a)->activity_time, &(*b)->activity_time, <))
|
|
|
|
return (1);
|
|
|
|
return (strcmp((*a)->name, (*b)->name));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
window_tree_cmp_window_name(const void *a0, const void *b0)
|
|
|
|
{
|
|
|
|
const struct winlink *const *a = a0;
|
|
|
|
const struct winlink *const *b = b0;
|
|
|
|
|
|
|
|
return (strcmp((*a)->window->name, (*b)->window->name));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
window_tree_cmp_window_time(const void *a0, const void *b0)
|
|
|
|
{
|
|
|
|
const struct winlink *const *a = a0;
|
|
|
|
const struct winlink *const *b = b0;
|
|
|
|
|
|
|
|
if (timercmp(&(*a)->window->activity_time,
|
|
|
|
&(*b)->window->activity_time, >))
|
|
|
|
return (-1);
|
|
|
|
if (timercmp(&(*a)->window->activity_time,
|
|
|
|
&(*b)->window->activity_time, <))
|
|
|
|
return (1);
|
|
|
|
return (strcmp((*a)->window->name, (*b)->window->name));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
window_tree_cmp_pane_time(const void *a0, const void *b0)
|
|
|
|
{
|
|
|
|
const struct window_pane *const *a = a0;
|
|
|
|
const struct window_pane *const *b = b0;
|
|
|
|
|
|
|
|
if ((*a)->active_point < (*b)->active_point)
|
|
|
|
return (-1);
|
|
|
|
if ((*a)->active_point > (*b)->active_point)
|
|
|
|
return (1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
window_tree_build_pane(struct session *s, struct winlink *wl,
|
|
|
|
struct window_pane *wp, void *modedata, struct mode_tree_item *parent)
|
|
|
|
{
|
|
|
|
struct window_tree_modedata *data = modedata;
|
|
|
|
struct window_tree_itemdata *item;
|
|
|
|
char *name, *text;
|
|
|
|
u_int idx;
|
|
|
|
|
|
|
|
window_pane_index(wp, &idx);
|
|
|
|
|
|
|
|
item = window_tree_add_item(data);
|
|
|
|
item->type = WINDOW_TREE_PANE;
|
|
|
|
item->session = s->id;
|
|
|
|
item->winlink = wl->idx;
|
|
|
|
item->pane = wp->id;
|
|
|
|
|
2017-08-09 11:43:45 +00:00
|
|
|
text = format_single(NULL, data->format, NULL, s, wl, wp);
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
xasprintf(&name, "%u", idx);
|
|
|
|
|
|
|
|
mode_tree_add(data->data, parent, item, (uint64_t)wp, name, text, -1);
|
|
|
|
free(text);
|
|
|
|
free(name);
|
|
|
|
}
|
|
|
|
|
2017-08-09 13:44:36 +00:00
|
|
|
static int
|
|
|
|
window_tree_filter_pane(struct session *s, struct winlink *wl,
|
|
|
|
struct window_pane *wp, const char *filter)
|
|
|
|
{
|
|
|
|
char *cp;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
if (filter == NULL)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
cp = format_single(NULL, filter, NULL, s, wl, wp);
|
|
|
|
result = format_true(cp);
|
|
|
|
free(cp);
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
static int
|
|
|
|
window_tree_build_window(struct session *s, struct winlink *wl, void* modedata,
|
2017-06-09 16:01:39 +00:00
|
|
|
u_int sort_type, struct mode_tree_item *parent, const char *filter)
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
{
|
|
|
|
struct window_tree_modedata *data = modedata;
|
|
|
|
struct window_tree_itemdata *item;
|
|
|
|
struct mode_tree_item *mti;
|
2017-08-09 13:44:36 +00:00
|
|
|
char *name, *text;
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
struct window_pane *wp, **l;
|
|
|
|
u_int n, i;
|
|
|
|
int expanded;
|
|
|
|
|
|
|
|
item = window_tree_add_item(data);
|
|
|
|
item->type = WINDOW_TREE_WINDOW;
|
|
|
|
item->session = s->id;
|
|
|
|
item->winlink = wl->idx;
|
|
|
|
item->pane = -1;
|
|
|
|
|
2017-08-09 11:43:45 +00:00
|
|
|
text = format_single(NULL, data->format, NULL, s, wl, NULL);
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
xasprintf(&name, "%u", wl->idx);
|
|
|
|
|
|
|
|
if (data->type == WINDOW_TREE_SESSION ||
|
|
|
|
data->type == WINDOW_TREE_WINDOW)
|
|
|
|
expanded = 0;
|
|
|
|
else
|
|
|
|
expanded = 1;
|
|
|
|
mti = mode_tree_add(data->data, parent, item, (uint64_t)wl, name, text,
|
|
|
|
expanded);
|
|
|
|
free(text);
|
|
|
|
free(name);
|
|
|
|
|
2017-08-09 13:44:36 +00:00
|
|
|
wp = TAILQ_FIRST(&wl->window->panes);
|
|
|
|
if (TAILQ_NEXT(wp, entry) == NULL) {
|
|
|
|
if (!window_tree_filter_pane(s, wl, wp, filter))
|
|
|
|
goto empty;
|
2017-07-12 14:31:06 +00:00
|
|
|
return (1);
|
2017-08-09 13:44:36 +00:00
|
|
|
}
|
2017-07-12 14:31:06 +00:00
|
|
|
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
l = NULL;
|
|
|
|
n = 0;
|
2017-07-12 14:31:06 +00:00
|
|
|
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
|
2017-08-09 13:44:36 +00:00
|
|
|
if (!window_tree_filter_pane(s, wl, wp, filter))
|
|
|
|
continue;
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
l = xreallocarray(l, n + 1, sizeof *l);
|
|
|
|
l[n++] = wp;
|
|
|
|
}
|
2017-08-09 13:44:36 +00:00
|
|
|
if (n == 0)
|
|
|
|
goto empty;
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
|
|
|
|
switch (sort_type) {
|
|
|
|
case WINDOW_TREE_BY_INDEX:
|
|
|
|
break;
|
|
|
|
case WINDOW_TREE_BY_NAME:
|
|
|
|
/* Panes don't have names, so leave in number order. */
|
|
|
|
break;
|
|
|
|
case WINDOW_TREE_BY_TIME:
|
|
|
|
qsort(l, n, sizeof *l, window_tree_cmp_pane_time);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
window_tree_build_pane(s, wl, l[i], modedata, mti);
|
|
|
|
free(l);
|
|
|
|
return (1);
|
2017-08-09 13:44:36 +00:00
|
|
|
|
|
|
|
empty:
|
|
|
|
window_tree_free_item(item);
|
|
|
|
data->item_size--;
|
|
|
|
mode_tree_remove(data->data, mti);
|
|
|
|
return (0);
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
window_tree_build_session(struct session *s, void* modedata,
|
2017-06-09 16:01:39 +00:00
|
|
|
u_int sort_type, const char *filter)
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
{
|
|
|
|
struct window_tree_modedata *data = modedata;
|
|
|
|
struct window_tree_itemdata *item;
|
|
|
|
struct mode_tree_item *mti;
|
|
|
|
char *text;
|
|
|
|
struct winlink *wl, **l;
|
|
|
|
u_int n, i, empty;
|
|
|
|
int expanded;
|
|
|
|
|
|
|
|
item = window_tree_add_item(data);
|
|
|
|
item->type = WINDOW_TREE_SESSION;
|
|
|
|
item->session = s->id;
|
|
|
|
item->winlink = -1;
|
|
|
|
item->pane = -1;
|
|
|
|
|
2017-08-09 11:43:45 +00:00
|
|
|
text = format_single(NULL, data->format, NULL, s, NULL, NULL);
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
|
|
|
|
if (data->type == WINDOW_TREE_SESSION)
|
|
|
|
expanded = 0;
|
|
|
|
else
|
|
|
|
expanded = 1;
|
|
|
|
mti = mode_tree_add(data->data, NULL, item, (uint64_t)s, s->name, text,
|
|
|
|
expanded);
|
|
|
|
free(text);
|
|
|
|
|
|
|
|
l = NULL;
|
|
|
|
n = 0;
|
|
|
|
RB_FOREACH(wl, winlinks, &s->windows) {
|
|
|
|
l = xreallocarray(l, n + 1, sizeof *l);
|
|
|
|
l[n++] = wl;
|
|
|
|
}
|
|
|
|
switch (sort_type) {
|
|
|
|
case WINDOW_TREE_BY_INDEX:
|
|
|
|
break;
|
|
|
|
case WINDOW_TREE_BY_NAME:
|
|
|
|
qsort(l, n, sizeof *l, window_tree_cmp_window_name);
|
|
|
|
break;
|
|
|
|
case WINDOW_TREE_BY_TIME:
|
|
|
|
qsort(l, n, sizeof *l, window_tree_cmp_window_time);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
empty = 0;
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
if (!window_tree_build_window(s, l[i], modedata, sort_type, mti,
|
2017-06-09 16:01:39 +00:00
|
|
|
filter))
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
empty++;
|
|
|
|
}
|
|
|
|
if (empty == n) {
|
|
|
|
window_tree_free_item(item);
|
|
|
|
data->item_size--;
|
|
|
|
mode_tree_remove(data->data, mti);
|
|
|
|
}
|
|
|
|
free(l);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-06-09 16:01:39 +00:00
|
|
|
window_tree_build(void *modedata, u_int sort_type, uint64_t *tag,
|
|
|
|
const char *filter)
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
{
|
|
|
|
struct window_tree_modedata *data = modedata;
|
|
|
|
struct session *s, **l;
|
|
|
|
u_int n, i;
|
|
|
|
|
|
|
|
for (i = 0; i < data->item_size; i++)
|
|
|
|
window_tree_free_item(data->item_list[i]);
|
|
|
|
free(data->item_list);
|
|
|
|
data->item_list = NULL;
|
|
|
|
data->item_size = 0;
|
|
|
|
|
|
|
|
l = NULL;
|
|
|
|
n = 0;
|
|
|
|
RB_FOREACH(s, sessions, &sessions) {
|
|
|
|
l = xreallocarray(l, n + 1, sizeof *l);
|
|
|
|
l[n++] = s;
|
|
|
|
}
|
|
|
|
switch (sort_type) {
|
|
|
|
case WINDOW_TREE_BY_INDEX:
|
|
|
|
break;
|
|
|
|
case WINDOW_TREE_BY_NAME:
|
|
|
|
qsort(l, n, sizeof *l, window_tree_cmp_session_name);
|
|
|
|
break;
|
|
|
|
case WINDOW_TREE_BY_TIME:
|
|
|
|
qsort(l, n, sizeof *l, window_tree_cmp_session_time);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
2017-06-09 16:01:39 +00:00
|
|
|
window_tree_build_session(l[i], modedata, sort_type, filter);
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
free(l);
|
|
|
|
|
|
|
|
switch (data->type) {
|
|
|
|
case WINDOW_TREE_NONE:
|
|
|
|
break;
|
|
|
|
case WINDOW_TREE_SESSION:
|
|
|
|
*tag = (uint64_t)data->fs.s;
|
|
|
|
break;
|
|
|
|
case WINDOW_TREE_WINDOW:
|
|
|
|
*tag = (uint64_t)data->fs.wl;
|
|
|
|
break;
|
|
|
|
case WINDOW_TREE_PANE:
|
|
|
|
*tag = (uint64_t)data->fs.wp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-30 22:24:08 +00:00
|
|
|
static void
|
2017-07-04 22:21:31 +00:00
|
|
|
window_tree_draw_session(struct window_tree_modedata *data, struct session *s,
|
|
|
|
struct screen_write_ctx *ctx, u_int sx, u_int sy)
|
2017-06-30 22:24:08 +00:00
|
|
|
{
|
|
|
|
struct options *oo = s->options;
|
|
|
|
struct winlink *wl;
|
|
|
|
struct window *w;
|
2017-07-03 22:48:02 +00:00
|
|
|
u_int loop, total, visible, each, width, offset;
|
|
|
|
u_int current, start, end, remaining, i;
|
2017-06-30 22:24:08 +00:00
|
|
|
struct grid_cell gc;
|
2017-07-03 22:48:02 +00:00
|
|
|
int colour, active_colour, left, right;
|
2017-06-30 22:24:08 +00:00
|
|
|
char *label;
|
|
|
|
size_t len;
|
|
|
|
|
2017-07-03 22:48:02 +00:00
|
|
|
total = winlink_count(&s->windows);
|
2017-06-30 22:24:08 +00:00
|
|
|
|
|
|
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
|
|
|
colour = options_get_number(oo, "display-panes-colour");
|
|
|
|
active_colour = options_get_number(oo, "display-panes-active-colour");
|
|
|
|
|
2017-07-03 22:48:02 +00:00
|
|
|
if (sx / total < 24) {
|
|
|
|
visible = sx / 24;
|
|
|
|
if (visible == 0)
|
|
|
|
visible = 1;
|
|
|
|
} else
|
|
|
|
visible = total;
|
|
|
|
|
|
|
|
current = 0;
|
|
|
|
RB_FOREACH(wl, winlinks, &s->windows) {
|
|
|
|
if (wl == s->curw)
|
|
|
|
break;
|
|
|
|
current++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (current < visible) {
|
|
|
|
start = 0;
|
|
|
|
end = visible;
|
|
|
|
} else if (current >= total - visible) {
|
|
|
|
start = total - visible;
|
|
|
|
end = total;
|
|
|
|
} else {
|
|
|
|
start = current - (visible / 2);
|
|
|
|
end = start + visible;
|
|
|
|
}
|
|
|
|
|
2017-07-04 22:21:31 +00:00
|
|
|
if (data->offset < -(int)start)
|
|
|
|
data->offset = -(int)start;
|
|
|
|
if (data->offset > (int)(total - end))
|
|
|
|
data->offset = (int)(total - end);
|
|
|
|
start += data->offset;
|
|
|
|
end += data->offset;
|
|
|
|
|
2017-07-03 22:48:02 +00:00
|
|
|
left = (start != 0);
|
|
|
|
right = (end != total);
|
|
|
|
if (((left && right) && sx <= 6) || ((left || right) && sx <= 3))
|
|
|
|
left = right = 0;
|
|
|
|
if (left && right) {
|
|
|
|
each = (sx - 6) / visible;
|
|
|
|
remaining = (sx - 6) - (visible * each);
|
|
|
|
} else if (left || right) {
|
|
|
|
each = (sx - 3) / visible;
|
|
|
|
remaining = (sx - 3) - (visible * each);
|
|
|
|
} else {
|
|
|
|
each = sx / visible;
|
|
|
|
remaining = sx - (visible * each);
|
|
|
|
}
|
|
|
|
if (each == 0)
|
|
|
|
return;
|
2017-06-30 22:24:08 +00:00
|
|
|
|
2017-07-03 22:48:02 +00:00
|
|
|
if (left) {
|
|
|
|
screen_write_cursormove(ctx, 2, 0);
|
2017-06-30 22:24:08 +00:00
|
|
|
screen_write_vline(ctx, sy, 0, 0);
|
2017-07-03 22:48:02 +00:00
|
|
|
screen_write_cursormove(ctx, 0, sy / 2);
|
|
|
|
screen_write_puts(ctx, &grid_default_cell, "<");
|
|
|
|
}
|
|
|
|
if (right) {
|
|
|
|
screen_write_cursormove(ctx, sx - 3, 0);
|
|
|
|
screen_write_vline(ctx, sy, 0, 0);
|
|
|
|
screen_write_cursormove(ctx, sx - 1, sy / 2);
|
|
|
|
screen_write_puts(ctx, &grid_default_cell, ">");
|
|
|
|
}
|
2017-06-30 22:24:08 +00:00
|
|
|
|
2017-07-03 22:48:02 +00:00
|
|
|
i = loop = 0;
|
|
|
|
RB_FOREACH(wl, winlinks, &s->windows) {
|
|
|
|
if (loop == end)
|
|
|
|
break;
|
|
|
|
if (loop < start) {
|
|
|
|
loop++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
w = wl->window;
|
2017-06-30 22:24:08 +00:00
|
|
|
|
|
|
|
if (wl == s->curw)
|
|
|
|
gc.fg = active_colour;
|
|
|
|
else
|
|
|
|
gc.fg = colour;
|
2017-07-03 22:48:02 +00:00
|
|
|
|
|
|
|
if (left)
|
|
|
|
offset = 3 + (i * each);
|
|
|
|
else
|
|
|
|
offset = (i * each);
|
|
|
|
if (loop == end - 1)
|
2017-07-07 16:27:26 +00:00
|
|
|
width = each + remaining;
|
2017-06-30 22:24:08 +00:00
|
|
|
else
|
|
|
|
width = each - 1;
|
|
|
|
|
2017-07-03 22:48:02 +00:00
|
|
|
screen_write_cursormove(ctx, offset, 0);
|
2017-06-30 22:24:08 +00:00
|
|
|
screen_write_preview(ctx, &w->active->base, width, sy);
|
|
|
|
|
|
|
|
xasprintf(&label, " %u:%s ", wl->idx, w->name);
|
|
|
|
if (strlen(label) > width)
|
|
|
|
xasprintf(&label, " %u ", wl->idx);
|
|
|
|
len = strlen(label) / 2;
|
2017-07-03 22:48:02 +00:00
|
|
|
screen_write_cursormove(ctx, offset + (each / 2) - len, sy / 2);
|
2017-06-30 22:37:35 +00:00
|
|
|
if (len < width)
|
2017-06-30 22:36:11 +00:00
|
|
|
screen_write_puts(ctx, &gc, "%s", label);
|
2017-06-30 22:24:08 +00:00
|
|
|
free(label);
|
|
|
|
|
2017-07-03 22:48:02 +00:00
|
|
|
if (loop != end - 1) {
|
|
|
|
screen_write_cursormove(ctx, offset + width, 0);
|
2017-06-30 22:24:08 +00:00
|
|
|
screen_write_vline(ctx, sy, 0, 0);
|
|
|
|
}
|
2017-07-03 22:48:02 +00:00
|
|
|
loop++;
|
|
|
|
|
|
|
|
i++;
|
2017-06-30 22:24:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-07-04 22:21:31 +00:00
|
|
|
window_tree_draw_window(struct window_tree_modedata *data, struct session *s,
|
|
|
|
struct window *w, struct screen_write_ctx *ctx, u_int sx, u_int sy)
|
2017-06-30 22:24:08 +00:00
|
|
|
{
|
|
|
|
struct options *oo = s->options;
|
|
|
|
struct window_pane *wp;
|
2017-07-03 22:48:02 +00:00
|
|
|
u_int loop, total, visible, each, width, offset;
|
|
|
|
u_int current, start, end, remaining, i;
|
2017-06-30 22:24:08 +00:00
|
|
|
struct grid_cell gc;
|
2017-07-03 22:48:02 +00:00
|
|
|
int colour, active_colour, left, right;
|
2017-06-30 22:24:08 +00:00
|
|
|
char *label;
|
|
|
|
size_t len;
|
|
|
|
|
2017-07-03 22:48:02 +00:00
|
|
|
total = window_count_panes(w);
|
2017-06-30 22:24:08 +00:00
|
|
|
|
|
|
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
|
|
|
colour = options_get_number(oo, "display-panes-colour");
|
|
|
|
active_colour = options_get_number(oo, "display-panes-active-colour");
|
|
|
|
|
2017-07-03 22:48:02 +00:00
|
|
|
if (sx / total < 24) {
|
|
|
|
visible = sx / 24;
|
|
|
|
if (visible == 0)
|
|
|
|
visible = 1;
|
|
|
|
} else
|
|
|
|
visible = total;
|
|
|
|
|
|
|
|
current = 0;
|
|
|
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
|
|
|
if (wp == w->active)
|
|
|
|
break;
|
|
|
|
current++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (current < visible) {
|
|
|
|
start = 0;
|
|
|
|
end = visible;
|
|
|
|
} else if (current >= total - visible) {
|
|
|
|
start = total - visible;
|
|
|
|
end = total;
|
|
|
|
} else {
|
|
|
|
start = current - (visible / 2);
|
|
|
|
end = start + visible;
|
|
|
|
}
|
|
|
|
|
2017-07-04 22:21:31 +00:00
|
|
|
if (data->offset < -(int)start)
|
|
|
|
data->offset = -(int)start;
|
|
|
|
if (data->offset > (int)(total - end))
|
|
|
|
data->offset = (int)(total - end);
|
|
|
|
start += data->offset;
|
|
|
|
end += data->offset;
|
|
|
|
|
2017-07-03 22:48:02 +00:00
|
|
|
left = (start != 0);
|
|
|
|
right = (end != total);
|
|
|
|
if (((left && right) && sx <= 6) || ((left || right) && sx <= 3))
|
|
|
|
left = right = 0;
|
|
|
|
if (left && right) {
|
|
|
|
each = (sx - 6) / visible;
|
|
|
|
remaining = (sx - 6) - (visible * each);
|
|
|
|
} else if (left || right) {
|
|
|
|
each = (sx - 3) / visible;
|
|
|
|
remaining = (sx - 3) - (visible * each);
|
|
|
|
} else {
|
|
|
|
each = sx / visible;
|
|
|
|
remaining = sx - (visible * each);
|
|
|
|
}
|
|
|
|
if (each == 0)
|
|
|
|
return;
|
2017-06-30 22:24:08 +00:00
|
|
|
|
2017-07-03 22:48:02 +00:00
|
|
|
if (left) {
|
|
|
|
screen_write_cursormove(ctx, 2, 0);
|
|
|
|
screen_write_vline(ctx, sy, 0, 0);
|
|
|
|
screen_write_cursormove(ctx, 0, sy / 2);
|
|
|
|
screen_write_puts(ctx, &grid_default_cell, "<");
|
|
|
|
}
|
|
|
|
if (right) {
|
|
|
|
screen_write_cursormove(ctx, sx - 3, 0);
|
2017-06-30 22:24:08 +00:00
|
|
|
screen_write_vline(ctx, sy, 0, 0);
|
2017-07-03 22:48:02 +00:00
|
|
|
screen_write_cursormove(ctx, sx - 1, sy / 2);
|
|
|
|
screen_write_puts(ctx, &grid_default_cell, ">");
|
|
|
|
}
|
2017-06-30 22:24:08 +00:00
|
|
|
|
2017-07-03 22:48:02 +00:00
|
|
|
i = loop = 0;
|
|
|
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
|
|
|
if (loop == end)
|
|
|
|
break;
|
|
|
|
if (loop < start) {
|
|
|
|
loop++;
|
|
|
|
continue;
|
|
|
|
}
|
2017-06-30 22:24:08 +00:00
|
|
|
|
|
|
|
if (wp == w->active)
|
|
|
|
gc.fg = active_colour;
|
|
|
|
else
|
|
|
|
gc.fg = colour;
|
2017-07-03 22:48:02 +00:00
|
|
|
|
|
|
|
if (left)
|
|
|
|
offset = 3 + (i * each);
|
|
|
|
else
|
|
|
|
offset = (i * each);
|
|
|
|
if (loop == end - 1)
|
2017-07-07 16:27:26 +00:00
|
|
|
width = each + remaining;
|
2017-06-30 22:24:08 +00:00
|
|
|
else
|
|
|
|
width = each - 1;
|
|
|
|
|
2017-07-03 22:48:02 +00:00
|
|
|
screen_write_cursormove(ctx, offset, 0);
|
2017-06-30 22:24:08 +00:00
|
|
|
screen_write_preview(ctx, &wp->base, width, sy);
|
|
|
|
|
2017-07-03 22:48:02 +00:00
|
|
|
xasprintf(&label, " %u ", loop);
|
2017-06-30 22:24:08 +00:00
|
|
|
len = strlen(label) / 2;
|
2017-07-03 22:48:02 +00:00
|
|
|
screen_write_cursormove(ctx, offset + (each / 2) - len, sy / 2);
|
2017-06-30 22:37:35 +00:00
|
|
|
if (len < width)
|
2017-06-30 22:36:11 +00:00
|
|
|
screen_write_puts(ctx, &gc, "%s", label);
|
2017-06-30 22:24:08 +00:00
|
|
|
free(label);
|
|
|
|
|
2017-07-03 22:48:02 +00:00
|
|
|
if (loop != end - 1) {
|
|
|
|
screen_write_cursormove(ctx, offset + width, 0);
|
2017-06-30 22:24:08 +00:00
|
|
|
screen_write_vline(ctx, sy, 0, 0);
|
|
|
|
}
|
2017-07-03 22:48:02 +00:00
|
|
|
loop++;
|
|
|
|
|
|
|
|
i++;
|
2017-06-30 22:24:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
static struct screen *
|
2017-07-04 22:21:31 +00:00
|
|
|
window_tree_draw(void *modedata, void *itemdata, u_int sx, u_int sy)
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
{
|
|
|
|
struct window_tree_itemdata *item = itemdata;
|
|
|
|
struct session *sp;
|
|
|
|
struct winlink *wlp;
|
|
|
|
struct window_pane *wp;
|
|
|
|
static struct screen s;
|
|
|
|
struct screen_write_ctx ctx;
|
|
|
|
|
|
|
|
window_tree_pull_item(item, &sp, &wlp, &wp);
|
|
|
|
if (wp == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
screen_init(&s, sx, sy, 0);
|
|
|
|
screen_write_start(&ctx, NULL, &s);
|
|
|
|
|
2017-06-30 22:24:08 +00:00
|
|
|
switch (item->type) {
|
|
|
|
case WINDOW_TREE_NONE:
|
|
|
|
return (0);
|
|
|
|
case WINDOW_TREE_SESSION:
|
2017-07-04 22:21:31 +00:00
|
|
|
window_tree_draw_session(modedata, sp, &ctx, sx, sy);
|
2017-06-30 22:24:08 +00:00
|
|
|
break;
|
|
|
|
case WINDOW_TREE_WINDOW:
|
2017-07-04 22:21:31 +00:00
|
|
|
window_tree_draw_window(modedata, sp, wlp->window, &ctx, sx, sy);
|
2017-06-30 22:24:08 +00:00
|
|
|
break;
|
|
|
|
case WINDOW_TREE_PANE:
|
|
|
|
screen_write_preview(&ctx, &wp->base, sx, sy);
|
|
|
|
break;
|
|
|
|
}
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
|
|
|
|
screen_write_stop(&ctx);
|
|
|
|
return (&s);
|
|
|
|
}
|
|
|
|
|
2017-06-07 14:37:30 +00:00
|
|
|
static int
|
|
|
|
window_tree_search(__unused void *modedata, void *itemdata, const char *ss)
|
|
|
|
{
|
|
|
|
struct window_tree_itemdata *item = itemdata;
|
|
|
|
struct session *s;
|
|
|
|
struct winlink *wl;
|
|
|
|
struct window_pane *wp;
|
|
|
|
const char *cmd;
|
|
|
|
|
|
|
|
window_tree_pull_item(item, &s, &wl, &wp);
|
|
|
|
|
|
|
|
switch (item->type) {
|
|
|
|
case WINDOW_TREE_NONE:
|
|
|
|
return (0);
|
|
|
|
case WINDOW_TREE_SESSION:
|
|
|
|
if (s == NULL)
|
|
|
|
return (0);
|
|
|
|
return (strstr(s->name, ss) != NULL);
|
|
|
|
case WINDOW_TREE_WINDOW:
|
|
|
|
if (s == NULL || wl == NULL)
|
|
|
|
return (0);
|
|
|
|
return (strstr(wl->window->name, ss) != NULL);
|
|
|
|
case WINDOW_TREE_PANE:
|
|
|
|
if (s == NULL || wl == NULL || wp == NULL)
|
|
|
|
break;
|
2017-06-07 15:21:01 +00:00
|
|
|
cmd = osdep_get_name(wp->fd, wp->tty);
|
2017-06-07 14:37:30 +00:00
|
|
|
if (cmd == NULL || *cmd == '\0')
|
|
|
|
return (0);
|
|
|
|
return (strstr(cmd, ss) != NULL);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
static struct screen *
|
|
|
|
window_tree_init(struct window_pane *wp, struct cmd_find_state *fs,
|
|
|
|
struct args *args)
|
|
|
|
{
|
|
|
|
struct window_tree_modedata *data;
|
|
|
|
struct screen *s;
|
|
|
|
|
|
|
|
wp->modedata = data = xcalloc(1, sizeof *data);
|
|
|
|
|
|
|
|
if (args_has(args, 's'))
|
|
|
|
data->type = WINDOW_TREE_SESSION;
|
|
|
|
else if (args_has(args, 'w'))
|
|
|
|
data->type = WINDOW_TREE_WINDOW;
|
|
|
|
else
|
|
|
|
data->type = WINDOW_TREE_PANE;
|
|
|
|
memcpy(&data->fs, fs, sizeof data->fs);
|
|
|
|
|
|
|
|
data->wp = wp;
|
|
|
|
data->references = 1;
|
|
|
|
|
2017-08-09 11:43:45 +00:00
|
|
|
if (args == NULL || !args_has(args, 'F'))
|
|
|
|
data->format = xstrdup(WINDOW_TREE_DEFAULT_FORMAT);
|
|
|
|
else
|
|
|
|
data->format = xstrdup(args_get(args, 'F'));
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
if (args == NULL || args->argc == 0)
|
|
|
|
data->command = xstrdup(WINDOW_TREE_DEFAULT_COMMAND);
|
|
|
|
else
|
|
|
|
data->command = xstrdup(args->argv[0]);
|
|
|
|
|
2017-06-09 15:29:15 +00:00
|
|
|
data->data = mode_tree_start(wp, args, window_tree_build,
|
|
|
|
window_tree_draw, window_tree_search, data, window_tree_sort_list,
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
nitems(window_tree_sort_list), &s);
|
|
|
|
|
|
|
|
mode_tree_build(data->data);
|
|
|
|
mode_tree_draw(data->data);
|
|
|
|
|
|
|
|
data->type = WINDOW_TREE_NONE;
|
|
|
|
|
|
|
|
return (s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
window_tree_destroy(struct window_tree_modedata *data)
|
|
|
|
{
|
|
|
|
u_int i;
|
|
|
|
|
|
|
|
if (--data->references != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mode_tree_free(data->data);
|
|
|
|
|
|
|
|
for (i = 0; i < data->item_size; i++)
|
|
|
|
window_tree_free_item(data->item_list[i]);
|
|
|
|
free(data->item_list);
|
|
|
|
|
2017-08-09 11:43:45 +00:00
|
|
|
free(data->format);
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
free(data->command);
|
2017-08-09 11:43:45 +00:00
|
|
|
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
window_tree_free(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_tree_modedata *data = wp->modedata;
|
|
|
|
|
|
|
|
if (data == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
data->dead = 1;
|
|
|
|
window_tree_destroy(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
window_tree_resize(struct window_pane *wp, u_int sx, u_int sy)
|
|
|
|
{
|
|
|
|
struct window_tree_modedata *data = wp->modedata;
|
|
|
|
|
|
|
|
mode_tree_resize(data->data, sx, sy);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
window_tree_get_target(struct window_tree_itemdata *item,
|
|
|
|
struct cmd_find_state *fs)
|
|
|
|
{
|
|
|
|
struct session *s;
|
|
|
|
struct winlink *wl;
|
|
|
|
struct window_pane *wp;
|
|
|
|
char *target;
|
|
|
|
|
|
|
|
window_tree_pull_item(item, &s, &wl, &wp);
|
|
|
|
|
|
|
|
target = NULL;
|
|
|
|
switch (item->type) {
|
|
|
|
case WINDOW_TREE_NONE:
|
|
|
|
break;
|
|
|
|
case WINDOW_TREE_SESSION:
|
|
|
|
if (s == NULL)
|
|
|
|
break;
|
|
|
|
xasprintf(&target, "=%s:", s->name);
|
|
|
|
break;
|
|
|
|
case WINDOW_TREE_WINDOW:
|
|
|
|
if (s == NULL || wl == NULL)
|
|
|
|
break;
|
|
|
|
xasprintf(&target, "=%s:%u.", s->name, wl->idx);
|
|
|
|
break;
|
|
|
|
case WINDOW_TREE_PANE:
|
|
|
|
if (s == NULL || wl == NULL || wp == NULL)
|
|
|
|
break;
|
|
|
|
xasprintf(&target, "=%s:%u.%%%u", s->name, wl->idx, wp->id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (target == NULL)
|
|
|
|
cmd_find_clear_state(fs, 0);
|
|
|
|
else
|
|
|
|
cmd_find_from_winlink_pane(fs, wl, wp);
|
|
|
|
return (target);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
window_tree_command_each(void* modedata, void* itemdata, __unused key_code key)
|
|
|
|
{
|
|
|
|
struct window_tree_modedata *data = modedata;
|
|
|
|
struct window_tree_itemdata *item = itemdata;
|
|
|
|
char *name;
|
|
|
|
struct cmd_find_state fs;
|
|
|
|
|
|
|
|
name = window_tree_get_target(item, &fs);
|
|
|
|
if (name != NULL)
|
|
|
|
mode_tree_run_command(data->client, &fs, data->entered, name);
|
|
|
|
free(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum cmd_retval
|
|
|
|
window_tree_command_done(__unused struct cmdq_item *item, void *modedata)
|
|
|
|
{
|
|
|
|
struct window_tree_modedata *data = modedata;
|
|
|
|
|
|
|
|
if (!data->dead) {
|
|
|
|
mode_tree_build(data->data);
|
|
|
|
mode_tree_draw(data->data);
|
|
|
|
data->wp->flags |= PANE_REDRAW;
|
|
|
|
}
|
|
|
|
window_tree_destroy(data);
|
|
|
|
return (CMD_RETURN_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
window_tree_command_callback(struct client *c, void *modedata, const char *s,
|
|
|
|
__unused int done)
|
|
|
|
{
|
|
|
|
struct window_tree_modedata *data = modedata;
|
|
|
|
|
|
|
|
if (data->dead)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
data->client = c;
|
|
|
|
data->entered = s;
|
|
|
|
|
|
|
|
mode_tree_each_tagged(data->data, window_tree_command_each, KEYC_NONE,
|
|
|
|
1);
|
|
|
|
|
|
|
|
data->client = NULL;
|
|
|
|
data->entered = NULL;
|
|
|
|
|
|
|
|
data->references++;
|
|
|
|
cmdq_append(c, cmdq_get_callback(window_tree_command_done, data));
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
window_tree_command_free(void *modedata)
|
|
|
|
{
|
|
|
|
struct window_tree_modedata *data = modedata;
|
|
|
|
|
|
|
|
window_tree_destroy(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
window_tree_key(struct window_pane *wp, struct client *c,
|
|
|
|
__unused struct session *s, key_code key, struct mouse_event *m)
|
|
|
|
{
|
|
|
|
struct window_tree_modedata *data = wp->modedata;
|
|
|
|
struct window_tree_itemdata *item;
|
|
|
|
char *command, *name, *prompt;
|
|
|
|
struct cmd_find_state fs;
|
|
|
|
int finished;
|
|
|
|
u_int tagged;
|
|
|
|
|
2017-07-04 22:21:31 +00:00
|
|
|
item = mode_tree_get_current(data->data);
|
2017-06-07 14:37:30 +00:00
|
|
|
finished = mode_tree_key(data->data, c, &key, m);
|
2017-07-04 22:21:31 +00:00
|
|
|
if (item != mode_tree_get_current(data->data))
|
|
|
|
data->offset = 0;
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
switch (key) {
|
2017-07-04 22:21:31 +00:00
|
|
|
case '<':
|
|
|
|
data->offset--;
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
data->offset++;
|
|
|
|
break;
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
case ':':
|
|
|
|
tagged = mode_tree_count_tagged(data->data);
|
|
|
|
if (tagged != 0)
|
|
|
|
xasprintf(&prompt, "(%u tagged) ", tagged);
|
|
|
|
else
|
|
|
|
xasprintf(&prompt, "(current) ");
|
|
|
|
data->references++;
|
|
|
|
status_prompt_set(c, prompt, "", window_tree_command_callback,
|
|
|
|
window_tree_command_free, data, PROMPT_NOFORMAT);
|
|
|
|
free(prompt);
|
|
|
|
break;
|
|
|
|
case '\r':
|
|
|
|
item = mode_tree_get_current(data->data);
|
|
|
|
command = xstrdup(data->command);
|
|
|
|
name = window_tree_get_target(item, &fs);
|
|
|
|
window_pane_reset_mode(wp);
|
|
|
|
if (name != NULL)
|
2017-06-06 15:07:35 +00:00
|
|
|
mode_tree_run_command(c, NULL, command, name);
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
free(name);
|
|
|
|
free(command);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (finished)
|
|
|
|
window_pane_reset_mode(wp);
|
|
|
|
else {
|
|
|
|
mode_tree_draw(data->data);
|
|
|
|
wp->flags |= PANE_REDRAW;
|
|
|
|
}
|
|
|
|
}
|