Skip to content

Commit 2337aeb

Browse files
author
micahcowan
committed
Merge output (more) and copy modes into one single mode (called copy).
1 parent 8186452 commit 2337aeb

10 files changed

+235
-150
lines changed

cmd-copy-mode.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Id: cmd-copy-mode.c,v 1.26 2010-01-05 23:50:22 tcunha Exp $ */
1+
/* $Id: cmd-copy-mode.c,v 1.27 2010-04-05 05:11:42 micahcowan Exp $ */
22

33
/*
44
* Copyright (c) 2007 Nicholas Marriott <[email protected]>
@@ -63,6 +63,7 @@ cmd_copy_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
6363
return (-1);
6464

6565
window_pane_set_mode(wp, &window_copy_mode);
66+
window_copy_init_from_pane(wp);
6667
if (wp->mode == &window_copy_mode && cmd_check_flag(data->chflags, 'u'))
6768
window_copy_pageup(wp);
6869

cmd-new-session.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Id: cmd-new-session.c,v 1.76 2010-02-26 13:28:15 tcunha Exp $ */
1+
/* $Id: cmd-new-session.c,v 1.77 2010-04-05 05:11:43 micahcowan Exp $ */
22

33
/*
44
* Copyright (c) 2007 Nicholas Marriott <[email protected]>
@@ -287,10 +287,11 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
287287
*/
288288
if (cfg_finished && !ARRAY_EMPTY(&cfg_causes)) {
289289
wp = s->curw->window->active;
290-
window_pane_set_mode(wp, &window_more_mode);
290+
window_pane_set_mode(wp, &window_copy_mode);
291+
window_copy_init_for_output(wp);
291292
for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
292293
cause = ARRAY_ITEM(&cfg_causes, i);
293-
window_more_add(wp, "%s", cause);
294+
window_copy_add(wp, "%s", cause);
294295
xfree(cause);
295296
}
296297
ARRAY_FREE(&cfg_causes);

grid.c

+1-42
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Id: grid.c,v 1.36 2009-12-04 22:14:47 tcunha Exp $ */
1+
/* $Id: grid.c,v 1.37 2010-04-05 05:11:43 micahcowan Exp $ */
22

33
/*
44
* Copyright (c) 2008 Nicholas Marriott <[email protected]>
@@ -46,18 +46,9 @@ const struct grid_cell grid_default_cell = { 0, 0, 8, 8, ' ' };
4646
gc, sizeof gd->linedata[py].utf8data[px]); \
4747
} while (0)
4848

49-
int grid_check_x(struct grid *, u_int);
5049
int grid_check_y(struct grid *, u_int);
5150

5251
#ifdef DEBUG
53-
int
54-
grid_check_x(struct grid *gd, u_int px)
55-
{
56-
if ((px) >= (gd)->sx)
57-
log_fatalx("x out of range: %u", px);
58-
return (0);
59-
}
60-
6152
int
6253
grid_check_y(struct grid *gd, u_int py)
6354
{
@@ -66,16 +57,6 @@ grid_check_y(struct grid *gd, u_int py)
6657
return (0);
6758
}
6859
#else
69-
int
70-
grid_check_x(struct grid *gd, u_int px)
71-
{
72-
if ((px) >= (gd)->sx) {
73-
log_debug("x out of range: %u", px);
74-
return (-1);
75-
}
76-
return (0);
77-
}
78-
7960
int
8061
grid_check_y(struct grid *gd, u_int py)
8162
{
@@ -270,8 +251,6 @@ grid_expand_line_utf8(struct grid *gd, u_int py, u_int sx)
270251
const struct grid_cell *
271252
grid_peek_cell(struct grid *gd, u_int px, u_int py)
272253
{
273-
if (grid_check_x(gd, px) != 0)
274-
return (&grid_default_cell);
275254
if (grid_check_y(gd, py) != 0)
276255
return (&grid_default_cell);
277256

@@ -284,8 +263,6 @@ grid_peek_cell(struct grid *gd, u_int px, u_int py)
284263
struct grid_cell *
285264
grid_get_cell(struct grid *gd, u_int px, u_int py)
286265
{
287-
if (grid_check_x(gd, px) != 0)
288-
return (NULL);
289266
if (grid_check_y(gd, py) != 0)
290267
return (NULL);
291268

@@ -298,8 +275,6 @@ void
298275
grid_set_cell(
299276
struct grid *gd, u_int px, u_int py, const struct grid_cell *gc)
300277
{
301-
if (grid_check_x(gd, px) != 0)
302-
return;
303278
if (grid_check_y(gd, py) != 0)
304279
return;
305280

@@ -311,8 +286,6 @@ grid_set_cell(
311286
const struct grid_utf8 *
312287
grid_peek_utf8(struct grid *gd, u_int px, u_int py)
313288
{
314-
if (grid_check_x(gd, px) != 0)
315-
return (NULL);
316289
if (grid_check_y(gd, py) != 0)
317290
return (NULL);
318291

@@ -325,8 +298,6 @@ grid_peek_utf8(struct grid *gd, u_int px, u_int py)
325298
struct grid_utf8 *
326299
grid_get_utf8(struct grid *gd, u_int px, u_int py)
327300
{
328-
if (grid_check_x(gd, px) != 0)
329-
return (NULL);
330301
if (grid_check_y(gd, py) != 0)
331302
return (NULL);
332303

@@ -339,8 +310,6 @@ void
339310
grid_set_utf8(
340311
struct grid *gd, u_int px, u_int py, const struct grid_utf8 *gc)
341312
{
342-
if (grid_check_x(gd, px) != 0)
343-
return;
344313
if (grid_check_y(gd, py) != 0)
345314
return;
346315

@@ -364,10 +333,6 @@ grid_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny)
364333
return;
365334
}
366335

367-
if (grid_check_x(gd, px) != 0)
368-
return;
369-
if (grid_check_x(gd, px + nx - 1) != 0)
370-
return;
371336
if (grid_check_y(gd, py) != 0)
372337
return;
373338
if (grid_check_y(gd, py + ny - 1) != 0)
@@ -465,12 +430,6 @@ grid_move_cells(struct grid *gd, u_int dx, u_int px, u_int py, u_int nx)
465430
if (nx == 0 || px == dx)
466431
return;
467432

468-
if (grid_check_x(gd, px) != 0)
469-
return;
470-
if (grid_check_x(gd, px + nx - 1) != 0)
471-
return;
472-
if (grid_check_x(gd, dx + nx - 1) != 0)
473-
return;
474433
if (grid_check_y(gd, py) != 0)
475434
return;
476435
gl = &gd->linedata[py];

key-bindings.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Id: key-bindings.c,v 1.89 2010-03-15 22:03:38 nicm Exp $ */
1+
/* $Id: key-bindings.c,v 1.90 2010-04-05 05:11:43 micahcowan Exp $ */
22

