annotate src/terminal.c @ 14109:279465096a16 v8.1.0072

patch 8.1.0072: use of 'termwinkey' is inconsistent commit https://github.com/vim/vim/commit/dcdeaaf1505b96aa7a31ccd4becc92c32119bdda Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 17 22:19:12 2018 +0200 patch 8.1.0072: use of 'termwinkey' is inconsistent Problem: Use of 'termwinkey' is inconsistent. Solution: Change the documentation and the behavior. (Ken Takata)
author Christian Brabandt <cb@256bit.org>
date Sun, 17 Jun 2018 22:30:06 +0200
parents e271ca6f32f9
children 08b0b6d6cbe7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 *
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 *
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 * Terminal window support, see ":help :terminal".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 *
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 * There are three parts:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 * 1. Generic code for all systems.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 * Uses libvterm for the terminal emulator.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 * 2. The MS-Windows implementation.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 * Uses winpty.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 * 3. The Unix-like implementation.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 * Uses pseudo-tty's (pty's).
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 *
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 * For each terminal one VTerm is constructed. This uses libvterm. A copy of
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 * this library is in the libvterm directory.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 *
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 * When a terminal window is opened, a job is started that will be connected to
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 * the terminal emulator.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 *
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 * If the terminal window has keyboard focus, typed keys are converted to the
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 * terminal encoding and writing to the job over a channel.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 *
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 * If the job produces output, it is written to the terminal emulator. The
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 * terminal emulator invokes callbacks when its screen content changes. The
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 * line range is stored in tl_dirty_row_start and tl_dirty_row_end. Once in a
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 * while, if the terminal window is visible, the screen contents is drawn.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 *
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 * When the job ends the text is put in a buffer. Redrawing then happens from
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 * that buffer, attributes come from the scrollback buffer tl_scrollback.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 * When the buffer is changed it is turned into a normal buffer, the attributes
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 * in tl_scrollback are no longer used.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 #include "vim.h"
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 #if defined(FEAT_TERMINAL) || defined(PROTO)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 #ifndef MIN
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 # define MIN(x,y) ((x) < (y) ? (x) : (y))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 #ifndef MAX
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 # define MAX(x,y) ((x) > (y) ? (x) : (y))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 #include "libvterm/include/vterm.h"
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 /* This is VTermScreenCell without the characters, thus much smaller. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 typedef struct {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 VTermScreenCellAttrs attrs;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 char width;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
58 VTermColor fg;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
59 VTermColor bg;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 } cellattr_T;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 typedef struct sb_line_S {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 int sb_cols; /* can differ per line */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 cellattr_T *sb_cells; /* allocated */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 cellattr_T sb_fill_attr; /* for short line */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 } sb_line_T;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 /* typedef term_T in structs.h */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 struct terminal_S {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 term_T *tl_next;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 VTerm *tl_vterm;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73 job_T *tl_job;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 buf_T *tl_buffer;
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
75 #if defined(FEAT_GUI)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
76 int tl_system; /* when non-zero used for :!cmd output */
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
77 int tl_toprow; /* row with first line of system terminal */
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
78 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 /* Set when setting the size of a vterm, reset after redrawing. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 int tl_vterm_size_changed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83 int tl_normal_mode; /* TRUE: Terminal-Normal mode */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 int tl_channel_closed;
13888
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
85 int tl_channel_recently_closed; // still need to handle tl_finish
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
86
13476
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
87 int tl_finish;
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
88 #define TL_FINISH_UNSET NUL
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
89 #define TL_FINISH_CLOSE 'c' /* ++close or :terminal without argument */
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
90 #define TL_FINISH_NOCLOSE 'n' /* ++noclose */
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
91 #define TL_FINISH_OPEN 'o' /* ++open */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92 char_u *tl_opencmd;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 char_u *tl_eof_chars;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
94
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
95 #ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
96 void *tl_winpty_config;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
97 void *tl_winpty;
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
98
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
99 FILE *tl_out_fd;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
100 #endif
13435
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
101 #if defined(FEAT_SESSION)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
102 char_u *tl_command;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
103 #endif
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
104 char_u *tl_kill;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
105
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
106 /* last known vterm size */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
107 int tl_rows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
108 int tl_cols;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
109
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
110 char_u *tl_title; /* NULL or allocated */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
111 char_u *tl_status_text; /* NULL or allocated */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
112
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
113 /* Range of screen rows to update. Zero based. */
12578
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
114 int tl_dirty_row_start; /* MAX_ROW if nothing dirty */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
115 int tl_dirty_row_end; /* row below last one to update */
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
116 int tl_dirty_snapshot; /* text updated after making snapshot */
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
117 #ifdef FEAT_TIMERS
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
118 int tl_timer_set;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
119 proftime_T tl_timer_due;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
120 #endif
13851
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
121 int tl_postponed_scroll; /* to be scrolled up */
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
122
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
123 garray_T tl_scrollback;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
124 int tl_scrollback_scrolled;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
125 cellattr_T tl_default_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
126
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
127 linenr_T tl_top_diff_rows; /* rows of top diff file or zero */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
128 linenr_T tl_bot_diff_rows; /* rows of bottom diff file */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
129
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
130 VTermPos tl_cursor_pos;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
131 int tl_cursor_visible;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
132 int tl_cursor_blink;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
133 int tl_cursor_shape; /* 1: block, 2: underline, 3: bar */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
134 char_u *tl_cursor_color; /* NULL or allocated */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
135
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
136 int tl_using_altscreen;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
137 };
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
138
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
139 #define TMODE_ONCE 1 /* CTRL-\ CTRL-N used */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
140 #define TMODE_LOOP 2 /* CTRL-W N used */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
141
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
142 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
143 * List of all active terminals.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
144 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
145 static term_T *first_term = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
146
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
147 /* Terminal active in terminal_loop(). */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
148 static term_T *in_terminal_loop = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
149
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
150 #define MAX_ROW 999999 /* used for tl_dirty_row_end to update all rows */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
151 #define KEY_BUF_LEN 200
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
152
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
153 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
154 * Functions with separate implementation for MS-Windows and Unix-like systems.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
155 */
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
156 static int term_and_job_init(term_T *term, typval_T *argvar, char **argv, jobopt_T *opt, jobopt_T *orig_opt);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
157 static int create_pty_only(term_T *term, jobopt_T *opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
158 static void term_report_winsize(term_T *term, int rows, int cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
159 static void term_free_vterm(term_T *term);
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
160 #ifdef FEAT_GUI
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
161 static void update_system_term(term_T *term);
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
162 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
163
12800
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
164 /* The character that we know (or assume) that the terminal expects for the
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
165 * backspace key. */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
166 static int term_backspace_char = BS;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
167
12973
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
168 /* "Terminal" highlight group colors. */
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
169 static int term_default_cterm_fg = -1;
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
170 static int term_default_cterm_bg = -1;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
171
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
172 /* Store the last set and the desired cursor properties, so that we only update
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
173 * them when needed. Doing it unnecessary may result in flicker. */
13990
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
174 static char_u *last_set_cursor_color = NULL;
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
175 static char_u *desired_cursor_color = NULL;
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
176 static int last_set_cursor_shape = -1;
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
177 static int desired_cursor_shape = -1;
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
178 static int last_set_cursor_blink = -1;
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
179 static int desired_cursor_blink = -1;
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
180
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
181
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
182 /**************************************
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
183 * 1. Generic code for all systems.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
184 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
185
13994
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
186 static int
13990
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
187 cursor_color_equal(char_u *lhs_color, char_u *rhs_color)
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
188 {
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
189 if (lhs_color != NULL && rhs_color != NULL)
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
190 return STRCMP(lhs_color, rhs_color) == 0;
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
191 return lhs_color == NULL && rhs_color == NULL;
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
192 }
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
193
13994
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
194 static void
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
195 cursor_color_copy(char_u **to_color, char_u *from_color)
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
196 {
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
197 // Avoid a free & alloc if the value is already right.
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
198 if (cursor_color_equal(*to_color, from_color))
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
199 return;
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
200 vim_free(*to_color);
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
201 *to_color = (from_color == NULL) ? NULL : vim_strsave(from_color);
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
202 }
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
203
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
204 static char_u *
13990
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
205 cursor_color_get(char_u *color)
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
206 {
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
207 return (color == NULL) ? (char_u *)"" : color;
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
208 }
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
209
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
210
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
211 /*
13845
f22db93bd887 patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents: 13835
diff changeset
212 * Parse 'termwinsize' and set "rows" and "cols" for the terminal size in the
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
213 * current window.
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
214 * Sets "rows" and/or "cols" to zero when it should follow the window size.
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
215 * Return TRUE if the size is the minimum size: "24*80".
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
216 */
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
217 static int
13845
f22db93bd887 patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents: 13835
diff changeset
218 parse_termwinsize(win_T *wp, int *rows, int *cols)
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
219 {
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
220 int minsize = FALSE;
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
221
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
222 *rows = 0;
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
223 *cols = 0;
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
224
13742
a34b1323286c patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents: 13720
diff changeset
225 if (*wp->w_p_tws != NUL)
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
226 {
13742
a34b1323286c patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents: 13720
diff changeset
227 char_u *p = vim_strchr(wp->w_p_tws, 'x');
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
228
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
229 /* Syntax of value was already checked when it's set. */
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
230 if (p == NULL)
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
231 {
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
232 minsize = TRUE;
13742
a34b1323286c patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents: 13720
diff changeset
233 p = vim_strchr(wp->w_p_tws, '*');
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
234 }
13742
a34b1323286c patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents: 13720
diff changeset
235 *rows = atoi((char *)wp->w_p_tws);
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
236 *cols = atoi((char *)p + 1);
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
237 }
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
238 return minsize;
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
239 }
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
240
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
241 /*
13845
f22db93bd887 patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents: 13835
diff changeset
242 * Determine the terminal size from 'termwinsize' and the current window.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
243 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
244 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
245 set_term_and_win_size(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
246 {
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
247 #ifdef FEAT_GUI
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
248 if (term->tl_system)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
249 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
250 /* Use the whole screen for the system command. However, it will start
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
251 * at the command line and scroll up as needed, using tl_toprow. */
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
252 term->tl_rows = Rows;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
253 term->tl_cols = Columns;
13624
429f0eb87d6f patch 8.0.1684: ml_get errors when using terminal window for shell command
Christian Brabandt <cb@256bit.org>
parents: 13616
diff changeset
254 return;
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
255 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
256 #endif
13845
f22db93bd887 patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents: 13835
diff changeset
257 if (parse_termwinsize(curwin, &term->tl_rows, &term->tl_cols))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
258 {
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
259 if (term->tl_rows != 0)
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
260 term->tl_rows = MAX(term->tl_rows, curwin->w_height);
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
261 if (term->tl_cols != 0)
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
262 term->tl_cols = MAX(term->tl_cols, curwin->w_width);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
263 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
264 if (term->tl_rows == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
265 term->tl_rows = curwin->w_height;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
266 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
267 win_setheight_win(term->tl_rows, curwin);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
268 if (term->tl_cols == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
269 term->tl_cols = curwin->w_width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
270 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
271 win_setwidth_win(term->tl_cols, curwin);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
272 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
273
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
274 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
275 * Initialize job options for a terminal job.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
276 * Caller may overrule some of them.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
277 */
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
278 void
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
279 init_job_options(jobopt_T *opt)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
280 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
281 clear_job_options(opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
282
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
283 opt->jo_mode = MODE_RAW;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
284 opt->jo_out_mode = MODE_RAW;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
285 opt->jo_err_mode = MODE_RAW;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
286 opt->jo_set = JO_MODE | JO_OUT_MODE | JO_ERR_MODE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
287 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
288
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
289 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
290 * Set job options mandatory for a terminal job.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
291 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
292 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
293 setup_job_options(jobopt_T *opt, int rows, int cols)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
294 {
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
295 #ifndef WIN3264
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
296 /* Win32: Redirecting the job output won't work, thus always connect stdout
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
297 * here. */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
298 if (!(opt->jo_set & JO_OUT_IO))
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
299 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
300 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
301 /* Connect stdout to the terminal. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
302 opt->jo_io[PART_OUT] = JIO_BUFFER;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
303 opt->jo_io_buf[PART_OUT] = curbuf->b_fnum;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
304 opt->jo_modifiable[PART_OUT] = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
305 opt->jo_set |= JO_OUT_IO + JO_OUT_BUF + JO_OUT_MODIFIABLE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
306 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
307
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
308 #ifndef WIN3264
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
309 /* Win32: Redirecting the job output won't work, thus always connect stderr
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
310 * here. */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
311 if (!(opt->jo_set & JO_ERR_IO))
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
312 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
313 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
314 /* Connect stderr to the terminal. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
315 opt->jo_io[PART_ERR] = JIO_BUFFER;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
316 opt->jo_io_buf[PART_ERR] = curbuf->b_fnum;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
317 opt->jo_modifiable[PART_ERR] = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
318 opt->jo_set |= JO_ERR_IO + JO_ERR_BUF + JO_ERR_MODIFIABLE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
319 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
320
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
321 opt->jo_pty = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
322 if ((opt->jo_set2 & JO2_TERM_ROWS) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
323 opt->jo_term_rows = rows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
324 if ((opt->jo_set2 & JO2_TERM_COLS) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
325 opt->jo_term_cols = cols;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
326 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
327
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
328 /*
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
329 * Close a terminal buffer (and its window). Used when creating the terminal
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
330 * fails.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
331 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
332 static void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
333 term_close_buffer(buf_T *buf, buf_T *old_curbuf)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
334 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
335 free_terminal(buf);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
336 if (old_curbuf != NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
337 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
338 --curbuf->b_nwindows;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
339 curbuf = old_curbuf;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
340 curwin->w_buffer = curbuf;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
341 ++curbuf->b_nwindows;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
342 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
343
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
344 /* Wiping out the buffer will also close the window and call
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
345 * free_terminal(). */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
346 do_buffer(DOBUF_WIPE, DOBUF_FIRST, FORWARD, buf->b_fnum, TRUE);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
347 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
348
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
349 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
350 * Start a terminal window and return its buffer.
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
351 * Use either "argvar" or "argv", the other must be NULL.
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
352 * When "flags" has TERM_START_NOJOB only create the buffer, b_term and open
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
353 * the window.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
354 * Returns NULL when failed.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
355 */
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
356 buf_T *
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
357 term_start(
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
358 typval_T *argvar,
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
359 char **argv,
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
360 jobopt_T *opt,
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
361 int flags)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
362 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
363 exarg_T split_ea;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
364 win_T *old_curwin = curwin;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
365 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
366 buf_T *old_curbuf = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
367 int res;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
368 buf_T *newbuf;
13501
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
369 int vertical = opt->jo_vertical || (cmdmod.split & WSP_VERT);
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
370 jobopt_T orig_opt; // only partly filled
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
371
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
372 if (check_restricted() || check_secure())
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
373 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
374
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
375 if ((opt->jo_set & (JO_IN_IO + JO_OUT_IO + JO_ERR_IO))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
376 == (JO_IN_IO + JO_OUT_IO + JO_ERR_IO)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
377 || (!(opt->jo_set & JO_OUT_IO) && (opt->jo_set & JO_OUT_BUF))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
378 || (!(opt->jo_set & JO_ERR_IO) && (opt->jo_set & JO_ERR_BUF)))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
379 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
380 EMSG(_(e_invarg));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
381 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
382 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
383
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
384 term = (term_T *)alloc_clear(sizeof(term_T));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
385 if (term == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
386 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
387 term->tl_dirty_row_end = MAX_ROW;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
388 term->tl_cursor_visible = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
389 term->tl_cursor_shape = VTERM_PROP_CURSORSHAPE_BLOCK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
390 term->tl_finish = opt->jo_term_finish;
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
391 #ifdef FEAT_GUI
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
392 term->tl_system = (flags & TERM_START_SYSTEM);
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
393 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
394 ga_init2(&term->tl_scrollback, sizeof(sb_line_T), 300);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
395
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
396 vim_memset(&split_ea, 0, sizeof(split_ea));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
397 if (opt->jo_curwin)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
398 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
399 /* Create a new buffer in the current window. */
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
400 if (!can_abandon(curbuf, flags & TERM_START_FORCEIT))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
401 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
402 no_write_message();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
403 vim_free(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
404 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
405 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
406 if (do_ecmd(0, NULL, NULL, &split_ea, ECMD_ONE,
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
407 ECMD_HIDE
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
408 + ((flags & TERM_START_FORCEIT) ? ECMD_FORCEIT : 0),
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
409 curwin) == FAIL)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
410 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
411 vim_free(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
412 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
413 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
414 }
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
415 else if (opt->jo_hidden || (flags & TERM_START_SYSTEM))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
416 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
417 buf_T *buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
418
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
419 /* Create a new buffer without a window. Make it the current buffer for
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
420 * a moment to be able to do the initialisations. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
421 buf = buflist_new((char_u *)"", NULL, (linenr_T)0,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
422 BLN_NEW | BLN_LISTED);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
423 if (buf == NULL || ml_open(buf) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
424 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
425 vim_free(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
426 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
427 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
428 old_curbuf = curbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
429 --curbuf->b_nwindows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
430 curbuf = buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
431 curwin->w_buffer = buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
432 ++curbuf->b_nwindows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
433 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
434 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
435 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
436 /* Open a new window or tab. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
437 split_ea.cmdidx = CMD_new;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
438 split_ea.cmd = (char_u *)"new";
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
439 split_ea.arg = (char_u *)"";
13501
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
440 if (opt->jo_term_rows > 0 && !vertical)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
441 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
442 split_ea.line2 = opt->jo_term_rows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
443 split_ea.addr_count = 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
444 }
13501
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
445 if (opt->jo_term_cols > 0 && vertical)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
446 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
447 split_ea.line2 = opt->jo_term_cols;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
448 split_ea.addr_count = 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
449 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
450
13501
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
451 if (vertical)
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
452 cmdmod.split |= WSP_VERT;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
453 ex_splitview(&split_ea);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
454 if (curwin == old_curwin)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
455 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
456 /* split failed */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
457 vim_free(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
458 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
459 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
460 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
461 term->tl_buffer = curbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
462 curbuf->b_term = term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
463
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
464 if (!opt->jo_hidden)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
465 {
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents: 13300
diff changeset
466 /* Only one size was taken care of with :new, do the other one. With
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents: 13300
diff changeset
467 * "curwin" both need to be done. */
13501
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
468 if (opt->jo_term_rows > 0 && (opt->jo_curwin || vertical))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
469 win_setheight(opt->jo_term_rows);
13501
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
470 if (opt->jo_term_cols > 0 && (opt->jo_curwin || !vertical))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
471 win_setwidth(opt->jo_term_cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
472 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
473
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
474 /* Link the new terminal in the list of active terminals. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
475 term->tl_next = first_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
476 first_term = term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
477
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
478 if (opt->jo_term_name != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
479 curbuf->b_ffname = vim_strsave(opt->jo_term_name);
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
480 else if (argv != NULL)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
481 curbuf->b_ffname = vim_strsave((char_u *)"!system");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
482 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
483 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
484 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
485 size_t len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
486 char_u *cmd, *p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
487
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
488 if (argvar->v_type == VAR_STRING)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
489 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
490 cmd = argvar->vval.v_string;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
491 if (cmd == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
492 cmd = (char_u *)"";
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
493 else if (STRCMP(cmd, "NONE") == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
494 cmd = (char_u *)"pty";
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
495 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
496 else if (argvar->v_type != VAR_LIST
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
497 || argvar->vval.v_list == NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
498 || argvar->vval.v_list->lv_len < 1
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
499 || (cmd = get_tv_string_chk(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
500 &argvar->vval.v_list->lv_first->li_tv)) == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
501 cmd = (char_u*)"";
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
503 len = STRLEN(cmd) + 10;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
504 p = alloc((int)len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
505
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
506 for (i = 0; p != NULL; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
507 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
508 /* Prepend a ! to the command name to avoid the buffer name equals
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
509 * the executable, otherwise ":w!" would overwrite it. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
510 if (i == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
511 vim_snprintf((char *)p, len, "!%s", cmd);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
512 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
513 vim_snprintf((char *)p, len, "!%s (%d)", cmd, i);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
514 if (buflist_findname(p) == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
515 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
516 vim_free(curbuf->b_ffname);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
517 curbuf->b_ffname = p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
518 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
519 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
520 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
521 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
522 curbuf->b_fname = curbuf->b_ffname;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
523
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
524 if (opt->jo_term_opencmd != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
525 term->tl_opencmd = vim_strsave(opt->jo_term_opencmd);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
526
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
527 if (opt->jo_eof_chars != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
528 term->tl_eof_chars = vim_strsave(opt->jo_eof_chars);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
529
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
530 set_string_option_direct((char_u *)"buftype", -1,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
531 (char_u *)"terminal", OPT_FREE|OPT_LOCAL, 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
532
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
533 /* Mark the buffer as not modifiable. It can only be made modifiable after
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
534 * the job finished. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
535 curbuf->b_p_ma = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
536
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
537 set_term_and_win_size(term);
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
538 #ifdef WIN3264
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
539 mch_memmove(orig_opt.jo_io, opt->jo_io, sizeof(orig_opt.jo_io));
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
540 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
541 setup_job_options(opt, term->tl_rows, term->tl_cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
542
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
543 if (flags & TERM_START_NOJOB)
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
544 return curbuf;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
545
13435
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
546 #if defined(FEAT_SESSION)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
547 /* Remember the command for the session file. */
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
548 if (opt->jo_term_norestore || argv != NULL)
13435
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
549 {
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
550 term->tl_command = vim_strsave((char_u *)"NONE");
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
551 }
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
552 else if (argvar->v_type == VAR_STRING)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
553 {
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
554 char_u *cmd = argvar->vval.v_string;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
555
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
556 if (cmd != NULL && STRCMP(cmd, p_sh) != 0)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
557 term->tl_command = vim_strsave(cmd);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
558 }
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
559 else if (argvar->v_type == VAR_LIST
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
560 && argvar->vval.v_list != NULL
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
561 && argvar->vval.v_list->lv_len > 0)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
562 {
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
563 garray_T ga;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
564 listitem_T *item;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
565
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
566 ga_init2(&ga, 1, 100);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
567 for (item = argvar->vval.v_list->lv_first;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
568 item != NULL; item = item->li_next)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
569 {
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
570 char_u *s = get_tv_string_chk(&item->li_tv);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
571 char_u *p;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
572
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
573 if (s == NULL)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
574 break;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
575 p = vim_strsave_fnameescape(s, FALSE);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
576 if (p == NULL)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
577 break;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
578 ga_concat(&ga, p);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
579 vim_free(p);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
580 ga_append(&ga, ' ');
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
581 }
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
582 if (item == NULL)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
583 {
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
584 ga_append(&ga, NUL);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
585 term->tl_command = ga.ga_data;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
586 }
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
587 else
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
588 ga_clear(&ga);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
589 }
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
590 #endif
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
591
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
592 if (opt->jo_term_kill != NULL)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
593 {
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
594 char_u *p = skiptowhite(opt->jo_term_kill);
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
595
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
596 term->tl_kill = vim_strnsave(opt->jo_term_kill, p - opt->jo_term_kill);
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
597 }
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
598
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
599 /* System dependent: setup the vterm and maybe start the job in it. */
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
600 if (argv == NULL
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
601 && argvar->v_type == VAR_STRING
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
602 && argvar->vval.v_string != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
603 && STRCMP(argvar->vval.v_string, "NONE") == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
604 res = create_pty_only(term, opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
605 else
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
606 res = term_and_job_init(term, argvar, argv, opt, &orig_opt);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
607
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
608 newbuf = curbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
609 if (res == OK)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
610 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
611 /* Get and remember the size we ended up with. Update the pty. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
612 vterm_get_size(term->tl_vterm, &term->tl_rows, &term->tl_cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
613 term_report_winsize(term, term->tl_rows, term->tl_cols);
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
614 #ifdef FEAT_GUI
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
615 if (term->tl_system)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
616 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
617 /* display first line below typed command */
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
618 term->tl_toprow = msg_row + 1;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
619 term->tl_dirty_row_end = 0;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
620 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
621 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
622
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
623 /* Make sure we don't get stuck on sending keys to the job, it leads to
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
624 * a deadlock if the job is waiting for Vim to read. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
625 channel_set_nonblock(term->tl_job->jv_channel, PART_IN);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
626
13835
8e583c52eb44 patch 8.0.1789: BufWinEnter does not work well for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13829
diff changeset
627 if (old_curbuf != NULL)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
628 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
629 --curbuf->b_nwindows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
630 curbuf = old_curbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
631 curwin->w_buffer = curbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
632 ++curbuf->b_nwindows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
633 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
634 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
635 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
636 {
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
637 term_close_buffer(curbuf, old_curbuf);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
638 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
639 }
13444
9f06f7aca74c patch 8.0.1596: no autocommand specifically for opening a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13438
diff changeset
640
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
641 apply_autocmds(EVENT_TERMINALOPEN, NULL, NULL, FALSE, newbuf);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
642 return newbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
643 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
644
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
645 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
646 * ":terminal": open a terminal window and execute a job in it.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
647 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
648 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
649 ex_terminal(exarg_T *eap)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
650 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
651 typval_T argvar[2];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
652 jobopt_T opt;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
653 char_u *cmd;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
654 char_u *tofree = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
655
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
656 init_job_options(&opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
657
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
658 cmd = eap->arg;
13219
4b8d89ea9edb patch 8.0.1484: reduntant conditions
Christian Brabandt <cb@256bit.org>
parents: 13206
diff changeset
659 while (*cmd == '+' && *(cmd + 1) == '+')
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
660 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
661 char_u *p, *ep;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
662
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
663 cmd += 2;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
664 p = skiptowhite(cmd);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
665 ep = vim_strchr(cmd, '=');
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
666 if (ep != NULL && ep < p)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
667 p = ep;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
668
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
669 if ((int)(p - cmd) == 5 && STRNICMP(cmd, "close", 5) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
670 opt.jo_term_finish = 'c';
13476
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
671 else if ((int)(p - cmd) == 7 && STRNICMP(cmd, "noclose", 7) == 0)
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
672 opt.jo_term_finish = 'n';
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
673 else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "open", 4) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
674 opt.jo_term_finish = 'o';
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
675 else if ((int)(p - cmd) == 6 && STRNICMP(cmd, "curwin", 6) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
676 opt.jo_curwin = 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
677 else if ((int)(p - cmd) == 6 && STRNICMP(cmd, "hidden", 6) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
678 opt.jo_hidden = 1;
13435
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
679 else if ((int)(p - cmd) == 9 && STRNICMP(cmd, "norestore", 9) == 0)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
680 opt.jo_term_norestore = 1;
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
681 else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "kill", 4) == 0
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
682 && ep != NULL)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
683 {
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
684 opt.jo_set2 |= JO2_TERM_KILL;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
685 opt.jo_term_kill = ep + 1;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
686 p = skiptowhite(cmd);
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
687 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
688 else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "rows", 4) == 0
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
689 && ep != NULL && isdigit(ep[1]))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
690 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
691 opt.jo_set2 |= JO2_TERM_ROWS;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
692 opt.jo_term_rows = atoi((char *)ep + 1);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
693 p = skiptowhite(cmd);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
694 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
695 else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "cols", 4) == 0
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
696 && ep != NULL && isdigit(ep[1]))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
697 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
698 opt.jo_set2 |= JO2_TERM_COLS;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
699 opt.jo_term_cols = atoi((char *)ep + 1);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
700 p = skiptowhite(cmd);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
701 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
702 else if ((int)(p - cmd) == 3 && STRNICMP(cmd, "eof", 3) == 0
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
703 && ep != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
704 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
705 char_u *buf = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
706 char_u *keys;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
707
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
708 p = skiptowhite(cmd);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
709 *p = NUL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
710 keys = replace_termcodes(ep + 1, &buf, TRUE, TRUE, TRUE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
711 opt.jo_set2 |= JO2_EOF_CHARS;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
712 opt.jo_eof_chars = vim_strsave(keys);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
713 vim_free(buf);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
714 *p = ' ';
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
715 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
716 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
717 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
718 if (*p)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
719 *p = NUL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
720 EMSG2(_("E181: Invalid attribute: %s"), cmd);
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
721 goto theend;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
722 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
723 cmd = skipwhite(p);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
724 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
725 if (*cmd == NUL)
13476
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
726 {
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
727 /* Make a copy of 'shell', an autocommand may change the option. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
728 tofree = cmd = vim_strsave(p_sh);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
729
13476
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
730 /* default to close when the shell exits */
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
731 if (opt.jo_term_finish == NUL)
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
732 opt.jo_term_finish = 'c';
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
733 }
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
734
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
735 if (eap->addr_count > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
736 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
737 /* Write lines from current buffer to the job. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
738 opt.jo_set |= JO_IN_IO | JO_IN_BUF | JO_IN_TOP | JO_IN_BOT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
739 opt.jo_io[PART_IN] = JIO_BUFFER;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
740 opt.jo_io_buf[PART_IN] = curbuf->b_fnum;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
741 opt.jo_in_top = eap->line1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
742 opt.jo_in_bot = eap->line2;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
743 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
744
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
745 argvar[0].v_type = VAR_STRING;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
746 argvar[0].vval.v_string = cmd;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
747 argvar[1].v_type = VAR_UNKNOWN;
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
748 term_start(argvar, NULL, &opt, eap->forceit ? TERM_START_FORCEIT : 0);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
749 vim_free(tofree);
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
750
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
751 theend:
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
752 vim_free(opt.jo_eof_chars);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
753 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
754
13435
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
755 #if defined(FEAT_SESSION) || defined(PROTO)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
756 /*
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
757 * Write a :terminal command to the session file to restore the terminal in
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
758 * window "wp".
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
759 * Return FAIL if writing fails.
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
760 */
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
761 int
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
762 term_write_session(FILE *fd, win_T *wp)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
763 {
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
764 term_T *term = wp->w_buffer->b_term;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
765
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
766 /* Create the terminal and run the command. This is not without
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
767 * risk, but let's assume the user only creates a session when this
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
768 * will be OK. */
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
769 if (fprintf(fd, "terminal ++curwin ++cols=%d ++rows=%d ",
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
770 term->tl_cols, term->tl_rows) < 0)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
771 return FAIL;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
772 if (term->tl_command != NULL && fputs((char *)term->tl_command, fd) < 0)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
773 return FAIL;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
774
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
775 return put_eol(fd);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
776 }
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
777
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
778 /*
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
779 * Return TRUE if "buf" has a terminal that should be restored.
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
780 */
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
781 int
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
782 term_should_restore(buf_T *buf)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
783 {
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
784 term_T *term = buf->b_term;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
785
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
786 return term != NULL && (term->tl_command == NULL
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
787 || STRCMP(term->tl_command, "NONE") != 0);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
788 }
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
789 #endif
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
790
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
791 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
792 * Free the scrollback buffer for "term".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
793 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
794 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
795 free_scrollback(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
796 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
797 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
798
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
799 for (i = 0; i < term->tl_scrollback.ga_len; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
800 vim_free(((sb_line_T *)term->tl_scrollback.ga_data + i)->sb_cells);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
801 ga_clear(&term->tl_scrollback);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
802 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
803
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
804 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
805 * Free a terminal and everything it refers to.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
806 * Kills the job if there is one.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
807 * Called when wiping out a buffer.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
808 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
809 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
810 free_terminal(buf_T *buf)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
811 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
812 term_T *term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
813 term_T *tp;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
814
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
815 if (term == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
816 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
817 if (first_term == term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
818 first_term = term->tl_next;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
819 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
820 for (tp = first_term; tp->tl_next != NULL; tp = tp->tl_next)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
821 if (tp->tl_next == term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
822 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
823 tp->tl_next = term->tl_next;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
824 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
825 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
826
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
827 if (term->tl_job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
828 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
829 if (term->tl_job->jv_status != JOB_ENDED
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
830 && term->tl_job->jv_status != JOB_FINISHED
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
831 && term->tl_job->jv_status != JOB_FAILED)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
832 job_stop(term->tl_job, NULL, "kill");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
833 job_unref(term->tl_job);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
834 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
835
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
836 free_scrollback(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
837
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
838 term_free_vterm(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
839 vim_free(term->tl_title);
13435
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
840 #ifdef FEAT_SESSION
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
841 vim_free(term->tl_command);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
842 #endif
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
843 vim_free(term->tl_kill);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
844 vim_free(term->tl_status_text);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
845 vim_free(term->tl_opencmd);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
846 vim_free(term->tl_eof_chars);
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
847 #ifdef WIN3264
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
848 if (term->tl_out_fd != NULL)
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
849 fclose(term->tl_out_fd);
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
850 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
851 vim_free(term->tl_cursor_color);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
852 vim_free(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
853 buf->b_term = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
854 if (in_terminal_loop == term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
855 in_terminal_loop = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
856 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
857
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
858 /*
13132
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
859 * Get the part that is connected to the tty. Normally this is PART_IN, but
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
860 * when writing buffer lines to the job it can be another. This makes it
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
861 * possible to do "1,5term vim -".
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
862 */
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
863 static ch_part_T
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
864 get_tty_part(term_T *term)
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
865 {
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
866 #ifdef UNIX
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
867 ch_part_T parts[3] = {PART_IN, PART_OUT, PART_ERR};
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
868 int i;
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
869
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
870 for (i = 0; i < 3; ++i)
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
871 {
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
872 int fd = term->tl_job->jv_channel->ch_part[parts[i]].ch_fd;
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
873
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
874 if (isatty(fd))
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
875 return parts[i];
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
876 }
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
877 #endif
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
878 return PART_IN;
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
879 }
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
880
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
881 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
882 * Write job output "msg[len]" to the vterm.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
883 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
884 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
885 term_write_job_output(term_T *term, char_u *msg, size_t len)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
886 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
887 VTerm *vterm = term->tl_vterm;
13132
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
888 size_t prevlen = vterm_output_get_buffer_current(vterm);
12800
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
889
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
890 vterm_input_write(vterm, (char *)msg, len);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
891
13132
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
892 /* flush vterm buffer when vterm responded to control sequence */
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
893 if (prevlen != vterm_output_get_buffer_current(vterm))
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
894 {
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
895 char buf[KEY_BUF_LEN];
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
896 size_t curlen = vterm_output_read(vterm, buf, KEY_BUF_LEN);
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
897
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
898 if (curlen > 0)
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
899 channel_send(term->tl_job->jv_channel, get_tty_part(term),
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
900 (char_u *)buf, (int)curlen, NULL);
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
901 }
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
902
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
903 /* this invokes the damage callbacks */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
904 vterm_screen_flush_damage(vterm_obtain_screen(vterm));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
905 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
906
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
907 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
908 update_cursor(term_T *term, int redraw)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
909 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
910 if (term->tl_normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
911 return;
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
912 #ifdef FEAT_GUI
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
913 if (term->tl_system)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
914 windgoto(term->tl_cursor_pos.row + term->tl_toprow,
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
915 term->tl_cursor_pos.col);
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
916 else
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
917 #endif
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
918 setcursor();
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
919 if (redraw)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
920 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
921 if (term->tl_buffer == curbuf && term->tl_cursor_visible)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
922 cursor_on();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
923 out_flush();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
924 #ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
925 if (gui.in_use)
13000
6f98a5fd0c19 patch 8.0.1376: cursor in terminal not always updated
Christian Brabandt <cb@256bit.org>
parents: 12984
diff changeset
926 {
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
927 gui_update_cursor(FALSE, FALSE);
13000
6f98a5fd0c19 patch 8.0.1376: cursor in terminal not always updated
Christian Brabandt <cb@256bit.org>
parents: 12984
diff changeset
928 gui_mch_flush();
6f98a5fd0c19 patch 8.0.1376: cursor in terminal not always updated
Christian Brabandt <cb@256bit.org>
parents: 12984
diff changeset
929 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
930 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
931 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
932 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
933
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
934 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
935 * Invoked when "msg" output from a job was received. Write it to the terminal
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
936 * of "buffer".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
937 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
938 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
939 write_to_term(buf_T *buffer, char_u *msg, channel_T *channel)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
940 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
941 size_t len = STRLEN(msg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
942 term_T *term = buffer->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
943
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
944 #ifdef WIN3264
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
945 /* Win32: Cannot redirect output of the job, intercept it here and write to
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
946 * the file. */
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
947 if (term->tl_out_fd != NULL)
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
948 {
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
949 ch_log(channel, "Writing %d bytes to output file", (int)len);
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
950 fwrite(msg, len, 1, term->tl_out_fd);
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
951 return;
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
952 }
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
953 #endif
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
954
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
955 if (term->tl_vterm == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
956 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
957 ch_log(channel, "NOT writing %d bytes to terminal", (int)len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
958 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
959 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
960 ch_log(channel, "writing %d bytes to terminal", (int)len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
961 term_write_job_output(term, msg, len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
962
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
963 #ifdef FEAT_GUI
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
964 if (term->tl_system)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
965 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
966 /* show system output, scrolling up the screen as needed */
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
967 update_system_term(term);
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
968 update_cursor(term, TRUE);
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
969 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
970 else
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
971 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
972 /* In Terminal-Normal mode we are displaying the buffer, not the terminal
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
973 * contents, thus no screen update is needed. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
974 if (!term->tl_normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
975 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
976 /* TODO: only update once in a while. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
977 ch_log(term->tl_job->jv_channel, "updating screen");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
978 if (buffer == curbuf)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
979 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
980 update_screen(0);
13886
bbf5bdba4a80 patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13878
diff changeset
981 /* update_screen() can be slow, check the terminal wasn't closed
bbf5bdba4a80 patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13878
diff changeset
982 * already */
bbf5bdba4a80 patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13878
diff changeset
983 if (buffer == curbuf && curbuf->b_term != NULL)
bbf5bdba4a80 patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13878
diff changeset
984 update_cursor(curbuf->b_term, TRUE);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
985 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
986 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
987 redraw_after_callback(TRUE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
988 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
989 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
990
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
991 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
992 * Send a mouse position and click to the vterm
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
993 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
994 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
995 term_send_mouse(VTerm *vterm, int button, int pressed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
996 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
997 VTermModifier mod = VTERM_MOD_NONE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
998
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
999 vterm_mouse_move(vterm, mouse_row - W_WINROW(curwin),
12513
3ca08bf99396 patch 8.0.1135: W_WINCOL() is always the same
Christian Brabandt <cb@256bit.org>
parents: 12509
diff changeset
1000 mouse_col - curwin->w_wincol, mod);
12865
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12845
diff changeset
1001 if (button != 0)
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12845
diff changeset
1002 vterm_mouse_button(vterm, button, pressed, mod);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1003 return TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1004 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1005
13448
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1006 static int enter_mouse_col = -1;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1007 static int enter_mouse_row = -1;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1008
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1009 /*
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1010 * Handle a mouse click, drag or release.
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1011 * Return TRUE when a mouse event is sent to the terminal.
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1012 */
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1013 static int
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1014 term_mouse_click(VTerm *vterm, int key)
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1015 {
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1016 #if defined(FEAT_CLIPBOARD)
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1017 /* For modeless selection mouse drag and release events are ignored, unless
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1018 * they are preceded with a mouse down event */
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1019 static int ignore_drag_release = TRUE;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1020 VTermMouseState mouse_state;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1021
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1022 vterm_state_get_mousestate(vterm_obtain_state(vterm), &mouse_state);
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1023 if (mouse_state.flags == 0)
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1024 {
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1025 /* Terminal is not using the mouse, use modeless selection. */
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1026 switch (key)
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1027 {
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1028 case K_LEFTDRAG:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1029 case K_LEFTRELEASE:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1030 case K_RIGHTDRAG:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1031 case K_RIGHTRELEASE:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1032 /* Ignore drag and release events when the button-down wasn't
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1033 * seen before. */
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1034 if (ignore_drag_release)
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1035 {
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1036 int save_mouse_col, save_mouse_row;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1037
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1038 if (enter_mouse_col < 0)
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1039 break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1040
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1041 /* mouse click in the window gave us focus, handle that
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1042 * click now */
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1043 save_mouse_col = mouse_col;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1044 save_mouse_row = mouse_row;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1045 mouse_col = enter_mouse_col;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1046 mouse_row = enter_mouse_row;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1047 clip_modeless(MOUSE_LEFT, TRUE, FALSE);
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1048 mouse_col = save_mouse_col;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1049 mouse_row = save_mouse_row;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1050 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1051 /* FALLTHROUGH */
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1052 case K_LEFTMOUSE:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1053 case K_RIGHTMOUSE:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1054 if (key == K_LEFTRELEASE || key == K_RIGHTRELEASE)
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1055 ignore_drag_release = TRUE;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1056 else
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1057 ignore_drag_release = FALSE;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1058 /* Should we call mouse_has() here? */
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1059 if (clip_star.available)
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1060 {
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1061 int button, is_click, is_drag;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1062
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1063 button = get_mouse_button(KEY2TERMCAP1(key),
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1064 &is_click, &is_drag);
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1065 if (mouse_model_popup() && button == MOUSE_LEFT
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1066 && (mod_mask & MOD_MASK_SHIFT))
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1067 {
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1068 /* Translate shift-left to right button. */
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1069 button = MOUSE_RIGHT;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1070 mod_mask &= ~MOD_MASK_SHIFT;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1071 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1072 clip_modeless(button, is_click, is_drag);
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1073 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1074 break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1075
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1076 case K_MIDDLEMOUSE:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1077 if (clip_star.available)
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1078 insert_reg('*', TRUE);
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1079 break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1080 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1081 enter_mouse_col = -1;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1082 return FALSE;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1083 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1084 #endif
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1085 enter_mouse_col = -1;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1086
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1087 switch (key)
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1088 {
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1089 case K_LEFTMOUSE:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1090 case K_LEFTMOUSE_NM: term_send_mouse(vterm, 1, 1); break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1091 case K_LEFTDRAG: term_send_mouse(vterm, 1, 1); break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1092 case K_LEFTRELEASE:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1093 case K_LEFTRELEASE_NM: term_send_mouse(vterm, 1, 0); break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1094 case K_MOUSEMOVE: term_send_mouse(vterm, 0, 0); break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1095 case K_MIDDLEMOUSE: term_send_mouse(vterm, 2, 1); break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1096 case K_MIDDLEDRAG: term_send_mouse(vterm, 2, 1); break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1097 case K_MIDDLERELEASE: term_send_mouse(vterm, 2, 0); break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1098 case K_RIGHTMOUSE: term_send_mouse(vterm, 3, 1); break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1099 case K_RIGHTDRAG: term_send_mouse(vterm, 3, 1); break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1100 case K_RIGHTRELEASE: term_send_mouse(vterm, 3, 0); break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1101 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1102 return TRUE;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1103 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1104
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1105 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1106 * Convert typed key "c" into bytes to send to the job.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1107 * Return the number of bytes in "buf".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1108 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1109 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1110 term_convert_key(term_T *term, int c, char *buf)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1111 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1112 VTerm *vterm = term->tl_vterm;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1113 VTermKey key = VTERM_KEY_NONE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1114 VTermModifier mod = VTERM_MOD_NONE;
12845
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
1115 int other = FALSE;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1116
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1117 switch (c)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1118 {
12800
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
1119 /* don't use VTERM_KEY_ENTER, it may do an unwanted conversion */
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
1120
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1121 /* don't use VTERM_KEY_BACKSPACE, it always
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1122 * becomes 0x7f DEL */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1123 case K_BS: c = term_backspace_char; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1124
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1125 case ESC: key = VTERM_KEY_ESCAPE; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1126 case K_DEL: key = VTERM_KEY_DEL; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1127 case K_DOWN: key = VTERM_KEY_DOWN; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1128 case K_S_DOWN: mod = VTERM_MOD_SHIFT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1129 key = VTERM_KEY_DOWN; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1130 case K_END: key = VTERM_KEY_END; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1131 case K_S_END: mod = VTERM_MOD_SHIFT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1132 key = VTERM_KEY_END; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1133 case K_C_END: mod = VTERM_MOD_CTRL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1134 key = VTERM_KEY_END; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1135 case K_F10: key = VTERM_KEY_FUNCTION(10); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1136 case K_F11: key = VTERM_KEY_FUNCTION(11); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1137 case K_F12: key = VTERM_KEY_FUNCTION(12); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1138 case K_F1: key = VTERM_KEY_FUNCTION(1); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1139 case K_F2: key = VTERM_KEY_FUNCTION(2); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1140 case K_F3: key = VTERM_KEY_FUNCTION(3); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1141 case K_F4: key = VTERM_KEY_FUNCTION(4); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1142 case K_F5: key = VTERM_KEY_FUNCTION(5); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1143 case K_F6: key = VTERM_KEY_FUNCTION(6); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1144 case K_F7: key = VTERM_KEY_FUNCTION(7); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1145 case K_F8: key = VTERM_KEY_FUNCTION(8); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1146 case K_F9: key = VTERM_KEY_FUNCTION(9); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1147 case K_HOME: key = VTERM_KEY_HOME; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1148 case K_S_HOME: mod = VTERM_MOD_SHIFT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1149 key = VTERM_KEY_HOME; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1150 case K_C_HOME: mod = VTERM_MOD_CTRL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1151 key = VTERM_KEY_HOME; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1152 case K_INS: key = VTERM_KEY_INS; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1153 case K_K0: key = VTERM_KEY_KP_0; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1154 case K_K1: key = VTERM_KEY_KP_1; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1155 case K_K2: key = VTERM_KEY_KP_2; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1156 case K_K3: key = VTERM_KEY_KP_3; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1157 case K_K4: key = VTERM_KEY_KP_4; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1158 case K_K5: key = VTERM_KEY_KP_5; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1159 case K_K6: key = VTERM_KEY_KP_6; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1160 case K_K7: key = VTERM_KEY_KP_7; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1161 case K_K8: key = VTERM_KEY_KP_8; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1162 case K_K9: key = VTERM_KEY_KP_9; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1163 case K_KDEL: key = VTERM_KEY_DEL; break; /* TODO */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1164 case K_KDIVIDE: key = VTERM_KEY_KP_DIVIDE; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1165 case K_KEND: key = VTERM_KEY_KP_1; break; /* TODO */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1166 case K_KENTER: key = VTERM_KEY_KP_ENTER; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1167 case K_KHOME: key = VTERM_KEY_KP_7; break; /* TODO */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1168 case K_KINS: key = VTERM_KEY_KP_0; break; /* TODO */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1169 case K_KMINUS: key = VTERM_KEY_KP_MINUS; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1170 case K_KMULTIPLY: key = VTERM_KEY_KP_MULT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1171 case K_KPAGEDOWN: key = VTERM_KEY_KP_3; break; /* TODO */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1172 case K_KPAGEUP: key = VTERM_KEY_KP_9; break; /* TODO */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1173 case K_KPLUS: key = VTERM_KEY_KP_PLUS; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1174 case K_KPOINT: key = VTERM_KEY_KP_PERIOD; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1175 case K_LEFT: key = VTERM_KEY_LEFT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1176 case K_S_LEFT: mod = VTERM_MOD_SHIFT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1177 key = VTERM_KEY_LEFT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1178 case K_C_LEFT: mod = VTERM_MOD_CTRL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1179 key = VTERM_KEY_LEFT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1180 case K_PAGEDOWN: key = VTERM_KEY_PAGEDOWN; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1181 case K_PAGEUP: key = VTERM_KEY_PAGEUP; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1182 case K_RIGHT: key = VTERM_KEY_RIGHT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1183 case K_S_RIGHT: mod = VTERM_MOD_SHIFT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1184 key = VTERM_KEY_RIGHT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1185 case K_C_RIGHT: mod = VTERM_MOD_CTRL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1186 key = VTERM_KEY_RIGHT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1187 case K_UP: key = VTERM_KEY_UP; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1188 case K_S_UP: mod = VTERM_MOD_SHIFT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1189 key = VTERM_KEY_UP; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1190 case TAB: key = VTERM_KEY_TAB; break;
13294
5fc59833a748 patch 8.0.1521: Shift-Tab does not work in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13292
diff changeset
1191 case K_S_TAB: mod = VTERM_MOD_SHIFT;
5fc59833a748 patch 8.0.1521: Shift-Tab does not work in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13292
diff changeset
1192 key = VTERM_KEY_TAB; break;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1193
12845
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
1194 case K_MOUSEUP: other = term_send_mouse(vterm, 5, 1); break;
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
1195 case K_MOUSEDOWN: other = term_send_mouse(vterm, 4, 1); break;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1196 case K_MOUSELEFT: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1197 case K_MOUSERIGHT: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1198
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1199 case K_LEFTMOUSE:
13448
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1200 case K_LEFTMOUSE_NM:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1201 case K_LEFTDRAG:
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1202 case K_LEFTRELEASE:
13448
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1203 case K_LEFTRELEASE_NM:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1204 case K_MOUSEMOVE:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1205 case K_MIDDLEMOUSE:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1206 case K_MIDDLEDRAG:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1207 case K_MIDDLERELEASE:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1208 case K_RIGHTMOUSE:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1209 case K_RIGHTDRAG:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1210 case K_RIGHTRELEASE: if (!term_mouse_click(vterm, c))
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1211 return 0;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1212 other = TRUE;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1213 break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1214
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1215 case K_X1MOUSE: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1216 case K_X1DRAG: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1217 case K_X1RELEASE: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1218 case K_X2MOUSE: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1219 case K_X2DRAG: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1220 case K_X2RELEASE: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1221
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1222 case K_IGNORE: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1223 case K_NOP: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1224 case K_UNDO: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1225 case K_HELP: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1226 case K_XF1: key = VTERM_KEY_FUNCTION(1); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1227 case K_XF2: key = VTERM_KEY_FUNCTION(2); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1228 case K_XF3: key = VTERM_KEY_FUNCTION(3); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1229 case K_XF4: key = VTERM_KEY_FUNCTION(4); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1230 case K_SELECT: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1231 #ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1232 case K_VER_SCROLLBAR: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1233 case K_HOR_SCROLLBAR: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1234 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1235 #ifdef FEAT_GUI_TABLINE
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1236 case K_TABLINE: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1237 case K_TABMENU: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1238 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1239 #ifdef FEAT_NETBEANS_INTG
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1240 case K_F21: key = VTERM_KEY_FUNCTION(21); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1241 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1242 #ifdef FEAT_DND
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1243 case K_DROP: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1244 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1245 case K_CURSORHOLD: return 0;
12845
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
1246 case K_PS: vterm_keyboard_start_paste(vterm);
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
1247 other = TRUE;
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
1248 break;
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
1249 case K_PE: vterm_keyboard_end_paste(vterm);
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
1250 other = TRUE;
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
1251 break;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1252 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1253
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1254 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1255 * Convert special keys to vterm keys:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1256 * - Write keys to vterm: vterm_keyboard_key()
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1257 * - Write output to channel.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1258 * TODO: use mod_mask
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1259 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1260 if (key != VTERM_KEY_NONE)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1261 /* Special key, let vterm convert it. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1262 vterm_keyboard_key(vterm, key, mod);
12845
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
1263 else if (!other)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1264 /* Normal character, let vterm convert it. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1265 vterm_keyboard_unichar(vterm, c, mod);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1266
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1267 /* Read back the converted escape sequence. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1268 return (int)vterm_output_read(vterm, buf, KEY_BUF_LEN);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1269 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1270
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1271 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1272 * Return TRUE if the job for "term" is still running.
13696
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1273 * If "check_job_status" is TRUE update the job status.
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1274 */
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1275 static int
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1276 term_job_running_check(term_T *term, int check_job_status)
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1277 {
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1278 /* Also consider the job finished when the channel is closed, to avoid a
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1279 * race condition when updating the title. */
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1280 if (term != NULL
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1281 && term->tl_job != NULL
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1282 && channel_is_open(term->tl_job->jv_channel))
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1283 {
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1284 if (check_job_status)
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1285 job_status(term->tl_job);
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1286 return (term->tl_job->jv_status == JOB_STARTED
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1287 || term->tl_job->jv_channel->ch_keep_open);
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1288 }
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1289 return FALSE;
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1290 }
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1291
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1292 /*
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1293 * Return TRUE if the job for "term" is still running.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1294 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1295 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1296 term_job_running(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1297 {
13696
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1298 return term_job_running_check(term, FALSE);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1299 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1300
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1301 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1302 * Return TRUE if "term" has an active channel and used ":term NONE".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1303 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1304 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1305 term_none_open(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1306 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1307 /* Also consider the job finished when the channel is closed, to avoid a
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1308 * race condition when updating the title. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1309 return term != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1310 && term->tl_job != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1311 && channel_is_open(term->tl_job->jv_channel)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1312 && term->tl_job->jv_channel->ch_keep_open;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1313 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1314
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1315 /*
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1316 * Used when exiting: kill the job in "buf" if so desired.
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1317 * Return OK when the job finished.
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1318 * Return FAIL when the job is still running.
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1319 */
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1320 int
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1321 term_try_stop_job(buf_T *buf)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1322 {
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1323 int count;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1324 char *how = (char *)buf->b_term->tl_kill;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1325
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1326 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1327 if ((how == NULL || *how == NUL) && (p_confirm || cmdmod.confirm))
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1328 {
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1329 char_u buff[DIALOG_MSG_SIZE];
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1330 int ret;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1331
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1332 dialog_msg(buff, _("Kill job in \"%s\"?"), buf->b_fname);
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1333 ret = vim_dialog_yesnocancel(VIM_QUESTION, NULL, buff, 1);
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1334 if (ret == VIM_YES)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1335 how = "kill";
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1336 else if (ret == VIM_CANCEL)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1337 return FAIL;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1338 }
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1339 #endif
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1340 if (how == NULL || *how == NUL)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1341 return FAIL;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1342
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1343 job_stop(buf->b_term->tl_job, NULL, how);
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1344
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1345 /* wait for up to a second for the job to die */
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1346 for (count = 0; count < 100; ++count)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1347 {
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1348 /* buffer, terminal and job may be cleaned up while waiting */
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1349 if (!buf_valid(buf)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1350 || buf->b_term == NULL
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1351 || buf->b_term->tl_job == NULL)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1352 return OK;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1353
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1354 /* call job_status() to update jv_status */
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1355 job_status(buf->b_term->tl_job);
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1356 if (buf->b_term->tl_job->jv_status >= JOB_ENDED)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1357 return OK;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1358 ui_delay(10L, FALSE);
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1359 mch_check_messages();
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1360 parse_queued_messages();
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1361 }
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1362 return FAIL;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1363 }
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1364
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1365 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1366 * Add the last line of the scrollback buffer to the buffer in the window.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1367 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1368 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1369 add_scrollback_line_to_buffer(term_T *term, char_u *text, int len)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1370 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1371 buf_T *buf = term->tl_buffer;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1372 int empty = (buf->b_ml.ml_flags & ML_EMPTY);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1373 linenr_T lnum = buf->b_ml.ml_line_count;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1374
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1375 #ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1376 if (!enc_utf8 && enc_codepage > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1377 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1378 WCHAR *ret = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1379 int length = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1380
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1381 MultiByteToWideChar_alloc(CP_UTF8, 0, (char*)text, len + 1,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1382 &ret, &length);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1383 if (ret != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1384 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1385 WideCharToMultiByte_alloc(enc_codepage, 0,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1386 ret, length, (char **)&text, &len, 0, 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1387 vim_free(ret);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1388 ml_append_buf(term->tl_buffer, lnum, text, len, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1389 vim_free(text);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1390 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1391 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1392 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1393 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1394 ml_append_buf(term->tl_buffer, lnum, text, len + 1, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1395 if (empty)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1396 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1397 /* Delete the empty line that was in the empty buffer. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1398 curbuf = buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1399 ml_delete(1, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1400 curbuf = curwin->w_buffer;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1401 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1402 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1403
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1404 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1405 cell2cellattr(const VTermScreenCell *cell, cellattr_T *attr)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1406 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1407 attr->width = cell->width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1408 attr->attrs = cell->attrs;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1409 attr->fg = cell->fg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1410 attr->bg = cell->bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1411 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1412
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1413 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1414 equal_celattr(cellattr_T *a, cellattr_T *b)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1415 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1416 /* Comparing the colors should be sufficient. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1417 return a->fg.red == b->fg.red
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1418 && a->fg.green == b->fg.green
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1419 && a->fg.blue == b->fg.blue
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1420 && a->bg.red == b->bg.red
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1421 && a->bg.green == b->bg.green
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1422 && a->bg.blue == b->bg.blue;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1423 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1424
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1425 /*
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1426 * Add an empty scrollback line to "term". When "lnum" is not zero, add the
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1427 * line at this position. Otherwise at the end.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1428 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1429 static int
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1430 add_empty_scrollback(term_T *term, cellattr_T *fill_attr, int lnum)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1431 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1432 if (ga_grow(&term->tl_scrollback, 1) == OK)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1433 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1434 sb_line_T *line = (sb_line_T *)term->tl_scrollback.ga_data
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1435 + term->tl_scrollback.ga_len;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1436
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1437 if (lnum > 0)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1438 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1439 int i;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1440
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1441 for (i = 0; i < term->tl_scrollback.ga_len - lnum; ++i)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1442 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1443 *line = *(line - 1);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1444 --line;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1445 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1446 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1447 line->sb_cols = 0;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1448 line->sb_cells = NULL;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1449 line->sb_fill_attr = *fill_attr;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1450 ++term->tl_scrollback.ga_len;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1451 return OK;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1452 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1453 return FALSE;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1454 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1455
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1456 /*
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1457 * Remove the terminal contents from the scrollback and the buffer.
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1458 * Used before adding a new scrollback line or updating the buffer for lines
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1459 * displayed in the terminal.
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1460 */
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1461 static void
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1462 cleanup_scrollback(term_T *term)
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1463 {
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1464 sb_line_T *line;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1465 garray_T *gap;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1466
13894
3969c9d3a859 patch 8.0.1818: lines remove from wrong buffer when using terminal window
Christian Brabandt <cb@256bit.org>
parents: 13888
diff changeset
1467 curbuf = term->tl_buffer;
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1468 gap = &term->tl_scrollback;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1469 while (curbuf->b_ml.ml_line_count > term->tl_scrollback_scrolled
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1470 && gap->ga_len > 0)
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1471 {
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1472 ml_delete(curbuf->b_ml.ml_line_count, FALSE);
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1473 line = (sb_line_T *)gap->ga_data + gap->ga_len - 1;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1474 vim_free(line->sb_cells);
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1475 --gap->ga_len;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1476 }
13894
3969c9d3a859 patch 8.0.1818: lines remove from wrong buffer when using terminal window
Christian Brabandt <cb@256bit.org>
parents: 13888
diff changeset
1477 curbuf = curwin->w_buffer;
3969c9d3a859 patch 8.0.1818: lines remove from wrong buffer when using terminal window
Christian Brabandt <cb@256bit.org>
parents: 13888
diff changeset
1478 if (curbuf == term->tl_buffer)
3969c9d3a859 patch 8.0.1818: lines remove from wrong buffer when using terminal window
Christian Brabandt <cb@256bit.org>
parents: 13888
diff changeset
1479 check_cursor();
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1480 }
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1481
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1482 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1483 * Add the current lines of the terminal to scrollback and to the buffer.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1484 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1485 static void
13919
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1486 update_snapshot(term_T *term)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1487 {
13919
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1488 VTermScreen *screen;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1489 int len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1490 int lines_skipped = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1491 VTermPos pos;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1492 VTermScreenCell cell;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1493 cellattr_T fill_attr, new_fill_attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1494 cellattr_T *p;
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1495
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1496 ch_log(term->tl_job == NULL ? NULL : term->tl_job->jv_channel,
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1497 "Adding terminal window snapshot to buffer");
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1498
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1499 /* First remove the lines that were appended before, they might be
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1500 * outdated. */
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1501 cleanup_scrollback(term);
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1502
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1503 screen = vterm_obtain_screen(term->tl_vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1504 fill_attr = new_fill_attr = term->tl_default_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1505 for (pos.row = 0; pos.row < term->tl_rows; ++pos.row)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1506 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1507 len = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1508 for (pos.col = 0; pos.col < term->tl_cols; ++pos.col)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1509 if (vterm_screen_get_cell(screen, pos, &cell) != 0
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1510 && cell.chars[0] != NUL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1511 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1512 len = pos.col + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1513 new_fill_attr = term->tl_default_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1514 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1515 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1516 /* Assume the last attr is the filler attr. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1517 cell2cellattr(&cell, &new_fill_attr);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1518
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1519 if (len == 0 && equal_celattr(&new_fill_attr, &fill_attr))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1520 ++lines_skipped;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1521 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1522 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1523 while (lines_skipped > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1524 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1525 /* Line was skipped, add an empty line. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1526 --lines_skipped;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1527 if (add_empty_scrollback(term, &fill_attr, 0) == OK)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1528 add_scrollback_line_to_buffer(term, (char_u *)"", 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1529 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1530
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1531 if (len == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1532 p = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1533 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1534 p = (cellattr_T *)alloc((int)sizeof(cellattr_T) * len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1535 if ((p != NULL || len == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1536 && ga_grow(&term->tl_scrollback, 1) == OK)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1537 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1538 garray_T ga;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1539 int width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1540 sb_line_T *line = (sb_line_T *)term->tl_scrollback.ga_data
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1541 + term->tl_scrollback.ga_len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1542
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1543 ga_init2(&ga, 1, 100);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1544 for (pos.col = 0; pos.col < len; pos.col += width)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1545 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1546 if (vterm_screen_get_cell(screen, pos, &cell) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1547 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1548 width = 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1549 vim_memset(p + pos.col, 0, sizeof(cellattr_T));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1550 if (ga_grow(&ga, 1) == OK)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1551 ga.ga_len += utf_char2bytes(' ',
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1552 (char_u *)ga.ga_data + ga.ga_len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1553 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1554 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1555 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1556 width = cell.width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1557
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1558 cell2cellattr(&cell, &p[pos.col]);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1559
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1560 if (ga_grow(&ga, MB_MAXBYTES) == OK)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1561 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1562 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1563 int c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1564
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1565 for (i = 0; (c = cell.chars[i]) > 0 || i == 0; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1566 ga.ga_len += utf_char2bytes(c == NUL ? ' ' : c,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1567 (char_u *)ga.ga_data + ga.ga_len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1568 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1569 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1570 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1571 line->sb_cols = len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1572 line->sb_cells = p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1573 line->sb_fill_attr = new_fill_attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1574 fill_attr = new_fill_attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1575 ++term->tl_scrollback.ga_len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1576
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1577 if (ga_grow(&ga, 1) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1578 add_scrollback_line_to_buffer(term, (char_u *)"", 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1579 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1580 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1581 *((char_u *)ga.ga_data + ga.ga_len) = NUL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1582 add_scrollback_line_to_buffer(term, ga.ga_data, ga.ga_len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1583 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1584 ga_clear(&ga);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1585 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1586 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1587 vim_free(p);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1588 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1589 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1590
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1591 term->tl_dirty_snapshot = FALSE;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1592 #ifdef FEAT_TIMERS
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1593 term->tl_timer_set = FALSE;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1594 #endif
13919
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1595 }
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1596
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1597 /*
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1598 * If needed, add the current lines of the terminal to scrollback and to the
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1599 * buffer. Called after the job has ended and when switching to
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1600 * Terminal-Normal mode.
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1601 * When "redraw" is TRUE redraw the windows that show the terminal.
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1602 */
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1603 static void
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1604 may_move_terminal_to_buffer(term_T *term, int redraw)
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1605 {
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1606 win_T *wp;
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1607
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1608 if (term->tl_vterm == NULL)
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1609 return;
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1610
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1611 /* Update the snapshot only if something changes or the buffer does not
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1612 * have all the lines. */
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1613 if (term->tl_dirty_snapshot || term->tl_buffer->b_ml.ml_line_count
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1614 <= term->tl_scrollback_scrolled)
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1615 update_snapshot(term);
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1616
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1617 /* Obtain the current background color. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1618 vterm_state_get_default_colors(vterm_obtain_state(term->tl_vterm),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1619 &term->tl_default_color.fg, &term->tl_default_color.bg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1620
13919
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1621 if (redraw)
13900
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1622 FOR_ALL_WINDOWS(wp)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1623 {
13900
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1624 if (wp->w_buffer == term->tl_buffer)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1625 {
13900
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1626 wp->w_cursor.lnum = term->tl_buffer->b_ml.ml_line_count;
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1627 wp->w_cursor.col = 0;
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1628 wp->w_valid = 0;
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1629 if (wp->w_cursor.lnum >= wp->w_height)
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1630 {
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1631 linenr_T min_topline = wp->w_cursor.lnum - wp->w_height + 1;
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1632
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1633 if (wp->w_topline < min_topline)
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1634 wp->w_topline = min_topline;
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1635 }
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1636 redraw_win_later(wp, NOT_VALID);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1637 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1638 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1639 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1640
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1641 #if defined(FEAT_TIMERS) || defined(PROTO)
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1642 /*
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1643 * Check if any terminal timer expired. If so, copy text from the terminal to
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1644 * the buffer.
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1645 * Return the time until the next timer will expire.
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1646 */
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1647 int
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1648 term_check_timers(int next_due_arg, proftime_T *now)
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1649 {
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1650 term_T *term;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1651 int next_due = next_due_arg;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1652
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1653 for (term = first_term; term != NULL; term = term->tl_next)
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1654 {
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1655 if (term->tl_timer_set && !term->tl_normal_mode)
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1656 {
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1657 long this_due = proftime_time_left(&term->tl_timer_due, now);
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1658
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1659 if (this_due <= 1)
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1660 {
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1661 term->tl_timer_set = FALSE;
13919
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1662 may_move_terminal_to_buffer(term, FALSE);
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1663 }
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1664 else if (next_due == -1 || next_due > this_due)
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1665 next_due = this_due;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1666 }
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1667 }
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1668
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1669 return next_due;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1670 }
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1671 #endif
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1672
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1673 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1674 set_terminal_mode(term_T *term, int normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1675 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1676 term->tl_normal_mode = normal_mode;
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13219
diff changeset
1677 VIM_CLEAR(term->tl_status_text);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1678 if (term->tl_buffer == curbuf)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1679 maketitle();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1680 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1681
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1682 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1683 * Called after the job if finished and Terminal mode is not active:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1684 * Move the vterm contents into the scrollback buffer and free the vterm.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1685 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1686 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1687 cleanup_vterm(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1688 {
13476
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
1689 if (term->tl_finish != TL_FINISH_CLOSE)
13919
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1690 may_move_terminal_to_buffer(term, TRUE);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1691 term_free_vterm(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1692 set_terminal_mode(term, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1693 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1694
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1695 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1696 * Switch from Terminal-Job mode to Terminal-Normal mode.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1697 * Suspends updating the terminal window.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1698 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1699 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1700 term_enter_normal_mode(void)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1701 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1702 term_T *term = curbuf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1703
13900
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1704 set_terminal_mode(term, TRUE);
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1705
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1706 /* Append the current terminal contents to the buffer. */
13919
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1707 may_move_terminal_to_buffer(term, TRUE);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1708
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1709 /* Move the window cursor to the position of the cursor in the
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1710 * terminal. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1711 curwin->w_cursor.lnum = term->tl_scrollback_scrolled
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1712 + term->tl_cursor_pos.row + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1713 check_cursor();
13935
cc25795aeec6 patch 8.0.1838: cursor in wrong pos when switching to Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13919
diff changeset
1714 if (coladvance(term->tl_cursor_pos.col) == FAIL)
cc25795aeec6 patch 8.0.1838: cursor in wrong pos when switching to Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13919
diff changeset
1715 coladvance(MAXCOL);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1716
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1717 /* Display the same lines as in the terminal. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1718 curwin->w_topline = term->tl_scrollback_scrolled + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1719 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1720
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1721 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1722 * Returns TRUE if the current window contains a terminal and we are in
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1723 * Terminal-Normal mode.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1724 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1725 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1726 term_in_normal_mode(void)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1727 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1728 term_T *term = curbuf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1729
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1730 return term != NULL && term->tl_normal_mode;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1731 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1732
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1733 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1734 * Switch from Terminal-Normal mode to Terminal-Job mode.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1735 * Restores updating the terminal window.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1736 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1737 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1738 term_enter_job_mode()
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1739 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1740 term_T *term = curbuf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1741
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1742 set_terminal_mode(term, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1743
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1744 if (term->tl_channel_closed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1745 cleanup_vterm(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1746 redraw_buf_and_status_later(curbuf, NOT_VALID);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1747 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1748
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1749 /*
13344
68c4fc9ae216 patch 8.0.1546: using feedkeys() in a terminal may trigger mappings
Christian Brabandt <cb@256bit.org>
parents: 13335
diff changeset
1750 * Get a key from the user with terminal mode mappings.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1751 * Note: while waiting a terminal may be closed and freed if the channel is
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1752 * closed and ++close was used.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1753 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1754 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1755 term_vgetc()
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1756 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1757 int c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1758 int save_State = State;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1759
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1760 State = TERMINAL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1761 got_int = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1762 #ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1763 ctrl_break_was_pressed = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1764 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1765 c = vgetc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1766 got_int = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1767 State = save_State;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1768 return c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1769 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1770
13448
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1771 static int mouse_was_outside = FALSE;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1772
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1773 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1774 * Send keys to terminal.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1775 * Return FAIL when the key needs to be handled in Normal mode.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1776 * Return OK when the key was dropped or sent to the terminal.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1777 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1778 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1779 send_keys_to_term(term_T *term, int c, int typed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1780 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1781 char msg[KEY_BUF_LEN];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1782 size_t len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1783 int dragging_outside = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1784
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1785 /* Catch keys that need to be handled as in Normal mode. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1786 switch (c)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1787 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1788 case NUL:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1789 case K_ZERO:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1790 if (typed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1791 stuffcharReadbuff(c);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1792 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1793
13849
58b6982ca049 patch 8.0.1796: GUI: click on tab fails when the focus is in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13847
diff changeset
1794 case K_TABLINE:
58b6982ca049 patch 8.0.1796: GUI: click on tab fails when the focus is in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13847
diff changeset
1795 stuffcharReadbuff(c);
58b6982ca049 patch 8.0.1796: GUI: click on tab fails when the focus is in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13847
diff changeset
1796 return FAIL;
58b6982ca049 patch 8.0.1796: GUI: click on tab fails when the focus is in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13847
diff changeset
1797
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1798 case K_IGNORE:
13829
044337cbf854 patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents: 13823
diff changeset
1799 case K_CANCEL: // used for :normal when running out of chars
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1800 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1801
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1802 case K_LEFTDRAG:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1803 case K_MIDDLEDRAG:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1804 case K_RIGHTDRAG:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1805 case K_X1DRAG:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1806 case K_X2DRAG:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1807 dragging_outside = mouse_was_outside;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1808 /* FALLTHROUGH */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1809 case K_LEFTMOUSE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1810 case K_LEFTMOUSE_NM:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1811 case K_LEFTRELEASE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1812 case K_LEFTRELEASE_NM:
12865
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12845
diff changeset
1813 case K_MOUSEMOVE:
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1814 case K_MIDDLEMOUSE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1815 case K_MIDDLERELEASE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1816 case K_RIGHTMOUSE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1817 case K_RIGHTRELEASE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1818 case K_X1MOUSE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1819 case K_X1RELEASE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1820 case K_X2MOUSE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1821 case K_X2RELEASE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1822
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1823 case K_MOUSEUP:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1824 case K_MOUSEDOWN:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1825 case K_MOUSELEFT:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1826 case K_MOUSERIGHT:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1827 if (mouse_row < W_WINROW(curwin)
12984
fc0d4a036654 patch 8.0.1368: cannot drag status or separator of new terminal window
Christian Brabandt <cb@256bit.org>
parents: 12973
diff changeset
1828 || mouse_row >= (W_WINROW(curwin) + curwin->w_height)
12513
3ca08bf99396 patch 8.0.1135: W_WINCOL() is always the same
Christian Brabandt <cb@256bit.org>
parents: 12509
diff changeset
1829 || mouse_col < curwin->w_wincol
12984
fc0d4a036654 patch 8.0.1368: cannot drag status or separator of new terminal window
Christian Brabandt <cb@256bit.org>
parents: 12973
diff changeset
1830 || mouse_col >= W_ENDCOL(curwin)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1831 || dragging_outside)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1832 {
12984
fc0d4a036654 patch 8.0.1368: cannot drag status or separator of new terminal window
Christian Brabandt <cb@256bit.org>
parents: 12973
diff changeset
1833 /* click or scroll outside the current window or on status line
fc0d4a036654 patch 8.0.1368: cannot drag status or separator of new terminal window
Christian Brabandt <cb@256bit.org>
parents: 12973
diff changeset
1834 * or vertical separator */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1835 if (typed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1836 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1837 stuffcharReadbuff(c);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1838 mouse_was_outside = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1839 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1840 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1841 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1842 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1843 if (typed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1844 mouse_was_outside = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1845
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1846 /* Convert the typed key to a sequence of bytes for the job. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1847 len = term_convert_key(term, c, msg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1848 if (len > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1849 /* TODO: if FAIL is returned, stop? */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1850 channel_send(term->tl_job->jv_channel, get_tty_part(term),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1851 (char_u *)msg, (int)len, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1852
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1853 return OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1854 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1855
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1856 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1857 position_cursor(win_T *wp, VTermPos *pos)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1858 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1859 wp->w_wrow = MIN(pos->row, MAX(0, wp->w_height - 1));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1860 wp->w_wcol = MIN(pos->col, MAX(0, wp->w_width - 1));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1861 wp->w_valid |= (VALID_WCOL|VALID_WROW);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1862 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1863
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1864 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1865 * Handle CTRL-W "": send register contents to the job.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1866 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1867 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1868 term_paste_register(int prev_c UNUSED)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1869 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1870 int c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1871 list_T *l;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1872 listitem_T *item;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1873 long reglen = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1874 int type;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1875
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1876 #ifdef FEAT_CMDL_INFO
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1877 if (add_to_showcmd(prev_c))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1878 if (add_to_showcmd('"'))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1879 out_flush();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1880 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1881 c = term_vgetc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1882 #ifdef FEAT_CMDL_INFO
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1883 clear_showcmd();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1884 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1885 if (!term_use_loop())
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1886 /* job finished while waiting for a character */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1887 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1888
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1889 /* CTRL-W "= prompt for expression to evaluate. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1890 if (c == '=' && get_expr_register() != '=')
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1891 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1892 if (!term_use_loop())
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1893 /* job finished while waiting for a character */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1894 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1895
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1896 l = (list_T *)get_reg_contents(c, GREG_LIST);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1897 if (l != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1898 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1899 type = get_reg_type(c, &reglen);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1900 for (item = l->lv_first; item != NULL; item = item->li_next)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1901 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1902 char_u *s = get_tv_string(&item->li_tv);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1903 #ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1904 char_u *tmp = s;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1905
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1906 if (!enc_utf8 && enc_codepage > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1907 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1908 WCHAR *ret = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1909 int length = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1910
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1911 MultiByteToWideChar_alloc(enc_codepage, 0, (char *)s,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1912 (int)STRLEN(s), &ret, &length);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1913 if (ret != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1914 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1915 WideCharToMultiByte_alloc(CP_UTF8, 0,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1916 ret, length, (char **)&s, &length, 0, 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1917 vim_free(ret);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1918 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1919 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1920 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1921 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1922 s, (int)STRLEN(s), NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1923 #ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1924 if (tmp != s)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1925 vim_free(s);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1926 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1927
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1928 if (item->li_next != NULL || type == MLINE)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1929 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1930 (char_u *)"\r", 1, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1931 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1932 list_free(l);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1933 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1934 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1935
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1936 /*
13829
044337cbf854 patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents: 13823
diff changeset
1937 * Return TRUE when waiting for a character in the terminal, the cursor of the
044337cbf854 patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents: 13823
diff changeset
1938 * terminal should be displayed.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1939 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1940 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1941 terminal_is_active()
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1942 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1943 return in_terminal_loop != NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1944 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1945
13829
044337cbf854 patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents: 13823
diff changeset
1946 #if defined(FEAT_GUI) || defined(PROTO)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1947 cursorentry_T *
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1948 term_get_cursor_shape(guicolor_T *fg, guicolor_T *bg)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1949 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1950 term_T *term = in_terminal_loop;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1951 static cursorentry_T entry;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1952
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1953 vim_memset(&entry, 0, sizeof(entry));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1954 entry.shape = entry.mshape =
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1955 term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_UNDERLINE ? SHAPE_HOR :
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1956 term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_BAR_LEFT ? SHAPE_VER :
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1957 SHAPE_BLOCK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1958 entry.percentage = 20;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1959 if (term->tl_cursor_blink)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1960 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1961 entry.blinkwait = 700;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1962 entry.blinkon = 400;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1963 entry.blinkoff = 250;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1964 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1965 *fg = gui.back_pixel;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1966 if (term->tl_cursor_color == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1967 *bg = gui.norm_pixel;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1968 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1969 *bg = color_name2handle(term->tl_cursor_color);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1970 entry.name = "n";
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1971 entry.used_for = SHAPE_CURSOR;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1972
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1973 return &entry;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1974 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1975 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1976
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1977 static void
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1978 may_output_cursor_props(void)
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1979 {
13990
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
1980 if (!cursor_color_equal(last_set_cursor_color, desired_cursor_color)
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1981 || last_set_cursor_shape != desired_cursor_shape
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1982 || last_set_cursor_blink != desired_cursor_blink)
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1983 {
13990
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
1984 cursor_color_copy(&last_set_cursor_color, desired_cursor_color);
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1985 last_set_cursor_shape = desired_cursor_shape;
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1986 last_set_cursor_blink = desired_cursor_blink;
13990
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
1987 term_cursor_color(cursor_color_get(desired_cursor_color));
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1988 if (desired_cursor_shape == -1 || desired_cursor_blink == -1)
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1989 /* this will restore the initial cursor style, if possible */
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1990 ui_cursor_shape_forced(TRUE);
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1991 else
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1992 term_cursor_shape(desired_cursor_shape, desired_cursor_blink);
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1993 }
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1994 }
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1995
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1996 /*
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1997 * Set the cursor color and shape, if not last set to these.
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1998 */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1999 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2000 may_set_cursor_props(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2001 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2002 #ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2003 /* For the GUI the cursor properties are obtained with
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2004 * term_get_cursor_shape(). */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2005 if (gui.in_use)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2006 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2007 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2008 if (in_terminal_loop == term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2009 {
13990
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
2010 cursor_color_copy(&desired_cursor_color, term->tl_cursor_color);
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2011 desired_cursor_shape = term->tl_cursor_shape;
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2012 desired_cursor_blink = term->tl_cursor_blink;
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2013 may_output_cursor_props();
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2014 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2015 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2016
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2017 /*
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2018 * Reset the desired cursor properties and restore them when needed.
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2019 */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2020 static void
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2021 prepare_restore_cursor_props(void)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2022 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2023 #ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2024 if (gui.in_use)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2025 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2026 #endif
13990
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
2027 cursor_color_copy(&desired_cursor_color, NULL);
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2028 desired_cursor_shape = -1;
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2029 desired_cursor_blink = -1;
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2030 may_output_cursor_props();
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2031 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2032
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2033 /*
13696
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2034 * Returns TRUE if the current window contains a terminal and we are sending
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2035 * keys to the job.
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2036 * If "check_job_status" is TRUE update the job status.
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2037 */
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2038 static int
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2039 term_use_loop_check(int check_job_status)
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2040 {
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2041 term_T *term = curbuf->b_term;
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2042
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2043 return term != NULL
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2044 && !term->tl_normal_mode
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2045 && term->tl_vterm != NULL
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2046 && term_job_running_check(term, check_job_status);
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2047 }
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2048
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2049 /*
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2050 * Returns TRUE if the current window contains a terminal and we are sending
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2051 * keys to the job.
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2052 */
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2053 int
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2054 term_use_loop(void)
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2055 {
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2056 return term_use_loop_check(FALSE);
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2057 }
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2058
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2059 /*
13448
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2060 * Called when entering a window with the mouse. If this is a terminal window
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2061 * we may want to change state.
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2062 */
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2063 void
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2064 term_win_entered()
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2065 {
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2066 term_T *term = curbuf->b_term;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2067
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2068 if (term != NULL)
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2069 {
13696
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2070 if (term_use_loop_check(TRUE))
13448
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2071 {
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2072 reset_VIsual_and_resel();
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2073 if (State & INSERT)
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2074 stop_insert_mode = TRUE;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2075 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2076 mouse_was_outside = FALSE;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2077 enter_mouse_col = mouse_col;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2078 enter_mouse_row = mouse_row;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2079 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2080 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2081
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2082 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2083 * Wait for input and send it to the job.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2084 * When "blocking" is TRUE wait for a character to be typed. Otherwise return
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2085 * when there is no more typahead.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2086 * Return when the start of a CTRL-W command is typed or anything else that
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2087 * should be handled as a Normal mode command.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2088 * Returns OK if a typed character is to be handled in Normal mode, FAIL if
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2089 * the terminal was closed.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2090 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2091 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2092 terminal_loop(int blocking)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2093 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2094 int c;
13845
f22db93bd887 patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents: 13835
diff changeset
2095 int termwinkey = 0;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2096 int ret;
12767
4d9cdb1d8bea patch 8.0.1261: program in terminal window gets NL instead of CR
Christian Brabandt <cb@256bit.org>
parents: 12724
diff changeset
2097 #ifdef UNIX
12800
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2098 int tty_fd = curbuf->b_term->tl_job->jv_channel
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2099 ->ch_part[get_tty_part(curbuf->b_term)].ch_fd;
12767
4d9cdb1d8bea patch 8.0.1261: program in terminal window gets NL instead of CR
Christian Brabandt <cb@256bit.org>
parents: 12724
diff changeset
2100 #endif
13906
0ae89b121c58 patch 8.0.1824: Coverity warns for variable that may be uninitialized
Christian Brabandt <cb@256bit.org>
parents: 13900
diff changeset
2101 int restore_cursor = FALSE;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2102
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2103 /* Remember the terminal we are sending keys to. However, the terminal
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2104 * might be closed while waiting for a character, e.g. typing "exit" in a
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2105 * shell and ++close was used. Therefore use curbuf->b_term instead of a
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2106 * stored reference. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2107 in_terminal_loop = curbuf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2108
13742
a34b1323286c patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents: 13720
diff changeset
2109 if (*curwin->w_p_twk != NUL)
14109
279465096a16 patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14065
diff changeset
2110 {
13845
f22db93bd887 patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents: 13835
diff changeset
2111 termwinkey = string_to_key(curwin->w_p_twk, TRUE);
14109
279465096a16 patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14065
diff changeset
2112 if (termwinkey == Ctrl_W)
279465096a16 patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14065
diff changeset
2113 termwinkey = 0;
279465096a16 patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14065
diff changeset
2114 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2115 position_cursor(curwin, &curbuf->b_term->tl_cursor_pos);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2116 may_set_cursor_props(curbuf->b_term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2117
13344
68c4fc9ae216 patch 8.0.1546: using feedkeys() in a terminal may trigger mappings
Christian Brabandt <cb@256bit.org>
parents: 13335
diff changeset
2118 while (blocking || vpeekc_nomap() != NUL)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2119 {
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2120 #ifdef FEAT_GUI
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2121 if (!curbuf->b_term->tl_system)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2122 #endif
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2123 /* TODO: skip screen update when handling a sequence of keys. */
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2124 /* Repeat redrawing in case a message is received while redrawing.
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2125 */
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2126 while (must_redraw != 0)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2127 if (update_screen(0) == FAIL)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2128 break;
13994
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
2129 if (!term_use_loop_check(TRUE) || in_terminal_loop != curbuf->b_term)
13886
bbf5bdba4a80 patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13878
diff changeset
2130 /* job finished while redrawing */
bbf5bdba4a80 patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13878
diff changeset
2131 break;
bbf5bdba4a80 patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13878
diff changeset
2132
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2133 update_cursor(curbuf->b_term, FALSE);
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2134 restore_cursor = TRUE;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2135
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2136 c = term_vgetc();
13994
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
2137 if (!term_use_loop_check(TRUE) || in_terminal_loop != curbuf->b_term)
12798
5ae0d05e046a patch 8.0.1276: key lost when window closed in exit callback
Christian Brabandt <cb@256bit.org>
parents: 12767
diff changeset
2138 {
12800
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2139 /* Job finished while waiting for a character. Push back the
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2140 * received character. */
12798
5ae0d05e046a patch 8.0.1276: key lost when window closed in exit callback
Christian Brabandt <cb@256bit.org>
parents: 12767
diff changeset
2141 if (c != K_IGNORE)
5ae0d05e046a patch 8.0.1276: key lost when window closed in exit callback
Christian Brabandt <cb@256bit.org>
parents: 12767
diff changeset
2142 vungetc(c);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2143 break;
12798
5ae0d05e046a patch 8.0.1276: key lost when window closed in exit callback
Christian Brabandt <cb@256bit.org>
parents: 12767
diff changeset
2144 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2145 if (c == K_IGNORE)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2146 continue;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2147
12800
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2148 #ifdef UNIX
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2149 /*
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2150 * The shell or another program may change the tty settings. Getting
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2151 * them for every typed character is a bit of overhead, but it's needed
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2152 * for the first character typed, e.g. when Vim starts in a shell.
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2153 */
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2154 if (isatty(tty_fd))
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2155 {
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2156 ttyinfo_T info;
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2157
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2158 /* Get the current backspace character of the pty. */
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2159 if (get_tty_info(tty_fd, &info) == OK)
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2160 term_backspace_char = info.backspace;
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2161 }
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2162 #endif
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2163
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2164 #ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2165 /* On Windows winpty handles CTRL-C, don't send a CTRL_C_EVENT.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2166 * Use CTRL-BREAK to kill the job. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2167 if (ctrl_break_was_pressed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2168 mch_signal_job(curbuf->b_term->tl_job, (char_u *)"kill");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2169 #endif
13845
f22db93bd887 patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents: 13835
diff changeset
2170 /* Was either CTRL-W (termwinkey) or CTRL-\ pressed?
13474
8a8daeb057d1 patch 8.0.1611: CTRL-W in system terminal does not go to job
Christian Brabandt <cb@256bit.org>
parents: 13472
diff changeset
2171 * Not in a system terminal. */
13845
f22db93bd887 patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents: 13835
diff changeset
2172 if ((c == (termwinkey == 0 ? Ctrl_W : termwinkey) || c == Ctrl_BSL)
13474
8a8daeb057d1 patch 8.0.1611: CTRL-W in system terminal does not go to job
Christian Brabandt <cb@256bit.org>
parents: 13472
diff changeset
2173 #ifdef FEAT_GUI
8a8daeb057d1 patch 8.0.1611: CTRL-W in system terminal does not go to job
Christian Brabandt <cb@256bit.org>
parents: 13472
diff changeset
2174 && !curbuf->b_term->tl_system
8a8daeb057d1 patch 8.0.1611: CTRL-W in system terminal does not go to job
Christian Brabandt <cb@256bit.org>
parents: 13472
diff changeset
2175 #endif
8a8daeb057d1 patch 8.0.1611: CTRL-W in system terminal does not go to job
Christian Brabandt <cb@256bit.org>
parents: 13472
diff changeset
2176 )
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2177 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2178 int prev_c = c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2179
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2180 #ifdef FEAT_CMDL_INFO
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2181 if (add_to_showcmd(c))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2182 out_flush();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2183 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2184 c = term_vgetc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2185 #ifdef FEAT_CMDL_INFO
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2186 clear_showcmd();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2187 #endif
13994
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
2188 if (!term_use_loop_check(TRUE)
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
2189 || in_terminal_loop != curbuf->b_term)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2190 /* job finished while waiting for a character */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2191 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2192
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2193 if (prev_c == Ctrl_BSL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2194 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2195 if (c == Ctrl_N)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2196 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2197 /* CTRL-\ CTRL-N : go to Terminal-Normal mode. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2198 term_enter_normal_mode();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2199 ret = FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2200 goto theend;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2201 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2202 /* Send both keys to the terminal. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2203 send_keys_to_term(curbuf->b_term, prev_c, TRUE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2204 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2205 else if (c == Ctrl_C)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2206 {
13845
f22db93bd887 patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents: 13835
diff changeset
2207 /* "CTRL-W CTRL-C" or 'termwinkey' CTRL-C: end the job */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2208 mch_signal_job(curbuf->b_term->tl_job, (char_u *)"kill");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2209 }
14109
279465096a16 patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14065
diff changeset
2210 else if (c == '.')
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2211 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2212 /* "CTRL-W .": send CTRL-W to the job */
14109
279465096a16 patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14065
diff changeset
2213 /* "'termwinkey' .": send 'termwinkey' to the job */
279465096a16 patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14065
diff changeset
2214 c = termwinkey == 0 ? Ctrl_W : termwinkey;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2215 }
14109
279465096a16 patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14065
diff changeset
2216 else if (c == Ctrl_BSL)
13668
6a84e3d2b810 patch 8.0.1706: cannot sent CTRL- to a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13630
diff changeset
2217 {
6a84e3d2b810 patch 8.0.1706: cannot sent CTRL- to a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13630
diff changeset
2218 /* "CTRL-W CTRL-\": send CTRL-\ to the job */
6a84e3d2b810 patch 8.0.1706: cannot sent CTRL- to a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13630
diff changeset
2219 c = Ctrl_BSL;
6a84e3d2b810 patch 8.0.1706: cannot sent CTRL- to a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13630
diff changeset
2220 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2221 else if (c == 'N')
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2222 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2223 /* CTRL-W N : go to Terminal-Normal mode. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2224 term_enter_normal_mode();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2225 ret = FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2226 goto theend;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2227 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2228 else if (c == '"')
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2229 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2230 term_paste_register(prev_c);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2231 continue;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2232 }
13845
f22db93bd887 patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents: 13835
diff changeset
2233 else if (termwinkey == 0 || c != termwinkey)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2234 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2235 stuffcharReadbuff(Ctrl_W);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2236 stuffcharReadbuff(c);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2237 ret = OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2238 goto theend;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2239 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2240 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2241 # ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2242 if (!enc_utf8 && has_mbyte && c >= 0x80)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2243 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2244 WCHAR wc;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2245 char_u mb[3];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2246
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2247 mb[0] = (unsigned)c >> 8;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2248 mb[1] = c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2249 if (MultiByteToWideChar(GetACP(), 0, (char*)mb, 2, &wc, 1) > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2250 c = wc;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2251 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2252 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2253 if (send_keys_to_term(curbuf->b_term, c, TRUE) != OK)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2254 {
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2255 if (c == K_MOUSEMOVE)
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2256 /* We are sure to come back here, don't reset the cursor color
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2257 * and shape to avoid flickering. */
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2258 restore_cursor = FALSE;
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2259
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2260 ret = OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2261 goto theend;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2262 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2263 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2264 ret = FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2265
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2266 theend:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2267 in_terminal_loop = NULL;
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2268 if (restore_cursor)
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2269 prepare_restore_cursor_props();
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2270
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2271 /* Move a snapshot of the screen contents to the buffer, so that completion
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2272 * works in other buffers. */
13935
cc25795aeec6 patch 8.0.1838: cursor in wrong pos when switching to Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13919
diff changeset
2273 if (curbuf->b_term != NULL && !curbuf->b_term->tl_normal_mode)
cc25795aeec6 patch 8.0.1838: cursor in wrong pos when switching to Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13919
diff changeset
2274 may_move_terminal_to_buffer(curbuf->b_term, FALSE);
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2275
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2276 return ret;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2277 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2278
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2279 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2280 * Called when a job has finished.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2281 * This updates the title and status, but does not close the vterm, because
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2282 * there might still be pending output in the channel.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2283 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2284 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2285 term_job_ended(job_T *job)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2286 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2287 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2288 int did_one = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2289
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2290 for (term = first_term; term != NULL; term = term->tl_next)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2291 if (term->tl_job == job)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2292 {
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13219
diff changeset
2293 VIM_CLEAR(term->tl_title);
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13219
diff changeset
2294 VIM_CLEAR(term->tl_status_text);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2295 redraw_buf_and_status_later(term->tl_buffer, VALID);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2296 did_one = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2297 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2298 if (did_one)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2299 redraw_statuslines();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2300 if (curbuf->b_term != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2301 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2302 if (curbuf->b_term->tl_job == job)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2303 maketitle();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2304 update_cursor(curbuf->b_term, TRUE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2305 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2306 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2307
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2308 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2309 may_toggle_cursor(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2310 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2311 if (in_terminal_loop == term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2312 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2313 if (term->tl_cursor_visible)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2314 cursor_on();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2315 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2316 cursor_off();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2317 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2318 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2319
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2320 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2321 * Reverse engineer the RGB value into a cterm color index.
12966
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2322 * First color is 1. Return 0 if no match found (default color).
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2323 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2324 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2325 color2index(VTermColor *color, int fg, int *boldp)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2326 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2327 int red = color->red;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2328 int blue = color->blue;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2329 int green = color->green;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2330
12966
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2331 if (color->ansi_index != VTERM_ANSI_INDEX_NONE)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2332 {
12966
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2333 /* First 16 colors and default: use the ANSI index, because these
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2334 * colors can be redefined. */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2335 if (t_colors >= 16)
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2336 return color->ansi_index;
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2337 switch (color->ansi_index)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2338 {
12966
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2339 case 0: return 0;
13329
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
2340 case 1: return lookup_color( 0, fg, boldp) + 1; /* black */
12966
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2341 case 2: return lookup_color( 4, fg, boldp) + 1; /* dark red */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2342 case 3: return lookup_color( 2, fg, boldp) + 1; /* dark green */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2343 case 4: return lookup_color( 6, fg, boldp) + 1; /* brown */
13668
6a84e3d2b810 patch 8.0.1706: cannot sent CTRL- to a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13630
diff changeset
2344 case 5: return lookup_color( 1, fg, boldp) + 1; /* dark blue */
12966
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2345 case 6: return lookup_color( 5, fg, boldp) + 1; /* dark magenta */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2346 case 7: return lookup_color( 3, fg, boldp) + 1; /* dark cyan */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2347 case 8: return lookup_color( 8, fg, boldp) + 1; /* light grey */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2348 case 9: return lookup_color(12, fg, boldp) + 1; /* dark grey */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2349 case 10: return lookup_color(20, fg, boldp) + 1; /* red */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2350 case 11: return lookup_color(16, fg, boldp) + 1; /* green */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2351 case 12: return lookup_color(24, fg, boldp) + 1; /* yellow */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2352 case 13: return lookup_color(14, fg, boldp) + 1; /* blue */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2353 case 14: return lookup_color(22, fg, boldp) + 1; /* magenta */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2354 case 15: return lookup_color(18, fg, boldp) + 1; /* cyan */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2355 case 16: return lookup_color(26, fg, boldp) + 1; /* white */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2356 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2357 }
12966
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2358
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2359 if (t_colors >= 256)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2360 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2361 if (red == blue && red == green)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2362 {
12541
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2363 /* 24-color greyscale plus white and black */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2364 static int cutoff[23] = {
12541
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2365 0x0D, 0x17, 0x21, 0x2B, 0x35, 0x3F, 0x49, 0x53, 0x5D, 0x67,
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2366 0x71, 0x7B, 0x85, 0x8F, 0x99, 0xA3, 0xAD, 0xB7, 0xC1, 0xCB,
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2367 0xD5, 0xDF, 0xE9};
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2368 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2369
12541
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2370 if (red < 5)
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2371 return 17; /* 00/00/00 */
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2372 if (red > 245) /* ff/ff/ff */
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2373 return 232;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2374 for (i = 0; i < 23; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2375 if (red < cutoff[i])
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2376 return i + 233;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2377 return 256;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2378 }
12541
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2379 {
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2380 static int cutoff[5] = {0x2F, 0x73, 0x9B, 0xC3, 0xEB};
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2381 int ri, gi, bi;
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2382
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2383 /* 216-color cube */
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2384 for (ri = 0; ri < 5; ++ri)
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2385 if (red < cutoff[ri])
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2386 break;
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2387 for (gi = 0; gi < 5; ++gi)
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2388 if (green < cutoff[gi])
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2389 break;
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2390 for (bi = 0; bi < 5; ++bi)
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2391 if (blue < cutoff[bi])
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2392 break;
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2393 return 17 + ri * 36 + gi * 6 + bi;
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2394 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2395 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2396 return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2397 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2398
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2399 /*
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2400 * Convert Vterm attributes to highlight flags.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2401 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2402 static int
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2403 vtermAttr2hl(VTermScreenCellAttrs cellattrs)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2404 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2405 int attr = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2406
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2407 if (cellattrs.bold)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2408 attr |= HL_BOLD;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2409 if (cellattrs.underline)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2410 attr |= HL_UNDERLINE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2411 if (cellattrs.italic)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2412 attr |= HL_ITALIC;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2413 if (cellattrs.strike)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2414 attr |= HL_STRIKETHROUGH;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2415 if (cellattrs.reverse)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2416 attr |= HL_INVERSE;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2417 return attr;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2418 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2419
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2420 /*
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2421 * Store Vterm attributes in "cell" from highlight flags.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2422 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2423 static void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2424 hl2vtermAttr(int attr, cellattr_T *cell)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2425 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2426 vim_memset(&cell->attrs, 0, sizeof(VTermScreenCellAttrs));
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2427 if (attr & HL_BOLD)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2428 cell->attrs.bold = 1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2429 if (attr & HL_UNDERLINE)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2430 cell->attrs.underline = 1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2431 if (attr & HL_ITALIC)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2432 cell->attrs.italic = 1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2433 if (attr & HL_STRIKETHROUGH)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2434 cell->attrs.strike = 1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2435 if (attr & HL_INVERSE)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2436 cell->attrs.reverse = 1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2437 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2438
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2439 /*
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2440 * Convert the attributes of a vterm cell into an attribute index.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2441 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2442 static int
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2443 cell2attr(VTermScreenCellAttrs cellattrs, VTermColor cellfg, VTermColor cellbg)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2444 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2445 int attr = vtermAttr2hl(cellattrs);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2446
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2447 #ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2448 if (gui.in_use)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2449 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2450 guicolor_T fg, bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2451
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2452 fg = gui_mch_get_rgb_color(cellfg.red, cellfg.green, cellfg.blue);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2453 bg = gui_mch_get_rgb_color(cellbg.red, cellbg.green, cellbg.blue);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2454 return get_gui_attr_idx(attr, fg, bg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2455 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2456 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2457 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2458 #ifdef FEAT_TERMGUICOLORS
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2459 if (p_tgc)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2460 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2461 guicolor_T fg, bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2462
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2463 fg = gui_get_rgb_color_cmn(cellfg.red, cellfg.green, cellfg.blue);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2464 bg = gui_get_rgb_color_cmn(cellbg.red, cellbg.green, cellbg.blue);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2465
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2466 return get_tgc_attr_idx(attr, fg, bg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2467 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2468 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2469 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2470 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2471 int bold = MAYBE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2472 int fg = color2index(&cellfg, TRUE, &bold);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2473 int bg = color2index(&cellbg, FALSE, &bold);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2474
12969
a9f6a874b64f patch 8.0.1360: the Terminal highlighting doesn't work in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12966
diff changeset
2475 /* Use the "Terminal" highlighting for the default colors. */
12973
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
2476 if ((fg == 0 || bg == 0) && t_colors >= 16)
12969
a9f6a874b64f patch 8.0.1360: the Terminal highlighting doesn't work in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12966
diff changeset
2477 {
12973
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
2478 if (fg == 0 && term_default_cterm_fg >= 0)
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
2479 fg = term_default_cterm_fg + 1;
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
2480 if (bg == 0 && term_default_cterm_bg >= 0)
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
2481 bg = term_default_cterm_bg + 1;
12969
a9f6a874b64f patch 8.0.1360: the Terminal highlighting doesn't work in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12966
diff changeset
2482 }
a9f6a874b64f patch 8.0.1360: the Terminal highlighting doesn't work in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12966
diff changeset
2483
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2484 /* with 8 colors set the bold attribute to get a bright foreground */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2485 if (bold == TRUE)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2486 attr |= HL_BOLD;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2487 return get_cterm_attr_idx(attr, fg, bg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2488 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2489 return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2490 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2491
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2492 static void
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2493 set_dirty_snapshot(term_T *term)
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2494 {
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2495 term->tl_dirty_snapshot = TRUE;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2496 #ifdef FEAT_TIMERS
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2497 if (!term->tl_normal_mode)
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2498 {
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2499 /* Update the snapshot after 100 msec of not getting updates. */
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2500 profile_setlimit(100L, &term->tl_timer_due);
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2501 term->tl_timer_set = TRUE;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2502 }
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2503 #endif
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2504 }
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2505
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2506 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2507 handle_damage(VTermRect rect, void *user)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2508 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2509 term_T *term = (term_T *)user;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2510
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2511 term->tl_dirty_row_start = MIN(term->tl_dirty_row_start, rect.start_row);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2512 term->tl_dirty_row_end = MAX(term->tl_dirty_row_end, rect.end_row);
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2513 set_dirty_snapshot(term);
13851
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2514 redraw_buf_later(term->tl_buffer, SOME_VALID);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2515 return 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2516 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2517
13851
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2518 static void
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2519 term_scroll_up(term_T *term, int start_row, int count)
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2520 {
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2521 win_T *wp;
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2522 VTermColor fg, bg;
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2523 VTermScreenCellAttrs attr;
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2524 int clear_attr;
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2525
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2526 /* Set the color to clear lines with. */
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2527 vterm_state_get_default_colors(vterm_obtain_state(term->tl_vterm),
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2528 &fg, &bg);
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2529 vim_memset(&attr, 0, sizeof(attr));
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2530 clear_attr = cell2attr(attr, fg, bg);
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2531
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2532 FOR_ALL_WINDOWS(wp)
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2533 {
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2534 if (wp->w_buffer == term->tl_buffer)
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2535 win_del_lines(wp, start_row, count, FALSE, FALSE, clear_attr);
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2536 }
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2537 }
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2538
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2539 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2540 handle_moverect(VTermRect dest, VTermRect src, void *user)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2541 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2542 term_T *term = (term_T *)user;
13851
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2543 int count = src.start_row - dest.start_row;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2544
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2545 /* Scrolling up is done much more efficiently by deleting lines instead of
13851
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2546 * redrawing the text. But avoid doing this multiple times, postpone until
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2547 * the redraw happens. */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2548 if (dest.start_col == src.start_col
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2549 && dest.end_col == src.end_col
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2550 && dest.start_row < src.start_row)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2551 {
13851
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2552 if (dest.start_row == 0)
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2553 term->tl_postponed_scroll += count;
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2554 else
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2555 term_scroll_up(term, dest.start_row, count);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2556 }
12578
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
2557
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
2558 term->tl_dirty_row_start = MIN(term->tl_dirty_row_start, dest.start_row);
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
2559 term->tl_dirty_row_end = MIN(term->tl_dirty_row_end, dest.end_row);
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2560 set_dirty_snapshot(term);
12578
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
2561
13851
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2562 /* Note sure if the scrolling will work correctly, let's do a complete
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2563 * redraw later. */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2564 redraw_buf_later(term->tl_buffer, NOT_VALID);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2565 return 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2566 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2567
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2568 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2569 handle_movecursor(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2570 VTermPos pos,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2571 VTermPos oldpos UNUSED,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2572 int visible,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2573 void *user)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2574 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2575 term_T *term = (term_T *)user;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2576 win_T *wp;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2577
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2578 term->tl_cursor_pos = pos;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2579 term->tl_cursor_visible = visible;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2580
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2581 FOR_ALL_WINDOWS(wp)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2582 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2583 if (wp->w_buffer == term->tl_buffer)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2584 position_cursor(wp, &pos);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2585 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2586 if (term->tl_buffer == curbuf && !term->tl_normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2587 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2588 may_toggle_cursor(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2589 update_cursor(term, term->tl_cursor_visible);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2590 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2591
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2592 return 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2593 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2594
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2595 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2596 handle_settermprop(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2597 VTermProp prop,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2598 VTermValue *value,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2599 void *user)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2600 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2601 term_T *term = (term_T *)user;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2602
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2603 switch (prop)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2604 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2605 case VTERM_PROP_TITLE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2606 vim_free(term->tl_title);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2607 /* a blank title isn't useful, make it empty, so that "running" is
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2608 * displayed */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2609 if (*skipwhite((char_u *)value->string) == NUL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2610 term->tl_title = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2611 #ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2612 else if (!enc_utf8 && enc_codepage > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2613 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2614 WCHAR *ret = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2615 int length = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2616
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2617 MultiByteToWideChar_alloc(CP_UTF8, 0,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2618 (char*)value->string, (int)STRLEN(value->string),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2619 &ret, &length);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2620 if (ret != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2621 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2622 WideCharToMultiByte_alloc(enc_codepage, 0,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2623 ret, length, (char**)&term->tl_title,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2624 &length, 0, 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2625 vim_free(ret);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2626 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2627 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2628 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2629 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2630 term->tl_title = vim_strsave((char_u *)value->string);
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13219
diff changeset
2631 VIM_CLEAR(term->tl_status_text);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2632 if (term == curbuf->b_term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2633 maketitle();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2634 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2635
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2636 case VTERM_PROP_CURSORVISIBLE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2637 term->tl_cursor_visible = value->boolean;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2638 may_toggle_cursor(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2639 out_flush();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2640 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2641
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2642 case VTERM_PROP_CURSORBLINK:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2643 term->tl_cursor_blink = value->boolean;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2644 may_set_cursor_props(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2645 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2646
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2647 case VTERM_PROP_CURSORSHAPE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2648 term->tl_cursor_shape = value->number;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2649 may_set_cursor_props(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2650 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2651
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2652 case VTERM_PROP_CURSORCOLOR:
13990
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
2653 cursor_color_copy(&term->tl_cursor_color, (char_u*)value->string);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2654 may_set_cursor_props(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2655 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2656
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2657 case VTERM_PROP_ALTSCREEN:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2658 /* TODO: do anything else? */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2659 term->tl_using_altscreen = value->boolean;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2660 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2661
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2662 default:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2663 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2664 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2665 /* Always return 1, otherwise vterm doesn't store the value internally. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2666 return 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2667 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2668
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2669 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2670 * The job running in the terminal resized the terminal.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2671 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2672 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2673 handle_resize(int rows, int cols, void *user)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2674 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2675 term_T *term = (term_T *)user;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2676 win_T *wp;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2677
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2678 term->tl_rows = rows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2679 term->tl_cols = cols;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2680 if (term->tl_vterm_size_changed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2681 /* Size was set by vterm_set_size(), don't set the window size. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2682 term->tl_vterm_size_changed = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2683 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2684 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2685 FOR_ALL_WINDOWS(wp)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2686 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2687 if (wp->w_buffer == term->tl_buffer)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2688 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2689 win_setheight_win(rows, wp);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2690 win_setwidth_win(cols, wp);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2691 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2692 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2693 redraw_buf_later(term->tl_buffer, NOT_VALID);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2694 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2695 return 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2696 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2697
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2698 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2699 * Handle a line that is pushed off the top of the screen.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2700 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2701 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2702 handle_pushline(int cols, const VTermScreenCell *cells, void *user)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2703 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2704 term_T *term = (term_T *)user;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2705
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2706 /* First remove the lines that were appended before, the pushed line goes
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2707 * above it. */
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2708 cleanup_scrollback(term);
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2709
13680
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
2710 /* If the number of lines that are stored goes over 'termscrollback' then
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
2711 * delete the first 10%. */
13742
a34b1323286c patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents: 13720
diff changeset
2712 if (term->tl_scrollback.ga_len >= term->tl_buffer->b_p_twsl)
13680
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
2713 {
13742
a34b1323286c patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents: 13720
diff changeset
2714 int todo = term->tl_buffer->b_p_twsl / 10;
13680
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
2715 int i;
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
2716
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
2717 curbuf = term->tl_buffer;
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
2718 for (i = 0; i < todo; ++i)
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
2719 {
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
2720 vim_free(((sb_line_T *)term->tl_scrollback.ga_data + i)->sb_cells);
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
2721 ml_delete(1, FALSE);
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
2722 }
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
2723 curbuf = curwin->w_buffer;
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
2724
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
2725 term->tl_scrollback.ga_len -= todo;
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
2726 mch_memmove(term->tl_scrollback.ga_data,
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
2727 (sb_line_T *)term->tl_scrollback.ga_data + todo,
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
2728 sizeof(sb_line_T) * term->tl_scrollback.ga_len);
13956
300aab3275c0 patch 8.0.1848: 'termwinscroll' does not work properly
Christian Brabandt <cb@256bit.org>
parents: 13935
diff changeset
2729 term->tl_scrollback_scrolled -= todo;
13680
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
2730 }
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
2731
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2732 if (ga_grow(&term->tl_scrollback, 1) == OK)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2733 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2734 cellattr_T *p = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2735 int len = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2736 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2737 int c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2738 int col;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2739 sb_line_T *line;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2740 garray_T ga;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2741 cellattr_T fill_attr = term->tl_default_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2742
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2743 /* do not store empty cells at the end */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2744 for (i = 0; i < cols; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2745 if (cells[i].chars[0] != 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2746 len = i + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2747 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2748 cell2cellattr(&cells[i], &fill_attr);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2749
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2750 ga_init2(&ga, 1, 100);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2751 if (len > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2752 p = (cellattr_T *)alloc((int)sizeof(cellattr_T) * len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2753 if (p != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2754 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2755 for (col = 0; col < len; col += cells[col].width)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2756 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2757 if (ga_grow(&ga, MB_MAXBYTES) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2758 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2759 ga.ga_len = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2760 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2761 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2762 for (i = 0; (c = cells[col].chars[i]) > 0 || i == 0; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2763 ga.ga_len += utf_char2bytes(c == NUL ? ' ' : c,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2764 (char_u *)ga.ga_data + ga.ga_len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2765 cell2cellattr(&cells[col], &p[col]);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2766 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2767 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2768 if (ga_grow(&ga, 1) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2769 add_scrollback_line_to_buffer(term, (char_u *)"", 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2770 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2771 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2772 *((char_u *)ga.ga_data + ga.ga_len) = NUL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2773 add_scrollback_line_to_buffer(term, ga.ga_data, ga.ga_len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2774 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2775 ga_clear(&ga);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2776
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2777 line = (sb_line_T *)term->tl_scrollback.ga_data
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2778 + term->tl_scrollback.ga_len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2779 line->sb_cols = len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2780 line->sb_cells = p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2781 line->sb_fill_attr = fill_attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2782 ++term->tl_scrollback.ga_len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2783 ++term->tl_scrollback_scrolled;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2784 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2785 return 0; /* ignored */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2786 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2787
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2788 static VTermScreenCallbacks screen_callbacks = {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2789 handle_damage, /* damage */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2790 handle_moverect, /* moverect */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2791 handle_movecursor, /* movecursor */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2792 handle_settermprop, /* settermprop */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2793 NULL, /* bell */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2794 handle_resize, /* resize */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2795 handle_pushline, /* sb_pushline */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2796 NULL /* sb_popline */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2797 };
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2798
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2799 /*
13888
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2800 * Do the work after the channel of a terminal was closed.
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2801 * Must be called only when updating_screen is FALSE.
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2802 * Returns TRUE when a buffer was closed (list of terminals may have changed).
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2803 */
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2804 static int
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2805 term_after_channel_closed(term_T *term)
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2806 {
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2807 /* Unless in Terminal-Normal mode: clear the vterm. */
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2808 if (!term->tl_normal_mode)
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2809 {
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2810 int fnum = term->tl_buffer->b_fnum;
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2811
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2812 cleanup_vterm(term);
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2813
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2814 if (term->tl_finish == TL_FINISH_CLOSE)
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2815 {
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2816 aco_save_T aco;
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2817
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2818 /* ++close or term_finish == "close" */
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2819 ch_log(NULL, "terminal job finished, closing window");
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2820 aucmd_prepbuf(&aco, term->tl_buffer);
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2821 do_bufdel(DOBUF_WIPE, (char_u *)"", 1, fnum, fnum, FALSE);
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2822 aucmd_restbuf(&aco);
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2823 return TRUE;
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2824 }
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2825 if (term->tl_finish == TL_FINISH_OPEN
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2826 && term->tl_buffer->b_nwindows == 0)
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2827 {
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2828 char buf[50];
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2829
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2830 /* TODO: use term_opencmd */
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2831 ch_log(NULL, "terminal job finished, opening window");
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2832 vim_snprintf(buf, sizeof(buf),
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2833 term->tl_opencmd == NULL
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2834 ? "botright sbuf %d"
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2835 : (char *)term->tl_opencmd, fnum);
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2836 do_cmdline_cmd((char_u *)buf);
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2837 }
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2838 else
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2839 ch_log(NULL, "terminal job finished");
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2840 }
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2841
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2842 redraw_buf_and_status_later(term->tl_buffer, NOT_VALID);
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2843 return FALSE;
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2844 }
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2845
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2846 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2847 * Called when a channel has been closed.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2848 * If this was a channel for a terminal window then finish it up.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2849 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2850 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2851 term_channel_closed(channel_T *ch)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2852 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2853 term_T *term;
13888
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2854 term_T *next_term;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2855 int did_one = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2856
13888
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2857 for (term = first_term; term != NULL; term = next_term)
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2858 {
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2859 next_term = term->tl_next;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2860 if (term->tl_job == ch->ch_job)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2861 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2862 term->tl_channel_closed = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2863 did_one = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2864
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13219
diff changeset
2865 VIM_CLEAR(term->tl_title);
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13219
diff changeset
2866 VIM_CLEAR(term->tl_status_text);
13862
b201372b91a4 patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents: 13860
diff changeset
2867 #ifdef WIN3264
b201372b91a4 patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents: 13860
diff changeset
2868 if (term->tl_out_fd != NULL)
b201372b91a4 patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents: 13860
diff changeset
2869 {
b201372b91a4 patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents: 13860
diff changeset
2870 fclose(term->tl_out_fd);
b201372b91a4 patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents: 13860
diff changeset
2871 term->tl_out_fd = NULL;
b201372b91a4 patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents: 13860
diff changeset
2872 }
b201372b91a4 patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents: 13860
diff changeset
2873 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2874
13888
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2875 if (updating_screen)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2876 {
13888
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2877 /* Cannot open or close windows now. Can happen when
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2878 * 'lazyredraw' is set. */
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2879 term->tl_channel_recently_closed = TRUE;
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2880 continue;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2881 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2882
13888
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2883 if (term_after_channel_closed(term))
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2884 next_term = first_term;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2885 }
13888
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2886 }
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2887
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2888 if (did_one)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2889 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2890 redraw_statuslines();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2891
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2892 /* Need to break out of vgetc(). */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2893 ins_char_typebuf(K_IGNORE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2894 typebuf_was_filled = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2895
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2896 term = curbuf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2897 if (term != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2898 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2899 if (term->tl_job == ch->ch_job)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2900 maketitle();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2901 update_cursor(term, term->tl_cursor_visible);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2902 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2903 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2904 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2905
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2906 /*
13888
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2907 * To be called after resetting updating_screen: handle any terminal where the
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2908 * channel was closed.
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2909 */
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2910 void
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2911 term_check_channel_closed_recently()
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2912 {
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2913 term_T *term;
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2914 term_T *next_term;
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2915
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2916 for (term = first_term; term != NULL; term = next_term)
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2917 {
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2918 next_term = term->tl_next;
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2919 if (term->tl_channel_recently_closed)
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2920 {
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2921 term->tl_channel_recently_closed = FALSE;
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2922 if (term_after_channel_closed(term))
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2923 // start over, the list may have changed
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2924 next_term = first_term;
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2925 }
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2926 }
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2927 }
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2928
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
2929 /*
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2930 * Fill one screen line from a line of the terminal.
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2931 * Advances "pos" to past the last column.
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2932 */
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2933 static void
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2934 term_line2screenline(VTermScreen *screen, VTermPos *pos, int max_col)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2935 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2936 int off = screen_get_current_line_off();
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2937
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2938 for (pos->col = 0; pos->col < max_col; )
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2939 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2940 VTermScreenCell cell;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2941 int c;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2942
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2943 if (vterm_screen_get_cell(screen, *pos, &cell) == 0)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2944 vim_memset(&cell, 0, sizeof(cell));
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2945
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2946 c = cell.chars[0];
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2947 if (c == NUL)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2948 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2949 ScreenLines[off] = ' ';
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2950 if (enc_utf8)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2951 ScreenLinesUC[off] = NUL;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2952 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2953 else
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2954 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2955 if (enc_utf8)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2956 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2957 int i;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2958
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2959 /* composing chars */
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2960 for (i = 0; i < Screen_mco
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2961 && i + 1 < VTERM_MAX_CHARS_PER_CELL; ++i)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2962 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2963 ScreenLinesC[i][off] = cell.chars[i + 1];
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2964 if (cell.chars[i + 1] == 0)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2965 break;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2966 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2967 if (c >= 0x80 || (Screen_mco > 0
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2968 && ScreenLinesC[0][off] != 0))
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2969 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2970 ScreenLines[off] = ' ';
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2971 ScreenLinesUC[off] = c;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2972 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2973 else
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2974 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2975 ScreenLines[off] = c;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2976 ScreenLinesUC[off] = NUL;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2977 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2978 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2979 #ifdef WIN3264
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2980 else if (has_mbyte && c >= 0x80)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2981 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2982 char_u mb[MB_MAXBYTES+1];
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2983 WCHAR wc = c;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2984
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2985 if (WideCharToMultiByte(GetACP(), 0, &wc, 1,
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2986 (char*)mb, 2, 0, 0) > 1)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2987 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2988 ScreenLines[off] = mb[0];
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2989 ScreenLines[off + 1] = mb[1];
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2990 cell.width = mb_ptr2cells(mb);
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2991 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2992 else
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2993 ScreenLines[off] = c;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2994 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2995 #endif
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2996 else
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2997 ScreenLines[off] = c;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2998 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2999 ScreenAttrs[off] = cell2attr(cell.attrs, cell.fg, cell.bg);
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3000
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3001 ++pos->col;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3002 ++off;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3003 if (cell.width == 2)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3004 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3005 if (enc_utf8)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3006 ScreenLinesUC[off] = NUL;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3007
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3008 /* don't set the second byte to NUL for a DBCS encoding, it
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3009 * has been set above */
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3010 if (enc_utf8 || !has_mbyte)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3011 ScreenLines[off] = NUL;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3012
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3013 ++pos->col;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3014 ++off;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3015 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3016 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3017 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3018
13472
f6a4614edea4 patch 8.0.1610: cannot build without GUI
Christian Brabandt <cb@256bit.org>
parents: 13470
diff changeset
3019 #if defined(FEAT_GUI)
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3020 static void
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3021 update_system_term(term_T *term)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3022 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3023 VTermPos pos;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3024 VTermScreen *screen;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3025
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3026 if (term->tl_vterm == NULL)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3027 return;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3028 screen = vterm_obtain_screen(term->tl_vterm);
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3029
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3030 /* Scroll up to make more room for terminal lines if needed. */
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3031 while (term->tl_toprow > 0
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3032 && (Rows - term->tl_toprow) < term->tl_dirty_row_end)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3033 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3034 int save_p_more = p_more;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3035
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3036 p_more = FALSE;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3037 msg_row = Rows - 1;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3038 msg_puts((char_u *)"\n");
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3039 p_more = save_p_more;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3040 --term->tl_toprow;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3041 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3042
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3043 for (pos.row = term->tl_dirty_row_start; pos.row < term->tl_dirty_row_end
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3044 && pos.row < Rows; ++pos.row)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3045 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3046 if (pos.row < term->tl_rows)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3047 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3048 int max_col = MIN(Columns, term->tl_cols);
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3049
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3050 term_line2screenline(screen, &pos, max_col);
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3051 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3052 else
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3053 pos.col = 0;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3054
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3055 screen_line(term->tl_toprow + pos.row, 0, pos.col, Columns, FALSE);
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3056 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3057
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3058 term->tl_dirty_row_start = MAX_ROW;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3059 term->tl_dirty_row_end = 0;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3060 update_cursor(term, TRUE);
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3061 }
13472
f6a4614edea4 patch 8.0.1610: cannot build without GUI
Christian Brabandt <cb@256bit.org>
parents: 13470
diff changeset
3062 #endif
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3063
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3064 /*
13851
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3065 * Return TRUE if window "wp" is to be redrawn with term_update_window().
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3066 * Returns FALSE when there is no terminal running in this window or it is in
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3067 * Terminal-Normal mode.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3068 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3069 int
13851
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3070 term_do_update_window(win_T *wp)
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3071 {
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3072 term_T *term = wp->w_buffer->b_term;
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3073
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3074 return term != NULL && term->tl_vterm != NULL && !term->tl_normal_mode;
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3075 }
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3076
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3077 /*
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3078 * Called to update a window that contains an active terminal.
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3079 */
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3080 void
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3081 term_update_window(win_T *wp)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3082 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3083 term_T *term = wp->w_buffer->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3084 VTerm *vterm;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3085 VTermScreen *screen;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3086 VTermState *state;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3087 VTermPos pos;
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3088 int rows, cols;
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3089 int newrows, newcols;
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3090 int minsize;
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3091 win_T *twp;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3092
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3093 vterm = term->tl_vterm;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3094 screen = vterm_obtain_screen(vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3095 state = vterm_obtain_state(vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3096
13851
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3097 /* We use NOT_VALID on a resize or scroll, redraw everything then. With
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3098 * SOME_VALID only redraw what was marked dirty. */
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3099 if (wp->w_redr_type > SOME_VALID)
12590
3c46dcf3b335 patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents: 12578
diff changeset
3100 {
3c46dcf3b335 patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents: 12578
diff changeset
3101 term->tl_dirty_row_start = 0;
3c46dcf3b335 patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents: 12578
diff changeset
3102 term->tl_dirty_row_end = MAX_ROW;
13851
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3103
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3104 if (term->tl_postponed_scroll > 0
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3105 && term->tl_postponed_scroll < term->tl_rows / 3)
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3106 /* Scrolling is usually faster than redrawing, when there are only
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3107 * a few lines to scroll. */
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3108 term_scroll_up(term, 0, term->tl_postponed_scroll);
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3109 term->tl_postponed_scroll = 0;
12590
3c46dcf3b335 patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents: 12578
diff changeset
3110 }
3c46dcf3b335 patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents: 12578
diff changeset
3111
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3112 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3113 * If the window was resized a redraw will be triggered and we get here.
13845
f22db93bd887 patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents: 13835
diff changeset
3114 * Adjust the size of the vterm unless 'termwinsize' specifies a fixed size.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3115 */
13845
f22db93bd887 patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents: 13835
diff changeset
3116 minsize = parse_termwinsize(wp, &rows, &cols);
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3117
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3118 newrows = 99999;
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3119 newcols = 99999;
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3120 FOR_ALL_WINDOWS(twp)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3121 {
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3122 /* When more than one window shows the same terminal, use the
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3123 * smallest size. */
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3124 if (twp->w_buffer == term->tl_buffer)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3125 {
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3126 newrows = MIN(newrows, twp->w_height);
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3127 newcols = MIN(newcols, twp->w_width);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3128 }
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3129 }
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3130 newrows = rows == 0 ? newrows : minsize ? MAX(rows, newrows) : rows;
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3131 newcols = cols == 0 ? newcols : minsize ? MAX(cols, newcols) : cols;
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3132
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3133 if (term->tl_rows != newrows || term->tl_cols != newcols)
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3134 {
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3135
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3136
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3137 term->tl_vterm_size_changed = TRUE;
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3138 vterm_set_size(vterm, newrows, newcols);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3139 ch_log(term->tl_job->jv_channel, "Resizing terminal to %d lines",
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3140 newrows);
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3141 term_report_winsize(term, newrows, newcols);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3142 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3143
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3144 /* The cursor may have been moved when resizing. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3145 vterm_state_get_cursorpos(state, &pos);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3146 position_cursor(wp, &pos);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3147
12578
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
3148 for (pos.row = term->tl_dirty_row_start; pos.row < term->tl_dirty_row_end
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
3149 && pos.row < wp->w_height; ++pos.row)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3150 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3151 if (pos.row < term->tl_rows)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3152 {
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3153 int max_col = MIN(wp->w_width, term->tl_cols);
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3154
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3155 term_line2screenline(screen, &pos, max_col);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3156 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3157 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3158 pos.col = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3159
13458
0e7a56b18d61 patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents: 13448
diff changeset
3160 screen_line(wp->w_winrow + pos.row
0e7a56b18d61 patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents: 13448
diff changeset
3161 #ifdef FEAT_MENU
0e7a56b18d61 patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents: 13448
diff changeset
3162 + winbar_height(wp)
0e7a56b18d61 patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents: 13448
diff changeset
3163 #endif
0e7a56b18d61 patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents: 13448
diff changeset
3164 , wp->w_wincol, pos.col, wp->w_width, FALSE);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3165 }
12578
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
3166 term->tl_dirty_row_start = MAX_ROW;
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
3167 term->tl_dirty_row_end = 0;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3168 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3169
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3170 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3171 * Return TRUE if "wp" is a terminal window where the job has finished.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3172 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3173 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3174 term_is_finished(buf_T *buf)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3175 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3176 return buf->b_term != NULL && buf->b_term->tl_vterm == NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3177 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3178
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3179 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3180 * Return TRUE if "wp" is a terminal window where the job has finished or we
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3181 * are in Terminal-Normal mode, thus we show the buffer contents.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3182 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3183 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3184 term_show_buffer(buf_T *buf)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3185 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3186 term_T *term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3187
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3188 return term != NULL && (term->tl_vterm == NULL || term->tl_normal_mode);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3189 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3190
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3191 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3192 * The current buffer is going to be changed. If there is terminal
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3193 * highlighting remove it now.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3194 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3195 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3196 term_change_in_curbuf(void)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3197 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3198 term_T *term = curbuf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3199
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3200 if (term_is_finished(curbuf) && term->tl_scrollback.ga_len > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3201 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3202 free_scrollback(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3203 redraw_buf_later(term->tl_buffer, NOT_VALID);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3204
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3205 /* The buffer is now like a normal buffer, it cannot be easily
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3206 * abandoned when changed. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3207 set_string_option_direct((char_u *)"buftype", -1,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3208 (char_u *)"", OPT_FREE|OPT_LOCAL, 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3209 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3210 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3211
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3212 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3213 * Get the screen attribute for a position in the buffer.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3214 * Use a negative "col" to get the filler background color.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3215 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3216 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3217 term_get_attr(buf_T *buf, linenr_T lnum, int col)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3218 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3219 term_T *term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3220 sb_line_T *line;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3221 cellattr_T *cellattr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3222
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3223 if (lnum > term->tl_scrollback.ga_len)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3224 cellattr = &term->tl_default_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3225 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3226 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3227 line = (sb_line_T *)term->tl_scrollback.ga_data + lnum - 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3228 if (col < 0 || col >= line->sb_cols)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3229 cellattr = &line->sb_fill_attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3230 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3231 cellattr = line->sb_cells + col;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3232 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3233 return cell2attr(cellattr->attrs, cellattr->fg, cellattr->bg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3234 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3235
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3236 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3237 * Convert a cterm color number 0 - 255 to RGB.
12541
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
3238 * This is compatible with xterm.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3239 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3240 static void
13823
d0d8125ba692 patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13750
diff changeset
3241 cterm_color2vterm(int nr, VTermColor *rgb)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3242 {
13823
d0d8125ba692 patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13750
diff changeset
3243 cterm_color2rgb(nr, &rgb->red, &rgb->green, &rgb->blue, &rgb->ansi_index);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3244 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3245
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3246 /*
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3247 * Initialize term->tl_default_color from the environment.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3248 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3249 static void
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3250 init_default_colors(term_T *term)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3251 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3252 VTermColor *fg, *bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3253 int fgval, bgval;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3254 int id;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3255
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3256 vim_memset(&term->tl_default_color.attrs, 0, sizeof(VTermScreenCellAttrs));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3257 term->tl_default_color.width = 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3258 fg = &term->tl_default_color.fg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3259 bg = &term->tl_default_color.bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3260
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3261 /* Vterm uses a default black background. Set it to white when
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3262 * 'background' is "light". */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3263 if (*p_bg == 'l')
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3264 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3265 fgval = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3266 bgval = 255;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3267 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3268 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3269 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3270 fgval = 255;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3271 bgval = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3272 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3273 fg->red = fg->green = fg->blue = fgval;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3274 bg->red = bg->green = bg->blue = bgval;
12973
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3275 fg->ansi_index = bg->ansi_index = VTERM_ANSI_INDEX_DEFAULT;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3276
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3277 /* The "Terminal" highlight group overrules the defaults. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3278 id = syn_name2id((char_u *)"Terminal");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3279
12966
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
3280 /* Use the actual color for the GUI and when 'termguicolors' is set. */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3281 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3282 if (0
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3283 # ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3284 || gui.in_use
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3285 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3286 # ifdef FEAT_TERMGUICOLORS
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3287 || p_tgc
13823
d0d8125ba692 patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13750
diff changeset
3288 # ifdef FEAT_VTP
d0d8125ba692 patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13750
diff changeset
3289 /* Finally get INVALCOLOR on this execution path */
d0d8125ba692 patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13750
diff changeset
3290 || (!p_tgc && t_colors >= 256)
d0d8125ba692 patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13750
diff changeset
3291 # endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3292 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3293 )
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3294 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3295 guicolor_T fg_rgb = INVALCOLOR;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3296 guicolor_T bg_rgb = INVALCOLOR;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3297
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3298 if (id != 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3299 syn_id2colors(id, &fg_rgb, &bg_rgb);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3300
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3301 # ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3302 if (gui.in_use)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3303 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3304 if (fg_rgb == INVALCOLOR)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3305 fg_rgb = gui.norm_pixel;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3306 if (bg_rgb == INVALCOLOR)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3307 bg_rgb = gui.back_pixel;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3308 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3309 # ifdef FEAT_TERMGUICOLORS
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3310 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3311 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3312 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3313 # ifdef FEAT_TERMGUICOLORS
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3314 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3315 if (fg_rgb == INVALCOLOR)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3316 fg_rgb = cterm_normal_fg_gui_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3317 if (bg_rgb == INVALCOLOR)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3318 bg_rgb = cterm_normal_bg_gui_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3319 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3320 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3321 if (fg_rgb != INVALCOLOR)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3322 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3323 long_u rgb = GUI_MCH_GET_RGB(fg_rgb);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3324
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3325 fg->red = (unsigned)(rgb >> 16);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3326 fg->green = (unsigned)(rgb >> 8) & 255;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3327 fg->blue = (unsigned)rgb & 255;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3328 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3329 if (bg_rgb != INVALCOLOR)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3330 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3331 long_u rgb = GUI_MCH_GET_RGB(bg_rgb);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3332
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3333 bg->red = (unsigned)(rgb >> 16);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3334 bg->green = (unsigned)(rgb >> 8) & 255;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3335 bg->blue = (unsigned)rgb & 255;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3336 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3337 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3338 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3339 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3340 if (id != 0 && t_colors >= 16)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3341 {
12973
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3342 if (term_default_cterm_fg >= 0)
13823
d0d8125ba692 patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13750
diff changeset
3343 cterm_color2vterm(term_default_cterm_fg, fg);
12973
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3344 if (term_default_cterm_bg >= 0)
13823
d0d8125ba692 patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13750
diff changeset
3345 cterm_color2vterm(term_default_cterm_bg, bg);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3346 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3347 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3348 {
12632
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
3349 #if defined(WIN3264) && !defined(FEAT_GUI_W32)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3350 int tmp;
12632
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
3351 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3352
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3353 /* In an MS-Windows console we know the normal colors. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3354 if (cterm_normal_fg_color > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3355 {
13823
d0d8125ba692 patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13750
diff changeset
3356 cterm_color2vterm(cterm_normal_fg_color - 1, fg);
12632
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
3357 # if defined(WIN3264) && !defined(FEAT_GUI_W32)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3358 tmp = fg->red;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3359 fg->red = fg->blue;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3360 fg->blue = tmp;
12632
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
3361 # endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3362 }
12634
94566ecb55f0 patch 8.0.1195: can't build on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 12632
diff changeset
3363 # ifdef FEAT_TERMRESPONSE
12632
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
3364 else
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
3365 term_get_fg_color(&fg->red, &fg->green, &fg->blue);
12634
94566ecb55f0 patch 8.0.1195: can't build on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 12632
diff changeset
3366 # endif
12632
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
3367
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3368 if (cterm_normal_bg_color > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3369 {
13823
d0d8125ba692 patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13750
diff changeset
3370 cterm_color2vterm(cterm_normal_bg_color - 1, bg);
12632
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
3371 # if defined(WIN3264) && !defined(FEAT_GUI_W32)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3372 tmp = bg->red;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3373 bg->red = bg->blue;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3374 bg->blue = tmp;
12632
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
3375 # endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3376 }
12634
94566ecb55f0 patch 8.0.1195: can't build on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 12632
diff changeset
3377 # ifdef FEAT_TERMRESPONSE
12632
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
3378 else
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
3379 term_get_bg_color(&bg->red, &bg->green, &bg->blue);
12634
94566ecb55f0 patch 8.0.1195: can't build on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 12632
diff changeset
3380 # endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3381 }
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3382 }
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3383
13626
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3384 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3385 /*
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3386 * Set the 16 ANSI colors from array of RGB values
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3387 */
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3388 static void
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3389 set_vterm_palette(VTerm *vterm, long_u *rgb)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3390 {
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3391 int index = 0;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3392 VTermState *state = vterm_obtain_state(vterm);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3393 for (; index < 16; index++)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3394 {
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3395 VTermColor color;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3396 color.red = (unsigned)(rgb[index] >> 16);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3397 color.green = (unsigned)(rgb[index] >> 8) & 255;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3398 color.blue = (unsigned)rgb[index] & 255;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3399 vterm_state_set_palette_color(state, index, &color);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3400 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3401 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3402
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3403 /*
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3404 * Set the ANSI color palette from a list of colors
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3405 */
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3406 static int
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3407 set_ansi_colors_list(VTerm *vterm, list_T *list)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3408 {
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3409 int n = 0;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3410 long_u rgb[16];
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3411 listitem_T *li = list->lv_first;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3412
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3413 for (; li != NULL && n < 16; li = li->li_next, n++)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3414 {
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3415 char_u *color_name;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3416 guicolor_T guicolor;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3417
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3418 color_name = get_tv_string_chk(&li->li_tv);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3419 if (color_name == NULL)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3420 return FAIL;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3421
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3422 guicolor = GUI_GET_COLOR(color_name);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3423 if (guicolor == INVALCOLOR)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3424 return FAIL;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3425
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3426 rgb[n] = GUI_MCH_GET_RGB(guicolor);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3427 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3428
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3429 if (n != 16 || li != NULL)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3430 return FAIL;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3431
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3432 set_vterm_palette(vterm, rgb);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3433
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3434 return OK;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3435 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3436
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3437 /*
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3438 * Initialize the ANSI color palette from g:terminal_ansi_colors[0:15]
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3439 */
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3440 static void
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3441 init_vterm_ansi_colors(VTerm *vterm)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3442 {
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3443 dictitem_T *var = find_var((char_u *)"g:terminal_ansi_colors", NULL, TRUE);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3444
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3445 if (var != NULL
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3446 && (var->di_tv.v_type != VAR_LIST
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3447 || var->di_tv.vval.v_list == NULL
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3448 || set_ansi_colors_list(vterm, var->di_tv.vval.v_list) == FAIL))
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3449 EMSG2(_(e_invarg2), "g:terminal_ansi_colors");
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3450 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3451 #endif
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3452
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3453 /*
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3454 * Handles a "drop" command from the job in the terminal.
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3455 * "item" is the file name, "item->li_next" may have options.
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3456 */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3457 static void
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3458 handle_drop_command(listitem_T *item)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3459 {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3460 char_u *fname = get_tv_string(&item->li_tv);
13575
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3461 listitem_T *opt_item = item->li_next;
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3462 int bufnr;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3463 win_T *wp;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3464 tabpage_T *tp;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3465 exarg_T ea;
13575
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3466 char_u *tofree = NULL;
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3467
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3468 bufnr = buflist_add(fname, BLN_LISTED | BLN_NOOPT);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3469 FOR_ALL_TAB_WINDOWS(tp, wp)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3470 {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3471 if (wp->w_buffer->b_fnum == bufnr)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3472 {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3473 /* buffer is in a window already, go there */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3474 goto_tabpage_win(tp, wp);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3475 return;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3476 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3477 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3478
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3479 vim_memset(&ea, 0, sizeof(ea));
13575
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3480
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3481 if (opt_item != NULL && opt_item->li_tv.v_type == VAR_DICT
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3482 && opt_item->li_tv.vval.v_dict != NULL)
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3483 {
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3484 dict_T *dict = opt_item->li_tv.vval.v_dict;
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3485 char_u *p;
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3486
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3487 p = get_dict_string(dict, (char_u *)"ff", FALSE);
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3488 if (p == NULL)
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3489 p = get_dict_string(dict, (char_u *)"fileformat", FALSE);
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3490 if (p != NULL)
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3491 {
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3492 if (check_ff_value(p) == FAIL)
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3493 ch_log(NULL, "Invalid ff argument to drop: %s", p);
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3494 else
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3495 ea.force_ff = *p;
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3496 }
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3497 p = get_dict_string(dict, (char_u *)"enc", FALSE);
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3498 if (p == NULL)
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3499 p = get_dict_string(dict, (char_u *)"encoding", FALSE);
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3500 if (p != NULL)
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3501 {
13583
200ef826e7dd patch 8.0.1664: test failure because of not allocating enough space
Christian Brabandt <cb@256bit.org>
parents: 13579
diff changeset
3502 ea.cmd = alloc((int)STRLEN(p) + 12);
13575
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3503 if (ea.cmd != NULL)
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3504 {
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3505 sprintf((char *)ea.cmd, "sbuf ++enc=%s", p);
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3506 ea.force_enc = 11;
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3507 tofree = ea.cmd;
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3508 }
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3509 }
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3510
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3511 p = get_dict_string(dict, (char_u *)"bad", FALSE);
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3512 if (p != NULL)
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3513 get_bad_opt(p, &ea);
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3514
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3515 if (dict_find(dict, (char_u *)"bin", -1) != NULL)
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3516 ea.force_bin = FORCE_BIN;
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3517 if (dict_find(dict, (char_u *)"binary", -1) != NULL)
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3518 ea.force_bin = FORCE_BIN;
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3519 if (dict_find(dict, (char_u *)"nobin", -1) != NULL)
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3520 ea.force_bin = FORCE_NOBIN;
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3521 if (dict_find(dict, (char_u *)"nobinary", -1) != NULL)
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3522 ea.force_bin = FORCE_NOBIN;
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3523 }
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3524
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3525 /* open in new window, like ":split fname" */
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3526 if (ea.cmd == NULL)
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3527 ea.cmd = (char_u *)"split";
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3528 ea.arg = fname;
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3529 ea.cmdidx = CMD_split;
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3530 ex_splitview(&ea);
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3531
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3532 vim_free(tofree);
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3533 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3534
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3535 /*
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3536 * Handles a function call from the job running in a terminal.
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3537 * "item" is the function name, "item->li_next" has the arguments.
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3538 */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3539 static void
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3540 handle_call_command(term_T *term, channel_T *channel, listitem_T *item)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3541 {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3542 char_u *func;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3543 typval_T argvars[2];
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3544 typval_T rettv;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3545 int doesrange;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3546
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3547 if (item->li_next == NULL)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3548 {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3549 ch_log(channel, "Missing function arguments for call");
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3550 return;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3551 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3552 func = get_tv_string(&item->li_tv);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3553
13547
87a9c1be0ae3 patch 8.0.1647: terminal API may call any user function
Christian Brabandt <cb@256bit.org>
parents: 13535
diff changeset
3554 if (STRNCMP(func, "Tapi_", 5) != 0)
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3555 {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3556 ch_log(channel, "Invalid function name: %s", func);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3557 return;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3558 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3559
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3560 argvars[0].v_type = VAR_NUMBER;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3561 argvars[0].vval.v_number = term->tl_buffer->b_fnum;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3562 argvars[1] = item->li_next->li_tv;
13577
4cb743db55b3 patch 8.0.1661: warnings from 64 bit compiler
Christian Brabandt <cb@256bit.org>
parents: 13575
diff changeset
3563 if (call_func(func, (int)STRLEN(func), &rettv,
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3564 2, argvars, /* argv_func */ NULL,
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3565 /* firstline */ 1, /* lastline */ 1,
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3566 &doesrange, /* evaluate */ TRUE,
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3567 /* partial */ NULL, /* selfdict */ NULL) == OK)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3568 {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3569 clear_tv(&rettv);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3570 ch_log(channel, "Function %s called", func);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3571 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3572 else
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3573 ch_log(channel, "Calling function %s failed", func);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3574 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3575
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3576 /*
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3577 * Called by libvterm when it cannot recognize an OSC sequence.
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3578 * We recognize a terminal API command.
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3579 */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3580 static int
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3581 parse_osc(const char *command, size_t cmdlen, void *user)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3582 {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3583 term_T *term = (term_T *)user;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3584 js_read_T reader;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3585 typval_T tv;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3586 channel_T *channel = term->tl_job == NULL ? NULL
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3587 : term->tl_job->jv_channel;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3588
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3589 /* We recognize only OSC 5 1 ; {command} */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3590 if (cmdlen < 3 || STRNCMP(command, "51;", 3) != 0)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3591 return 0; /* not handled */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3592
13577
4cb743db55b3 patch 8.0.1661: warnings from 64 bit compiler
Christian Brabandt <cb@256bit.org>
parents: 13575
diff changeset
3593 reader.js_buf = vim_strnsave((char_u *)command + 3, (int)(cmdlen - 3));
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3594 if (reader.js_buf == NULL)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3595 return 1;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3596 reader.js_fill = NULL;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3597 reader.js_used = 0;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3598 if (json_decode(&reader, &tv, 0) == OK
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3599 && tv.v_type == VAR_LIST
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3600 && tv.vval.v_list != NULL)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3601 {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3602 listitem_T *item = tv.vval.v_list->lv_first;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3603
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3604 if (item == NULL)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3605 ch_log(channel, "Missing command");
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3606 else
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3607 {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3608 char_u *cmd = get_tv_string(&item->li_tv);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3609
13720
7d2039b2ecc8 patch 8.0.1732: crash when terminal API call deletes the buffer
Christian Brabandt <cb@256bit.org>
parents: 13700
diff changeset
3610 /* Make sure an invoked command doesn't delete the buffer (and the
7d2039b2ecc8 patch 8.0.1732: crash when terminal API call deletes the buffer
Christian Brabandt <cb@256bit.org>
parents: 13700
diff changeset
3611 * terminal) under our fingers. */
7d2039b2ecc8 patch 8.0.1732: crash when terminal API call deletes the buffer
Christian Brabandt <cb@256bit.org>
parents: 13700
diff changeset
3612 ++term->tl_buffer->b_locked;
7d2039b2ecc8 patch 8.0.1732: crash when terminal API call deletes the buffer
Christian Brabandt <cb@256bit.org>
parents: 13700
diff changeset
3613
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3614 item = item->li_next;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3615 if (item == NULL)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3616 ch_log(channel, "Missing argument for %s", cmd);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3617 else if (STRCMP(cmd, "drop") == 0)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3618 handle_drop_command(item);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3619 else if (STRCMP(cmd, "call") == 0)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3620 handle_call_command(term, channel, item);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3621 else
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3622 ch_log(channel, "Invalid command received: %s", cmd);
13720
7d2039b2ecc8 patch 8.0.1732: crash when terminal API call deletes the buffer
Christian Brabandt <cb@256bit.org>
parents: 13700
diff changeset
3623 --term->tl_buffer->b_locked;
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3624 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3625 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3626 else
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3627 ch_log(channel, "Invalid JSON received");
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3628
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3629 vim_free(reader.js_buf);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3630 clear_tv(&tv);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3631 return 1;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3632 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3633
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3634 static VTermParserCallbacks parser_fallbacks = {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3635 NULL, /* text */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3636 NULL, /* control */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3637 NULL, /* escape */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3638 NULL, /* csi */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3639 parse_osc, /* osc */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3640 NULL, /* dcs */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3641 NULL /* resize */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3642 };
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3643
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3644 /*
13616
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3645 * Use Vim's allocation functions for vterm so profiling works.
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3646 */
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3647 static void *
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3648 vterm_malloc(size_t size, void *data UNUSED)
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3649 {
13630
fd3389d64825 patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents: 13626
diff changeset
3650 return alloc_clear((unsigned) size);
13616
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3651 }
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3652
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3653 static void
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3654 vterm_memfree(void *ptr, void *data UNUSED)
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3655 {
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3656 vim_free(ptr);
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3657 }
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3658
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3659 static VTermAllocatorFunctions vterm_allocator = {
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3660 &vterm_malloc,
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3661 &vterm_memfree
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3662 };
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3663
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3664 /*
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3665 * Create a new vterm and initialize it.
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3666 */
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3667 static void
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3668 create_vterm(term_T *term, int rows, int cols)
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3669 {
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3670 VTerm *vterm;
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3671 VTermScreen *screen;
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3672 VTermState *state;
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3673 VTermValue value;
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3674
13616
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3675 vterm = vterm_new_with_allocator(rows, cols, &vterm_allocator, NULL);
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3676 term->tl_vterm = vterm;
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3677 screen = vterm_obtain_screen(vterm);
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3678 vterm_screen_set_callbacks(screen, &screen_callbacks, term);
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3679 /* TODO: depends on 'encoding'. */
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3680 vterm_set_utf8(vterm, 1);
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3681
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3682 init_default_colors(term);
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3683
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3684 vterm_state_set_default_colors(
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3685 vterm_obtain_state(vterm),
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3686 &term->tl_default_color.fg,
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3687 &term->tl_default_color.bg);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3688
13626
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3689 if (t_colors >= 16)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3690 vterm_state_set_bold_highbright(vterm_obtain_state(vterm), 1);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3691
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3692 /* Required to initialize most things. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3693 vterm_screen_reset(screen, 1 /* hard */);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3694
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3695 /* Allow using alternate screen. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3696 vterm_screen_enable_altscreen(screen, 1);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3697
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3698 /* For unix do not use a blinking cursor. In an xterm this causes the
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3699 * cursor to blink if it's blinking in the xterm.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3700 * For Windows we respect the system wide setting. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3701 #ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3702 if (GetCaretBlinkTime() == INFINITE)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3703 value.boolean = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3704 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3705 value.boolean = 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3706 #else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3707 value.boolean = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3708 #endif
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3709 state = vterm_obtain_state(vterm);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3710 vterm_state_set_termprop(state, VTERM_PROP_CURSORBLINK, &value);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3711 vterm_state_set_unrecognised_fallbacks(state, &parser_fallbacks, term);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3712 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3713
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3714 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3715 * Return the text to show for the buffer name and status.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3716 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3717 char_u *
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3718 term_get_status_text(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3719 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3720 if (term->tl_status_text == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3721 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3722 char_u *txt;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3723 size_t len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3724
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3725 if (term->tl_normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3726 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3727 if (term_job_running(term))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3728 txt = (char_u *)_("Terminal");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3729 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3730 txt = (char_u *)_("Terminal-finished");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3731 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3732 else if (term->tl_title != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3733 txt = term->tl_title;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3734 else if (term_none_open(term))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3735 txt = (char_u *)_("active");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3736 else if (term_job_running(term))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3737 txt = (char_u *)_("running");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3738 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3739 txt = (char_u *)_("finished");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3740 len = 9 + STRLEN(term->tl_buffer->b_fname) + STRLEN(txt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3741 term->tl_status_text = alloc((int)len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3742 if (term->tl_status_text != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3743 vim_snprintf((char *)term->tl_status_text, len, "%s [%s]",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3744 term->tl_buffer->b_fname, txt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3745 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3746 return term->tl_status_text;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3747 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3748
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3749 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3750 * Mark references in jobs of terminals.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3751 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3752 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3753 set_ref_in_term(int copyID)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3754 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3755 int abort = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3756 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3757 typval_T tv;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3758
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3759 for (term = first_term; term != NULL; term = term->tl_next)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3760 if (term->tl_job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3761 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3762 tv.v_type = VAR_JOB;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3763 tv.vval.v_job = term->tl_job;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3764 abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3765 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3766 return abort;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3767 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3768
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3769 /*
12973
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3770 * Cache "Terminal" highlight group colors.
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3771 */
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3772 void
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3773 set_terminal_default_colors(int cterm_fg, int cterm_bg)
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3774 {
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3775 term_default_cterm_fg = cterm_fg - 1;
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3776 term_default_cterm_bg = cterm_bg - 1;
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3777 }
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3778
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3779 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3780 * Get the buffer from the first argument in "argvars".
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
3781 * Returns NULL when the buffer is not for a terminal window and logs a message
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
3782 * with "where".
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3783 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3784 static buf_T *
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
3785 term_get_buf(typval_T *argvars, char *where)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3786 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3787 buf_T *buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3788
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3789 (void)get_tv_number(&argvars[0]); /* issue errmsg if type error */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3790 ++emsg_off;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3791 buf = get_buf_tv(&argvars[0], FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3792 --emsg_off;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3793 if (buf == NULL || buf->b_term == NULL)
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
3794 {
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
3795 ch_log(NULL, "%s: invalid buffer argument", where);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3796 return NULL;
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
3797 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3798 return buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3799 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3800
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3801 static int
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3802 same_color(VTermColor *a, VTermColor *b)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3803 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3804 return a->red == b->red
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3805 && a->green == b->green
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3806 && a->blue == b->blue
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3807 && a->ansi_index == b->ansi_index;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3808 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3809
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3810 static void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3811 dump_term_color(FILE *fd, VTermColor *color)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3812 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3813 fprintf(fd, "%02x%02x%02x%d",
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3814 (int)color->red, (int)color->green, (int)color->blue,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3815 (int)color->ansi_index);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3816 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3817
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3818 /*
13329
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3819 * "term_dumpwrite(buf, filename, options)" function
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3820 *
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3821 * Each screen cell in full is:
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3822 * |{characters}+{attributes}#{fg-color}{color-idx}#{bg-color}{color-idx}
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3823 * {characters} is a space for an empty cell
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3824 * For a double-width character "+" is changed to "*" and the next cell is
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3825 * skipped.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3826 * {attributes} is the decimal value of HL_BOLD + HL_UNDERLINE, etc.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3827 * when "&" use the same as the previous cell.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3828 * {fg-color} is hex RGB, when "&" use the same as the previous cell.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3829 * {bg-color} is hex RGB, when "&" use the same as the previous cell.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3830 * {color-idx} is a number from 0 to 255
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3831 *
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3832 * Screen cell with same width, attributes and color as the previous one:
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3833 * |{characters}
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3834 *
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3835 * To use the color of the previous cell, use "&" instead of {color}-{idx}.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3836 *
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3837 * Repeating the previous screen cell:
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3838 * @{count}
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3839 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3840 void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3841 f_term_dumpwrite(typval_T *argvars, typval_T *rettv UNUSED)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3842 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
3843 buf_T *buf = term_get_buf(argvars, "term_dumpwrite()");
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3844 term_T *term;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3845 char_u *fname;
13329
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3846 int max_height = 0;
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3847 int max_width = 0;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3848 stat_T st;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3849 FILE *fd;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3850 VTermPos pos;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3851 VTermScreen *screen;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3852 VTermScreenCell prev_cell;
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
3853 VTermState *state;
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
3854 VTermPos cursor_pos;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3855
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3856 if (check_restricted() || check_secure())
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3857 return;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3858 if (buf == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3859 return;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3860 term = buf->b_term;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3861
13329
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3862 if (argvars[2].v_type != VAR_UNKNOWN)
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3863 {
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3864 dict_T *d;
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3865
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3866 if (argvars[2].v_type != VAR_DICT)
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3867 {
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3868 EMSG(_(e_dictreq));
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3869 return;
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3870 }
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3871 d = argvars[2].vval.v_dict;
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3872 if (d != NULL)
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3873 {
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3874 max_height = get_dict_number(d, (char_u *)"rows");
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3875 max_width = get_dict_number(d, (char_u *)"columns");
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3876 }
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3877 }
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3878
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3879 fname = get_tv_string_chk(&argvars[1]);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3880 if (fname == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3881 return;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3882 if (mch_stat((char *)fname, &st) >= 0)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3883 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3884 EMSG2(_("E953: File exists: %s"), fname);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3885 return;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3886 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3887
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3888 if (*fname == NUL || (fd = mch_fopen((char *)fname, WRITEBIN)) == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3889 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3890 EMSG2(_(e_notcreate), *fname == NUL ? (char_u *)_("<empty>") : fname);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3891 return;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3892 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3893
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3894 vim_memset(&prev_cell, 0, sizeof(prev_cell));
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3895
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3896 screen = vterm_obtain_screen(term->tl_vterm);
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
3897 state = vterm_obtain_state(term->tl_vterm);
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
3898 vterm_state_get_cursorpos(state, &cursor_pos);
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
3899
13329
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3900 for (pos.row = 0; (max_height == 0 || pos.row < max_height)
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3901 && pos.row < term->tl_rows; ++pos.row)
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3902 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3903 int repeat = 0;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3904
13329
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3905 for (pos.col = 0; (max_width == 0 || pos.col < max_width)
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3906 && pos.col < term->tl_cols; ++pos.col)
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3907 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3908 VTermScreenCell cell;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3909 int same_attr;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3910 int same_chars = TRUE;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3911 int i;
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
3912 int is_cursor_pos = (pos.col == cursor_pos.col
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
3913 && pos.row == cursor_pos.row);
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3914
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3915 if (vterm_screen_get_cell(screen, pos, &cell) == 0)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3916 vim_memset(&cell, 0, sizeof(cell));
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3917
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3918 for (i = 0; i < VTERM_MAX_CHARS_PER_CELL; ++i)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3919 {
13517
d0d66898e98b patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents: 13505
diff changeset
3920 int c = cell.chars[i];
d0d66898e98b patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents: 13505
diff changeset
3921 int pc = prev_cell.chars[i];
d0d66898e98b patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents: 13505
diff changeset
3922
d0d66898e98b patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents: 13505
diff changeset
3923 /* For the first character NUL is the same as space. */
d0d66898e98b patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents: 13505
diff changeset
3924 if (i == 0)
d0d66898e98b patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents: 13505
diff changeset
3925 {
d0d66898e98b patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents: 13505
diff changeset
3926 c = (c == NUL) ? ' ' : c;
d0d66898e98b patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents: 13505
diff changeset
3927 pc = (pc == NUL) ? ' ' : pc;
d0d66898e98b patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents: 13505
diff changeset
3928 }
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3929 if (cell.chars[i] != prev_cell.chars[i])
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3930 same_chars = FALSE;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3931 if (cell.chars[i] == NUL || prev_cell.chars[i] == NUL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3932 break;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3933 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3934 same_attr = vtermAttr2hl(cell.attrs)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3935 == vtermAttr2hl(prev_cell.attrs)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3936 && same_color(&cell.fg, &prev_cell.fg)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3937 && same_color(&cell.bg, &prev_cell.bg);
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
3938 if (same_chars && cell.width == prev_cell.width && same_attr
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
3939 && !is_cursor_pos)
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3940 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3941 ++repeat;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3942 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3943 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3944 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3945 if (repeat > 0)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3946 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3947 fprintf(fd, "@%d", repeat);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3948 repeat = 0;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3949 }
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
3950 fputs(is_cursor_pos ? ">" : "|", fd);
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3951
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3952 if (cell.chars[0] == NUL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3953 fputs(" ", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3954 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3955 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3956 char_u charbuf[10];
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3957 int len;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3958
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3959 for (i = 0; i < VTERM_MAX_CHARS_PER_CELL
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3960 && cell.chars[i] != NUL; ++i)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3961 {
13557
4911058c43eb patch 8.0.1652: term_dumpwrite() does not output composing characters
Christian Brabandt <cb@256bit.org>
parents: 13547
diff changeset
3962 len = utf_char2bytes(cell.chars[i], charbuf);
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3963 fwrite(charbuf, len, 1, fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3964 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3965 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3966
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3967 /* When only the characters differ we don't write anything, the
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3968 * following "|", "@" or NL will indicate using the same
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3969 * attributes. */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3970 if (cell.width != prev_cell.width || !same_attr)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3971 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3972 if (cell.width == 2)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3973 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3974 fputs("*", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3975 ++pos.col;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3976 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3977 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3978 fputs("+", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3979
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3980 if (same_attr)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3981 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3982 fputs("&", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3983 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3984 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3985 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3986 fprintf(fd, "%d", vtermAttr2hl(cell.attrs));
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3987 if (same_color(&cell.fg, &prev_cell.fg))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3988 fputs("&", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3989 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3990 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3991 fputs("#", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3992 dump_term_color(fd, &cell.fg);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3993 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3994 if (same_color(&cell.bg, &prev_cell.bg))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3995 fputs("&", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3996 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3997 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3998 fputs("#", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3999 dump_term_color(fd, &cell.bg);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4000 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4001 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4002 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4003
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4004 prev_cell = cell;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4005 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4006 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4007 if (repeat > 0)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4008 fprintf(fd, "@%d", repeat);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4009 fputs("\n", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4010 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4011
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4012 fclose(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4013 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4014
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4015 /*
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4016 * Called when a dump is corrupted. Put a breakpoint here when debugging.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4017 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4018 static void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4019 dump_is_corrupt(garray_T *gap)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4020 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4021 ga_concat(gap, (char_u *)"CORRUPT");
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4022 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4023
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4024 static void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4025 append_cell(garray_T *gap, cellattr_T *cell)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4026 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4027 if (ga_grow(gap, 1) == OK)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4028 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4029 *(((cellattr_T *)gap->ga_data) + gap->ga_len) = *cell;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4030 ++gap->ga_len;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4031 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4032 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4033
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4034 /*
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4035 * Read the dump file from "fd" and append lines to the current buffer.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4036 * Return the cell width of the longest line.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4037 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4038 static int
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4039 read_dump_file(FILE *fd, VTermPos *cursor_pos)
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4040 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4041 int c;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4042 garray_T ga_text;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4043 garray_T ga_cell;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4044 char_u *prev_char = NULL;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4045 int attr = 0;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4046 cellattr_T cell;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4047 term_T *term = curbuf->b_term;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4048 int max_cells = 0;
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4049 int start_row = term->tl_scrollback.ga_len;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4050
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4051 ga_init2(&ga_text, 1, 90);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4052 ga_init2(&ga_cell, sizeof(cellattr_T), 90);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4053 vim_memset(&cell, 0, sizeof(cell));
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4054 cursor_pos->row = -1;
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4055 cursor_pos->col = -1;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4056
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4057 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4058 for (;;)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4059 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4060 if (c == EOF)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4061 break;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4062 if (c == '\n')
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4063 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4064 /* End of a line: append it to the buffer. */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4065 if (ga_text.ga_data == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4066 dump_is_corrupt(&ga_text);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4067 if (ga_grow(&term->tl_scrollback, 1) == OK)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4068 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4069 sb_line_T *line = (sb_line_T *)term->tl_scrollback.ga_data
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4070 + term->tl_scrollback.ga_len;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4071
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4072 if (max_cells < ga_cell.ga_len)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4073 max_cells = ga_cell.ga_len;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4074 line->sb_cols = ga_cell.ga_len;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4075 line->sb_cells = ga_cell.ga_data;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4076 line->sb_fill_attr = term->tl_default_color;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4077 ++term->tl_scrollback.ga_len;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4078 ga_init(&ga_cell);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4079
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4080 ga_append(&ga_text, NUL);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4081 ml_append(curbuf->b_ml.ml_line_count, ga_text.ga_data,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4082 ga_text.ga_len, FALSE);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4083 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4084 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4085 ga_clear(&ga_cell);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4086 ga_text.ga_len = 0;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4087
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4088 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4089 }
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4090 else if (c == '|' || c == '>')
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4091 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4092 int prev_len = ga_text.ga_len;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4093
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4094 if (c == '>')
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4095 {
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4096 if (cursor_pos->row != -1)
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4097 dump_is_corrupt(&ga_text); /* duplicate cursor */
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4098 cursor_pos->row = term->tl_scrollback.ga_len - start_row;
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4099 cursor_pos->col = ga_cell.ga_len;
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4100 }
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4101
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4102 /* normal character(s) followed by "+", "*", "|", "@" or NL */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4103 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4104 if (c != EOF)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4105 ga_append(&ga_text, c);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4106 for (;;)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4107 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4108 c = fgetc(fd);
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4109 if (c == '+' || c == '*' || c == '|' || c == '>' || c == '@'
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4110 || c == EOF || c == '\n')
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4111 break;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4112 ga_append(&ga_text, c);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4113 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4114
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4115 /* save the character for repeating it */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4116 vim_free(prev_char);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4117 if (ga_text.ga_data != NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4118 prev_char = vim_strnsave(((char_u *)ga_text.ga_data) + prev_len,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4119 ga_text.ga_len - prev_len);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4120
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4121 if (c == '@' || c == '|' || c == '>' || c == '\n')
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4122 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4123 /* use all attributes from previous cell */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4124 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4125 else if (c == '+' || c == '*')
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4126 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4127 int is_bg;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4128
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4129 cell.width = c == '+' ? 1 : 2;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4130
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4131 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4132 if (c == '&')
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4133 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4134 /* use same attr as previous cell */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4135 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4136 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4137 else if (isdigit(c))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4138 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4139 /* get the decimal attribute */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4140 attr = 0;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4141 while (isdigit(c))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4142 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4143 attr = attr * 10 + (c - '0');
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4144 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4145 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4146 hl2vtermAttr(attr, &cell);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4147 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4148 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4149 dump_is_corrupt(&ga_text);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4150
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4151 /* is_bg == 0: fg, is_bg == 1: bg */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4152 for (is_bg = 0; is_bg <= 1; ++is_bg)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4153 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4154 if (c == '&')
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4155 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4156 /* use same color as previous cell */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4157 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4158 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4159 else if (c == '#')
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4160 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4161 int red, green, blue, index = 0;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4162
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4163 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4164 red = hex2nr(c);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4165 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4166 red = (red << 4) + hex2nr(c);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4167 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4168 green = hex2nr(c);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4169 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4170 green = (green << 4) + hex2nr(c);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4171 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4172 blue = hex2nr(c);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4173 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4174 blue = (blue << 4) + hex2nr(c);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4175 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4176 if (!isdigit(c))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4177 dump_is_corrupt(&ga_text);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4178 while (isdigit(c))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4179 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4180 index = index * 10 + (c - '0');
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4181 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4182 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4183
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4184 if (is_bg)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4185 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4186 cell.bg.red = red;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4187 cell.bg.green = green;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4188 cell.bg.blue = blue;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4189 cell.bg.ansi_index = index;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4190 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4191 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4192 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4193 cell.fg.red = red;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4194 cell.fg.green = green;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4195 cell.fg.blue = blue;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4196 cell.fg.ansi_index = index;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4197 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4198 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4199 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4200 dump_is_corrupt(&ga_text);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4201 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4202 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4203 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4204 dump_is_corrupt(&ga_text);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4205
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4206 append_cell(&ga_cell, &cell);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4207 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4208 else if (c == '@')
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4209 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4210 if (prev_char == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4211 dump_is_corrupt(&ga_text);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4212 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4213 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4214 int count = 0;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4215
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4216 /* repeat previous character, get the count */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4217 for (;;)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4218 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4219 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4220 if (!isdigit(c))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4221 break;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4222 count = count * 10 + (c - '0');
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4223 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4224
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4225 while (count-- > 0)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4226 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4227 ga_concat(&ga_text, prev_char);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4228 append_cell(&ga_cell, &cell);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4229 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4230 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4231 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4232 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4233 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4234 dump_is_corrupt(&ga_text);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4235 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4236 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4237 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4238
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4239 if (ga_text.ga_len > 0)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4240 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4241 /* trailing characters after last NL */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4242 dump_is_corrupt(&ga_text);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4243 ga_append(&ga_text, NUL);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4244 ml_append(curbuf->b_ml.ml_line_count, ga_text.ga_data,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4245 ga_text.ga_len, FALSE);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4246 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4247
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4248 ga_clear(&ga_text);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4249 vim_free(prev_char);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4250
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4251 return max_cells;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4252 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4253
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4254 /*
13579
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4255 * Return an allocated string with at least "text_width" "=" characters and
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4256 * "fname" inserted in the middle.
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4257 */
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4258 static char_u *
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4259 get_separator(int text_width, char_u *fname)
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4260 {
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4261 int width = MAX(text_width, curwin->w_width);
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4262 char_u *textline;
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4263 int fname_size;
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4264 char_u *p = fname;
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4265 int i;
13630
fd3389d64825 patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents: 13626
diff changeset
4266 size_t off;
fd3389d64825 patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents: 13626
diff changeset
4267
fd3389d64825 patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents: 13626
diff changeset
4268 textline = alloc(width + (int)STRLEN(fname) + 1);
13579
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4269 if (textline == NULL)
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4270 return NULL;
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4271
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4272 fname_size = vim_strsize(fname);
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4273 if (fname_size < width - 8)
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4274 {
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4275 /* enough room, don't use the full window width */
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4276 width = MAX(text_width, fname_size + 8);
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4277 }
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4278 else if (fname_size > width - 8)
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4279 {
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4280 /* full name doesn't fit, use only the tail */
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4281 p = gettail(fname);
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4282 fname_size = vim_strsize(p);
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4283 }
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4284 /* skip characters until the name fits */
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4285 while (fname_size > width - 8)
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4286 {
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4287 p += (*mb_ptr2len)(p);
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4288 fname_size = vim_strsize(p);
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4289 }
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4290
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4291 for (i = 0; i < (width - fname_size) / 2 - 1; ++i)
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4292 textline[i] = '=';
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4293 textline[i++] = ' ';
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4294
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4295 STRCPY(textline + i, p);
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4296 off = STRLEN(textline);
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4297 textline[off] = ' ';
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4298 for (i = 1; i < (width - fname_size) / 2; ++i)
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4299 textline[off + i] = '=';
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4300 textline[off + i] = NUL;
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4301
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4302 return textline;
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4303 }
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4304
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4305 /*
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4306 * Common for "term_dumpdiff()" and "term_dumpload()".
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4307 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4308 static void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4309 term_load_dump(typval_T *argvars, typval_T *rettv, int do_diff)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4310 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4311 jobopt_T opt;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4312 buf_T *buf;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4313 char_u buf1[NUMBUFLEN];
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4314 char_u buf2[NUMBUFLEN];
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4315 char_u *fname1;
13300
803294329951 patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents: 13298
diff changeset
4316 char_u *fname2 = NULL;
13501
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4317 char_u *fname_tofree = NULL;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4318 FILE *fd1;
13300
803294329951 patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents: 13298
diff changeset
4319 FILE *fd2 = NULL;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4320 char_u *textline = NULL;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4321
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4322 /* First open the files. If this fails bail out. */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4323 fname1 = get_tv_string_buf_chk(&argvars[0], buf1);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4324 if (do_diff)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4325 fname2 = get_tv_string_buf_chk(&argvars[1], buf2);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4326 if (fname1 == NULL || (do_diff && fname2 == NULL))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4327 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4328 EMSG(_(e_invarg));
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4329 return;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4330 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4331 fd1 = mch_fopen((char *)fname1, READBIN);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4332 if (fd1 == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4333 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4334 EMSG2(_(e_notread), fname1);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4335 return;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4336 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4337 if (do_diff)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4338 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4339 fd2 = mch_fopen((char *)fname2, READBIN);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4340 if (fd2 == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4341 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4342 fclose(fd1);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4343 EMSG2(_(e_notread), fname2);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4344 return;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4345 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4346 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4347
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4348 init_job_options(&opt);
13501
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4349 if (argvars[do_diff ? 2 : 1].v_type != VAR_UNKNOWN
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4350 && get_job_options(&argvars[do_diff ? 2 : 1], &opt, 0,
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4351 JO2_TERM_NAME + JO2_TERM_COLS + JO2_TERM_ROWS
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4352 + JO2_VERTICAL + JO2_CURWIN + JO2_NORESTORE) == FAIL)
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4353 goto theend;
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4354
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4355 if (opt.jo_term_name == NULL)
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4356 {
13505
a784ef72b617 patch 8.0.1626: compiler warning for possible loss of data
Christian Brabandt <cb@256bit.org>
parents: 13501
diff changeset
4357 size_t len = STRLEN(fname1) + 12;
a784ef72b617 patch 8.0.1626: compiler warning for possible loss of data
Christian Brabandt <cb@256bit.org>
parents: 13501
diff changeset
4358
a784ef72b617 patch 8.0.1626: compiler warning for possible loss of data
Christian Brabandt <cb@256bit.org>
parents: 13501
diff changeset
4359 fname_tofree = alloc((int)len);
13501
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4360 if (fname_tofree != NULL)
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4361 {
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4362 vim_snprintf((char *)fname_tofree, len, "dump diff %s", fname1);
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4363 opt.jo_term_name = fname_tofree;
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4364 }
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4365 }
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4366
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
4367 buf = term_start(&argvars[0], NULL, &opt, TERM_START_NOJOB);
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4368 if (buf != NULL && buf->b_term != NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4369 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4370 int i;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4371 linenr_T bot_lnum;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4372 linenr_T lnum;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4373 term_T *term = buf->b_term;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4374 int width;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4375 int width2;
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4376 VTermPos cursor_pos1;
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4377 VTermPos cursor_pos2;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4378
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
4379 init_default_colors(term);
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
4380
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4381 rettv->vval.v_number = buf->b_fnum;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4382
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4383 /* read the files, fill the buffer with the diff */
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4384 width = read_dump_file(fd1, &cursor_pos1);
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4385
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4386 /* position the cursor */
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4387 if (cursor_pos1.row >= 0)
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4388 {
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4389 curwin->w_cursor.lnum = cursor_pos1.row + 1;
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4390 coladvance(cursor_pos1.col);
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4391 }
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4392
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4393 /* Delete the empty line that was in the empty buffer. */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4394 ml_delete(1, FALSE);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4395
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4396 /* For term_dumpload() we are done here. */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4397 if (!do_diff)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4398 goto theend;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4399
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4400 term->tl_top_diff_rows = curbuf->b_ml.ml_line_count;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4401
13579
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4402 textline = get_separator(width, fname1);
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4403 if (textline == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4404 goto theend;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4405 if (add_empty_scrollback(term, &term->tl_default_color, 0) == OK)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4406 ml_append(curbuf->b_ml.ml_line_count, textline, 0, FALSE);
13579
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4407 vim_free(textline);
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4408
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4409 textline = get_separator(width, fname2);
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4410 if (textline == NULL)
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4411 goto theend;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4412 if (add_empty_scrollback(term, &term->tl_default_color, 0) == OK)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4413 ml_append(curbuf->b_ml.ml_line_count, textline, 0, FALSE);
13579
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4414 textline[width] = NUL;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4415
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4416 bot_lnum = curbuf->b_ml.ml_line_count;
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4417 width2 = read_dump_file(fd2, &cursor_pos2);
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4418 if (width2 > width)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4419 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4420 vim_free(textline);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4421 textline = alloc(width2 + 1);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4422 if (textline == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4423 goto theend;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4424 width = width2;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4425 textline[width] = NUL;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4426 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4427 term->tl_bot_diff_rows = curbuf->b_ml.ml_line_count - bot_lnum;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4428
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4429 for (lnum = 1; lnum <= term->tl_top_diff_rows; ++lnum)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4430 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4431 if (lnum + bot_lnum > curbuf->b_ml.ml_line_count)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4432 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4433 /* bottom part has fewer rows, fill with "-" */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4434 for (i = 0; i < width; ++i)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4435 textline[i] = '-';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4436 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4437 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4438 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4439 char_u *line1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4440 char_u *line2;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4441 char_u *p1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4442 char_u *p2;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4443 int col;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4444 sb_line_T *sb_line = (sb_line_T *)term->tl_scrollback.ga_data;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4445 cellattr_T *cellattr1 = (sb_line + lnum - 1)->sb_cells;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4446 cellattr_T *cellattr2 = (sb_line + lnum + bot_lnum - 1)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4447 ->sb_cells;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4448
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4449 /* Make a copy, getting the second line will invalidate it. */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4450 line1 = vim_strsave(ml_get(lnum));
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4451 if (line1 == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4452 break;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4453 p1 = line1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4454
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4455 line2 = ml_get(lnum + bot_lnum);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4456 p2 = line2;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4457 for (col = 0; col < width && *p1 != NUL && *p2 != NUL; ++col)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4458 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4459 int len1 = utfc_ptr2len(p1);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4460 int len2 = utfc_ptr2len(p2);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4461
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4462 textline[col] = ' ';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4463 if (len1 != len2 || STRNCMP(p1, p2, len1) != 0)
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4464 /* text differs */
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4465 textline[col] = 'X';
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4466 else if (lnum == cursor_pos1.row + 1
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4467 && col == cursor_pos1.col
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4468 && (cursor_pos1.row != cursor_pos2.row
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4469 || cursor_pos1.col != cursor_pos2.col))
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4470 /* cursor in first but not in second */
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4471 textline[col] = '>';
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4472 else if (lnum == cursor_pos2.row + 1
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4473 && col == cursor_pos2.col
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4474 && (cursor_pos1.row != cursor_pos2.row
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4475 || cursor_pos1.col != cursor_pos2.col))
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4476 /* cursor in second but not in first */
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4477 textline[col] = '<';
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4478 else if (cellattr1 != NULL && cellattr2 != NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4479 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4480 if ((cellattr1 + col)->width
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4481 != (cellattr2 + col)->width)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4482 textline[col] = 'w';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4483 else if (!same_color(&(cellattr1 + col)->fg,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4484 &(cellattr2 + col)->fg))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4485 textline[col] = 'f';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4486 else if (!same_color(&(cellattr1 + col)->bg,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4487 &(cellattr2 + col)->bg))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4488 textline[col] = 'b';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4489 else if (vtermAttr2hl((cellattr1 + col)->attrs)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4490 != vtermAttr2hl(((cellattr2 + col)->attrs)))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4491 textline[col] = 'a';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4492 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4493 p1 += len1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4494 p2 += len2;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4495 /* TODO: handle different width */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4496 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4497 vim_free(line1);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4498
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4499 while (col < width)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4500 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4501 if (*p1 == NUL && *p2 == NUL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4502 textline[col] = '?';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4503 else if (*p1 == NUL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4504 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4505 textline[col] = '+';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4506 p2 += utfc_ptr2len(p2);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4507 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4508 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4509 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4510 textline[col] = '-';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4511 p1 += utfc_ptr2len(p1);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4512 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4513 ++col;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4514 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4515 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4516 if (add_empty_scrollback(term, &term->tl_default_color,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4517 term->tl_top_diff_rows) == OK)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4518 ml_append(term->tl_top_diff_rows + lnum, textline, 0, FALSE);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4519 ++bot_lnum;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4520 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4521
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4522 while (lnum + bot_lnum <= curbuf->b_ml.ml_line_count)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4523 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4524 /* bottom part has more rows, fill with "+" */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4525 for (i = 0; i < width; ++i)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4526 textline[i] = '+';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4527 if (add_empty_scrollback(term, &term->tl_default_color,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4528 term->tl_top_diff_rows) == OK)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4529 ml_append(term->tl_top_diff_rows + lnum, textline, 0, FALSE);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4530 ++lnum;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4531 ++bot_lnum;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4532 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4533
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4534 term->tl_cols = width;
13579
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4535
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4536 /* looks better without wrapping */
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4537 curwin->w_p_wrap = 0;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4538 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4539
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4540 theend:
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4541 vim_free(textline);
13501
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4542 vim_free(fname_tofree);
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4543 fclose(fd1);
13300
803294329951 patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents: 13298
diff changeset
4544 if (fd2 != NULL)
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4545 fclose(fd2);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4546 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4547
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4548 /*
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4549 * If the current buffer shows the output of term_dumpdiff(), swap the top and
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4550 * bottom files.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4551 * Return FAIL when this is not possible.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4552 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4553 int
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4554 term_swap_diff()
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4555 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4556 term_T *term = curbuf->b_term;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4557 linenr_T line_count;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4558 linenr_T top_rows;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4559 linenr_T bot_rows;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4560 linenr_T bot_start;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4561 linenr_T lnum;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4562 char_u *p;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4563 sb_line_T *sb_line;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4564
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4565 if (term == NULL
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4566 || !term_is_finished(curbuf)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4567 || term->tl_top_diff_rows == 0
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4568 || term->tl_scrollback.ga_len == 0)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4569 return FAIL;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4570
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4571 line_count = curbuf->b_ml.ml_line_count;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4572 top_rows = term->tl_top_diff_rows;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4573 bot_rows = term->tl_bot_diff_rows;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4574 bot_start = line_count - bot_rows;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4575 sb_line = (sb_line_T *)term->tl_scrollback.ga_data;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4576
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4577 /* move lines from top to above the bottom part */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4578 for (lnum = 1; lnum <= top_rows; ++lnum)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4579 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4580 p = vim_strsave(ml_get(1));
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4581 if (p == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4582 return OK;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4583 ml_append(bot_start, p, 0, FALSE);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4584 ml_delete(1, FALSE);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4585 vim_free(p);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4586 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4587
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4588 /* move lines from bottom to the top */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4589 for (lnum = 1; lnum <= bot_rows; ++lnum)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4590 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4591 p = vim_strsave(ml_get(bot_start + lnum));
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4592 if (p == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4593 return OK;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4594 ml_delete(bot_start + lnum, FALSE);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4595 ml_append(lnum - 1, p, 0, FALSE);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4596 vim_free(p);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4597 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4598
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4599 if (top_rows == bot_rows)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4600 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4601 /* rows counts are equal, can swap cell properties */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4602 for (lnum = 0; lnum < top_rows; ++lnum)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4603 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4604 sb_line_T temp;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4605
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4606 temp = *(sb_line + lnum);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4607 *(sb_line + lnum) = *(sb_line + bot_start + lnum);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4608 *(sb_line + bot_start + lnum) = temp;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4609 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4610 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4611 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4612 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4613 size_t size = sizeof(sb_line_T) * term->tl_scrollback.ga_len;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4614 sb_line_T *temp = (sb_line_T *)alloc((int)size);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4615
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4616 /* need to copy cell properties into temp memory */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4617 if (temp != NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4618 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4619 mch_memmove(temp, term->tl_scrollback.ga_data, size);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4620 mch_memmove(term->tl_scrollback.ga_data,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4621 temp + bot_start,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4622 sizeof(sb_line_T) * bot_rows);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4623 mch_memmove((sb_line_T *)term->tl_scrollback.ga_data + bot_rows,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4624 temp + top_rows,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4625 sizeof(sb_line_T) * (line_count - top_rows - bot_rows));
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4626 mch_memmove((sb_line_T *)term->tl_scrollback.ga_data
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4627 + line_count - top_rows,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4628 temp,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4629 sizeof(sb_line_T) * top_rows);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4630 vim_free(temp);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4631 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4632 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4633
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4634 term->tl_top_diff_rows = bot_rows;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4635 term->tl_bot_diff_rows = top_rows;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4636
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4637 update_screen(NOT_VALID);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4638 return OK;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4639 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4640
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4641 /*
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4642 * "term_dumpdiff(filename, filename, options)" function
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4643 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4644 void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4645 f_term_dumpdiff(typval_T *argvars, typval_T *rettv)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4646 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4647 term_load_dump(argvars, rettv, TRUE);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4648 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4649
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4650 /*
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4651 * "term_dumpload(filename, options)" function
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4652 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4653 void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4654 f_term_dumpload(typval_T *argvars, typval_T *rettv)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4655 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4656 term_load_dump(argvars, rettv, FALSE);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4657 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4658
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4659 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4660 * "term_getaltscreen(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4661 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4662 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4663 f_term_getaltscreen(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4664 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4665 buf_T *buf = term_get_buf(argvars, "term_getaltscreen()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4666
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4667 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4668 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4669 rettv->vval.v_number = buf->b_term->tl_using_altscreen;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4670 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4671
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4672 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4673 * "term_getattr(attr, name)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4674 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4675 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4676 f_term_getattr(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4677 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4678 int attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4679 size_t i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4680 char_u *name;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4681
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4682 static struct {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4683 char *name;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4684 int attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4685 } attrs[] = {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4686 {"bold", HL_BOLD},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4687 {"italic", HL_ITALIC},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4688 {"underline", HL_UNDERLINE},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4689 {"strike", HL_STRIKETHROUGH},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4690 {"reverse", HL_INVERSE},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4691 };
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4692
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4693 attr = get_tv_number(&argvars[0]);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4694 name = get_tv_string_chk(&argvars[1]);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4695 if (name == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4696 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4697
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4698 for (i = 0; i < sizeof(attrs)/sizeof(attrs[0]); ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4699 if (STRCMP(name, attrs[i].name) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4700 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4701 rettv->vval.v_number = (attr & attrs[i].attr) != 0 ? 1 : 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4702 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4703 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4704 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4705
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4706 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4707 * "term_getcursor(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4708 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4709 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4710 f_term_getcursor(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4711 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4712 buf_T *buf = term_get_buf(argvars, "term_getcursor()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4713 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4714 list_T *l;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4715 dict_T *d;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4716
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4717 if (rettv_list_alloc(rettv) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4718 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4719 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4720 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4721 term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4722
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4723 l = rettv->vval.v_list;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4724 list_append_number(l, term->tl_cursor_pos.row + 1);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4725 list_append_number(l, term->tl_cursor_pos.col + 1);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4726
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4727 d = dict_alloc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4728 if (d != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4729 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4730 dict_add_nr_str(d, "visible", term->tl_cursor_visible, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4731 dict_add_nr_str(d, "blink", blink_state_is_inverted()
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4732 ? !term->tl_cursor_blink : term->tl_cursor_blink, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4733 dict_add_nr_str(d, "shape", term->tl_cursor_shape, NULL);
13990
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
4734 dict_add_nr_str(d, "color", 0L, cursor_color_get(term->tl_cursor_color));
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4735 list_append_dict(l, d);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4736 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4737 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4738
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4739 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4740 * "term_getjob(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4741 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4742 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4743 f_term_getjob(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4744 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4745 buf_T *buf = term_get_buf(argvars, "term_getjob()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4746
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4747 rettv->v_type = VAR_JOB;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4748 rettv->vval.v_job = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4749 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4750 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4751
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4752 rettv->vval.v_job = buf->b_term->tl_job;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4753 if (rettv->vval.v_job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4754 ++rettv->vval.v_job->jv_refcount;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4755 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4756
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4757 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4758 get_row_number(typval_T *tv, term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4759 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4760 if (tv->v_type == VAR_STRING
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4761 && tv->vval.v_string != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4762 && STRCMP(tv->vval.v_string, ".") == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4763 return term->tl_cursor_pos.row;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4764 return (int)get_tv_number(tv) - 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4765 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4766
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4767 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4768 * "term_getline(buf, row)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4769 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4770 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4771 f_term_getline(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4772 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4773 buf_T *buf = term_get_buf(argvars, "term_getline()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4774 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4775 int row;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4776
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4777 rettv->v_type = VAR_STRING;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4778 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4779 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4780 term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4781 row = get_row_number(&argvars[1], term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4782
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4783 if (term->tl_vterm == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4784 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4785 linenr_T lnum = row + term->tl_scrollback_scrolled + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4786
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4787 /* vterm is finished, get the text from the buffer */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4788 if (lnum > 0 && lnum <= buf->b_ml.ml_line_count)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4789 rettv->vval.v_string = vim_strsave(ml_get_buf(buf, lnum, FALSE));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4790 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4791 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4792 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4793 VTermScreen *screen = vterm_obtain_screen(term->tl_vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4794 VTermRect rect;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4795 int len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4796 char_u *p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4797
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4798 if (row < 0 || row >= term->tl_rows)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4799 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4800 len = term->tl_cols * MB_MAXBYTES + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4801 p = alloc(len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4802 if (p == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4803 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4804 rettv->vval.v_string = p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4805
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4806 rect.start_col = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4807 rect.end_col = term->tl_cols;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4808 rect.start_row = row;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4809 rect.end_row = row + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4810 p[vterm_screen_get_text(screen, (char *)p, len, rect)] = NUL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4811 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4812 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4813
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4814 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4815 * "term_getscrolled(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4816 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4817 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4818 f_term_getscrolled(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4819 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4820 buf_T *buf = term_get_buf(argvars, "term_getscrolled()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4821
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4822 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4823 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4824 rettv->vval.v_number = buf->b_term->tl_scrollback_scrolled;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4825 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4826
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4827 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4828 * "term_getsize(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4829 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4830 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4831 f_term_getsize(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4832 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4833 buf_T *buf = term_get_buf(argvars, "term_getsize()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4834 list_T *l;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4835
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4836 if (rettv_list_alloc(rettv) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4837 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4838 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4839 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4840
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4841 l = rettv->vval.v_list;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4842 list_append_number(l, buf->b_term->tl_rows);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4843 list_append_number(l, buf->b_term->tl_cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4844 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4845
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4846 /*
13678
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4847 * "term_setsize(buf, rows, cols)" function
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4848 */
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4849 void
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4850 f_term_setsize(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4851 {
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4852 buf_T *buf = term_get_buf(argvars, "term_setsize()");
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4853 term_T *term;
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4854 varnumber_T rows, cols;
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4855
13684
1651a4c5c27a patch 8.0.1714: term_setsize() does not give an error in a normal buffer
Christian Brabandt <cb@256bit.org>
parents: 13680
diff changeset
4856 if (buf == NULL)
1651a4c5c27a patch 8.0.1714: term_setsize() does not give an error in a normal buffer
Christian Brabandt <cb@256bit.org>
parents: 13680
diff changeset
4857 {
1651a4c5c27a patch 8.0.1714: term_setsize() does not give an error in a normal buffer
Christian Brabandt <cb@256bit.org>
parents: 13680
diff changeset
4858 EMSG(_("E955: Not a terminal buffer"));
1651a4c5c27a patch 8.0.1714: term_setsize() does not give an error in a normal buffer
Christian Brabandt <cb@256bit.org>
parents: 13680
diff changeset
4859 return;
1651a4c5c27a patch 8.0.1714: term_setsize() does not give an error in a normal buffer
Christian Brabandt <cb@256bit.org>
parents: 13680
diff changeset
4860 }
1651a4c5c27a patch 8.0.1714: term_setsize() does not give an error in a normal buffer
Christian Brabandt <cb@256bit.org>
parents: 13680
diff changeset
4861 if (buf->b_term->tl_vterm == NULL)
13678
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4862 return;
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4863 term = buf->b_term;
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4864 rows = get_tv_number(&argvars[1]);
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4865 rows = rows <= 0 ? term->tl_rows : rows;
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4866 cols = get_tv_number(&argvars[2]);
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4867 cols = cols <= 0 ? term->tl_cols : cols;
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4868 vterm_set_size(term->tl_vterm, rows, cols);
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4869 /* handle_resize() will resize the windows */
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4870
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4871 /* Get and remember the size we ended up with. Update the pty. */
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4872 vterm_get_size(term->tl_vterm, &term->tl_rows, &term->tl_cols);
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4873 term_report_winsize(term, term->tl_rows, term->tl_cols);
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4874 }
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4875
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4876 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4877 * "term_getstatus(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4878 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4879 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4880 f_term_getstatus(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4881 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4882 buf_T *buf = term_get_buf(argvars, "term_getstatus()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4883 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4884 char_u val[100];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4885
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4886 rettv->v_type = VAR_STRING;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4887 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4888 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4889 term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4890
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4891 if (term_job_running(term))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4892 STRCPY(val, "running");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4893 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4894 STRCPY(val, "finished");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4895 if (term->tl_normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4896 STRCAT(val, ",normal");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4897 rettv->vval.v_string = vim_strsave(val);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4898 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4899
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4900 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4901 * "term_gettitle(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4902 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4903 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4904 f_term_gettitle(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4905 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4906 buf_T *buf = term_get_buf(argvars, "term_gettitle()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4907
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4908 rettv->v_type = VAR_STRING;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4909 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4910 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4911
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4912 if (buf->b_term->tl_title != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4913 rettv->vval.v_string = vim_strsave(buf->b_term->tl_title);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4914 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4915
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4916 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4917 * "term_gettty(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4918 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4919 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4920 f_term_gettty(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4921 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4922 buf_T *buf = term_get_buf(argvars, "term_gettty()");
13864
de8455bd2d05 patch 8.0.1803: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents: 13862
diff changeset
4923 char_u *p = NULL;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4924 int num = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4925
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4926 rettv->v_type = VAR_STRING;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4927 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4928 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4929 if (argvars[1].v_type != VAR_UNKNOWN)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4930 num = get_tv_number(&argvars[1]);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4931
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4932 switch (num)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4933 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4934 case 0:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4935 if (buf->b_term->tl_job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4936 p = buf->b_term->tl_job->jv_tty_out;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4937 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4938 case 1:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4939 if (buf->b_term->tl_job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4940 p = buf->b_term->tl_job->jv_tty_in;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4941 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4942 default:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4943 EMSG2(_(e_invarg2), get_tv_string(&argvars[1]));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4944 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4945 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4946 if (p != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4947 rettv->vval.v_string = vim_strsave(p);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4948 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4949
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4950 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4951 * "term_list()" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4952 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4953 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4954 f_term_list(typval_T *argvars UNUSED, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4955 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4956 term_T *tp;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4957 list_T *l;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4958
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4959 if (rettv_list_alloc(rettv) == FAIL || first_term == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4960 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4961
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4962 l = rettv->vval.v_list;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4963 for (tp = first_term; tp != NULL; tp = tp->tl_next)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4964 if (tp != NULL && tp->tl_buffer != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4965 if (list_append_number(l,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4966 (varnumber_T)tp->tl_buffer->b_fnum) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4967 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4968 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4969
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4970 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4971 * "term_scrape(buf, row)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4972 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4973 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4974 f_term_scrape(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4975 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4976 buf_T *buf = term_get_buf(argvars, "term_scrape()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4977 VTermScreen *screen = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4978 VTermPos pos;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4979 list_T *l;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4980 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4981 char_u *p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4982 sb_line_T *line;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4983
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4984 if (rettv_list_alloc(rettv) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4985 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4986 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4987 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4988 term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4989
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4990 l = rettv->vval.v_list;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4991 pos.row = get_row_number(&argvars[1], term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4992
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4993 if (term->tl_vterm != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4994 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4995 screen = vterm_obtain_screen(term->tl_vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4996 p = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4997 line = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4998 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4999 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5000 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5001 linenr_T lnum = pos.row + term->tl_scrollback_scrolled;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5002
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5003 if (lnum < 0 || lnum >= term->tl_scrollback.ga_len)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5004 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5005 p = ml_get_buf(buf, lnum + 1, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5006 line = (sb_line_T *)term->tl_scrollback.ga_data + lnum;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5007 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5008
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5009 for (pos.col = 0; pos.col < term->tl_cols; )
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5010 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5011 dict_T *dcell;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5012 int width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5013 VTermScreenCellAttrs attrs;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5014 VTermColor fg, bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5015 char_u rgb[8];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5016 char_u mbs[MB_MAXBYTES * VTERM_MAX_CHARS_PER_CELL + 1];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5017 int off = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5018 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5019
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5020 if (screen == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5021 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5022 cellattr_T *cellattr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5023 int len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5024
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5025 /* vterm has finished, get the cell from scrollback */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5026 if (pos.col >= line->sb_cols)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5027 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5028 cellattr = line->sb_cells + pos.col;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5029 width = cellattr->width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5030 attrs = cellattr->attrs;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5031 fg = cellattr->fg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5032 bg = cellattr->bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5033 len = MB_PTR2LEN(p);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5034 mch_memmove(mbs, p, len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5035 mbs[len] = NUL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5036 p += len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5037 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5038 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5039 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5040 VTermScreenCell cell;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5041 if (vterm_screen_get_cell(screen, pos, &cell) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5042 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5043 for (i = 0; i < VTERM_MAX_CHARS_PER_CELL; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5044 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5045 if (cell.chars[i] == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5046 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5047 off += (*utf_char2bytes)((int)cell.chars[i], mbs + off);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5048 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5049 mbs[off] = NUL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5050 width = cell.width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5051 attrs = cell.attrs;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5052 fg = cell.fg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5053 bg = cell.bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5054 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5055 dcell = dict_alloc();
13250
fc33325c91c1 patch 8.0.1499: out-of-memory situation not correctly handled
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
5056 if (dcell == NULL)
fc33325c91c1 patch 8.0.1499: out-of-memory situation not correctly handled
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
5057 break;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5058 list_append_dict(l, dcell);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5059
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5060 dict_add_nr_str(dcell, "chars", 0, mbs);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5061
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5062 vim_snprintf((char *)rgb, 8, "#%02x%02x%02x",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5063 fg.red, fg.green, fg.blue);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5064 dict_add_nr_str(dcell, "fg", 0, rgb);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5065 vim_snprintf((char *)rgb, 8, "#%02x%02x%02x",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5066 bg.red, bg.green, bg.blue);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5067 dict_add_nr_str(dcell, "bg", 0, rgb);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5068
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5069 dict_add_nr_str(dcell, "attr",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5070 cell2attr(attrs, fg, bg), NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5071 dict_add_nr_str(dcell, "width", width, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5072
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5073 ++pos.col;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5074 if (width == 2)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5075 ++pos.col;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5076 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5077 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5078
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5079 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5080 * "term_sendkeys(buf, keys)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5081 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5082 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5083 f_term_sendkeys(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5084 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5085 buf_T *buf = term_get_buf(argvars, "term_sendkeys()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5086 char_u *msg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5087 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5088
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5089 rettv->v_type = VAR_UNKNOWN;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5090 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5091 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5092
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5093 msg = get_tv_string_chk(&argvars[1]);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5094 if (msg == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5095 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5096 term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5097 if (term->tl_vterm == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5098 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5099
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5100 while (*msg != NUL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5101 {
14029
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 13996
diff changeset
5102 int c;
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 13996
diff changeset
5103
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 13996
diff changeset
5104 if (*msg == K_SPECIAL && msg[1] != NUL && msg[2] != NUL)
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 13996
diff changeset
5105 {
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 13996
diff changeset
5106 c = TO_SPECIAL(msg[1], msg[2]);
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 13996
diff changeset
5107 msg += 3;
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 13996
diff changeset
5108 }
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 13996
diff changeset
5109 else
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 13996
diff changeset
5110 {
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 13996
diff changeset
5111 c = PTR2CHAR(msg);
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 13996
diff changeset
5112 msg += MB_CPTR2LEN(msg);
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 13996
diff changeset
5113 }
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 13996
diff changeset
5114 send_keys_to_term(term, c, FALSE);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5115 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5116 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5117
13626
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5118 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) || defined(PROTO)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5119 /*
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5120 * "term_getansicolors(buf)" function
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5121 */
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5122 void
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5123 f_term_getansicolors(typval_T *argvars, typval_T *rettv)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5124 {
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5125 buf_T *buf = term_get_buf(argvars, "term_getansicolors()");
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5126 term_T *term;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5127 VTermState *state;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5128 VTermColor color;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5129 char_u hexbuf[10];
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5130 int index;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5131 list_T *list;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5132
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5133 if (rettv_list_alloc(rettv) == FAIL)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5134 return;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5135
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5136 if (buf == NULL)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5137 return;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5138 term = buf->b_term;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5139 if (term->tl_vterm == NULL)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5140 return;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5141
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5142 list = rettv->vval.v_list;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5143 state = vterm_obtain_state(term->tl_vterm);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5144 for (index = 0; index < 16; index++)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5145 {
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5146 vterm_state_get_palette_color(state, index, &color);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5147 sprintf((char *)hexbuf, "#%02x%02x%02x",
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5148 color.red, color.green, color.blue);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5149 if (list_append_string(list, hexbuf, 7) == FAIL)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5150 return;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5151 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5152 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5153
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5154 /*
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5155 * "term_setansicolors(buf, list)" function
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5156 */
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5157 void
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5158 f_term_setansicolors(typval_T *argvars, typval_T *rettv UNUSED)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5159 {
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5160 buf_T *buf = term_get_buf(argvars, "term_setansicolors()");
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5161 term_T *term;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5162
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5163 if (buf == NULL)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5164 return;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5165 term = buf->b_term;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5166 if (term->tl_vterm == NULL)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5167 return;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5168
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5169 if (argvars[1].v_type != VAR_LIST || argvars[1].vval.v_list == NULL)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5170 {
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5171 EMSG(_(e_listreq));
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5172 return;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5173 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5174
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5175 if (set_ansi_colors_list(term->tl_vterm, argvars[1].vval.v_list) == FAIL)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5176 EMSG(_(e_invarg));
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5177 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5178 #endif
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5179
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5180 /*
13435
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5181 * "term_setrestore(buf, command)" function
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5182 */
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5183 void
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5184 f_term_setrestore(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5185 {
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5186 #if defined(FEAT_SESSION)
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5187 buf_T *buf = term_get_buf(argvars, "term_setrestore()");
13435
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5188 term_T *term;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5189 char_u *cmd;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5190
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5191 if (buf == NULL)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5192 return;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5193 term = buf->b_term;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5194 vim_free(term->tl_command);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5195 cmd = get_tv_string_chk(&argvars[1]);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5196 if (cmd != NULL)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5197 term->tl_command = vim_strsave(cmd);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5198 else
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5199 term->tl_command = NULL;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5200 #endif
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5201 }
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5202
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5203 /*
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5204 * "term_setkill(buf, how)" function
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5205 */
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5206 void
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5207 f_term_setkill(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5208 {
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5209 buf_T *buf = term_get_buf(argvars, "term_setkill()");
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5210 term_T *term;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5211 char_u *how;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5212
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5213 if (buf == NULL)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5214 return;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5215 term = buf->b_term;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5216 vim_free(term->tl_kill);
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5217 how = get_tv_string_chk(&argvars[1]);
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5218 if (how != NULL)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5219 term->tl_kill = vim_strsave(how);
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5220 else
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5221 term->tl_kill = NULL;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5222 }
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5223
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5224 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5225 * "term_start(command, options)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5226 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5227 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5228 f_term_start(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5229 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5230 jobopt_T opt;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5231 buf_T *buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5232
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5233 init_job_options(&opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5234 if (argvars[1].v_type != VAR_UNKNOWN
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5235 && get_job_options(&argvars[1], &opt,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5236 JO_TIMEOUT_ALL + JO_STOPONEXIT
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5237 + JO_CALLBACK + JO_OUT_CALLBACK + JO_ERR_CALLBACK
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5238 + JO_EXIT_CB + JO_CLOSE_CALLBACK + JO_OUT_IO,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5239 JO2_TERM_NAME + JO2_TERM_FINISH + JO2_HIDDEN + JO2_TERM_OPENCMD
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5240 + JO2_TERM_COLS + JO2_TERM_ROWS + JO2_VERTICAL + JO2_CURWIN
13435
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5241 + JO2_CWD + JO2_ENV + JO2_EOF_CHARS
13626
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5242 + JO2_NORESTORE + JO2_TERM_KILL
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5243 + JO2_ANSI_COLORS) == FAIL)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5244 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5245
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
5246 buf = term_start(&argvars[0], NULL, &opt, 0);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5247
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5248 if (buf != NULL && buf->b_term != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5249 rettv->vval.v_number = buf->b_fnum;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5250 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5251
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5252 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5253 * "term_wait" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5254 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5255 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5256 f_term_wait(typval_T *argvars, typval_T *rettv UNUSED)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5257 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5258 buf_T *buf = term_get_buf(argvars, "term_wait()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5259
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5260 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5261 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5262 if (buf->b_term->tl_job == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5263 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5264 ch_log(NULL, "term_wait(): no job to wait for");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5265 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5266 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5267 if (buf->b_term->tl_job->jv_channel == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5268 /* channel is closed, nothing to do */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5269 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5270
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5271 /* Get the job status, this will detect a job that finished. */
13219
4b8d89ea9edb patch 8.0.1484: reduntant conditions
Christian Brabandt <cb@256bit.org>
parents: 13206
diff changeset
5272 if (!buf->b_term->tl_job->jv_channel->ch_keep_open
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5273 && STRCMP(job_status(buf->b_term->tl_job), "dead") == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5274 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5275 /* The job is dead, keep reading channel I/O until the channel is
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5276 * closed. buf->b_term may become NULL if the terminal was closed while
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5277 * waiting. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5278 ch_log(NULL, "term_wait(): waiting for channel to close");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5279 while (buf->b_term != NULL && !buf->b_term->tl_channel_closed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5280 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5281 mch_check_messages();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5282 parse_queued_messages();
13996
59121ffd7fce patch 8.1.0016: possible crash in term_wait()
Christian Brabandt <cb@256bit.org>
parents: 13994
diff changeset
5283 ui_delay(10L, FALSE);
12881
1c05b29ab125 patch 8.0.1317: accessing freed memory in term_wait()
Christian Brabandt <cb@256bit.org>
parents: 12865
diff changeset
5284 if (!buf_valid(buf))
1c05b29ab125 patch 8.0.1317: accessing freed memory in term_wait()
Christian Brabandt <cb@256bit.org>
parents: 12865
diff changeset
5285 /* If the terminal is closed when the channel is closed the
1c05b29ab125 patch 8.0.1317: accessing freed memory in term_wait()
Christian Brabandt <cb@256bit.org>
parents: 12865
diff changeset
5286 * buffer disappears. */
1c05b29ab125 patch 8.0.1317: accessing freed memory in term_wait()
Christian Brabandt <cb@256bit.org>
parents: 12865
diff changeset
5287 break;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5288 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5289 mch_check_messages();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5290 parse_queued_messages();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5291 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5292 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5293 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5294 long wait = 10L;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5295
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5296 mch_check_messages();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5297 parse_queued_messages();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5298
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5299 /* Wait for some time for any channel I/O. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5300 if (argvars[1].v_type != VAR_UNKNOWN)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5301 wait = get_tv_number(&argvars[1]);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5302 ui_delay(wait, TRUE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5303 mch_check_messages();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5304
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5305 /* Flushing messages on channels is hopefully sufficient.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5306 * TODO: is there a better way? */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5307 parse_queued_messages();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5308 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5309 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5310
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5311 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5312 * Called when a channel has sent all the lines to a terminal.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5313 * Send a CTRL-D to mark the end of the text.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5314 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5315 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5316 term_send_eof(channel_T *ch)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5317 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5318 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5319
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5320 for (term = first_term; term != NULL; term = term->tl_next)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5321 if (term->tl_job == ch->ch_job)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5322 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5323 if (term->tl_eof_chars != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5324 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5325 channel_send(ch, PART_IN, term->tl_eof_chars,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5326 (int)STRLEN(term->tl_eof_chars), NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5327 channel_send(ch, PART_IN, (char_u *)"\r", 1, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5328 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5329 # ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5330 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5331 /* Default: CTRL-D */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5332 channel_send(ch, PART_IN, (char_u *)"\004\r", 2, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5333 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5334 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5335 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5336
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5337 # if defined(WIN3264) || defined(PROTO)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5338
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5339 /**************************************
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5340 * 2. MS-Windows implementation.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5341 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5342
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5343 # ifndef PROTO
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5344
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5345 #define WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN 1ul
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5346 #define WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN 2ull
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
5347 #define WINPTY_MOUSE_MODE_FORCE 2
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5348
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5349 void* (*winpty_config_new)(UINT64, void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5350 void* (*winpty_open)(void*, void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5351 void* (*winpty_spawn_config_new)(UINT64, void*, LPCWSTR, void*, void*, void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5352 BOOL (*winpty_spawn)(void*, void*, HANDLE*, HANDLE*, DWORD*, void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5353 void (*winpty_config_set_mouse_mode)(void*, int);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5354 void (*winpty_config_set_initial_size)(void*, int, int);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5355 LPCWSTR (*winpty_conin_name)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5356 LPCWSTR (*winpty_conout_name)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5357 LPCWSTR (*winpty_conerr_name)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5358 void (*winpty_free)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5359 void (*winpty_config_free)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5360 void (*winpty_spawn_config_free)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5361 void (*winpty_error_free)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5362 LPCWSTR (*winpty_error_msg)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5363 BOOL (*winpty_set_size)(void*, int, int, void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5364 HANDLE (*winpty_agent_process)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5365
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5366 #define WINPTY_DLL "winpty.dll"
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5367
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5368 static HINSTANCE hWinPtyDLL = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5369 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5370
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5371 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5372 dyn_winpty_init(int verbose)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5373 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5374 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5375 static struct
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5376 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5377 char *name;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5378 FARPROC *ptr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5379 } winpty_entry[] =
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5380 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5381 {"winpty_conerr_name", (FARPROC*)&winpty_conerr_name},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5382 {"winpty_config_free", (FARPROC*)&winpty_config_free},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5383 {"winpty_config_new", (FARPROC*)&winpty_config_new},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5384 {"winpty_config_set_mouse_mode",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5385 (FARPROC*)&winpty_config_set_mouse_mode},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5386 {"winpty_config_set_initial_size",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5387 (FARPROC*)&winpty_config_set_initial_size},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5388 {"winpty_conin_name", (FARPROC*)&winpty_conin_name},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5389 {"winpty_conout_name", (FARPROC*)&winpty_conout_name},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5390 {"winpty_error_free", (FARPROC*)&winpty_error_free},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5391 {"winpty_free", (FARPROC*)&winpty_free},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5392 {"winpty_open", (FARPROC*)&winpty_open},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5393 {"winpty_spawn", (FARPROC*)&winpty_spawn},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5394 {"winpty_spawn_config_free", (FARPROC*)&winpty_spawn_config_free},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5395 {"winpty_spawn_config_new", (FARPROC*)&winpty_spawn_config_new},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5396 {"winpty_error_msg", (FARPROC*)&winpty_error_msg},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5397 {"winpty_set_size", (FARPROC*)&winpty_set_size},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5398 {"winpty_agent_process", (FARPROC*)&winpty_agent_process},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5399 {NULL, NULL}
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5400 };
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5401
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5402 /* No need to initialize twice. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5403 if (hWinPtyDLL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5404 return OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5405 /* Load winpty.dll, prefer using the 'winptydll' option, fall back to just
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5406 * winpty.dll. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5407 if (*p_winptydll != NUL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5408 hWinPtyDLL = vimLoadLib((char *)p_winptydll);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5409 if (!hWinPtyDLL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5410 hWinPtyDLL = vimLoadLib(WINPTY_DLL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5411 if (!hWinPtyDLL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5412 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5413 if (verbose)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5414 EMSG2(_(e_loadlib), *p_winptydll != NUL ? p_winptydll
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5415 : (char_u *)WINPTY_DLL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5416 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5417 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5418 for (i = 0; winpty_entry[i].name != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5419 && winpty_entry[i].ptr != NULL; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5420 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5421 if ((*winpty_entry[i].ptr = (FARPROC)GetProcAddress(hWinPtyDLL,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5422 winpty_entry[i].name)) == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5423 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5424 if (verbose)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5425 EMSG2(_(e_loadfunc), winpty_entry[i].name);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5426 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5427 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5428 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5429
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5430 return OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5431 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5432
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5433 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5434 * Create a new terminal of "rows" by "cols" cells.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5435 * Store a reference in "term".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5436 * Return OK or FAIL.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5437 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5438 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5439 term_and_job_init(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5440 term_T *term,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5441 typval_T *argvar,
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
5442 char **argv UNUSED,
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
5443 jobopt_T *opt,
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
5444 jobopt_T *orig_opt)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5445 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5446 WCHAR *cmd_wchar = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5447 WCHAR *cwd_wchar = NULL;
12724
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
5448 WCHAR *env_wchar = NULL;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5449 channel_T *channel = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5450 job_T *job = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5451 DWORD error;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5452 HANDLE jo = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5453 HANDLE child_process_handle;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5454 HANDLE child_thread_handle;
13111
149347fda678 patch 8.0.1430: crash when term_start() fails
Christian Brabandt <cb@256bit.org>
parents: 13109
diff changeset
5455 void *winpty_err = NULL;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5456 void *spawn_config = NULL;
12724
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
5457 garray_T ga_cmd, ga_env;
13109
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
5458 char_u *cmd = NULL;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5459
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5460 if (dyn_winpty_init(TRUE) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5461 return FAIL;
13109
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
5462 ga_init2(&ga_cmd, (int)sizeof(char*), 20);
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
5463 ga_init2(&ga_env, (int)sizeof(char*), 20);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5464
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5465 if (argvar->v_type == VAR_STRING)
13109
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
5466 {
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5467 cmd = argvar->vval.v_string;
13109
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
5468 }
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
5469 else if (argvar->v_type == VAR_LIST)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5470 {
12724
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
5471 if (win32_build_cmd(argvar->vval.v_list, &ga_cmd) == FAIL)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5472 goto failed;
12724
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
5473 cmd = ga_cmd.ga_data;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5474 }
13109
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
5475 if (cmd == NULL || *cmd == NUL)
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
5476 {
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
5477 EMSG(_(e_invarg));
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
5478 goto failed;
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
5479 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5480
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5481 cmd_wchar = enc_to_utf16(cmd, NULL);
13109
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
5482 ga_clear(&ga_cmd);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5483 if (cmd_wchar == NULL)
13109
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
5484 goto failed;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5485 if (opt->jo_cwd != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5486 cwd_wchar = enc_to_utf16(opt->jo_cwd, NULL);
12907
32531a3eab1f patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents: 12903
diff changeset
5487
32531a3eab1f patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents: 12903
diff changeset
5488 win32_build_env(opt->jo_env, &ga_env, TRUE);
32531a3eab1f patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents: 12903
diff changeset
5489 env_wchar = ga_env.ga_data;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5490
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5491 term->tl_winpty_config = winpty_config_new(0, &winpty_err);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5492 if (term->tl_winpty_config == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5493 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5494
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5495 winpty_config_set_mouse_mode(term->tl_winpty_config,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5496 WINPTY_MOUSE_MODE_FORCE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5497 winpty_config_set_initial_size(term->tl_winpty_config,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5498 term->tl_cols, term->tl_rows);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5499 term->tl_winpty = winpty_open(term->tl_winpty_config, &winpty_err);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5500 if (term->tl_winpty == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5501 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5503 spawn_config = winpty_spawn_config_new(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5504 WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN |
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5505 WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5506 NULL,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5507 cmd_wchar,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5508 cwd_wchar,
12724
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
5509 env_wchar,
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5510 &winpty_err);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5511 if (spawn_config == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5512 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5513
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5514 channel = add_channel();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5515 if (channel == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5516 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5517
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5518 job = job_alloc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5519 if (job == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5520 goto failed;
13750
3ab6198c1f9a patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents: 13746
diff changeset
5521 if (argvar->v_type == VAR_STRING)
3ab6198c1f9a patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents: 13746
diff changeset
5522 {
3ab6198c1f9a patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents: 13746
diff changeset
5523 int argc;
3ab6198c1f9a patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents: 13746
diff changeset
5524
3ab6198c1f9a patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents: 13746
diff changeset
5525 build_argv_from_string(cmd, &job->jv_argv, &argc);
3ab6198c1f9a patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents: 13746
diff changeset
5526 }
3ab6198c1f9a patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents: 13746
diff changeset
5527 else
3ab6198c1f9a patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents: 13746
diff changeset
5528 {
3ab6198c1f9a patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents: 13746
diff changeset
5529 int argc;
3ab6198c1f9a patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents: 13746
diff changeset
5530
3ab6198c1f9a patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents: 13746
diff changeset
5531 build_argv_from_list(argvar->vval.v_list, &job->jv_argv, &argc);
3ab6198c1f9a patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents: 13746
diff changeset
5532 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5533
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5534 if (opt->jo_set & JO_IN_BUF)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5535 job->jv_in_buf = buflist_findnr(opt->jo_io_buf[PART_IN]);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5536
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5537 if (!winpty_spawn(term->tl_winpty, spawn_config, &child_process_handle,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5538 &child_thread_handle, &error, &winpty_err))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5539 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5540
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5541 channel_set_pipes(channel,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5542 (sock_T)CreateFileW(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5543 winpty_conin_name(term->tl_winpty),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5544 GENERIC_WRITE, 0, NULL,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5545 OPEN_EXISTING, 0, NULL),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5546 (sock_T)CreateFileW(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5547 winpty_conout_name(term->tl_winpty),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5548 GENERIC_READ, 0, NULL,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5549 OPEN_EXISTING, 0, NULL),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5550 (sock_T)CreateFileW(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5551 winpty_conerr_name(term->tl_winpty),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5552 GENERIC_READ, 0, NULL,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5553 OPEN_EXISTING, 0, NULL));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5554
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5555 /* Write lines with CR instead of NL. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5556 channel->ch_write_text_mode = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5557
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5558 jo = CreateJobObject(NULL, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5559 if (jo == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5560 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5561
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5562 if (!AssignProcessToJobObject(jo, child_process_handle))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5563 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5564 /* Failed, switch the way to terminate process with TerminateProcess. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5565 CloseHandle(jo);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5566 jo = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5567 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5568
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5569 winpty_spawn_config_free(spawn_config);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5570 vim_free(cmd_wchar);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5571 vim_free(cwd_wchar);
13109
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
5572 vim_free(env_wchar);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5573
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5574 create_vterm(term, term->tl_rows, term->tl_cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5575
13626
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5576 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5577 if (opt->jo_set2 & JO2_ANSI_COLORS)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5578 set_vterm_palette(term->tl_vterm, opt->jo_ansi_colors);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5579 else
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5580 init_vterm_ansi_colors(term->tl_vterm);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5581 #endif
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5582
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5583 channel_set_job(channel, job, opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5584 job_set_options(job, opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5585
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5586 job->jv_channel = channel;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5587 job->jv_proc_info.hProcess = child_process_handle;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5588 job->jv_proc_info.dwProcessId = GetProcessId(child_process_handle);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5589 job->jv_job_object = jo;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5590 job->jv_status = JOB_STARTED;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5591 job->jv_tty_in = utf16_to_enc(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5592 (short_u*)winpty_conin_name(term->tl_winpty), NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5593 job->jv_tty_out = utf16_to_enc(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5594 (short_u*)winpty_conout_name(term->tl_winpty), NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5595 ++job->jv_refcount;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5596 term->tl_job = job;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5597
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
5598 /* Redirecting stdout and stderr doesn't work at the job level. Instead
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
5599 * open the file here and handle it in. opt->jo_io was changed in
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
5600 * setup_job_options(), use the original flags here. */
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
5601 if (orig_opt->jo_io[PART_OUT] == JIO_FILE)
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
5602 {
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
5603 char_u *fname = opt->jo_io_name[PART_OUT];
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
5604
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
5605 ch_log(channel, "Opening output file %s", fname);
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
5606 term->tl_out_fd = mch_fopen((char *)fname, WRITEBIN);
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
5607 if (term->tl_out_fd == NULL)
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
5608 EMSG2(_(e_notopen), fname);
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
5609 }
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
5610
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5611 return OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5612
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5613 failed:
13109
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
5614 ga_clear(&ga_cmd);
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
5615 ga_clear(&ga_env);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5616 vim_free(cmd_wchar);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5617 vim_free(cwd_wchar);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5618 if (spawn_config != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5619 winpty_spawn_config_free(spawn_config);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5620 if (channel != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5621 channel_clear(channel);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5622 if (job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5623 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5624 job->jv_channel = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5625 job_cleanup(job);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5626 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5627 term->tl_job = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5628 if (jo != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5629 CloseHandle(jo);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5630 if (term->tl_winpty != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5631 winpty_free(term->tl_winpty);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5632 term->tl_winpty = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5633 if (term->tl_winpty_config != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5634 winpty_config_free(term->tl_winpty_config);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5635 term->tl_winpty_config = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5636 if (winpty_err != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5637 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5638 char_u *msg = utf16_to_enc(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5639 (short_u *)winpty_error_msg(winpty_err), NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5640
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5641 EMSG(msg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5642 winpty_error_free(winpty_err);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5643 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5644 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5645 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5646
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5647 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5648 create_pty_only(term_T *term, jobopt_T *options)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5649 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5650 HANDLE hPipeIn = INVALID_HANDLE_VALUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5651 HANDLE hPipeOut = INVALID_HANDLE_VALUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5652 char in_name[80], out_name[80];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5653 channel_T *channel = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5654
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5655 create_vterm(term, term->tl_rows, term->tl_cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5656
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5657 vim_snprintf(in_name, sizeof(in_name), "\\\\.\\pipe\\vim-%d-in-%d",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5658 GetCurrentProcessId(),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5659 curbuf->b_fnum);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5660 hPipeIn = CreateNamedPipe(in_name, PIPE_ACCESS_OUTBOUND,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5661 PIPE_TYPE_MESSAGE | PIPE_NOWAIT,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5662 PIPE_UNLIMITED_INSTANCES,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5663 0, 0, NMPWAIT_NOWAIT, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5664 if (hPipeIn == INVALID_HANDLE_VALUE)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5665 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5666
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5667 vim_snprintf(out_name, sizeof(out_name), "\\\\.\\pipe\\vim-%d-out-%d",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5668 GetCurrentProcessId(),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5669 curbuf->b_fnum);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5670 hPipeOut = CreateNamedPipe(out_name, PIPE_ACCESS_INBOUND,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5671 PIPE_TYPE_MESSAGE | PIPE_NOWAIT,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5672 PIPE_UNLIMITED_INSTANCES,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5673 0, 0, 0, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5674 if (hPipeOut == INVALID_HANDLE_VALUE)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5675 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5676
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5677 ConnectNamedPipe(hPipeIn, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5678 ConnectNamedPipe(hPipeOut, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5679
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5680 term->tl_job = job_alloc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5681 if (term->tl_job == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5682 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5683 ++term->tl_job->jv_refcount;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5684
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5685 /* behave like the job is already finished */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5686 term->tl_job->jv_status = JOB_FINISHED;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5687
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5688 channel = add_channel();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5689 if (channel == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5690 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5691 term->tl_job->jv_channel = channel;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5692 channel->ch_keep_open = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5693 channel->ch_named_pipe = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5694
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5695 channel_set_pipes(channel,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5696 (sock_T)hPipeIn,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5697 (sock_T)hPipeOut,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5698 (sock_T)hPipeOut);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5699 channel_set_job(channel, term->tl_job, options);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5700 term->tl_job->jv_tty_in = vim_strsave((char_u*)in_name);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5701 term->tl_job->jv_tty_out = vim_strsave((char_u*)out_name);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5702
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5703 return OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5704
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5705 failed:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5706 if (hPipeIn != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5707 CloseHandle(hPipeIn);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5708 if (hPipeOut != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5709 CloseHandle(hPipeOut);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5710 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5711 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5712
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5713 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5714 * Free the terminal emulator part of "term".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5715 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5716 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5717 term_free_vterm(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5718 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5719 if (term->tl_winpty != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5720 winpty_free(term->tl_winpty);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5721 term->tl_winpty = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5722 if (term->tl_winpty_config != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5723 winpty_config_free(term->tl_winpty_config);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5724 term->tl_winpty_config = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5725 if (term->tl_vterm != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5726 vterm_free(term->tl_vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5727 term->tl_vterm = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5728 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5729
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5730 /*
13678
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
5731 * Report the size to the terminal.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5732 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5733 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5734 term_report_winsize(term_T *term, int rows, int cols)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5735 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5736 if (term->tl_winpty)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5737 winpty_set_size(term->tl_winpty, cols, rows, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5738 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5739
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5740 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5741 terminal_enabled(void)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5742 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5743 return dyn_winpty_init(FALSE) == OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5744 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5745
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5746 # else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5747
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5748 /**************************************
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5749 * 3. Unix-like implementation.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5750 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5751
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5752 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5753 * Create a new terminal of "rows" by "cols" cells.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5754 * Start job for "cmd".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5755 * Store the pointers in "term".
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
5756 * When "argv" is not NULL then "argvar" is not used.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5757 * Return OK or FAIL.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5758 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5759 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5760 term_and_job_init(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5761 term_T *term,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5762 typval_T *argvar,
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
5763 char **argv,
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
5764 jobopt_T *opt,
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
5765 jobopt_T *orig_opt UNUSED)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5766 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5767 create_vterm(term, term->tl_rows, term->tl_cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5768
13626
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5769 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5770 if (opt->jo_set2 & JO2_ANSI_COLORS)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5771 set_vterm_palette(term->tl_vterm, opt->jo_ansi_colors);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5772 else
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5773 init_vterm_ansi_colors(term->tl_vterm);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5774 #endif
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5775
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
5776 /* This may change a string in "argvar". */
14065
e271ca6f32f9 patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 14029
diff changeset
5777 term->tl_job = job_start(argvar, argv, opt, TRUE);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5778 if (term->tl_job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5779 ++term->tl_job->jv_refcount;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5780
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5781 return term->tl_job != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5782 && term->tl_job->jv_channel != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5783 && term->tl_job->jv_status != JOB_FAILED ? OK : FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5784 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5785
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5786 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5787 create_pty_only(term_T *term, jobopt_T *opt)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5788 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5789 create_vterm(term, term->tl_rows, term->tl_cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5790
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5791 term->tl_job = job_alloc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5792 if (term->tl_job == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5793 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5794 ++term->tl_job->jv_refcount;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5795
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5796 /* behave like the job is already finished */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5797 term->tl_job->jv_status = JOB_FINISHED;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5798
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5799 return mch_create_pty_channel(term->tl_job, opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5800 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5801
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5802 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5803 * Free the terminal emulator part of "term".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5804 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5805 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5806 term_free_vterm(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5807 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5808 if (term->tl_vterm != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5809 vterm_free(term->tl_vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5810 term->tl_vterm = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5811 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5812
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5813 /*
13678
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
5814 * Report the size to the terminal.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5815 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5816 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5817 term_report_winsize(term_T *term, int rows, int cols)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5818 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5819 /* Use an ioctl() to report the new window size to the job. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5820 if (term->tl_job != NULL && term->tl_job->jv_channel != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5821 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5822 int fd = -1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5823 int part;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5824
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5825 for (part = PART_OUT; part < PART_COUNT; ++part)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5826 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5827 fd = term->tl_job->jv_channel->ch_part[part].ch_fd;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5828 if (isatty(fd))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5829 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5830 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5831 if (part < PART_COUNT && mch_report_winsize(fd, rows, cols) == OK)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5832 mch_signal_job(term->tl_job, (char_u *)"winch");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5833 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5834 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5835
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5836 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5837
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5838 #endif /* FEAT_TERMINAL */