33
/*
44
* Copyright (c) 2007 Nicholas Marriott <[email protected]>
@@ -211,12 +211,14 @@ key_bindings_print(struct cmd_ctx *ctx, const char *fmt, ...)
211211
struct winlink *wl = ctx->curclient->session->curw;
212212
va_list ap;
213213

214-
if (wl->window->active->mode != &window_more_mode)
214+
if (wl->window->active->mode != &window_copy_mode) {
215215
window_pane_reset_mode(wl->window->active);
216-
window_pane_set_mode(wl->window->active, &window_more_mode);
216+
window_pane_set_mode(wl->window->active, &window_copy_mode);
217+
window_copy_init_for_output(wl->window->active);
218+
}
217219

218220
va_start(ap, fmt);
219-
window_more_vadd(wl->window->active, fmt, ap);
221+
window_copy_vadd(wl->window->active, fmt, ap);
220222
va_end(ap);
221223
}
222224

screen-write.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Id: screen-write.c,v 1.88 2009-12-04 22:14:47 tcunha Exp $ */
1+
/* $Id: screen-write.c,v 1.89 2010-04-05 05:11:43 micahcowan Exp $ */
22

33
/*
44
* Copyright (c) 2007 Nicholas Marriott <[email protected]>
@@ -1009,13 +1009,14 @@ screen_write_cell(struct screen_write_ctx *ctx,
10091009
}
10101010

10111011
/* Check this will fit on the current line and wrap if not. */
1012-
if (s->cx > screen_size_x(s) - width) {
1012+
if ((s->mode & MODE_WRAP) && s->cx > screen_size_x(s) - width) {
10131013
screen_write_linefeed(ctx, 1);
10141014
s->cx = 0; /* carriage return */
10151015
}
10161016

10171017
/* Sanity checks. */
1018-
if (s->cx > screen_size_x(s) - 1 || s->cy > screen_size_y(s) - 1)
1018+
if (((s->mode & MODE_WRAP) && s->cx > screen_size_x(s) - 1)
1019+
|| s->cy > screen_size_y(s) - 1)
10191020
return;
10201021

10211022
/* Handle overwriting of UTF-8 characters. */

screen.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Id: screen.c,v 1.99 2010-02-08 18:13:17 tcunha Exp $ */
1+
/* $Id: screen.c,v 1.100 2010-04-05 05:11:44 micahcowan Exp $ */
22

33
/*
44
* Copyright (c) 2007 Nicholas Marriott <[email protected]>
@@ -49,7 +49,7 @@ screen_reinit(struct screen *s)
4949
s->rupper = 0;
5050
s->rlower = screen_size_y(s) - 1;
5151

52-
s->mode = MODE_CURSOR;
52+
s->mode = MODE_CURSOR | MODE_WRAP;
5353

5454
screen_reset_tabs(s);
5555

server.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Id: server.c,v 1.236 2010-03-16 23:40:14 nicm Exp $ */
1+
/* $Id: server.c,v 1.237 2010-04-05 05:11:44 micahcowan Exp $ */
22

33
/*
44
* Copyright (c) 2007 Nicholas Marriott <[email protected]>
@@ -200,10 +200,11 @@ server_start(char *path)
200200
*/
201201
if (!ARRAY_EMPTY(&sessions) && !ARRAY_EMPTY(&cfg_causes)) {
202202
wp = ARRAY_FIRST(&sessions)->curw->window->active;
203-
window_pane_set_mode(wp, &window_more_mode);
203+
window_pane_set_mode(wp, &window_copy_mode);
204+
window_copy_init_for_output(wp);
204205
for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
205206
cause = ARRAY_ITEM(&cfg_causes, i);
206-
window_more_add(wp, "%s", cause);
207+
window_copy_add(wp, "%s", cause);
207208
xfree(cause);
208209
}
209210
ARRAY_FREE(&cfg_causes);

tmux.1

+13-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.\" $Id: tmux.1,v 1.243 2010-03-27 15:12:56 nicm Exp $
1+
.\" $Id: tmux.1,v 1.244 2010-04-05 05:11:44 micahcowan Exp $
22
.\"
33
.\" Copyright (c) 2007 Nicholas Marriott <[email protected]>
44
.\"
@@ -588,22 +588,18 @@ A
588588
.Nm
589589
window may be in one of several modes.
590590
The default permits direct access to the terminal attached to the window.
591-
The others are:
592-
.Bl -tag -width Ds
593-
.It Em output mode
594-
This is entered when a command which produces output, such as
595-
.Ic list-keys ,
596-
is executed from a key binding.
597-
.It Em copy mode
598-
This permits a section of a window or its history to be copied to a
591+
The other is copy mode, which permits a section of a window or its
592+
history to be copied to a
599593
.Em paste buffer
600594
for later insertion into another window.
601595
This mode is entered with the
602596
.Ic copy-mode
603597
command, bound to
604598
.Ql \&[
605599
by default.
606-
.El
600+
It is also entered when a command that produces output, such as
601+
.Ic list-keys ,
602+
is executed from a key binding.
607603
.Pp
608604
The keys available depend on whether emacs or vi mode is selected
609605
(see the
@@ -701,7 +697,7 @@ and
701697
.Em emacs-choice
702698
for keys used when choosing from lists (such as produced by the
703699
.Ic choose-window
704-
command) or in output mode; and
700+
command); and
705701
.Em vi-copy
706702
and
707703
.Em emacs-copy
@@ -716,7 +712,9 @@ and
716712
The paste buffer key pastes the first line from the top paste buffer on the
717713
stack.
718714
.Pp
719-
The mode commands are as follows:
715+
The synopsis for the
716+
.Ic copy-mode
717+
command is:
720718
.Bl -tag -width Ds
721719
.It Xo Ic copy-mode
722720
.Op Fl u
@@ -2021,8 +2019,8 @@ command.
20212019
.It Xo Ic synchronize-panes
20222020
.Op Ic on | off
20232021
.Xc
2024-
Duplicate input to any pane to all other panes in the same window, except
2025-
for panes that are not in output mode.
2022+
Duplicate input to any pane to all other panes in the same window (only
2023+
for panes that are not in any special mode).
20262024
.Pp
20272025
.It Xo Ic alternate-screen
20282026
.Op Ic on | off
@@ -2432,7 +2430,7 @@ option.
24322430
Execute
24332431
.Ar shell-command
24342432
in the background without creating a window.
2435-
After it finishes, any output to stdout is displayed in output mode.
2433+
After it finishes, any output to stdout is displayed in copy mode.
24362434
If the command doesn't return success, the exit status is also displayed.
24372435
.It Ic server-info
24382436
.D1 (alias: Ic info )

tmux.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Id: tmux.h,v 1.551 2010-03-27 15:12:56 nicm Exp $ */
1+
/* $Id: tmux.h,v 1.552 2010-04-05 05:11:44 micahcowan Exp $ */
22

33
/*
44
* Copyright (c) 2007 Nicholas Marriott <[email protected]>
@@ -540,6 +540,8 @@ struct mode_key_table {
540540
#define MODE_KCURSOR 0x4
541541
#define MODE_KKEYPAD 0x8 /* set = application, clear = number */
542542
#define MODE_MOUSE 0x10
543+
#define MODE_WRAP 0x20 /* whether lines wrap */
544+
543545

544546
/*
545547
* A single UTF-8 character.
@@ -1879,13 +1881,12 @@ extern const struct window_mode window_clock_mode;
18791881

18801882
/* window-copy.c */
18811883
extern const struct window_mode window_copy_mode;
1884+
void window_copy_init_from_pane(struct window_pane *);
1885+
void window_copy_init_for_output(struct window_pane *);
1886+
void window_copy_add(struct window_pane *, const char *, ...);
1887+
void window_copy_vadd(struct window_pane *, const char *, va_list);
18821888
void window_copy_pageup(struct window_pane *);
18831889

1884-
/* window-more.c */
1885-
extern const struct window_mode window_more_mode;
1886-
void window_more_add(struct window_pane *, const char *, ...);
1887-
void window_more_vadd(struct window_pane *, const char *, va_list);
1888-
18891890
/* window-choose.c */
18901891
extern const struct window_mode window_choose_mode;
18911892
void window_choose_vadd(

0 commit comments

Comments
 (0)