annotate src/terminal.c @ 12064:407a475c67fd v8.0.0912

patch 8.0.0912: cannot run a job in a hidden terminal commit https://github.com/vim/vim/commit/8cad930a259a05a95c7d0c527a5881d5f9a59057 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Aug 12 14:32:32 2017 +0200 patch 8.0.0912: cannot run a job in a hidden terminal Problem: Cannot run a job in a hidden terminal. Solution: Add option "hidden" and ++hidden.
author Christian Brabandt <cb@256bit.org>
date Sat, 12 Aug 2017 14:45:04 +0200
parents a879814b8a37
children 8ad282dee649
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 *
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 *
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 */
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 /*
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 * Terminal window support, see ":help :terminal".
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 *
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
13 * There are three parts:
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
14 * 1. Generic code for all systems.
11741
b4d8f956eb18 patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents: 11729
diff changeset
15 * Uses libvterm for the terminal emulator.
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
16 * 2. The MS-Windows implementation.
11741
b4d8f956eb18 patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents: 11729
diff changeset
17 * Uses winpty.
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
18 * 3. The Unix-like implementation.
11741
b4d8f956eb18 patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents: 11729
diff changeset
19 * Uses pseudo-tty's (pty's).
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
20 *
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
21 * For each terminal one VTerm is constructed. This uses libvterm. A copy of
11836
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
22 * this library is in the libvterm directory.
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 *
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
24 * When a terminal window is opened, a job is started that will be connected to
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
25 * the terminal emulator.
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 *
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 * If the terminal window has keyboard focus, typed keys are converted to the
11774
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
28 * terminal encoding and writing to the job over a channel.
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 *
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
30 * If the job produces output, it is written to the terminal emulator. The
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
31 * terminal emulator invokes callbacks when its screen content changes. The
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
32 * line range is stored in tl_dirty_row_start and tl_dirty_row_end. Once in a
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
33 * while, if the terminal window is visible, the screen contents is drawn.
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 *
11836
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
35 * When the job ends the text is put in a buffer. Redrawing then happens from
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
36 * that buffer, attributes come from the scrollback buffer tl_scrollback.
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
37 *
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 * TODO:
12031
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
39 * - When using term_finish "open" have a way to specify how the window is to
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
40 * be opened. E.g. term_opencmd "10split buffer %d".
11880
45558e0507e8 patch 8.0.0820: GUI: cursor in terminal window lags behind
Christian Brabandt <cb@256bit.org>
parents: 11878
diff changeset
41 * - support different cursor shapes, colors and attributes
45558e0507e8 patch 8.0.0820: GUI: cursor in terminal window lags behind
Christian Brabandt <cb@256bit.org>
parents: 11878
diff changeset
42 * - make term_getcursor() return type (none/block/bar/underline) and
45558e0507e8 patch 8.0.0820: GUI: cursor in terminal window lags behind
Christian Brabandt <cb@256bit.org>
parents: 11878
diff changeset
43 * attributes (color, blink, etc.)
12031
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
44 * - Make argument list work on MS-Windows. #1954
12023
0197e3f52192 patch 8.0.0892: when opening a terminal the pty size doesn't always match
Christian Brabandt <cb@256bit.org>
parents: 12021
diff changeset
45 * - MS-Windows: no redraw for 'updatetime' #1915
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
46 * - To set BS correctly, check get_stty(); Pass the fd of the pty.
11965
a932d3da41c8 patch 8.0.0863: a remote command does not work in the terminal window
Christian Brabandt <cb@256bit.org>
parents: 11958
diff changeset
47 * For the GUI fill termios with default values, perhaps like pangoterm:
a932d3da41c8 patch 8.0.0863: a remote command does not work in the terminal window
Christian Brabandt <cb@256bit.org>
parents: 11958
diff changeset
48 * http://bazaar.launchpad.net/~leonerd/pangoterm/trunk/view/head:/main.c#L134
a932d3da41c8 patch 8.0.0863: a remote command does not work in the terminal window
Christian Brabandt <cb@256bit.org>
parents: 11958
diff changeset
49 * Also get the NL behavior from there.
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
50 * - do not store terminal window in viminfo. Or prefix term:// ?
11772
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
51 * - add a character in :ls output
11870
c29e498aa77d patch 8.0.0815: terminal window not correctly updated
Christian Brabandt <cb@256bit.org>
parents: 11866
diff changeset
52 * - add 't' to mode()
11931
689bcb8f241c patch 8.0.0845: MS-Windows: missing semicolon in terminal code
Christian Brabandt <cb@256bit.org>
parents: 11927
diff changeset
53 * - set 'filetype' to "terminal"?
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
54 * - use win_del_lines() to make scroll-up efficient.
11933
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
55 * - Make StatusLineTerm adjust UserN highlighting like StatusLineNC does, see
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
56 * use of hightlight_stlnc[].
11917
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
57 * - implement term_setsize()
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
58 * - add test for giving error for invalid 'termsize' value.
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59 * - support minimal size when 'termsize' is "rows*cols".
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
60 * - support minimal size when 'termsize' is empty?
11723
1922710ee8fa patch 8.0.0744: terminal window does not use a pty
Christian Brabandt <cb@256bit.org>
parents: 11719
diff changeset
61 * - implement "term" for job_start(): more job options when starting a
11967
12833414cc02 patch 8.0.0864: cannot specify the name of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11965
diff changeset
62 * terminal. Allow:
12833414cc02 patch 8.0.0864: cannot specify the name of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11965
diff changeset
63 * "in_io", "in_top", "in_bot", "in_name", "in_buf"
12833414cc02 patch 8.0.0864: cannot specify the name of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11965
diff changeset
64 "out_io", "out_name", "out_buf", "out_modifiable", "out_msg"
12833414cc02 patch 8.0.0864: cannot specify the name of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11965
diff changeset
65 "err_io", "err_name", "err_buf", "err_modifiable", "err_msg"
12833414cc02 patch 8.0.0864: cannot specify the name of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11965
diff changeset
66 * Check that something is connected to the terminal.
12833414cc02 patch 8.0.0864: cannot specify the name of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11965
diff changeset
67 * Test: "cat" reading from a file or buffer
12833414cc02 patch 8.0.0864: cannot specify the name of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11965
diff changeset
68 * "ls" writing stdout to a file or buffer
12833414cc02 patch 8.0.0864: cannot specify the name of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11965
diff changeset
69 * shell writing stderr to a file or buffer
11933
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
70 * - support ":term NONE" to open a terminal with a pty but not running a job
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
71 * in it. The pty can be passed to gdb to run the executable in.
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
72 * - if the job in the terminal does not support the mouse, we can use the
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
73 * mouse in the Terminal window for copy/paste.
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
74 * - when 'encoding' is not utf-8, or the job is using another encoding, setup
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
75 * conversions.
11886
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
76 * - update ":help function-list" for terminal functions.
11764
b82dad3fa176 patch 8.0.0764: 'termkey' does not work yet
Christian Brabandt <cb@256bit.org>
parents: 11757
diff changeset
77 * - In the GUI use a terminal emulator for :!cmd.
11902
35d7459251fd patch 8.0.0831: with 8 colors the bold attribute is not set properly
Christian Brabandt <cb@256bit.org>
parents: 11888
diff changeset
78 * - Copy text in the vterm to the Vim buffer once in a while, so that
35d7459251fd patch 8.0.0831: with 8 colors the bold attribute is not set properly
Christian Brabandt <cb@256bit.org>
parents: 11888
diff changeset
79 * completion works.
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 */
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82 #include "vim.h"
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
84 #if defined(FEAT_TERMINAL) || defined(PROTO)
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85
11971
2baa88d64217 patch 8.0.0866: Solaris also doesn't have MIN and MAX
Christian Brabandt <cb@256bit.org>
parents: 11967
diff changeset
86 #ifndef MIN
2baa88d64217 patch 8.0.0866: Solaris also doesn't have MIN and MAX
Christian Brabandt <cb@256bit.org>
parents: 11967
diff changeset
87 # define MIN(x,y) ((x) < (y) ? (x) : (y))
2baa88d64217 patch 8.0.0866: Solaris also doesn't have MIN and MAX
Christian Brabandt <cb@256bit.org>
parents: 11967
diff changeset
88 #endif
2baa88d64217 patch 8.0.0866: Solaris also doesn't have MIN and MAX
Christian Brabandt <cb@256bit.org>
parents: 11967
diff changeset
89 #ifndef MAX
2baa88d64217 patch 8.0.0866: Solaris also doesn't have MIN and MAX
Christian Brabandt <cb@256bit.org>
parents: 11967
diff changeset
90 # define MAX(x,y) ((x) > (y) ? (x) : (y))
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
91 #endif
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
93 #include "libvterm/include/vterm.h"
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
94
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
95 /* This is VTermScreenCell without the characters, thus much smaller. */
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
96 typedef struct {
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
97 VTermScreenCellAttrs attrs;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
98 char width;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
99 VTermColor fg, bg;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
100 } cellattr_T;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
101
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
102 typedef struct sb_line_S {
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
103 int sb_cols; /* can differ per line */
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
104 cellattr_T *sb_cells; /* allocated */
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
105 } sb_line_T;
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
106
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
107 /* typedef term_T in structs.h */
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
108 struct terminal_S {
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
109 term_T *tl_next;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
110
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
111 VTerm *tl_vterm;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
112 job_T *tl_job;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
113 buf_T *tl_buffer;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
114
11933
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
115 /* used when tl_job is NULL and only a pty was created */
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
116 int tl_tty_fd;
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
117 char_u *tl_tty_name;
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
118
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
119 int tl_normal_mode; /* TRUE: Terminal-Normal mode */
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
120 int tl_channel_closed;
12031
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
121 int tl_finish; /* 'c' for ++close, 'o' for ++open */
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
122
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
123 #ifdef WIN3264
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
124 void *tl_winpty_config;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
125 void *tl_winpty;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
126 #endif
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
127
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
128 /* last known vterm size */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
129 int tl_rows;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
130 int tl_cols;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
131 /* vterm size does not follow window size */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
132 int tl_rows_fixed;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
133 int tl_cols_fixed;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
134
11772
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
135 char_u *tl_title; /* NULL or allocated */
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
136 char_u *tl_status_text; /* NULL or allocated */
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
137
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
138 /* Range of screen rows to update. Zero based. */
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
139 int tl_dirty_row_start; /* -1 if nothing dirty */
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
140 int tl_dirty_row_end; /* row below last one to update */
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
141
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
142 garray_T tl_scrollback;
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
143 int tl_scrollback_scrolled;
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
144
11874
d444e087b8fd patch 8.0.0817: cannot get the terminal line at the cursor
Christian Brabandt <cb@256bit.org>
parents: 11872
diff changeset
145 VTermPos tl_cursor_pos;
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
146 int tl_cursor_visible;
12035
a3ed3d236839 patch 8.0.0898: can't use the alternate screen in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12031
diff changeset
147
a3ed3d236839 patch 8.0.0898: can't use the alternate screen in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12031
diff changeset
148 int tl_using_altscreen;
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
149 };
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
150
11985
d036c1c8537d patch 8.0.0873: in terminal cannot use CTRL- CTRL-N to start Visual mode
Christian Brabandt <cb@256bit.org>
parents: 11983
diff changeset
151 #define TMODE_ONCE 1 /* CTRL-\ CTRL-N used */
d036c1c8537d patch 8.0.0873: in terminal cannot use CTRL- CTRL-N to start Visual mode
Christian Brabandt <cb@256bit.org>
parents: 11983
diff changeset
152 #define TMODE_LOOP 2 /* CTRL-W N used */
d036c1c8537d patch 8.0.0873: in terminal cannot use CTRL- CTRL-N to start Visual mode
Christian Brabandt <cb@256bit.org>
parents: 11983
diff changeset
153
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
154 /*
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
155 * List of all active terminals.
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
156 */
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
157 static term_T *first_term = NULL;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
158
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
159
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
160 #define MAX_ROW 999999 /* used for tl_dirty_row_end to update all rows */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
161 #define KEY_BUF_LEN 200
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
162
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
163 /*
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
164 * Functions with separate implementation for MS-Windows and Unix-like systems.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
165 */
11939
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
166 static int term_and_job_init(term_T *term, int rows, int cols, char_u *cmd, jobopt_T *opt);
11753
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
167 static void term_report_winsize(term_T *term, int rows, int cols);
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
168 static void term_free_vterm(term_T *term);
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
169
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
170 /**************************************
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
171 * 1. Generic code for all systems.
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
172 */
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
173
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
174 /*
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
175 * Determine the terminal size from 'termsize' and the current window.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
176 * Assumes term->tl_rows and term->tl_cols are zero.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
177 */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
178 static void
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
179 set_term_and_win_size(term_T *term)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
180 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
181 if (*curwin->w_p_tms != NUL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
182 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
183 char_u *p = vim_strchr(curwin->w_p_tms, 'x') + 1;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
184
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
185 term->tl_rows = atoi((char *)curwin->w_p_tms);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
186 term->tl_cols = atoi((char *)p);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
187 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
188 if (term->tl_rows == 0)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
189 term->tl_rows = curwin->w_height;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
190 else
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
191 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
192 win_setheight_win(term->tl_rows, curwin);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
193 term->tl_rows_fixed = TRUE;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
194 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
195 if (term->tl_cols == 0)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
196 term->tl_cols = curwin->w_width;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
197 else
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
198 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
199 win_setwidth_win(term->tl_cols, curwin);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
200 term->tl_cols_fixed = TRUE;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
201 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
202 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
203
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
204 /*
11939
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
205 * Initialize job options for a terminal job.
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
206 * Caller may overrule some of them.
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
207 */
11939
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
208 static void
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
209 init_job_options(jobopt_T *opt)
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
210 {
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
211 clear_job_options(opt);
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
212
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
213 opt->jo_mode = MODE_RAW;
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
214 opt->jo_out_mode = MODE_RAW;
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
215 opt->jo_err_mode = MODE_RAW;
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
216 opt->jo_set = JO_MODE | JO_OUT_MODE | JO_ERR_MODE;
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
217
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
218 opt->jo_io[PART_OUT] = JIO_BUFFER;
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
219 opt->jo_io[PART_ERR] = JIO_BUFFER;
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
220 opt->jo_set |= JO_OUT_IO + JO_ERR_IO;
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
221
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
222 opt->jo_modifiable[PART_OUT] = 0;
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
223 opt->jo_modifiable[PART_ERR] = 0;
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
224 opt->jo_set |= JO_OUT_MODIFIABLE + JO_ERR_MODIFIABLE;
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
225
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
226 opt->jo_set |= JO_OUT_BUF + JO_ERR_BUF;
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
227 }
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
228
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
229 /*
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
230 * Set job options mandatory for a terminal job.
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
231 */
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
232 static void
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
233 setup_job_options(jobopt_T *opt, int rows, int cols)
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
234 {
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
235 opt->jo_io_buf[PART_OUT] = curbuf->b_fnum;
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
236 opt->jo_io_buf[PART_ERR] = curbuf->b_fnum;
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
237 opt->jo_pty = TRUE;
12056
0498547dace0 patch 8.0.0908: cannot set terminal size with options
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
238 if ((opt->jo_set2 & JO2_TERM_ROWS) == 0)
0498547dace0 patch 8.0.0908: cannot set terminal size with options
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
239 opt->jo_term_rows = rows;
0498547dace0 patch 8.0.0908: cannot set terminal size with options
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
240 if ((opt->jo_set2 & JO2_TERM_COLS) == 0)
0498547dace0 patch 8.0.0908: cannot set terminal size with options
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
241 opt->jo_term_cols = cols;
11939
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
242 }
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
243
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
244 static void
12060
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
245 term_start(char_u *cmd, jobopt_T *opt, int forceit)
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
246 {
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
247 exarg_T split_ea;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
248 win_T *old_curwin = curwin;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
249 term_T *term;
12064
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
250 buf_T *old_curbuf = NULL;
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
251
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
252 if (check_restricted() || check_secure())
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
253 return;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
254
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
255 term = (term_T *)alloc_clear(sizeof(term_T));
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
256 if (term == NULL)
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
257 return;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
258 term->tl_dirty_row_end = MAX_ROW;
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
259 term->tl_cursor_visible = TRUE;
12031
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
260 term->tl_finish = opt->jo_term_finish;
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
261 ga_init2(&term->tl_scrollback, sizeof(sb_line_T), 300);
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
262
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
263 vim_memset(&split_ea, 0, sizeof(split_ea));
12060
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
264 if (opt->jo_curwin)
11975
5cc005cf312f patch 8.0.0868: cannot specify the terminal size on the command line
Christian Brabandt <cb@256bit.org>
parents: 11971
diff changeset
265 {
12060
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
266 /* Create a new buffer in the current window. */
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
267 if (!can_abandon(curbuf, forceit))
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
268 {
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
269 EMSG(_(e_nowrtmsg));
12064
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
270 vim_free(term);
12060
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
271 return;
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
272 }
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
273 if (do_ecmd(0, NULL, NULL, &split_ea, ECMD_ONE,
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
274 ECMD_HIDE + (forceit ? ECMD_FORCEIT : 0), curwin) == FAIL)
12064
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
275 {
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
276 vim_free(term);
12060
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
277 return;
12064
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
278 }
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
279 }
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
280 else if (opt->jo_hidden)
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
281 {
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
282 buf_T *buf;
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
283
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
284 /* Create a new buffer without a window. Make it the current buffer for
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
285 * a moment to be able to do the initialisations. */
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
286 buf = buflist_new((char_u *)"", NULL, (linenr_T)0,
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
287 BLN_NEW | BLN_LISTED);
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
288 if (buf == NULL || ml_open(buf) == FAIL)
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
289 {
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
290 vim_free(term);
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
291 return;
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
292 }
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
293 old_curbuf = curbuf;
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
294 --curbuf->b_nwindows;
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
295 curbuf = buf;
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
296 curwin->w_buffer = buf;
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
297 ++curbuf->b_nwindows;
11975
5cc005cf312f patch 8.0.0868: cannot specify the terminal size on the command line
Christian Brabandt <cb@256bit.org>
parents: 11971
diff changeset
298 }
12060
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
299 else
11975
5cc005cf312f patch 8.0.0868: cannot specify the terminal size on the command line
Christian Brabandt <cb@256bit.org>
parents: 11971
diff changeset
300 {
12060
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
301 /* Open a new window or tab. */
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
302 split_ea.cmdidx = CMD_new;
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
303 split_ea.cmd = (char_u *)"new";
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
304 split_ea.arg = (char_u *)"";
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
305 if (opt->jo_term_rows > 0 && !(cmdmod.split & WSP_VERT))
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
306 {
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
307 split_ea.line2 = opt->jo_term_rows;
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
308 split_ea.addr_count = 1;
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
309 }
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
310 if (opt->jo_term_cols > 0 && (cmdmod.split & WSP_VERT))
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
311 {
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
312 split_ea.line2 = opt->jo_term_cols;
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
313 split_ea.addr_count = 1;
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
314 }
11975
5cc005cf312f patch 8.0.0868: cannot specify the terminal size on the command line
Christian Brabandt <cb@256bit.org>
parents: 11971
diff changeset
315
12060
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
316 ex_splitview(&split_ea);
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
317 if (curwin == old_curwin)
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
318 {
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
319 /* split failed */
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
320 vim_free(term);
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
321 return;
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
322 }
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
323 }
11670
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
324 term->tl_buffer = curbuf;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
325 curbuf->b_term = term;
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
326
12064
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
327 if (!opt->jo_hidden)
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
328 {
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
329 /* only one size was taken care of with :new, do the other one */
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
330 if (opt->jo_term_rows > 0 && (cmdmod.split & WSP_VERT))
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
331 win_setheight(opt->jo_term_rows);
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
332 if (opt->jo_term_cols > 0 && !(cmdmod.split & WSP_VERT))
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
333 win_setwidth(opt->jo_term_cols);
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
334 }
11975
5cc005cf312f patch 8.0.0868: cannot specify the terminal size on the command line
Christian Brabandt <cb@256bit.org>
parents: 11971
diff changeset
335
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
336 /* Link the new terminal in the list of active terminals. */
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
337 term->tl_next = first_term;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
338 first_term = term;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
339
11794
2e7e77e28063 patch 8.0.0779: :term without an argument uses empty buffer name
Christian Brabandt <cb@256bit.org>
parents: 11792
diff changeset
340 if (cmd == NULL || *cmd == NUL)
2e7e77e28063 patch 8.0.0779: :term without an argument uses empty buffer name
Christian Brabandt <cb@256bit.org>
parents: 11792
diff changeset
341 cmd = p_sh;
2e7e77e28063 patch 8.0.0779: :term without an argument uses empty buffer name
Christian Brabandt <cb@256bit.org>
parents: 11792
diff changeset
342
11967
12833414cc02 patch 8.0.0864: cannot specify the name of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11965
diff changeset
343 if (opt->jo_term_name != NULL)
12833414cc02 patch 8.0.0864: cannot specify the name of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11965
diff changeset
344 curbuf->b_ffname = vim_strsave(opt->jo_term_name);
12833414cc02 patch 8.0.0864: cannot specify the name of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11965
diff changeset
345 else
11757
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
346 {
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
347 int i;
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
348 size_t len = STRLEN(cmd) + 10;
11790
4dfebc1b2674 patch 8.0.0777: compiler warnings with 64 bit compiler
Christian Brabandt <cb@256bit.org>
parents: 11786
diff changeset
349 char_u *p = alloc((int)len);
11757
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
350
11912
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11904
diff changeset
351 for (i = 0; p != NULL; ++i)
11757
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
352 {
11912
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11904
diff changeset
353 /* Prepend a ! to the command name to avoid the buffer name equals
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11904
diff changeset
354 * the executable, otherwise ":w!" would overwrite it. */
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11904
diff changeset
355 if (i == 0)
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11904
diff changeset
356 vim_snprintf((char *)p, len, "!%s", cmd);
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11904
diff changeset
357 else
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11904
diff changeset
358 vim_snprintf((char *)p, len, "!%s (%d)", cmd, i);
11757
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
359 if (buflist_findname(p) == NULL)
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
360 {
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
361 curbuf->b_ffname = p;
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
362 break;
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
363 }
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
364 }
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
365 }
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
366 curbuf->b_fname = curbuf->b_ffname;
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
367
11957
bc0fee081e1e patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents: 11953
diff changeset
368 set_string_option_direct((char_u *)"buftype", -1,
bc0fee081e1e patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents: 11953
diff changeset
369 (char_u *)"terminal", OPT_FREE|OPT_LOCAL, 0);
bc0fee081e1e patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents: 11953
diff changeset
370
11912
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11904
diff changeset
371 /* Mark the buffer as not modifiable. It can only be made modifiable after
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11904
diff changeset
372 * the job finished. */
11757
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
373 curbuf->b_p_ma = FALSE;
11957
bc0fee081e1e patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents: 11953
diff changeset
374
bc0fee081e1e patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents: 11953
diff changeset
375 /* Set 'bufhidden' to "hide": allow closing the window. */
bc0fee081e1e patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents: 11953
diff changeset
376 set_string_option_direct((char_u *)"bufhidden", -1,
bc0fee081e1e patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents: 11953
diff changeset
377 (char_u *)"hide", OPT_FREE|OPT_LOCAL, 0);
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
378
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
379 set_term_and_win_size(term);
11939
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
380 setup_job_options(opt, term->tl_rows, term->tl_cols);
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
381
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
382 /* System dependent: setup the vterm and start the job in it. */
11939
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
383 if (term_and_job_init(term, term->tl_rows, term->tl_cols, cmd, opt) == OK)
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
384 {
12023
0197e3f52192 patch 8.0.0892: when opening a terminal the pty size doesn't always match
Christian Brabandt <cb@256bit.org>
parents: 12021
diff changeset
385 /* Get and remember the size we ended up with. Update the pty. */
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
386 vterm_get_size(term->tl_vterm, &term->tl_rows, &term->tl_cols);
12023
0197e3f52192 patch 8.0.0892: when opening a terminal the pty size doesn't always match
Christian Brabandt <cb@256bit.org>
parents: 12021
diff changeset
387 term_report_winsize(term, term->tl_rows, term->tl_cols);
12064
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
388
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
389 if (old_curbuf != NULL)
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
390 {
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
391 --curbuf->b_nwindows;
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
392 curbuf = old_curbuf;
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
393 curwin->w_buffer = curbuf;
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
394 ++curbuf->b_nwindows;
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
395 }
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
396 }
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
397 else
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
398 {
12064
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
399 buf_T *buf = curbuf;
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
400
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
401 free_terminal(curbuf);
12064
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
402 if (old_curbuf != NULL)
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
403 {
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
404 --curbuf->b_nwindows;
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
405 curbuf = old_curbuf;
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
406 curwin->w_buffer = curbuf;
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
407 ++curbuf->b_nwindows;
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
408 }
11727
cb1dc90d22cc patch 8.0.0746: when :term fails the job is not properly cleaned up
Christian Brabandt <cb@256bit.org>
parents: 11725
diff changeset
409
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
410 /* Wiping out the buffer will also close the window and call
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
411 * free_terminal(). */
12064
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
412 do_buffer(DOBUF_WIPE, DOBUF_FIRST, FORWARD, buf->b_fnum, TRUE);
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
413 }
11670
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
414 }
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
415
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
416 /*
11939
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
417 * ":terminal": open a terminal window and execute a job in it.
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
418 */
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
419 void
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
420 ex_terminal(exarg_T *eap)
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
421 {
12031
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
422 jobopt_T opt;
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
423 char_u *cmd;
11939
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
424
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
425 init_job_options(&opt);
11975
5cc005cf312f patch 8.0.0868: cannot specify the terminal size on the command line
Christian Brabandt <cb@256bit.org>
parents: 11971
diff changeset
426
12031
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
427 cmd = eap->arg;
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
428 while (*cmd && *cmd == '+' && *(cmd + 1) == '+')
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
429 {
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
430 char_u *p;
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
431
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
432 cmd += 2;
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
433 p = skiptowhite(cmd);
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
434 if ((int)(p - cmd) == 5 && STRNICMP(cmd, "close", 5) == 0)
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
435 opt.jo_term_finish = 'c';
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
436 else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "open", 4) == 0)
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
437 opt.jo_term_finish = 'o';
12060
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
438 else if ((int)(p - cmd) == 6 && STRNICMP(cmd, "curwin", 6) == 0)
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
439 opt.jo_curwin = 1;
12064
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
440 else if ((int)(p - cmd) == 6 && STRNICMP(cmd, "hidden", 6) == 0)
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
441 opt.jo_hidden = 1;
12031
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
442 else
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
443 {
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
444 if (*p)
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
445 *p = NUL;
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
446 EMSG2(_("E181: Invalid attribute: %s"), cmd);
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
447 return;
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
448 }
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
449 cmd = skipwhite(p);
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
450 }
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
451
11975
5cc005cf312f patch 8.0.0868: cannot specify the terminal size on the command line
Christian Brabandt <cb@256bit.org>
parents: 11971
diff changeset
452 if (eap->addr_count == 2)
5cc005cf312f patch 8.0.0868: cannot specify the terminal size on the command line
Christian Brabandt <cb@256bit.org>
parents: 11971
diff changeset
453 {
5cc005cf312f patch 8.0.0868: cannot specify the terminal size on the command line
Christian Brabandt <cb@256bit.org>
parents: 11971
diff changeset
454 opt.jo_term_rows = eap->line1;
5cc005cf312f patch 8.0.0868: cannot specify the terminal size on the command line
Christian Brabandt <cb@256bit.org>
parents: 11971
diff changeset
455 opt.jo_term_cols = eap->line2;
5cc005cf312f patch 8.0.0868: cannot specify the terminal size on the command line
Christian Brabandt <cb@256bit.org>
parents: 11971
diff changeset
456 }
5cc005cf312f patch 8.0.0868: cannot specify the terminal size on the command line
Christian Brabandt <cb@256bit.org>
parents: 11971
diff changeset
457 else if (eap->addr_count == 1)
5cc005cf312f patch 8.0.0868: cannot specify the terminal size on the command line
Christian Brabandt <cb@256bit.org>
parents: 11971
diff changeset
458 {
5cc005cf312f patch 8.0.0868: cannot specify the terminal size on the command line
Christian Brabandt <cb@256bit.org>
parents: 11971
diff changeset
459 if (cmdmod.split & WSP_VERT)
5cc005cf312f patch 8.0.0868: cannot specify the terminal size on the command line
Christian Brabandt <cb@256bit.org>
parents: 11971
diff changeset
460 opt.jo_term_cols = eap->line2;
5cc005cf312f patch 8.0.0868: cannot specify the terminal size on the command line
Christian Brabandt <cb@256bit.org>
parents: 11971
diff changeset
461 else
5cc005cf312f patch 8.0.0868: cannot specify the terminal size on the command line
Christian Brabandt <cb@256bit.org>
parents: 11971
diff changeset
462 opt.jo_term_rows = eap->line2;
5cc005cf312f patch 8.0.0868: cannot specify the terminal size on the command line
Christian Brabandt <cb@256bit.org>
parents: 11971
diff changeset
463 }
11939
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
464
12060
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
465 term_start(cmd, &opt, eap->forceit);
11939
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
466 }
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
467
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
468 /*
11836
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
469 * Free the scrollback buffer for "term".
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
470 */
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
471 static void
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
472 free_scrollback(term_T *term)
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
473 {
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
474 int i;
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
475
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
476 for (i = 0; i < term->tl_scrollback.ga_len; ++i)
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
477 vim_free(((sb_line_T *)term->tl_scrollback.ga_data + i)->sb_cells);
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
478 ga_clear(&term->tl_scrollback);
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
479 }
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
480
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
481 /*
11690
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
482 * Free a terminal and everything it refers to.
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
483 * Kills the job if there is one.
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
484 * Called when wiping out a buffer.
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
485 */
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
486 void
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
487 free_terminal(buf_T *buf)
11690
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
488 {
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
489 term_T *term = buf->b_term;
11690
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
490 term_T *tp;
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
491
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
492 if (term == NULL)
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
493 return;
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
494 if (first_term == term)
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
495 first_term = term->tl_next;
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
496 else
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
497 for (tp = first_term; tp->tl_next != NULL; tp = tp->tl_next)
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
498 if (tp->tl_next == term)
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
499 {
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
500 tp->tl_next = term->tl_next;
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
501 break;
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
502 }
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
503
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
504 if (term->tl_job != NULL)
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
505 {
11727
cb1dc90d22cc patch 8.0.0746: when :term fails the job is not properly cleaned up
Christian Brabandt <cb@256bit.org>
parents: 11725
diff changeset
506 if (term->tl_job->jv_status != JOB_ENDED
cb1dc90d22cc patch 8.0.0746: when :term fails the job is not properly cleaned up
Christian Brabandt <cb@256bit.org>
parents: 11725
diff changeset
507 && term->tl_job->jv_status != JOB_FAILED)
11690
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
508 job_stop(term->tl_job, NULL, "kill");
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
509 job_unref(term->tl_job);
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
510 }
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
511
11836
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
512 free_scrollback(term);
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
513
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
514 term_free_vterm(term);
11772
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
515 vim_free(term->tl_title);
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
516 vim_free(term->tl_status_text);
11690
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
517 vim_free(term);
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
518 buf->b_term = NULL;
11690
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
519 }
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
520
ce434212d682 patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents: 11684
diff changeset
521 /*
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
522 * Write job output "msg[len]" to the vterm.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
523 */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
524 static void
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
525 term_write_job_output(term_T *term, char_u *msg, size_t len)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
526 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
527 VTerm *vterm = term->tl_vterm;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
528 char_u *p;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
529 size_t done;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
530 size_t len_now;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
531
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
532 for (done = 0; done < len; done += len_now)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
533 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
534 for (p = msg + done; p < msg + len; )
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
535 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
536 if (*p == NL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
537 break;
11790
4dfebc1b2674 patch 8.0.0777: compiler warnings with 64 bit compiler
Christian Brabandt <cb@256bit.org>
parents: 11786
diff changeset
538 p += utf_ptr2len_len(p, (int)(len - (p - msg)));
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
539 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
540 len_now = p - msg - done;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
541 vterm_input_write(vterm, (char *)msg + done, len_now);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
542 if (p < msg + len && *p == NL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
543 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
544 /* Convert NL to CR-NL, that appears to work best. */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
545 vterm_input_write(vterm, "\r\n", 2);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
546 ++len_now;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
547 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
548 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
549
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
550 /* this invokes the damage callbacks */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
551 vterm_screen_flush_damage(vterm_obtain_screen(vterm));
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
552 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
553
11778
e8005055f845 patch 8.0.0771: cursor in terminal window not always updated in GUI
Christian Brabandt <cb@256bit.org>
parents: 11774
diff changeset
554 static void
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
555 update_cursor(term_T *term, int redraw)
11778
e8005055f845 patch 8.0.0771: cursor in terminal window not always updated in GUI
Christian Brabandt <cb@256bit.org>
parents: 11774
diff changeset
556 {
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
557 if (term->tl_normal_mode)
11888
4db6c74df788 patch 8.0.0824: in Terminal mode the cursor and screen gets redrawn
Christian Brabandt <cb@256bit.org>
parents: 11886
diff changeset
558 return;
11778
e8005055f845 patch 8.0.0771: cursor in terminal window not always updated in GUI
Christian Brabandt <cb@256bit.org>
parents: 11774
diff changeset
559 setcursor();
11792
4bc1f94afc34 patch 8.0.0778: in a terminal the cursor may be hidden
Christian Brabandt <cb@256bit.org>
parents: 11790
diff changeset
560 if (redraw && term->tl_buffer == curbuf)
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
561 {
11792
4bc1f94afc34 patch 8.0.0778: in a terminal the cursor may be hidden
Christian Brabandt <cb@256bit.org>
parents: 11790
diff changeset
562 if (term->tl_cursor_visible)
4bc1f94afc34 patch 8.0.0778: in a terminal the cursor may be hidden
Christian Brabandt <cb@256bit.org>
parents: 11790
diff changeset
563 cursor_on();
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
564 out_flush();
11778
e8005055f845 patch 8.0.0771: cursor in terminal window not always updated in GUI
Christian Brabandt <cb@256bit.org>
parents: 11774
diff changeset
565 #ifdef FEAT_GUI
11880
45558e0507e8 patch 8.0.0820: GUI: cursor in terminal window lags behind
Christian Brabandt <cb@256bit.org>
parents: 11878
diff changeset
566 if (gui.in_use)
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
567 gui_update_cursor(FALSE, FALSE);
11778
e8005055f845 patch 8.0.0771: cursor in terminal window not always updated in GUI
Christian Brabandt <cb@256bit.org>
parents: 11774
diff changeset
568 #endif
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
569 }
11778
e8005055f845 patch 8.0.0771: cursor in terminal window not always updated in GUI
Christian Brabandt <cb@256bit.org>
parents: 11774
diff changeset
570 }
e8005055f845 patch 8.0.0771: cursor in terminal window not always updated in GUI
Christian Brabandt <cb@256bit.org>
parents: 11774
diff changeset
571
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
572 /*
11670
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
573 * Invoked when "msg" output from a job was received. Write it to the terminal
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
574 * of "buffer".
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
575 */
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
576 void
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
577 write_to_term(buf_T *buffer, char_u *msg, channel_T *channel)
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
578 {
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
579 size_t len = STRLEN(msg);
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
580 term_T *term = buffer->b_term;
11670
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
581
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
582 if (term->tl_vterm == NULL)
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
583 {
11937
c893d6c00497 patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents: 11933
diff changeset
584 ch_log(channel, "NOT writing %d bytes to terminal", (int)len);
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
585 return;
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
586 }
11937
c893d6c00497 patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents: 11933
diff changeset
587 ch_log(channel, "writing %d bytes to terminal", (int)len);
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
588 term_write_job_output(term, msg, len);
11670
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
589
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
590 if (!term->tl_normal_mode)
11888
4db6c74df788 patch 8.0.0824: in Terminal mode the cursor and screen gets redrawn
Christian Brabandt <cb@256bit.org>
parents: 11886
diff changeset
591 {
4db6c74df788 patch 8.0.0824: in Terminal mode the cursor and screen gets redrawn
Christian Brabandt <cb@256bit.org>
parents: 11886
diff changeset
592 /* TODO: only update once in a while. */
4db6c74df788 patch 8.0.0824: in Terminal mode the cursor and screen gets redrawn
Christian Brabandt <cb@256bit.org>
parents: 11886
diff changeset
593 update_screen(0);
4db6c74df788 patch 8.0.0824: in Terminal mode the cursor and screen gets redrawn
Christian Brabandt <cb@256bit.org>
parents: 11886
diff changeset
594 update_cursor(term, TRUE);
4db6c74df788 patch 8.0.0824: in Terminal mode the cursor and screen gets redrawn
Christian Brabandt <cb@256bit.org>
parents: 11886
diff changeset
595 }
11670
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
596 }
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
597
11670
3b2afa2b77b3 patch 8.0.0718: output of job in terminal is not displayed
Christian Brabandt <cb@256bit.org>
parents: 11668
diff changeset
598 /*
11854
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
599 * Send a mouse position and click to the vterm
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
600 */
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
601 static int
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
602 term_send_mouse(VTerm *vterm, int button, int pressed)
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
603 {
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
604 VTermModifier mod = VTERM_MOD_NONE;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
605
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
606 vterm_mouse_move(vterm, mouse_row - W_WINROW(curwin),
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
607 mouse_col - W_WINCOL(curwin), mod);
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
608 vterm_mouse_button(vterm, button, pressed, mod);
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
609 return TRUE;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
610 }
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
611
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
612 /*
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
613 * Convert typed key "c" into bytes to send to the job.
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
614 * Return the number of bytes in "buf".
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
615 */
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
616 static int
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
617 term_convert_key(term_T *term, int c, char *buf)
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
618 {
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
619 VTerm *vterm = term->tl_vterm;
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
620 VTermKey key = VTERM_KEY_NONE;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
621 VTermModifier mod = VTERM_MOD_NONE;
11854
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
622 int mouse = FALSE;
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
623
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
624 switch (c)
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
625 {
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
626 case CAR: key = VTERM_KEY_ENTER; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
627 case ESC: key = VTERM_KEY_ESCAPE; break;
11715
d7430b56c9ed patch 8.0.0740: cannot resize a terminal window by the command
Christian Brabandt <cb@256bit.org>
parents: 11713
diff changeset
628 /* VTERM_KEY_BACKSPACE becomes 0x7f DEL */
d7430b56c9ed patch 8.0.0740: cannot resize a terminal window by the command
Christian Brabandt <cb@256bit.org>
parents: 11713
diff changeset
629 case K_BS: c = BS; break;
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
630 case K_DEL: key = VTERM_KEY_DEL; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
631 case K_DOWN: key = VTERM_KEY_DOWN; break;
11854
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
632 case K_S_DOWN: mod = VTERM_MOD_SHIFT;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
633 key = VTERM_KEY_DOWN; break;
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
634 case K_END: key = VTERM_KEY_END; break;
11854
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
635 case K_S_END: mod = VTERM_MOD_SHIFT;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
636 key = VTERM_KEY_END; break;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
637 case K_C_END: mod = VTERM_MOD_CTRL;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
638 key = VTERM_KEY_END; break;
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
639 case K_F10: key = VTERM_KEY_FUNCTION(10); break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
640 case K_F11: key = VTERM_KEY_FUNCTION(11); break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
641 case K_F12: key = VTERM_KEY_FUNCTION(12); break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
642 case K_F1: key = VTERM_KEY_FUNCTION(1); break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
643 case K_F2: key = VTERM_KEY_FUNCTION(2); break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
644 case K_F3: key = VTERM_KEY_FUNCTION(3); break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
645 case K_F4: key = VTERM_KEY_FUNCTION(4); break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
646 case K_F5: key = VTERM_KEY_FUNCTION(5); break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
647 case K_F6: key = VTERM_KEY_FUNCTION(6); break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
648 case K_F7: key = VTERM_KEY_FUNCTION(7); break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
649 case K_F8: key = VTERM_KEY_FUNCTION(8); break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
650 case K_F9: key = VTERM_KEY_FUNCTION(9); break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
651 case K_HOME: key = VTERM_KEY_HOME; break;
11854
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
652 case K_S_HOME: mod = VTERM_MOD_SHIFT;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
653 key = VTERM_KEY_HOME; break;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
654 case K_C_HOME: mod = VTERM_MOD_CTRL;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
655 key = VTERM_KEY_HOME; break;
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
656 case K_INS: key = VTERM_KEY_INS; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
657 case K_K0: key = VTERM_KEY_KP_0; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
658 case K_K1: key = VTERM_KEY_KP_1; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
659 case K_K2: key = VTERM_KEY_KP_2; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
660 case K_K3: key = VTERM_KEY_KP_3; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
661 case K_K4: key = VTERM_KEY_KP_4; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
662 case K_K5: key = VTERM_KEY_KP_5; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
663 case K_K6: key = VTERM_KEY_KP_6; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
664 case K_K7: key = VTERM_KEY_KP_7; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
665 case K_K8: key = VTERM_KEY_KP_8; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
666 case K_K9: key = VTERM_KEY_KP_9; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
667 case K_KDEL: key = VTERM_KEY_DEL; break; /* TODO */
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
668 case K_KDIVIDE: key = VTERM_KEY_KP_DIVIDE; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
669 case K_KEND: key = VTERM_KEY_KP_1; break; /* TODO */
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
670 case K_KENTER: key = VTERM_KEY_KP_ENTER; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
671 case K_KHOME: key = VTERM_KEY_KP_7; break; /* TODO */
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
672 case K_KINS: key = VTERM_KEY_KP_0; break; /* TODO */
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
673 case K_KMINUS: key = VTERM_KEY_KP_MINUS; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
674 case K_KMULTIPLY: key = VTERM_KEY_KP_MULT; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
675 case K_KPAGEDOWN: key = VTERM_KEY_KP_3; break; /* TODO */
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
676 case K_KPAGEUP: key = VTERM_KEY_KP_9; break; /* TODO */
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
677 case K_KPLUS: key = VTERM_KEY_KP_PLUS; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
678 case K_KPOINT: key = VTERM_KEY_KP_PERIOD; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
679 case K_LEFT: key = VTERM_KEY_LEFT; break;
11854
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
680 case K_S_LEFT: mod = VTERM_MOD_SHIFT;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
681 key = VTERM_KEY_LEFT; break;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
682 case K_C_LEFT: mod = VTERM_MOD_CTRL;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
683 key = VTERM_KEY_LEFT; break;
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
684 case K_PAGEDOWN: key = VTERM_KEY_PAGEDOWN; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
685 case K_PAGEUP: key = VTERM_KEY_PAGEUP; break;
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
686 case K_RIGHT: key = VTERM_KEY_RIGHT; break;
11854
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
687 case K_S_RIGHT: mod = VTERM_MOD_SHIFT;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
688 key = VTERM_KEY_RIGHT; break;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
689 case K_C_RIGHT: mod = VTERM_MOD_CTRL;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
690 key = VTERM_KEY_RIGHT; break;
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
691 case K_UP: key = VTERM_KEY_UP; break;
11854
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
692 case K_S_UP: mod = VTERM_MOD_SHIFT;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
693 key = VTERM_KEY_UP; break;
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
694 case TAB: key = VTERM_KEY_TAB; break;
11711
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
695
11854
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
696 case K_MOUSEUP: mouse = term_send_mouse(vterm, 5, 1); break;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
697 case K_MOUSEDOWN: mouse = term_send_mouse(vterm, 4, 1); break;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
698 case K_MOUSELEFT: /* TODO */ return 0;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
699 case K_MOUSERIGHT: /* TODO */ return 0;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
700
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
701 case K_LEFTMOUSE:
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
702 case K_LEFTMOUSE_NM: mouse = term_send_mouse(vterm, 1, 1); break;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
703 case K_LEFTDRAG: mouse = term_send_mouse(vterm, 1, 1); break;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
704 case K_LEFTRELEASE:
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
705 case K_LEFTRELEASE_NM: mouse = term_send_mouse(vterm, 1, 0); break;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
706 case K_MIDDLEMOUSE: mouse = term_send_mouse(vterm, 2, 1); break;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
707 case K_MIDDLEDRAG: mouse = term_send_mouse(vterm, 2, 1); break;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
708 case K_MIDDLERELEASE: mouse = term_send_mouse(vterm, 2, 0); break;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
709 case K_RIGHTMOUSE: mouse = term_send_mouse(vterm, 3, 1); break;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
710 case K_RIGHTDRAG: mouse = term_send_mouse(vterm, 3, 1); break;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
711 case K_RIGHTRELEASE: mouse = term_send_mouse(vterm, 3, 0); break;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
712 case K_X1MOUSE: /* TODO */ return 0;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
713 case K_X1DRAG: /* TODO */ return 0;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
714 case K_X1RELEASE: /* TODO */ return 0;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
715 case K_X2MOUSE: /* TODO */ return 0;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
716 case K_X2DRAG: /* TODO */ return 0;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
717 case K_X2RELEASE: /* TODO */ return 0;
11711
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
718
11854
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
719 case K_IGNORE: return 0;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
720 case K_NOP: return 0;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
721 case K_UNDO: return 0;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
722 case K_HELP: return 0;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
723 case K_XF1: key = VTERM_KEY_FUNCTION(1); break;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
724 case K_XF2: key = VTERM_KEY_FUNCTION(2); break;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
725 case K_XF3: key = VTERM_KEY_FUNCTION(3); break;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
726 case K_XF4: key = VTERM_KEY_FUNCTION(4); break;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
727 case K_SELECT: return 0;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
728 #ifdef FEAT_GUI
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
729 case K_VER_SCROLLBAR: return 0;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
730 case K_HOR_SCROLLBAR: return 0;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
731 #endif
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
732 #ifdef FEAT_GUI_TABLINE
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
733 case K_TABLINE: return 0;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
734 case K_TABMENU: return 0;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
735 #endif
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
736 #ifdef FEAT_NETBEANS_INTG
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
737 case K_F21: key = VTERM_KEY_FUNCTION(21); break;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
738 #endif
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
739 #ifdef FEAT_DND
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
740 case K_DROP: return 0;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
741 #endif
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
742 #ifdef FEAT_AUTOCMD
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
743 case K_CURSORHOLD: return 0;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
744 #endif
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
745 case K_PS: vterm_keyboard_start_paste(vterm); return 0;
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
746 case K_PE: vterm_keyboard_end_paste(vterm); return 0;
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
747 }
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
748
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
749 /*
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
750 * Convert special keys to vterm keys:
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
751 * - Write keys to vterm: vterm_keyboard_key()
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
752 * - Write output to channel.
11854
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
753 * TODO: use mod_mask
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
754 */
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
755 if (key != VTERM_KEY_NONE)
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
756 /* Special key, let vterm convert it. */
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
757 vterm_keyboard_key(vterm, key, mod);
11854
092dd1ef0eda patch 8.0.0807: terminal window can't handle mouse buttons
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
758 else if (!mouse)
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
759 /* Normal character, let vterm convert it. */
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
760 vterm_keyboard_unichar(vterm, c, mod);
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
761
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
762 /* Read back the converted escape sequence. */
11790
4dfebc1b2674 patch 8.0.0777: compiler warnings with 64 bit compiler
Christian Brabandt <cb@256bit.org>
parents: 11786
diff changeset
763 return (int)vterm_output_read(vterm, buf, KEY_BUF_LEN);
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
764 }
11684
1ce1376fbbf8 patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents: 11670
diff changeset
765
1ce1376fbbf8 patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents: 11670
diff changeset
766 /*
11882
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
767 * Return TRUE if the job for "term" is still running.
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
768 */
11917
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
769 int
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
770 term_job_running(term_T *term)
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
771 {
11842
6bfcedcc0262 patch 8.0.0801: terminal window title says "running" after job exits
Christian Brabandt <cb@256bit.org>
parents: 11840
diff changeset
772 /* Also consider the job finished when the channel is closed, to avoid a
6bfcedcc0262 patch 8.0.0801: terminal window title says "running" after job exits
Christian Brabandt <cb@256bit.org>
parents: 11840
diff changeset
773 * race condition when updating the title. */
11947
8b9a1be7bb82 patch 8.0.0853: crash when running terminal with unknown command
Christian Brabandt <cb@256bit.org>
parents: 11939
diff changeset
774 return term != NULL
8b9a1be7bb82 patch 8.0.0853: crash when running terminal with unknown command
Christian Brabandt <cb@256bit.org>
parents: 11939
diff changeset
775 && term->tl_job != NULL
11842
6bfcedcc0262 patch 8.0.0801: terminal window title says "running" after job exits
Christian Brabandt <cb@256bit.org>
parents: 11840
diff changeset
776 && term->tl_job->jv_status == JOB_STARTED
6bfcedcc0262 patch 8.0.0801: terminal window title says "running" after job exits
Christian Brabandt <cb@256bit.org>
parents: 11840
diff changeset
777 && channel_is_open(term->tl_job->jv_channel);
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
778 }
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
779
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
780 /*
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
781 * Add the last line of the scrollback buffer to the buffer in the window.
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
782 */
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
783 static void
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
784 add_scrollback_line_to_buffer(term_T *term, char_u *text, int len)
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
785 {
12011
1f4e7361ce89 patch 8.0.0886: crash when using ":term ls"
Christian Brabandt <cb@256bit.org>
parents: 12009
diff changeset
786 buf_T *buf = term->tl_buffer;
1f4e7361ce89 patch 8.0.0886: crash when using ":term ls"
Christian Brabandt <cb@256bit.org>
parents: 12009
diff changeset
787 int empty = (buf->b_ml.ml_flags & ML_EMPTY);
1f4e7361ce89 patch 8.0.0886: crash when using ":term ls"
Christian Brabandt <cb@256bit.org>
parents: 12009
diff changeset
788 linenr_T lnum = buf->b_ml.ml_line_count;
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
789
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
790 ml_append_buf(term->tl_buffer, lnum, text, len + 1, FALSE);
12011
1f4e7361ce89 patch 8.0.0886: crash when using ":term ls"
Christian Brabandt <cb@256bit.org>
parents: 12009
diff changeset
791 if (empty)
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
792 {
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
793 /* Delete the empty line that was in the empty buffer. */
12011
1f4e7361ce89 patch 8.0.0886: crash when using ":term ls"
Christian Brabandt <cb@256bit.org>
parents: 12009
diff changeset
794 curbuf = buf;
1f4e7361ce89 patch 8.0.0886: crash when using ":term ls"
Christian Brabandt <cb@256bit.org>
parents: 12009
diff changeset
795 ml_delete(1, FALSE);
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
796 curbuf = curwin->w_buffer;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
797 }
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
798 }
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
799
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
800 /*
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
801 * Add the current lines of the terminal to scrollback and to the buffer.
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
802 * Called after the job has ended and when switching to Terminal-Normal mode.
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
803 */
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
804 static void
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
805 move_terminal_to_buffer(term_T *term)
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
806 {
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
807 win_T *wp;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
808 int len;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
809 int lines_skipped = 0;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
810 VTermPos pos;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
811 VTermScreenCell cell;
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
812 cellattr_T *p;
11958
052270a67371 patch 8.0.0859: NULL pointer access when term_free_vterm called twice
Christian Brabandt <cb@256bit.org>
parents: 11957
diff changeset
813 VTermScreen *screen;
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
814
11958
052270a67371 patch 8.0.0859: NULL pointer access when term_free_vterm called twice
Christian Brabandt <cb@256bit.org>
parents: 11957
diff changeset
815 if (term->tl_vterm == NULL)
052270a67371 patch 8.0.0859: NULL pointer access when term_free_vterm called twice
Christian Brabandt <cb@256bit.org>
parents: 11957
diff changeset
816 return;
052270a67371 patch 8.0.0859: NULL pointer access when term_free_vterm called twice
Christian Brabandt <cb@256bit.org>
parents: 11957
diff changeset
817 screen = vterm_obtain_screen(term->tl_vterm);
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
818 for (pos.row = 0; pos.row < term->tl_rows; ++pos.row)
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
819 {
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
820 len = 0;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
821 for (pos.col = 0; pos.col < term->tl_cols; ++pos.col)
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
822 if (vterm_screen_get_cell(screen, pos, &cell) != 0
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
823 && cell.chars[0] != NUL)
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
824 len = pos.col + 1;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
825
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
826 if (len == 0)
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
827 ++lines_skipped;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
828 else
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
829 {
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
830 while (lines_skipped > 0)
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
831 {
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
832 /* Line was skipped, add an empty line. */
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
833 --lines_skipped;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
834 if (ga_grow(&term->tl_scrollback, 1) == OK)
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
835 {
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
836 sb_line_T *line = (sb_line_T *)term->tl_scrollback.ga_data
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
837 + term->tl_scrollback.ga_len;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
838
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
839 line->sb_cols = 0;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
840 line->sb_cells = NULL;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
841 ++term->tl_scrollback.ga_len;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
842
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
843 add_scrollback_line_to_buffer(term, (char_u *)"", 0);
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
844 }
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
845 }
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
846
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
847 p = (cellattr_T *)alloc((int)sizeof(cellattr_T) * len);
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
848 if (p != NULL && ga_grow(&term->tl_scrollback, 1) == OK)
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
849 {
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
850 garray_T ga;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
851 int width;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
852 sb_line_T *line = (sb_line_T *)term->tl_scrollback.ga_data
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
853 + term->tl_scrollback.ga_len;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
854
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
855 ga_init2(&ga, 1, 100);
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
856 for (pos.col = 0; pos.col < len; pos.col += width)
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
857 {
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
858 if (vterm_screen_get_cell(screen, pos, &cell) == 0)
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
859 {
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
860 width = 1;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
861 vim_memset(p + pos.col, 0, sizeof(cellattr_T));
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
862 if (ga_grow(&ga, 1) == OK)
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
863 ga.ga_len += mb_char2bytes(' ',
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
864 (char_u *)ga.ga_data + ga.ga_len);
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
865 }
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
866 else
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
867 {
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
868 width = cell.width;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
869
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
870 p[pos.col].width = cell.width;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
871 p[pos.col].attrs = cell.attrs;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
872 p[pos.col].fg = cell.fg;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
873 p[pos.col].bg = cell.bg;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
874
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
875 if (ga_grow(&ga, MB_MAXBYTES) == OK)
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
876 {
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
877 int i;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
878 int c;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
879
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
880 for (i = 0; (c = cell.chars[i]) > 0 || i == 0; ++i)
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
881 ga.ga_len += mb_char2bytes(c == NUL ? ' ' : c,
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
882 (char_u *)ga.ga_data + ga.ga_len);
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
883 }
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
884 }
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
885 }
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
886 line->sb_cols = len;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
887 line->sb_cells = p;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
888 ++term->tl_scrollback.ga_len;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
889
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
890 if (ga_grow(&ga, 1) == FAIL)
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
891 add_scrollback_line_to_buffer(term, (char_u *)"", 0);
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
892 else
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
893 {
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
894 *((char_u *)ga.ga_data + ga.ga_len) = NUL;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
895 add_scrollback_line_to_buffer(term, ga.ga_data, ga.ga_len);
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
896 }
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
897 ga_clear(&ga);
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
898 }
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
899 else
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
900 vim_free(p);
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
901 }
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
902 }
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
903
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
904 FOR_ALL_WINDOWS(wp)
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
905 {
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
906 if (wp->w_buffer == term->tl_buffer)
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
907 {
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
908 wp->w_cursor.lnum = term->tl_buffer->b_ml.ml_line_count;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
909 wp->w_cursor.col = 0;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
910 wp->w_valid = 0;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
911 redraw_win_later(wp, NOT_VALID);
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
912 }
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
913 }
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
914 }
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
915
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
916 static void
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
917 set_terminal_mode(term_T *term, int normal_mode)
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
918 {
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
919 term->tl_normal_mode = normal_mode;
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
920 vim_free(term->tl_status_text);
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
921 term->tl_status_text = NULL;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
922 if (term->tl_buffer == curbuf)
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
923 maketitle();
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
924 }
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
925
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
926 /*
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
927 * Called after the job if finished and Terminal mode is not active:
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
928 * Move the vterm contents into the scrollback buffer and free the vterm.
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
929 */
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
930 static void
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
931 cleanup_vterm(term_T *term)
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
932 {
12064
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
933 if (term->tl_finish != 'c')
12031
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
934 move_terminal_to_buffer(term);
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
935 term_free_vterm(term);
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
936 set_terminal_mode(term, FALSE);
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
937 }
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
938
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
939 /*
11985
d036c1c8537d patch 8.0.0873: in terminal cannot use CTRL- CTRL-N to start Visual mode
Christian Brabandt <cb@256bit.org>
parents: 11983
diff changeset
940 * Switch from Terminal-Job mode to Terminal-Normal mode.
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
941 * Suspends updating the terminal window.
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
942 */
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
943 static void
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
944 term_enter_normal_mode(void)
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
945 {
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
946 term_T *term = curbuf->b_term;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
947
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
948 /* Append the current terminal contents to the buffer. */
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
949 move_terminal_to_buffer(term);
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
950
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
951 set_terminal_mode(term, TRUE);
11985
d036c1c8537d patch 8.0.0873: in terminal cannot use CTRL- CTRL-N to start Visual mode
Christian Brabandt <cb@256bit.org>
parents: 11983
diff changeset
952
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
953 /* Move the window cursor to the position of the cursor in the
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
954 * terminal. */
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
955 curwin->w_cursor.lnum = term->tl_scrollback_scrolled
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
956 + term->tl_cursor_pos.row + 1;
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
957 check_cursor();
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
958 coladvance(term->tl_cursor_pos.col);
11985
d036c1c8537d patch 8.0.0873: in terminal cannot use CTRL- CTRL-N to start Visual mode
Christian Brabandt <cb@256bit.org>
parents: 11983
diff changeset
959
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
960 /* Display the same lines as in the terminal. */
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
961 curwin->w_topline = term->tl_scrollback_scrolled + 1;
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
962 }
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
963
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
964 /*
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
965 * Returns TRUE if the current window contains a terminal and we are in
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
966 * Terminal-Normal mode.
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
967 */
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
968 int
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
969 term_in_normal_mode(void)
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
970 {
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
971 term_T *term = curbuf->b_term;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
972
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
973 return term != NULL && term->tl_normal_mode;
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
974 }
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
975
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
976 /*
11985
d036c1c8537d patch 8.0.0873: in terminal cannot use CTRL- CTRL-N to start Visual mode
Christian Brabandt <cb@256bit.org>
parents: 11983
diff changeset
977 * Switch from Terminal-Normal mode to Terminal-Job mode.
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
978 * Restores updating the terminal window.
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
979 */
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
980 void
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
981 term_enter_job_mode()
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
982 {
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
983 term_T *term = curbuf->b_term;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
984 sb_line_T *line;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
985 garray_T *gap;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
986
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
987 /* Remove the terminal contents from the scrollback and the buffer. */
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
988 gap = &term->tl_scrollback;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
989 while (curbuf->b_ml.ml_line_count > term->tl_scrollback_scrolled)
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
990 {
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
991 ml_delete(curbuf->b_ml.ml_line_count, FALSE);
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
992 line = (sb_line_T *)gap->ga_data + gap->ga_len - 1;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
993 vim_free(line->sb_cells);
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
994 --gap->ga_len;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
995 if (gap->ga_len == 0)
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
996 break;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
997 }
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
998 check_cursor();
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
999
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
1000 set_terminal_mode(term, FALSE);
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1001
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1002 if (term->tl_channel_closed)
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1003 cleanup_vterm(term);
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1004 redraw_buf_and_status_later(curbuf, NOT_VALID);
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1005 }
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1006
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1007 /*
11814
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1008 * Get a key from the user without mapping.
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1009 * TODO: use terminal mode mappings.
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1010 */
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1011 static int
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1012 term_vgetc()
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1013 {
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1014 int c;
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1015
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1016 ++no_mapping;
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1017 ++allow_keys;
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1018 got_int = FALSE;
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1019 c = vgetc();
11870
c29e498aa77d patch 8.0.0815: terminal window not correctly updated
Christian Brabandt <cb@256bit.org>
parents: 11866
diff changeset
1020 got_int = FALSE;
11814
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1021 --no_mapping;
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1022 --allow_keys;
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1023 return c;
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1024 }
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1025
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1026 /*
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1027 * Send keys to terminal.
11965
a932d3da41c8 patch 8.0.0863: a remote command does not work in the terminal window
Christian Brabandt <cb@256bit.org>
parents: 11958
diff changeset
1028 * Return FAIL when the key needs to be handled in Normal mode.
a932d3da41c8 patch 8.0.0863: a remote command does not work in the terminal window
Christian Brabandt <cb@256bit.org>
parents: 11958
diff changeset
1029 * Return OK when the key was dropped or sent to the terminal.
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1030 */
11983
448635f73e09 patch 8.0.0872: no mouse scroll with a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11979
diff changeset
1031 int
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1032 send_keys_to_term(term_T *term, int c, int typed)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1033 {
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1034 char msg[KEY_BUF_LEN];
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1035 size_t len;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1036 static int mouse_was_outside = FALSE;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1037 int dragging_outside = FALSE;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1038
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1039 /* Catch keys that need to be handled as in Normal mode. */
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1040 switch (c)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1041 {
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1042 case NUL:
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1043 case K_ZERO:
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1044 if (typed)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1045 stuffcharReadbuff(c);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1046 return FAIL;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1047
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1048 case K_IGNORE:
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1049 return FAIL;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1050
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1051 case K_LEFTDRAG:
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1052 case K_MIDDLEDRAG:
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1053 case K_RIGHTDRAG:
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1054 case K_X1DRAG:
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1055 case K_X2DRAG:
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1056 dragging_outside = mouse_was_outside;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1057 /* FALLTHROUGH */
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1058 case K_LEFTMOUSE:
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1059 case K_LEFTMOUSE_NM:
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1060 case K_LEFTRELEASE:
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1061 case K_LEFTRELEASE_NM:
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1062 case K_MIDDLEMOUSE:
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1063 case K_MIDDLERELEASE:
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1064 case K_RIGHTMOUSE:
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1065 case K_RIGHTRELEASE:
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1066 case K_X1MOUSE:
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1067 case K_X1RELEASE:
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1068 case K_X2MOUSE:
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1069 case K_X2RELEASE:
11983
448635f73e09 patch 8.0.0872: no mouse scroll with a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11979
diff changeset
1070
448635f73e09 patch 8.0.0872: no mouse scroll with a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11979
diff changeset
1071 case K_MOUSEUP:
448635f73e09 patch 8.0.0872: no mouse scroll with a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11979
diff changeset
1072 case K_MOUSEDOWN:
448635f73e09 patch 8.0.0872: no mouse scroll with a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11979
diff changeset
1073 case K_MOUSELEFT:
448635f73e09 patch 8.0.0872: no mouse scroll with a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11979
diff changeset
1074 case K_MOUSERIGHT:
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1075 if (mouse_row < W_WINROW(curwin)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1076 || mouse_row >= (W_WINROW(curwin) + curwin->w_height)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1077 || mouse_col < W_WINCOL(curwin)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1078 || mouse_col >= W_ENDCOL(curwin)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1079 || dragging_outside)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1080 {
11983
448635f73e09 patch 8.0.0872: no mouse scroll with a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11979
diff changeset
1081 /* click or scroll outside the current window */
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1082 if (typed)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1083 {
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1084 stuffcharReadbuff(c);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1085 mouse_was_outside = TRUE;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1086 }
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1087 return FAIL;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1088 }
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1089 }
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1090 if (typed)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1091 mouse_was_outside = FALSE;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1092
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1093 /* Convert the typed key to a sequence of bytes for the job. */
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1094 len = term_convert_key(term, c, msg);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1095 if (len > 0)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1096 /* TODO: if FAIL is returned, stop? */
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1097 channel_send(term->tl_job->jv_channel, PART_IN,
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1098 (char_u *)msg, (int)len, NULL);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1099
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1100 return OK;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1101 }
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1102
11878
a83b19a8d7e4 patch 8.0.0819: cursor not positioned in terminal window
Christian Brabandt <cb@256bit.org>
parents: 11876
diff changeset
1103 static void
a83b19a8d7e4 patch 8.0.0819: cursor not positioned in terminal window
Christian Brabandt <cb@256bit.org>
parents: 11876
diff changeset
1104 position_cursor(win_T *wp, VTermPos *pos)
a83b19a8d7e4 patch 8.0.0819: cursor not positioned in terminal window
Christian Brabandt <cb@256bit.org>
parents: 11876
diff changeset
1105 {
a83b19a8d7e4 patch 8.0.0819: cursor not positioned in terminal window
Christian Brabandt <cb@256bit.org>
parents: 11876
diff changeset
1106 wp->w_wrow = MIN(pos->row, MAX(0, wp->w_height - 1));
a83b19a8d7e4 patch 8.0.0819: cursor not positioned in terminal window
Christian Brabandt <cb@256bit.org>
parents: 11876
diff changeset
1107 wp->w_wcol = MIN(pos->col, MAX(0, wp->w_width - 1));
a83b19a8d7e4 patch 8.0.0819: cursor not positioned in terminal window
Christian Brabandt <cb@256bit.org>
parents: 11876
diff changeset
1108 wp->w_valid |= (VALID_WCOL|VALID_WROW);
a83b19a8d7e4 patch 8.0.0819: cursor not positioned in terminal window
Christian Brabandt <cb@256bit.org>
parents: 11876
diff changeset
1109 }
a83b19a8d7e4 patch 8.0.0819: cursor not positioned in terminal window
Christian Brabandt <cb@256bit.org>
parents: 11876
diff changeset
1110
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1111 /*
11886
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1112 * Handle CTRL-W "": send register contents to the job.
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1113 */
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1114 static void
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1115 term_paste_register(int prev_c UNUSED)
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1116 {
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1117 int c;
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1118 list_T *l;
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1119 listitem_T *item;
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1120 long reglen = 0;
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1121 int type;
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1122
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1123 #ifdef FEAT_CMDL_INFO
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1124 if (add_to_showcmd(prev_c))
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1125 if (add_to_showcmd('"'))
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1126 out_flush();
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1127 #endif
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1128 c = term_vgetc();
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1129 #ifdef FEAT_CMDL_INFO
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1130 clear_showcmd();
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1131 #endif
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1132
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1133 /* CTRL-W "= prompt for expression to evaluate. */
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1134 if (c == '=' && get_expr_register() != '=')
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1135 return;
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1136
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1137 l = (list_T *)get_reg_contents(c, GREG_LIST);
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1138 if (l != NULL)
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1139 {
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1140 type = get_reg_type(c, &reglen);
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1141 for (item = l->lv_first; item != NULL; item = item->li_next)
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1142 {
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1143 char_u *s = get_tv_string(&item->li_tv);
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1144
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1145 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN,
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1146 s, STRLEN(s), NULL);
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1147 if (item->li_next != NULL || type == MLINE)
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1148 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN,
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1149 (char_u *)"\r", 1, NULL);
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1150 }
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1151 list_free(l);
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1152 }
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1153 }
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1154
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1155 /*
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1156 * Returns TRUE if the current window contains a terminal and we are sending
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1157 * keys to the job.
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1158 */
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1159 int
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
1160 term_use_loop(void)
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1161 {
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1162 term_T *term = curbuf->b_term;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1163
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1164 return term != NULL
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
1165 && !term->tl_normal_mode
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1166 && term->tl_vterm != NULL
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1167 && term_job_running(term);
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1168 }
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1169
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1170 /*
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1171 * Wait for input and send it to the job.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1172 * Return when the start of a CTRL-W command is typed or anything else that
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1173 * should be handled as a Normal mode command.
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1174 * Returns OK if a typed character is to be handled in Normal mode, FAIL if
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1175 * the terminal was closed.
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1176 */
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1177 int
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1178 terminal_loop(void)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1179 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1180 int c;
11764
b82dad3fa176 patch 8.0.0764: 'termkey' does not work yet
Christian Brabandt <cb@256bit.org>
parents: 11757
diff changeset
1181 int termkey = 0;
b82dad3fa176 patch 8.0.0764: 'termkey' does not work yet
Christian Brabandt <cb@256bit.org>
parents: 11757
diff changeset
1182
b82dad3fa176 patch 8.0.0764: 'termkey' does not work yet
Christian Brabandt <cb@256bit.org>
parents: 11757
diff changeset
1183 if (*curwin->w_p_tk != NUL)
b82dad3fa176 patch 8.0.0764: 'termkey' does not work yet
Christian Brabandt <cb@256bit.org>
parents: 11757
diff changeset
1184 termkey = string_to_key(curwin->w_p_tk, TRUE);
11878
a83b19a8d7e4 patch 8.0.0819: cursor not positioned in terminal window
Christian Brabandt <cb@256bit.org>
parents: 11876
diff changeset
1185 position_cursor(curwin, &curbuf->b_term->tl_cursor_pos);
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1186
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1187 for (;;)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1188 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1189 /* TODO: skip screen update when handling a sequence of keys. */
11870
c29e498aa77d patch 8.0.0815: terminal window not correctly updated
Christian Brabandt <cb@256bit.org>
parents: 11866
diff changeset
1190 /* Repeat redrawing in case a message is received while redrawing. */
c29e498aa77d patch 8.0.0815: terminal window not correctly updated
Christian Brabandt <cb@256bit.org>
parents: 11866
diff changeset
1191 while (curwin->w_redr_type != 0)
c29e498aa77d patch 8.0.0815: terminal window not correctly updated
Christian Brabandt <cb@256bit.org>
parents: 11866
diff changeset
1192 update_screen(0);
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
1193 update_cursor(curbuf->b_term, FALSE);
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1194
11814
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1195 c = term_vgetc();
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
1196 if (!term_use_loop())
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1197 /* job finished while waiting for a character */
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1198 break;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1199
11919
cca097489de5 patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents: 11917
diff changeset
1200 #ifdef UNIX
cca097489de5 patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents: 11917
diff changeset
1201 may_send_sigint(c, curbuf->b_term->tl_job->jv_pid, 0);
cca097489de5 patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents: 11917
diff changeset
1202 #endif
cca097489de5 patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents: 11917
diff changeset
1203 #ifdef WIN3264
cca097489de5 patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents: 11917
diff changeset
1204 if (c == Ctrl_C)
cca097489de5 patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents: 11917
diff changeset
1205 /* We don't know if the job can handle CTRL-C itself or not, this
cca097489de5 patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents: 11917
diff changeset
1206 * may kill the shell instead of killing the command running in the
cca097489de5 patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents: 11917
diff changeset
1207 * shell. */
12037
85f0f557661e patch 8.0.0899: function name mch_stop_job() is confusing
Christian Brabandt <cb@256bit.org>
parents: 12035
diff changeset
1208 mch_signal_job(curbuf->b_term->tl_job, (char_u *)"quit");
11919
cca097489de5 patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents: 11917
diff changeset
1209 #endif
cca097489de5 patch 8.0.0839: cannot kill a job in a terminal with CTRL-C
Christian Brabandt <cb@256bit.org>
parents: 11917
diff changeset
1210
11965
a932d3da41c8 patch 8.0.0863: a remote command does not work in the terminal window
Christian Brabandt <cb@256bit.org>
parents: 11958
diff changeset
1211 if (c == (termkey == 0 ? Ctrl_W : termkey) || c == Ctrl_BSL)
11764
b82dad3fa176 patch 8.0.0764: 'termkey' does not work yet
Christian Brabandt <cb@256bit.org>
parents: 11757
diff changeset
1212 {
11886
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1213 int prev_c = c;
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1214
11814
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1215 #ifdef FEAT_CMDL_INFO
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1216 if (add_to_showcmd(c))
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1217 out_flush();
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1218 #endif
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1219 c = term_vgetc();
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1220 #ifdef FEAT_CMDL_INFO
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1221 clear_showcmd();
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1222 #endif
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
1223 if (!term_use_loop())
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1224 /* job finished while waiting for a character */
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1225 break;
11814
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1226
11965
a932d3da41c8 patch 8.0.0863: a remote command does not work in the terminal window
Christian Brabandt <cb@256bit.org>
parents: 11958
diff changeset
1227 if (prev_c == Ctrl_BSL)
a932d3da41c8 patch 8.0.0863: a remote command does not work in the terminal window
Christian Brabandt <cb@256bit.org>
parents: 11958
diff changeset
1228 {
a932d3da41c8 patch 8.0.0863: a remote command does not work in the terminal window
Christian Brabandt <cb@256bit.org>
parents: 11958
diff changeset
1229 if (c == Ctrl_N)
11985
d036c1c8537d patch 8.0.0873: in terminal cannot use CTRL- CTRL-N to start Visual mode
Christian Brabandt <cb@256bit.org>
parents: 11983
diff changeset
1230 {
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
1231 /* CTRL-\ CTRL-N : go to Terminal-Normal mode. */
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
1232 term_enter_normal_mode();
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
1233 return FAIL;
11985
d036c1c8537d patch 8.0.0873: in terminal cannot use CTRL- CTRL-N to start Visual mode
Christian Brabandt <cb@256bit.org>
parents: 11983
diff changeset
1234 }
11965
a932d3da41c8 patch 8.0.0863: a remote command does not work in the terminal window
Christian Brabandt <cb@256bit.org>
parents: 11958
diff changeset
1235 /* Send both keys to the terminal. */
a932d3da41c8 patch 8.0.0863: a remote command does not work in the terminal window
Christian Brabandt <cb@256bit.org>
parents: 11958
diff changeset
1236 send_keys_to_term(curbuf->b_term, prev_c, TRUE);
a932d3da41c8 patch 8.0.0863: a remote command does not work in the terminal window
Christian Brabandt <cb@256bit.org>
parents: 11958
diff changeset
1237 }
a932d3da41c8 patch 8.0.0863: a remote command does not work in the terminal window
Christian Brabandt <cb@256bit.org>
parents: 11958
diff changeset
1238 else if (termkey == 0 && c == '.')
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1239 {
11814
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1240 /* "CTRL-W .": send CTRL-W to the job */
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1241 c = Ctrl_W;
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1242 }
11886
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1243 else if (c == 'N')
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1244 {
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
1245 /* CTRL-W N : go to Terminal-Normal mode. */
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
1246 term_enter_normal_mode();
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1247 return FAIL;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1248 }
11886
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1249 else if (c == '"')
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1250 {
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1251 term_paste_register(prev_c);
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1252 continue;
7928d62d29ee patch 8.0.0823: cannot paste text into a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11882
diff changeset
1253 }
11814
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1254 else if (termkey == 0 || c != termkey)
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1255 {
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1256 stuffcharReadbuff(Ctrl_W);
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1257 stuffcharReadbuff(c);
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1258 return OK;
11814
d3d0db111d17 patch 8.0.0787: cannot send CTRL-W command to terminal job
Christian Brabandt <cb@256bit.org>
parents: 11804
diff changeset
1259 }
11764
b82dad3fa176 patch 8.0.0764: 'termkey' does not work yet
Christian Brabandt <cb@256bit.org>
parents: 11757
diff changeset
1260 }
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1261 if (send_keys_to_term(curbuf->b_term, c, TRUE) != OK)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1262 return OK;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1263 }
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1264 return FAIL;
11757
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
1265 }
74abb6c84984 patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents: 11755
diff changeset
1266
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1267 /*
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1268 * Called when a job has finished.
12064
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
1269 * This updates the title and status, but does not close the vterm, because
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1270 * there might still be pending output in the channel.
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1271 */
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1272 void
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1273 term_job_ended(job_T *job)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1274 {
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1275 term_T *term;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1276 int did_one = FALSE;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1277
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1278 for (term = first_term; term != NULL; term = term->tl_next)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1279 if (term->tl_job == job)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1280 {
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1281 vim_free(term->tl_title);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1282 term->tl_title = NULL;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1283 vim_free(term->tl_status_text);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1284 term->tl_status_text = NULL;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1285 redraw_buf_and_status_later(term->tl_buffer, VALID);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1286 did_one = TRUE;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1287 }
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1288 if (did_one)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1289 redraw_statuslines();
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1290 if (curbuf->b_term != NULL)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1291 {
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1292 if (curbuf->b_term->tl_job == job)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1293 maketitle();
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1294 update_cursor(curbuf->b_term, TRUE);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1295 }
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1296 }
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1297
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1298 static void
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
1299 may_toggle_cursor(term_T *term)
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
1300 {
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
1301 if (curbuf == term->tl_buffer)
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
1302 {
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
1303 if (term->tl_cursor_visible)
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
1304 cursor_on();
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
1305 else
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
1306 cursor_off();
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
1307 }
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
1308 }
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
1309
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1310 static int
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1311 handle_damage(VTermRect rect, void *user)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1312 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1313 term_T *term = (term_T *)user;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1314
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1315 term->tl_dirty_row_start = MIN(term->tl_dirty_row_start, rect.start_row);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1316 term->tl_dirty_row_end = MAX(term->tl_dirty_row_end, rect.end_row);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1317 redraw_buf_later(term->tl_buffer, NOT_VALID);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1318 return 1;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1319 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1320
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1321 static int
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1322 handle_moverect(VTermRect dest UNUSED, VTermRect src UNUSED, void *user)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1323 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1324 term_T *term = (term_T *)user;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1325
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1326 /* TODO */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1327 redraw_buf_later(term->tl_buffer, NOT_VALID);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1328 return 1;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1329 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1330
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1331 static int
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1332 handle_movecursor(
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1333 VTermPos pos,
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1334 VTermPos oldpos UNUSED,
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
1335 int visible,
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1336 void *user)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1337 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1338 term_T *term = (term_T *)user;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1339 win_T *wp;
11874
d444e087b8fd patch 8.0.0817: cannot get the terminal line at the cursor
Christian Brabandt <cb@256bit.org>
parents: 11872
diff changeset
1340
d444e087b8fd patch 8.0.0817: cannot get the terminal line at the cursor
Christian Brabandt <cb@256bit.org>
parents: 11872
diff changeset
1341 term->tl_cursor_pos = pos;
d444e087b8fd patch 8.0.0817: cannot get the terminal line at the cursor
Christian Brabandt <cb@256bit.org>
parents: 11872
diff changeset
1342 term->tl_cursor_visible = visible;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1343
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1344 FOR_ALL_WINDOWS(wp)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1345 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1346 if (wp->w_buffer == term->tl_buffer)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1347 position_cursor(wp, &pos);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1348 }
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
1349 if (term->tl_buffer == curbuf && !term->tl_normal_mode)
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
1350 {
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
1351 may_toggle_cursor(term);
11880
45558e0507e8 patch 8.0.0820: GUI: cursor in terminal window lags behind
Christian Brabandt <cb@256bit.org>
parents: 11878
diff changeset
1352 update_cursor(term, term->tl_cursor_visible);
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
1353 }
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1354
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1355 return 1;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1356 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1357
11772
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1358 static int
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1359 handle_settermprop(
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1360 VTermProp prop,
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1361 VTermValue *value,
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1362 void *user)
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1363 {
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1364 term_T *term = (term_T *)user;
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1365
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1366 switch (prop)
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1367 {
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1368 case VTERM_PROP_TITLE:
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1369 vim_free(term->tl_title);
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1370 term->tl_title = vim_strsave((char_u *)value->string);
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1371 vim_free(term->tl_status_text);
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1372 term->tl_status_text = NULL;
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1373 if (term == curbuf->b_term)
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1374 maketitle();
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
1375 break;
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
1376
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
1377 case VTERM_PROP_CURSORVISIBLE:
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
1378 term->tl_cursor_visible = value->boolean;
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
1379 may_toggle_cursor(term);
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
1380 out_flush();
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
1381 break;
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
1382
12035
a3ed3d236839 patch 8.0.0898: can't use the alternate screen in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12031
diff changeset
1383 case VTERM_PROP_ALTSCREEN:
a3ed3d236839 patch 8.0.0898: can't use the alternate screen in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12031
diff changeset
1384 /* TODO: do anything else? */
a3ed3d236839 patch 8.0.0898: can't use the alternate screen in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12031
diff changeset
1385 term->tl_using_altscreen = value->boolean;
a3ed3d236839 patch 8.0.0898: can't use the alternate screen in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12031
diff changeset
1386 break;
a3ed3d236839 patch 8.0.0898: can't use the alternate screen in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12031
diff changeset
1387
11772
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1388 default:
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1389 break;
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1390 }
11786
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
1391 /* Always return 1, otherwise vterm doesn't store the value internally. */
98154b91e43a patch 8.0.0775: in a terminal the cursor is updated too often
Christian Brabandt <cb@256bit.org>
parents: 11778
diff changeset
1392 return 1;
11772
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1393 }
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1394
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1395 /*
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1396 * The job running in the terminal resized the terminal.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1397 */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1398 static int
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1399 handle_resize(int rows, int cols, void *user)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1400 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1401 term_T *term = (term_T *)user;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1402 win_T *wp;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1403
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1404 term->tl_rows = rows;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1405 term->tl_cols = cols;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1406 FOR_ALL_WINDOWS(wp)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1407 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1408 if (wp->w_buffer == term->tl_buffer)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1409 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1410 win_setheight_win(rows, wp);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1411 win_setwidth_win(cols, wp);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1412 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1413 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1414
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1415 redraw_buf_later(term->tl_buffer, NOT_VALID);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1416 return 1;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1417 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1418
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1419 /*
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1420 * Handle a line that is pushed off the top of the screen.
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1421 */
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1422 static int
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1423 handle_pushline(int cols, const VTermScreenCell *cells, void *user)
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1424 {
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1425 term_T *term = (term_T *)user;
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1426
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1427 /* TODO: Limit the number of lines that are stored. */
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1428 if (ga_grow(&term->tl_scrollback, 1) == OK)
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1429 {
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1430 cellattr_T *p = NULL;
11840
3c1f89d85151 patch 8.0.0800 Problem: Terminal window scrollback contents is wrong. Solution: Fix handling of multi-byte characters (Yasuhiro Matsumoto) Handle empty lines correctly. (closes #1891)
Christian Brabandt <cb@256bit.org>
parents: 11838
diff changeset
1431 int len = 0;
3c1f89d85151 patch 8.0.0800 Problem: Terminal window scrollback contents is wrong. Solution: Fix handling of multi-byte characters (Yasuhiro Matsumoto) Handle empty lines correctly. (closes #1891)
Christian Brabandt <cb@256bit.org>
parents: 11838
diff changeset
1432 int i;
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1433 int c;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1434 int col;
11840
3c1f89d85151 patch 8.0.0800 Problem: Terminal window scrollback contents is wrong. Solution: Fix handling of multi-byte characters (Yasuhiro Matsumoto) Handle empty lines correctly. (closes #1891)
Christian Brabandt <cb@256bit.org>
parents: 11838
diff changeset
1435 sb_line_T *line;
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1436 garray_T ga;
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1437
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1438 /* do not store empty cells at the end */
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1439 for (i = 0; i < cols; ++i)
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1440 if (cells[i].chars[0] != 0)
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1441 len = i + 1;
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1442
12021
a7457aed7e80 patch 8.0.0891: uninitialized memory use with empty line in terminal
Christian Brabandt <cb@256bit.org>
parents: 12017
diff changeset
1443 ga_init2(&ga, 1, 100);
11840
3c1f89d85151 patch 8.0.0800 Problem: Terminal window scrollback contents is wrong. Solution: Fix handling of multi-byte characters (Yasuhiro Matsumoto) Handle empty lines correctly. (closes #1891)
Christian Brabandt <cb@256bit.org>
parents: 11838
diff changeset
1444 if (len > 0)
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1445 p = (cellattr_T *)alloc((int)sizeof(cellattr_T) * len);
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1446 if (p != NULL)
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1447 {
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1448 for (col = 0; col < len; col += cells[col].width)
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1449 {
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1450 if (ga_grow(&ga, MB_MAXBYTES) == FAIL)
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1451 {
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1452 ga.ga_len = 0;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1453 break;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1454 }
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1455 for (i = 0; (c = cells[col].chars[i]) > 0 || i == 0; ++i)
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1456 ga.ga_len += mb_char2bytes(c == NUL ? ' ' : c,
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1457 (char_u *)ga.ga_data + ga.ga_len);
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1458 p[col].width = cells[col].width;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1459 p[col].attrs = cells[col].attrs;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1460 p[col].fg = cells[col].fg;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1461 p[col].bg = cells[col].bg;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1462 }
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1463 }
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1464 if (ga_grow(&ga, 1) == FAIL)
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1465 add_scrollback_line_to_buffer(term, (char_u *)"", 0);
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1466 else
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1467 {
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1468 *((char_u *)ga.ga_data + ga.ga_len) = NUL;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1469 add_scrollback_line_to_buffer(term, ga.ga_data, ga.ga_len);
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1470 }
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1471 ga_clear(&ga);
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1472
11840
3c1f89d85151 patch 8.0.0800 Problem: Terminal window scrollback contents is wrong. Solution: Fix handling of multi-byte characters (Yasuhiro Matsumoto) Handle empty lines correctly. (closes #1891)
Christian Brabandt <cb@256bit.org>
parents: 11838
diff changeset
1473 line = (sb_line_T *)term->tl_scrollback.ga_data
3c1f89d85151 patch 8.0.0800 Problem: Terminal window scrollback contents is wrong. Solution: Fix handling of multi-byte characters (Yasuhiro Matsumoto) Handle empty lines correctly. (closes #1891)
Christian Brabandt <cb@256bit.org>
parents: 11838
diff changeset
1474 + term->tl_scrollback.ga_len;
3c1f89d85151 patch 8.0.0800 Problem: Terminal window scrollback contents is wrong. Solution: Fix handling of multi-byte characters (Yasuhiro Matsumoto) Handle empty lines correctly. (closes #1891)
Christian Brabandt <cb@256bit.org>
parents: 11838
diff changeset
1475 line->sb_cols = len;
3c1f89d85151 patch 8.0.0800 Problem: Terminal window scrollback contents is wrong. Solution: Fix handling of multi-byte characters (Yasuhiro Matsumoto) Handle empty lines correctly. (closes #1891)
Christian Brabandt <cb@256bit.org>
parents: 11838
diff changeset
1476 line->sb_cells = p;
3c1f89d85151 patch 8.0.0800 Problem: Terminal window scrollback contents is wrong. Solution: Fix handling of multi-byte characters (Yasuhiro Matsumoto) Handle empty lines correctly. (closes #1891)
Christian Brabandt <cb@256bit.org>
parents: 11838
diff changeset
1477 ++term->tl_scrollback.ga_len;
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1478 ++term->tl_scrollback_scrolled;
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1479 }
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1480 return 0; /* ignored */
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1481 }
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1482
11772
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1483 static VTermScreenCallbacks screen_callbacks = {
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1484 handle_damage, /* damage */
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1485 handle_moverect, /* moverect */
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1486 handle_movecursor, /* movecursor */
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1487 handle_settermprop, /* settermprop */
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1488 NULL, /* bell */
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1489 handle_resize, /* resize */
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1490 handle_pushline, /* sb_pushline */
11772
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1491 NULL /* sb_popline */
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1492 };
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1493
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1494 /*
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1495 * Called when a channel has been closed.
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1496 * If this was a channel for a terminal window then finish it up.
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1497 */
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1498 void
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1499 term_channel_closed(channel_T *ch)
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1500 {
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1501 term_T *term;
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1502 int did_one = FALSE;
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1503
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1504 for (term = first_term; term != NULL; term = term->tl_next)
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1505 if (term->tl_job == ch->ch_job)
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1506 {
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1507 term->tl_channel_closed = TRUE;
12031
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
1508 did_one = TRUE;
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1509
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1510 vim_free(term->tl_title);
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1511 term->tl_title = NULL;
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1512 vim_free(term->tl_status_text);
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1513 term->tl_status_text = NULL;
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1514
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1515 /* Unless in Terminal-Normal mode: clear the vterm. */
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
1516 if (!term->tl_normal_mode)
12031
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
1517 {
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
1518 int fnum = term->tl_buffer->b_fnum;
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
1519
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1520 cleanup_vterm(term);
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1521
12031
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
1522 if (term->tl_finish == 'c')
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
1523 {
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
1524 /* ++close or term_finish == "close" */
12064
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
1525 ch_log(NULL, "terminal job finished, closing window");
12031
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
1526 curbuf = term->tl_buffer;
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
1527 do_bufdel(DOBUF_WIPE, (char_u *)"", 1, fnum, fnum, FALSE);
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
1528 break;
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
1529 }
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
1530 if (term->tl_finish == 'o' && term->tl_buffer->b_nwindows == 0)
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
1531 {
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
1532 char buf[50];
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
1533
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
1534 /* TODO: use term_opencmd */
12064
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
1535 ch_log(NULL, "terminal job finished, opening window");
12031
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
1536 vim_snprintf(buf, sizeof(buf), "botright sbuf %d", fnum);
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
1537 do_cmdline_cmd((char_u *)buf);
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
1538 }
12064
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
1539 else
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
1540 ch_log(NULL, "terminal job finished");
12031
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
1541 }
9897241c08b5 patch 8.0.0896: cannot close a terminal window when the job ends
Christian Brabandt <cb@256bit.org>
parents: 12025
diff changeset
1542
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1543 redraw_buf_and_status_later(term->tl_buffer, NOT_VALID);
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1544 }
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1545 if (did_one)
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1546 {
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1547 redraw_statuslines();
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1548
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1549 /* Need to break out of vgetc(). */
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1550 ins_char_typebuf(K_IGNORE);
11949
74e45c11b754 patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents: 11947
diff changeset
1551 typebuf_was_filled = TRUE;
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1552
11880
45558e0507e8 patch 8.0.0820: GUI: cursor in terminal window lags behind
Christian Brabandt <cb@256bit.org>
parents: 11878
diff changeset
1553 term = curbuf->b_term;
45558e0507e8 patch 8.0.0820: GUI: cursor in terminal window lags behind
Christian Brabandt <cb@256bit.org>
parents: 11878
diff changeset
1554 if (term != NULL)
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1555 {
11880
45558e0507e8 patch 8.0.0820: GUI: cursor in terminal window lags behind
Christian Brabandt <cb@256bit.org>
parents: 11878
diff changeset
1556 if (term->tl_job == ch->ch_job)
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1557 maketitle();
11880
45558e0507e8 patch 8.0.0820: GUI: cursor in terminal window lags behind
Christian Brabandt <cb@256bit.org>
parents: 11878
diff changeset
1558 update_cursor(term, term->tl_cursor_visible);
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1559 }
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1560 }
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1561 }
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1562
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1563 /*
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1564 * Reverse engineer the RGB value into a cterm color index.
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1565 * First color is 1. Return 0 if no match found.
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1566 */
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1567 static int
11902
35d7459251fd patch 8.0.0831: with 8 colors the bold attribute is not set properly
Christian Brabandt <cb@256bit.org>
parents: 11888
diff changeset
1568 color2index(VTermColor *color, int fg, int *boldp)
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1569 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1570 int red = color->red;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1571 int blue = color->blue;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1572 int green = color->green;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1573
11822
1e237c5994fc patch 8.0.0791: terminal colors depend on the system
Christian Brabandt <cb@256bit.org>
parents: 11818
diff changeset
1574 /* The argument for lookup_color() is for the color_names[] table. */
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1575 if (red == 0)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1576 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1577 if (green == 0)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1578 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1579 if (blue == 0)
11902
35d7459251fd patch 8.0.0831: with 8 colors the bold attribute is not set properly
Christian Brabandt <cb@256bit.org>
parents: 11888
diff changeset
1580 return lookup_color(0, fg, boldp) + 1; /* black */
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1581 if (blue == 224)
11902
35d7459251fd patch 8.0.0831: with 8 colors the bold attribute is not set properly
Christian Brabandt <cb@256bit.org>
parents: 11888
diff changeset
1582 return lookup_color(1, fg, boldp) + 1; /* dark blue */
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1583 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1584 else if (green == 224)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1585 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1586 if (blue == 0)
11902
35d7459251fd patch 8.0.0831: with 8 colors the bold attribute is not set properly
Christian Brabandt <cb@256bit.org>
parents: 11888
diff changeset
1587 return lookup_color(2, fg, boldp) + 1; /* dark green */
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1588 if (blue == 224)
11902
35d7459251fd patch 8.0.0831: with 8 colors the bold attribute is not set properly
Christian Brabandt <cb@256bit.org>
parents: 11888
diff changeset
1589 return lookup_color(3, fg, boldp) + 1; /* dark cyan */
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1590 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1591 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1592 else if (red == 224)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1593 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1594 if (green == 0)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1595 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1596 if (blue == 0)
11902
35d7459251fd patch 8.0.0831: with 8 colors the bold attribute is not set properly
Christian Brabandt <cb@256bit.org>
parents: 11888
diff changeset
1597 return lookup_color(4, fg, boldp) + 1; /* dark red */
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1598 if (blue == 224)
11902
35d7459251fd patch 8.0.0831: with 8 colors the bold attribute is not set properly
Christian Brabandt <cb@256bit.org>
parents: 11888
diff changeset
1599 return lookup_color(5, fg, boldp) + 1; /* dark magenta */
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1600 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1601 else if (green == 224)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1602 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1603 if (blue == 0)
11902
35d7459251fd patch 8.0.0831: with 8 colors the bold attribute is not set properly
Christian Brabandt <cb@256bit.org>
parents: 11888
diff changeset
1604 return lookup_color(6, fg, boldp) + 1; /* dark yellow / brown */
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1605 if (blue == 224)
11902
35d7459251fd patch 8.0.0831: with 8 colors the bold attribute is not set properly
Christian Brabandt <cb@256bit.org>
parents: 11888
diff changeset
1606 return lookup_color(8, fg, boldp) + 1; /* white / light grey */
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1607 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1608 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1609 else if (red == 128)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1610 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1611 if (green == 128 && blue == 128)
11902
35d7459251fd patch 8.0.0831: with 8 colors the bold attribute is not set properly
Christian Brabandt <cb@256bit.org>
parents: 11888
diff changeset
1612 return lookup_color(12, fg, boldp) + 1; /* high intensity black / dark grey */
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1613 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1614 else if (red == 255)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1615 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1616 if (green == 64)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1617 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1618 if (blue == 64)
11902
35d7459251fd patch 8.0.0831: with 8 colors the bold attribute is not set properly
Christian Brabandt <cb@256bit.org>
parents: 11888
diff changeset
1619 return lookup_color(20, fg, boldp) + 1; /* light red */
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1620 if (blue == 255)
11902
35d7459251fd patch 8.0.0831: with 8 colors the bold attribute is not set properly
Christian Brabandt <cb@256bit.org>
parents: 11888
diff changeset
1621 return lookup_color(22, fg, boldp) + 1; /* light magenta */
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1622 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1623 else if (green == 255)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1624 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1625 if (blue == 64)
11902
35d7459251fd patch 8.0.0831: with 8 colors the bold attribute is not set properly
Christian Brabandt <cb@256bit.org>
parents: 11888
diff changeset
1626 return lookup_color(24, fg, boldp) + 1; /* yellow */
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1627 if (blue == 255)
11902
35d7459251fd patch 8.0.0831: with 8 colors the bold attribute is not set properly
Christian Brabandt <cb@256bit.org>
parents: 11888
diff changeset
1628 return lookup_color(26, fg, boldp) + 1; /* white */
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1629 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1630 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1631 else if (red == 64)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1632 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1633 if (green == 64)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1634 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1635 if (blue == 255)
11902
35d7459251fd patch 8.0.0831: with 8 colors the bold attribute is not set properly
Christian Brabandt <cb@256bit.org>
parents: 11888
diff changeset
1636 return lookup_color(14, fg, boldp) + 1; /* light blue */
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1637 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1638 else if (green == 255)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1639 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1640 if (blue == 64)
11902
35d7459251fd patch 8.0.0831: with 8 colors the bold attribute is not set properly
Christian Brabandt <cb@256bit.org>
parents: 11888
diff changeset
1641 return lookup_color(16, fg, boldp) + 1; /* light green */
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1642 if (blue == 255)
11902
35d7459251fd patch 8.0.0831: with 8 colors the bold attribute is not set properly
Christian Brabandt <cb@256bit.org>
parents: 11888
diff changeset
1643 return lookup_color(18, fg, boldp) + 1; /* light cyan */
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1644 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1645 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1646 if (t_colors >= 256)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1647 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1648 if (red == blue && red == green)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1649 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1650 /* 24-color greyscale */
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1651 static int cutoff[23] = {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1652 0x05, 0x10, 0x1B, 0x26, 0x31, 0x3C, 0x47, 0x52,
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1653 0x5D, 0x68, 0x73, 0x7F, 0x8A, 0x95, 0xA0, 0xAB,
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1654 0xB6, 0xC1, 0xCC, 0xD7, 0xE2, 0xED, 0xF9};
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1655 int i;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1656
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1657 for (i = 0; i < 23; ++i)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1658 if (red < cutoff[i])
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1659 return i + 233;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1660 return 256;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1661 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1662
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1663 /* 216-color cube */
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1664 return 17 + ((red + 25) / 0x33) * 36
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1665 + ((green + 25) / 0x33) * 6
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1666 + (blue + 25) / 0x33;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1667 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1668 return 0;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1669 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1670
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1671 /*
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1672 * Convert the attributes of a vterm cell into an attribute index.
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1673 */
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1674 static int
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1675 cell2attr(VTermScreenCellAttrs cellattrs, VTermColor cellfg, VTermColor cellbg)
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1676 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1677 int attr = 0;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1678
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1679 if (cellattrs.bold)
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1680 attr |= HL_BOLD;
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1681 if (cellattrs.underline)
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1682 attr |= HL_UNDERLINE;
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1683 if (cellattrs.italic)
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1684 attr |= HL_ITALIC;
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1685 if (cellattrs.strike)
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1686 attr |= HL_STANDOUT;
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1687 if (cellattrs.reverse)
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1688 attr |= HL_INVERSE;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1689
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1690 #ifdef FEAT_GUI
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1691 if (gui.in_use)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1692 {
11745
5a5709918a98 patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents: 11743
diff changeset
1693 guicolor_T fg, bg;
5a5709918a98 patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents: 11743
diff changeset
1694
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1695 fg = gui_mch_get_rgb_color(cellfg.red, cellfg.green, cellfg.blue);
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1696 bg = gui_mch_get_rgb_color(cellbg.red, cellbg.green, cellbg.blue);
11745
5a5709918a98 patch 8.0.0755: terminal window does not have colors in the GUI
Christian Brabandt <cb@256bit.org>
parents: 11743
diff changeset
1697 return get_gui_attr_idx(attr, fg, bg);
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1698 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1699 else
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1700 #endif
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1701 #ifdef FEAT_TERMGUICOLORS
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1702 if (p_tgc)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1703 {
11755
12fa6072977a patch 8.0.0760: terminal window colors wrong with 'termguicolors'
Christian Brabandt <cb@256bit.org>
parents: 11753
diff changeset
1704 guicolor_T fg, bg;
12fa6072977a patch 8.0.0760: terminal window colors wrong with 'termguicolors'
Christian Brabandt <cb@256bit.org>
parents: 11753
diff changeset
1705
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1706 fg = gui_get_rgb_color_cmn(cellfg.red, cellfg.green, cellfg.blue);
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1707 bg = gui_get_rgb_color_cmn(cellbg.red, cellbg.green, cellbg.blue);
11755
12fa6072977a patch 8.0.0760: terminal window colors wrong with 'termguicolors'
Christian Brabandt <cb@256bit.org>
parents: 11753
diff changeset
1708
12fa6072977a patch 8.0.0760: terminal window colors wrong with 'termguicolors'
Christian Brabandt <cb@256bit.org>
parents: 11753
diff changeset
1709 return get_tgc_attr_idx(attr, fg, bg);
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1710 }
11755
12fa6072977a patch 8.0.0760: terminal window colors wrong with 'termguicolors'
Christian Brabandt <cb@256bit.org>
parents: 11753
diff changeset
1711 else
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1712 #endif
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1713 {
11902
35d7459251fd patch 8.0.0831: with 8 colors the bold attribute is not set properly
Christian Brabandt <cb@256bit.org>
parents: 11888
diff changeset
1714 int bold = MAYBE;
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1715 int fg = color2index(&cellfg, TRUE, &bold);
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1716 int bg = color2index(&cellbg, FALSE, &bold);
11902
35d7459251fd patch 8.0.0831: with 8 colors the bold attribute is not set properly
Christian Brabandt <cb@256bit.org>
parents: 11888
diff changeset
1717
35d7459251fd patch 8.0.0831: with 8 colors the bold attribute is not set properly
Christian Brabandt <cb@256bit.org>
parents: 11888
diff changeset
1718 /* with 8 colors set the bold attribute to get a bright foreground */
35d7459251fd patch 8.0.0831: with 8 colors the bold attribute is not set properly
Christian Brabandt <cb@256bit.org>
parents: 11888
diff changeset
1719 if (bold == TRUE)
35d7459251fd patch 8.0.0831: with 8 colors the bold attribute is not set properly
Christian Brabandt <cb@256bit.org>
parents: 11888
diff changeset
1720 attr |= HL_BOLD;
35d7459251fd patch 8.0.0831: with 8 colors the bold attribute is not set properly
Christian Brabandt <cb@256bit.org>
parents: 11888
diff changeset
1721 return get_cterm_attr_idx(attr, fg, bg);
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1722 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1723 return 0;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1724 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1725
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1726 /*
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
1727 * Called to update a window that contains an active terminal.
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
1728 * Returns FAIL when there is no terminal running in this window or in
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
1729 * Terminal-Normal mode.
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1730 */
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1731 int
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1732 term_update_window(win_T *wp)
11684
1ce1376fbbf8 patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents: 11670
diff changeset
1733 {
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1734 term_T *term = wp->w_buffer->b_term;
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1735 VTerm *vterm;
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1736 VTermScreen *screen;
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1737 VTermState *state;
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
1738 VTermPos pos;
11684
1ce1376fbbf8 patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents: 11670
diff changeset
1739
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
1740 if (term == NULL || term->tl_vterm == NULL || term->tl_normal_mode)
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1741 return FAIL;
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1742
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1743 vterm = term->tl_vterm;
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1744 screen = vterm_obtain_screen(vterm);
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1745 state = vterm_obtain_state(vterm);
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1746
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1747 /*
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1748 * If the window was resized a redraw will be triggered and we get here.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1749 * Adjust the size of the vterm unless 'termsize' specifies a fixed size.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1750 */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1751 if ((!term->tl_rows_fixed && term->tl_rows != wp->w_height)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1752 || (!term->tl_cols_fixed && term->tl_cols != wp->w_width))
11741
b4d8f956eb18 patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents: 11729
diff changeset
1753 {
11818
0f9780ee4207 patch 8.0.0789: splitting terminal window has resizing problems
Christian Brabandt <cb@256bit.org>
parents: 11816
diff changeset
1754 int rows = term->tl_rows_fixed ? term->tl_rows : wp->w_height;
0f9780ee4207 patch 8.0.0789: splitting terminal window has resizing problems
Christian Brabandt <cb@256bit.org>
parents: 11816
diff changeset
1755 int cols = term->tl_cols_fixed ? term->tl_cols : wp->w_width;
0f9780ee4207 patch 8.0.0789: splitting terminal window has resizing problems
Christian Brabandt <cb@256bit.org>
parents: 11816
diff changeset
1756 win_T *twp;
0f9780ee4207 patch 8.0.0789: splitting terminal window has resizing problems
Christian Brabandt <cb@256bit.org>
parents: 11816
diff changeset
1757
0f9780ee4207 patch 8.0.0789: splitting terminal window has resizing problems
Christian Brabandt <cb@256bit.org>
parents: 11816
diff changeset
1758 FOR_ALL_WINDOWS(twp)
0f9780ee4207 patch 8.0.0789: splitting terminal window has resizing problems
Christian Brabandt <cb@256bit.org>
parents: 11816
diff changeset
1759 {
0f9780ee4207 patch 8.0.0789: splitting terminal window has resizing problems
Christian Brabandt <cb@256bit.org>
parents: 11816
diff changeset
1760 /* When more than one window shows the same terminal, use the
0f9780ee4207 patch 8.0.0789: splitting terminal window has resizing problems
Christian Brabandt <cb@256bit.org>
parents: 11816
diff changeset
1761 * smallest size. */
0f9780ee4207 patch 8.0.0789: splitting terminal window has resizing problems
Christian Brabandt <cb@256bit.org>
parents: 11816
diff changeset
1762 if (twp->w_buffer == term->tl_buffer)
0f9780ee4207 patch 8.0.0789: splitting terminal window has resizing problems
Christian Brabandt <cb@256bit.org>
parents: 11816
diff changeset
1763 {
0f9780ee4207 patch 8.0.0789: splitting terminal window has resizing problems
Christian Brabandt <cb@256bit.org>
parents: 11816
diff changeset
1764 if (!term->tl_rows_fixed && rows > twp->w_height)
0f9780ee4207 patch 8.0.0789: splitting terminal window has resizing problems
Christian Brabandt <cb@256bit.org>
parents: 11816
diff changeset
1765 rows = twp->w_height;
0f9780ee4207 patch 8.0.0789: splitting terminal window has resizing problems
Christian Brabandt <cb@256bit.org>
parents: 11816
diff changeset
1766 if (!term->tl_cols_fixed && cols > twp->w_width)
0f9780ee4207 patch 8.0.0789: splitting terminal window has resizing problems
Christian Brabandt <cb@256bit.org>
parents: 11816
diff changeset
1767 cols = twp->w_width;
0f9780ee4207 patch 8.0.0789: splitting terminal window has resizing problems
Christian Brabandt <cb@256bit.org>
parents: 11816
diff changeset
1768 }
0f9780ee4207 patch 8.0.0789: splitting terminal window has resizing problems
Christian Brabandt <cb@256bit.org>
parents: 11816
diff changeset
1769 }
11741
b4d8f956eb18 patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents: 11729
diff changeset
1770
b4d8f956eb18 patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents: 11729
diff changeset
1771 vterm_set_size(vterm, rows, cols);
11937
c893d6c00497 patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents: 11933
diff changeset
1772 ch_log(term->tl_job->jv_channel, "Resizing terminal to %d lines",
11741
b4d8f956eb18 patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents: 11729
diff changeset
1773 rows);
11753
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
1774 term_report_winsize(term, rows, cols);
11741
b4d8f956eb18 patch 8.0.0753: no size reports to a job running in a terminal
Christian Brabandt <cb@256bit.org>
parents: 11729
diff changeset
1775 }
11713
2ec27561dd76 patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents: 11711
diff changeset
1776
2ec27561dd76 patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents: 11711
diff changeset
1777 /* The cursor may have been moved when resizing. */
2ec27561dd76 patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents: 11711
diff changeset
1778 vterm_state_get_cursorpos(state, &pos);
2ec27561dd76 patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents: 11711
diff changeset
1779 position_cursor(wp, &pos);
2ec27561dd76 patch 8.0.0739: terminal resizing doesn't work well.
Christian Brabandt <cb@256bit.org>
parents: 11711
diff changeset
1780
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
1781 /* TODO: Only redraw what changed. */
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
1782 for (pos.row = 0; pos.row < wp->w_height; ++pos.row)
11684
1ce1376fbbf8 patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents: 11670
diff changeset
1783 {
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
1784 int off = screen_get_current_line_off();
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1785 int max_col = MIN(wp->w_width, term->tl_cols);
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1786
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1787 if (pos.row < term->tl_rows)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1788 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1789 for (pos.col = 0; pos.col < max_col; )
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
1790 {
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
1791 VTermScreenCell cell;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1792 int c;
11684
1ce1376fbbf8 patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents: 11670
diff changeset
1793
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1794 if (vterm_screen_get_cell(screen, pos, &cell) == 0)
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1795 vim_memset(&cell, 0, sizeof(cell));
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1796
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1797 /* TODO: composing chars */
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1798 c = cell.chars[0];
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1799 if (c == NUL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1800 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1801 ScreenLines[off] = ' ';
11774
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
1802 #if defined(FEAT_MBYTE)
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
1803 if (enc_utf8)
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
1804 ScreenLinesUC[off] = NUL;
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
1805 #endif
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1806 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1807 else
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1808 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1809 #if defined(FEAT_MBYTE)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1810 if (enc_utf8 && c >= 0x80)
11725
22cef8face93 patch 8.0.0745: multi-byte characters in a terminal don't display well
Christian Brabandt <cb@256bit.org>
parents: 11723
diff changeset
1811 {
22cef8face93 patch 8.0.0745: multi-byte characters in a terminal don't display well
Christian Brabandt <cb@256bit.org>
parents: 11723
diff changeset
1812 ScreenLines[off] = ' ';
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1813 ScreenLinesUC[off] = c;
11725
22cef8face93 patch 8.0.0745: multi-byte characters in a terminal don't display well
Christian Brabandt <cb@256bit.org>
parents: 11723
diff changeset
1814 }
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1815 else
11725
22cef8face93 patch 8.0.0745: multi-byte characters in a terminal don't display well
Christian Brabandt <cb@256bit.org>
parents: 11723
diff changeset
1816 {
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1817 ScreenLines[off] = c;
11774
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
1818 if (enc_utf8)
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
1819 ScreenLinesUC[off] = NUL;
11725
22cef8face93 patch 8.0.0745: multi-byte characters in a terminal don't display well
Christian Brabandt <cb@256bit.org>
parents: 11723
diff changeset
1820 }
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1821 #else
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1822 ScreenLines[off] = c;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1823 #endif
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1824 }
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1825 ScreenAttrs[off] = cell2attr(cell.attrs, cell.fg, cell.bg);
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1826
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1827 ++pos.col;
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
1828 ++off;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1829 if (cell.width == 2)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1830 {
11725
22cef8face93 patch 8.0.0745: multi-byte characters in a terminal don't display well
Christian Brabandt <cb@256bit.org>
parents: 11723
diff changeset
1831 ScreenLines[off] = NUL;
11774
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
1832 #if defined(FEAT_MBYTE)
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
1833 if (enc_utf8)
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
1834 ScreenLinesUC[off] = NUL;
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
1835 #endif
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1836 ++pos.col;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1837 ++off;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1838 }
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
1839 }
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1840 }
11711
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
1841 else
dac96f8800be patch 8.0.0738: cannot use the mouse to resize a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11694
diff changeset
1842 pos.col = 0;
11684
1ce1376fbbf8 patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents: 11670
diff changeset
1843
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1844 screen_line(wp->w_winrow + pos.row, wp->w_wincol,
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1845 pos.col, wp->w_width, FALSE);
11684
1ce1376fbbf8 patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents: 11670
diff changeset
1846 }
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1847
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
1848 return OK;
11684
1ce1376fbbf8 patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents: 11670
diff changeset
1849 }
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1850
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1851 /*
11836
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1852 * Return TRUE if "wp" is a terminal window where the job has finished.
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1853 */
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1854 int
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1855 term_is_finished(buf_T *buf)
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1856 {
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1857 return buf->b_term != NULL && buf->b_term->tl_vterm == NULL;
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1858 }
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1859
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1860 /*
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1861 * Return TRUE if "wp" is a terminal window where the job has finished or we
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
1862 * are in Terminal-Normal mode, thus we show the buffer contents.
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1863 */
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1864 int
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1865 term_show_buffer(buf_T *buf)
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1866 {
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1867 term_T *term = buf->b_term;
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1868
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
1869 return term != NULL && (term->tl_vterm == NULL || term->tl_normal_mode);
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1870 }
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1871
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1872 /*
11836
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1873 * The current buffer is going to be changed. If there is terminal
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1874 * highlighting remove it now.
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1875 */
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1876 void
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1877 term_change_in_curbuf(void)
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1878 {
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1879 term_T *term = curbuf->b_term;
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1880
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1881 if (term_is_finished(curbuf) && term->tl_scrollback.ga_len > 0)
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1882 {
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1883 free_scrollback(term);
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1884 redraw_buf_later(term->tl_buffer, NOT_VALID);
11912
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11904
diff changeset
1885
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11904
diff changeset
1886 /* The buffer is now like a normal buffer, it cannot be easily
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11904
diff changeset
1887 * abandoned when changed. */
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11904
diff changeset
1888 set_string_option_direct((char_u *)"buftype", -1,
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11904
diff changeset
1889 (char_u *)"", OPT_FREE|OPT_LOCAL, 0);
11836
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1890 }
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1891 }
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1892
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1893 /*
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1894 * Get the screen attribute for a position in the buffer.
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1895 */
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1896 int
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1897 term_get_attr(buf_T *buf, linenr_T lnum, int col)
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1898 {
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1899 term_T *term = buf->b_term;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1900 sb_line_T *line;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1901 cellattr_T *cellattr;
11836
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1902
11844
42585fee5e66 patch 8.0.0802: last line of terminal window has no color
Christian Brabandt <cb@256bit.org>
parents: 11842
diff changeset
1903 if (lnum > term->tl_scrollback.ga_len)
11836
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1904 return 0;
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1905 line = (sb_line_T *)term->tl_scrollback.ga_data + lnum - 1;
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1906 if (col >= line->sb_cols)
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1907 return 0;
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1908 cellattr = line->sb_cells + col;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
1909 return cell2attr(cellattr->attrs, cellattr->fg, cellattr->bg);
11836
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1910 }
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1911
f080b225a2a4 patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents: 11834
diff changeset
1912 /*
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1913 * Create a new vterm and initialize it.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1914 */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1915 static void
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1916 create_vterm(term_T *term, int rows, int cols)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1917 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1918 VTerm *vterm;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1919 VTermScreen *screen;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1920
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1921 vterm = vterm_new(rows, cols);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1922 term->tl_vterm = vterm;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1923 screen = vterm_obtain_screen(vterm);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1924 vterm_screen_set_callbacks(screen, &screen_callbacks, term);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1925 /* TODO: depends on 'encoding'. */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1926 vterm_set_utf8(vterm, 1);
11743
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1927
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1928 /* Vterm uses a default black background. Set it to white when
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1929 * 'background' is "light". */
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1930 if (*p_bg == 'l')
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1931 {
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1932 VTermColor fg, bg;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1933
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1934 fg.red = fg.green = fg.blue = 0;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1935 bg.red = bg.green = bg.blue = 255;
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1936 vterm_state_set_default_colors(vterm_obtain_state(vterm), &fg, &bg);
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1937 }
6141a21dd232 patch 8.0.0754: terminal window does not support colors
Christian Brabandt <cb@256bit.org>
parents: 11741
diff changeset
1938
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1939 /* Required to initialize most things. */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1940 vterm_screen_reset(screen, 1 /* hard */);
12035
a3ed3d236839 patch 8.0.0898: can't use the alternate screen in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12031
diff changeset
1941
a3ed3d236839 patch 8.0.0898: can't use the alternate screen in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12031
diff changeset
1942 /* Allow using alternate screen. */
a3ed3d236839 patch 8.0.0898: can't use the alternate screen in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12031
diff changeset
1943 vterm_screen_enable_altscreen(screen, 1);
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1944 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
1945
11772
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1946 /*
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1947 * Return the text to show for the buffer name and status.
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1948 */
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1949 char_u *
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1950 term_get_status_text(term_T *term)
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1951 {
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1952 if (term->tl_status_text == NULL)
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1953 {
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1954 char_u *txt;
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1955 size_t len;
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1956
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
1957 if (term->tl_normal_mode)
11866
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1958 {
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1959 if (term_job_running(term))
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1960 txt = (char_u *)_("Terminal");
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1961 else
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1962 txt = (char_u *)_("Terminal-finished");
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1963 }
be40c8a9240d patch 8.0.0813: cannot use a terminal window while the job is running
Christian Brabandt <cb@256bit.org>
parents: 11854
diff changeset
1964 else if (term->tl_title != NULL)
11772
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1965 txt = term->tl_title;
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1966 else if (term_job_running(term))
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1967 txt = (char_u *)_("running");
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1968 else
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1969 txt = (char_u *)_("finished");
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1970 len = 9 + STRLEN(term->tl_buffer->b_fname) + STRLEN(txt);
11790
4dfebc1b2674 patch 8.0.0777: compiler warnings with 64 bit compiler
Christian Brabandt <cb@256bit.org>
parents: 11786
diff changeset
1971 term->tl_status_text = alloc((int)len);
11772
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1972 if (term->tl_status_text != NULL)
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1973 vim_snprintf((char *)term->tl_status_text, len, "%s [%s]",
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1974 term->tl_buffer->b_fname, txt);
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1975 }
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1976 return term->tl_status_text;
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1977 }
f33b9375ba03 patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents: 11764
diff changeset
1978
11816
f6575adc6ee8 patch 8.0.0788: MS-Windows: cannot build with terminal feature
Christian Brabandt <cb@256bit.org>
parents: 11814
diff changeset
1979 /*
f6575adc6ee8 patch 8.0.0788: MS-Windows: cannot build with terminal feature
Christian Brabandt <cb@256bit.org>
parents: 11814
diff changeset
1980 * Mark references in jobs of terminals.
f6575adc6ee8 patch 8.0.0788: MS-Windows: cannot build with terminal feature
Christian Brabandt <cb@256bit.org>
parents: 11814
diff changeset
1981 */
f6575adc6ee8 patch 8.0.0788: MS-Windows: cannot build with terminal feature
Christian Brabandt <cb@256bit.org>
parents: 11814
diff changeset
1982 int
f6575adc6ee8 patch 8.0.0788: MS-Windows: cannot build with terminal feature
Christian Brabandt <cb@256bit.org>
parents: 11814
diff changeset
1983 set_ref_in_term(int copyID)
f6575adc6ee8 patch 8.0.0788: MS-Windows: cannot build with terminal feature
Christian Brabandt <cb@256bit.org>
parents: 11814
diff changeset
1984 {
f6575adc6ee8 patch 8.0.0788: MS-Windows: cannot build with terminal feature
Christian Brabandt <cb@256bit.org>
parents: 11814
diff changeset
1985 int abort = FALSE;
f6575adc6ee8 patch 8.0.0788: MS-Windows: cannot build with terminal feature
Christian Brabandt <cb@256bit.org>
parents: 11814
diff changeset
1986 term_T *term;
f6575adc6ee8 patch 8.0.0788: MS-Windows: cannot build with terminal feature
Christian Brabandt <cb@256bit.org>
parents: 11814
diff changeset
1987 typval_T tv;
f6575adc6ee8 patch 8.0.0788: MS-Windows: cannot build with terminal feature
Christian Brabandt <cb@256bit.org>
parents: 11814
diff changeset
1988
f6575adc6ee8 patch 8.0.0788: MS-Windows: cannot build with terminal feature
Christian Brabandt <cb@256bit.org>
parents: 11814
diff changeset
1989 for (term = first_term; term != NULL; term = term->tl_next)
f6575adc6ee8 patch 8.0.0788: MS-Windows: cannot build with terminal feature
Christian Brabandt <cb@256bit.org>
parents: 11814
diff changeset
1990 if (term->tl_job != NULL)
f6575adc6ee8 patch 8.0.0788: MS-Windows: cannot build with terminal feature
Christian Brabandt <cb@256bit.org>
parents: 11814
diff changeset
1991 {
f6575adc6ee8 patch 8.0.0788: MS-Windows: cannot build with terminal feature
Christian Brabandt <cb@256bit.org>
parents: 11814
diff changeset
1992 tv.v_type = VAR_JOB;
f6575adc6ee8 patch 8.0.0788: MS-Windows: cannot build with terminal feature
Christian Brabandt <cb@256bit.org>
parents: 11814
diff changeset
1993 tv.vval.v_job = term->tl_job;
f6575adc6ee8 patch 8.0.0788: MS-Windows: cannot build with terminal feature
Christian Brabandt <cb@256bit.org>
parents: 11814
diff changeset
1994 abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL);
f6575adc6ee8 patch 8.0.0788: MS-Windows: cannot build with terminal feature
Christian Brabandt <cb@256bit.org>
parents: 11814
diff changeset
1995 }
f6575adc6ee8 patch 8.0.0788: MS-Windows: cannot build with terminal feature
Christian Brabandt <cb@256bit.org>
parents: 11814
diff changeset
1996 return abort;
f6575adc6ee8 patch 8.0.0788: MS-Windows: cannot build with terminal feature
Christian Brabandt <cb@256bit.org>
parents: 11814
diff changeset
1997 }
f6575adc6ee8 patch 8.0.0788: MS-Windows: cannot build with terminal feature
Christian Brabandt <cb@256bit.org>
parents: 11814
diff changeset
1998
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
1999 /*
11876
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2000 * Get the buffer from the first argument in "argvars".
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2001 * Returns NULL when the buffer is not for a terminal window.
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2002 */
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2003 static buf_T *
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2004 term_get_buf(typval_T *argvars)
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2005 {
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2006 buf_T *buf;
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2007
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2008 (void)get_tv_number(&argvars[0]); /* issue errmsg if type error */
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2009 ++emsg_off;
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2010 buf = get_buf_tv(&argvars[0], FALSE);
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2011 --emsg_off;
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2012 if (buf == NULL || buf->b_term == NULL)
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2013 return NULL;
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2014 return buf;
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2015 }
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2016
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2017 /*
12035
a3ed3d236839 patch 8.0.0898: can't use the alternate screen in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12031
diff changeset
2018 * "term_getaltscreen(buf)" function
a3ed3d236839 patch 8.0.0898: can't use the alternate screen in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12031
diff changeset
2019 */
a3ed3d236839 patch 8.0.0898: can't use the alternate screen in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12031
diff changeset
2020 void
a3ed3d236839 patch 8.0.0898: can't use the alternate screen in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12031
diff changeset
2021 f_term_getaltscreen(typval_T *argvars, typval_T *rettv)
a3ed3d236839 patch 8.0.0898: can't use the alternate screen in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12031
diff changeset
2022 {
a3ed3d236839 patch 8.0.0898: can't use the alternate screen in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12031
diff changeset
2023 buf_T *buf = term_get_buf(argvars);
a3ed3d236839 patch 8.0.0898: can't use the alternate screen in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12031
diff changeset
2024
a3ed3d236839 patch 8.0.0898: can't use the alternate screen in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12031
diff changeset
2025 if (buf == NULL)
a3ed3d236839 patch 8.0.0898: can't use the alternate screen in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12031
diff changeset
2026 return;
a3ed3d236839 patch 8.0.0898: can't use the alternate screen in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12031
diff changeset
2027 rettv->vval.v_number = buf->b_term->tl_using_altscreen;
a3ed3d236839 patch 8.0.0898: can't use the alternate screen in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12031
diff changeset
2028 }
a3ed3d236839 patch 8.0.0898: can't use the alternate screen in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12031
diff changeset
2029
a3ed3d236839 patch 8.0.0898: can't use the alternate screen in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12031
diff changeset
2030 /*
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2031 * "term_getattr(attr, name)" function
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2032 */
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2033 void
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2034 f_term_getattr(typval_T *argvars, typval_T *rettv)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2035 {
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2036 int attr;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2037 size_t i;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2038 char_u *name;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2039
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2040 static struct {
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2041 char *name;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2042 int attr;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2043 } attrs[] = {
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2044 {"bold", HL_BOLD},
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2045 {"italic", HL_ITALIC},
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2046 {"underline", HL_UNDERLINE},
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2047 {"strike", HL_STANDOUT},
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2048 {"reverse", HL_INVERSE},
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2049 };
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2050
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2051 attr = get_tv_number(&argvars[0]);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2052 name = get_tv_string_chk(&argvars[1]);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2053 if (name == NULL)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2054 return;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2055
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2056 for (i = 0; i < sizeof(attrs)/sizeof(attrs[0]); ++i)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2057 if (STRCMP(name, attrs[i].name) == 0)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2058 {
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2059 rettv->vval.v_number = (attr & attrs[i].attr) != 0 ? 1 : 0;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2060 break;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2061 }
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2062 }
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2063
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2064 /*
11876
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2065 * "term_getcursor(buf)" function
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2066 */
11876
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2067 void
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2068 f_term_getcursor(typval_T *argvars, typval_T *rettv)
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2069 {
11876
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2070 buf_T *buf = term_get_buf(argvars);
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2071 list_T *l;
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2072
11876
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2073 if (rettv_list_alloc(rettv) == FAIL)
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2074 return;
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2075 if (buf == NULL)
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2076 return;
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2077
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2078 l = rettv->vval.v_list;
11904
40322e8f07e7 patch 8.0.0832: terminal function arguments are not consistent
Christian Brabandt <cb@256bit.org>
parents: 11902
diff changeset
2079 list_append_number(l, buf->b_term->tl_cursor_pos.row + 1);
40322e8f07e7 patch 8.0.0832: terminal function arguments are not consistent
Christian Brabandt <cb@256bit.org>
parents: 11902
diff changeset
2080 list_append_number(l, buf->b_term->tl_cursor_pos.col + 1);
11876
3704ca24c9a2 patch 8.0.0818: cannot get the cursor position of a terminal
Christian Brabandt <cb@256bit.org>
parents: 11874
diff changeset
2081 list_append_number(l, buf->b_term->tl_cursor_visible);
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2082 }
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2083
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2084 /*
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2085 * "term_getjob(buf)" function
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2086 */
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2087 void
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2088 f_term_getjob(typval_T *argvars, typval_T *rettv)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2089 {
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2090 buf_T *buf = term_get_buf(argvars);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2091
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2092 rettv->v_type = VAR_JOB;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2093 rettv->vval.v_job = NULL;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2094 if (buf == NULL)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2095 return;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2096
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2097 rettv->vval.v_job = buf->b_term->tl_job;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2098 if (rettv->vval.v_job != NULL)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2099 ++rettv->vval.v_job->jv_refcount;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2100 }
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2101
11904
40322e8f07e7 patch 8.0.0832: terminal function arguments are not consistent
Christian Brabandt <cb@256bit.org>
parents: 11902
diff changeset
2102 static int
40322e8f07e7 patch 8.0.0832: terminal function arguments are not consistent
Christian Brabandt <cb@256bit.org>
parents: 11902
diff changeset
2103 get_row_number(typval_T *tv, term_T *term)
40322e8f07e7 patch 8.0.0832: terminal function arguments are not consistent
Christian Brabandt <cb@256bit.org>
parents: 11902
diff changeset
2104 {
40322e8f07e7 patch 8.0.0832: terminal function arguments are not consistent
Christian Brabandt <cb@256bit.org>
parents: 11902
diff changeset
2105 if (tv->v_type == VAR_STRING
40322e8f07e7 patch 8.0.0832: terminal function arguments are not consistent
Christian Brabandt <cb@256bit.org>
parents: 11902
diff changeset
2106 && tv->vval.v_string != NULL
40322e8f07e7 patch 8.0.0832: terminal function arguments are not consistent
Christian Brabandt <cb@256bit.org>
parents: 11902
diff changeset
2107 && STRCMP(tv->vval.v_string, ".") == 0)
40322e8f07e7 patch 8.0.0832: terminal function arguments are not consistent
Christian Brabandt <cb@256bit.org>
parents: 11902
diff changeset
2108 return term->tl_cursor_pos.row;
40322e8f07e7 patch 8.0.0832: terminal function arguments are not consistent
Christian Brabandt <cb@256bit.org>
parents: 11902
diff changeset
2109 return (int)get_tv_number(tv) - 1;
40322e8f07e7 patch 8.0.0832: terminal function arguments are not consistent
Christian Brabandt <cb@256bit.org>
parents: 11902
diff changeset
2110 }
40322e8f07e7 patch 8.0.0832: terminal function arguments are not consistent
Christian Brabandt <cb@256bit.org>
parents: 11902
diff changeset
2111
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2112 /*
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2113 * "term_getline(buf, row)" function
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2114 */
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2115 void
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2116 f_term_getline(typval_T *argvars, typval_T *rettv)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2117 {
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2118 buf_T *buf = term_get_buf(argvars);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2119 term_T *term;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2120 int row;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2121
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2122 rettv->v_type = VAR_STRING;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2123 if (buf == NULL)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2124 return;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2125 term = buf->b_term;
11904
40322e8f07e7 patch 8.0.0832: terminal function arguments are not consistent
Christian Brabandt <cb@256bit.org>
parents: 11902
diff changeset
2126 row = get_row_number(&argvars[1], term);
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2127
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2128 if (term->tl_vterm == NULL)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2129 {
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2130 linenr_T lnum = row + term->tl_scrollback_scrolled + 1;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2131
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2132 /* vterm is finished, get the text from the buffer */
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2133 if (lnum > 0 && lnum <= buf->b_ml.ml_line_count)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2134 rettv->vval.v_string = vim_strsave(ml_get_buf(buf, lnum, FALSE));
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2135 }
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2136 else
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2137 {
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2138 VTermScreen *screen = vterm_obtain_screen(term->tl_vterm);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2139 VTermRect rect;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2140 int len;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2141 char_u *p;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2142
11923
c9da7b42fdf5 patch 8.0.0841: term_getline() may cause a crash
Christian Brabandt <cb@256bit.org>
parents: 11919
diff changeset
2143 if (row < 0 || row >= term->tl_rows)
c9da7b42fdf5 patch 8.0.0841: term_getline() may cause a crash
Christian Brabandt <cb@256bit.org>
parents: 11919
diff changeset
2144 return;
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2145 len = term->tl_cols * MB_MAXBYTES + 1;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2146 p = alloc(len);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2147 if (p == NULL)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2148 return;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2149 rettv->vval.v_string = p;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2150
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2151 rect.start_col = 0;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2152 rect.end_col = term->tl_cols;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2153 rect.start_row = row;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2154 rect.end_row = row + 1;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2155 p[vterm_screen_get_text(screen, (char *)p, len, rect)] = NUL;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2156 }
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2157 }
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2158
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2159 /*
12025
c0ee48f48a2b patch 8.0.0893: cannot get the scroll count of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12023
diff changeset
2160 * "term_getscrolled(buf)" function
c0ee48f48a2b patch 8.0.0893: cannot get the scroll count of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12023
diff changeset
2161 */
c0ee48f48a2b patch 8.0.0893: cannot get the scroll count of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12023
diff changeset
2162 void
c0ee48f48a2b patch 8.0.0893: cannot get the scroll count of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12023
diff changeset
2163 f_term_getscrolled(typval_T *argvars, typval_T *rettv)
c0ee48f48a2b patch 8.0.0893: cannot get the scroll count of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12023
diff changeset
2164 {
c0ee48f48a2b patch 8.0.0893: cannot get the scroll count of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12023
diff changeset
2165 buf_T *buf = term_get_buf(argvars);
c0ee48f48a2b patch 8.0.0893: cannot get the scroll count of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12023
diff changeset
2166
c0ee48f48a2b patch 8.0.0893: cannot get the scroll count of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12023
diff changeset
2167 if (buf == NULL)
c0ee48f48a2b patch 8.0.0893: cannot get the scroll count of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12023
diff changeset
2168 return;
c0ee48f48a2b patch 8.0.0893: cannot get the scroll count of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12023
diff changeset
2169 rettv->vval.v_number = buf->b_term->tl_scrollback_scrolled;
c0ee48f48a2b patch 8.0.0893: cannot get the scroll count of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12023
diff changeset
2170 }
c0ee48f48a2b patch 8.0.0893: cannot get the scroll count of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12023
diff changeset
2171
c0ee48f48a2b patch 8.0.0893: cannot get the scroll count of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 12023
diff changeset
2172 /*
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2173 * "term_getsize(buf)" function
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2174 */
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2175 void
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2176 f_term_getsize(typval_T *argvars, typval_T *rettv)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2177 {
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2178 buf_T *buf = term_get_buf(argvars);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2179 list_T *l;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2180
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2181 if (rettv_list_alloc(rettv) == FAIL)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2182 return;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2183 if (buf == NULL)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2184 return;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2185
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2186 l = rettv->vval.v_list;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2187 list_append_number(l, buf->b_term->tl_rows);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2188 list_append_number(l, buf->b_term->tl_cols);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2189 }
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2190
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2191 /*
11882
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2192 * "term_getstatus(buf)" function
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2193 */
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2194 void
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2195 f_term_getstatus(typval_T *argvars, typval_T *rettv)
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2196 {
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2197 buf_T *buf = term_get_buf(argvars);
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2198 term_T *term;
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2199 char_u val[100];
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2200
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2201 rettv->v_type = VAR_STRING;
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2202 if (buf == NULL)
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2203 return;
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2204 term = buf->b_term;
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2205
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2206 if (term_job_running(term))
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2207 STRCPY(val, "running");
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2208 else
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2209 STRCPY(val, "finished");
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
2210 if (term->tl_normal_mode)
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
2211 STRCAT(val, ",normal");
11882
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2212 rettv->vval.v_string = vim_strsave(val);
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2213 }
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2214
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2215 /*
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2216 * "term_gettitle(buf)" function
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2217 */
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2218 void
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2219 f_term_gettitle(typval_T *argvars, typval_T *rettv)
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2220 {
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2221 buf_T *buf = term_get_buf(argvars);
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2222
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2223 rettv->v_type = VAR_STRING;
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2224 if (buf == NULL)
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2225 return;
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2226
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2227 if (buf->b_term->tl_title != NULL)
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2228 rettv->vval.v_string = vim_strsave(buf->b_term->tl_title);
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2229 }
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2230
69e7379f46db patch 8.0.0821: cannot get the title and status of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11880
diff changeset
2231 /*
11933
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
2232 * "term_gettty(buf)" function
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
2233 */
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
2234 void
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
2235 f_term_gettty(typval_T *argvars, typval_T *rettv)
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
2236 {
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
2237 buf_T *buf = term_get_buf(argvars);
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
2238 char_u *p;
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
2239
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
2240 rettv->v_type = VAR_STRING;
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
2241 if (buf == NULL)
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
2242 return;
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
2243 if (buf->b_term->tl_job != NULL)
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
2244 p = buf->b_term->tl_job->jv_tty_name;
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
2245 else
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
2246 p = buf->b_term->tl_tty_name;
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
2247 if (p != NULL)
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
2248 rettv->vval.v_string = vim_strsave(p);
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
2249 }
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
2250
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
2251 /*
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2252 * "term_list()" function
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2253 */
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2254 void
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2255 f_term_list(typval_T *argvars UNUSED, typval_T *rettv)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2256 {
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2257 term_T *tp;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2258 list_T *l;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2259
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2260 if (rettv_list_alloc(rettv) == FAIL || first_term == NULL)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2261 return;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2262
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2263 l = rettv->vval.v_list;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2264 for (tp = first_term; tp != NULL; tp = tp->tl_next)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2265 if (tp != NULL && tp->tl_buffer != NULL)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2266 if (list_append_number(l,
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2267 (varnumber_T)tp->tl_buffer->b_fnum) == FAIL)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2268 return;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2269 }
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2270
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2271 /*
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2272 * "term_scrape(buf, row)" function
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2273 */
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2274 void
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2275 f_term_scrape(typval_T *argvars, typval_T *rettv)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2276 {
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2277 buf_T *buf = term_get_buf(argvars);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2278 VTermScreen *screen = NULL;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2279 VTermPos pos;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2280 list_T *l;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2281 term_T *term;
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2282 char_u *p;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2283 sb_line_T *line;
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2284
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2285 if (rettv_list_alloc(rettv) == FAIL)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2286 return;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2287 if (buf == NULL)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2288 return;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2289 term = buf->b_term;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2290
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2291 l = rettv->vval.v_list;
11904
40322e8f07e7 patch 8.0.0832: terminal function arguments are not consistent
Christian Brabandt <cb@256bit.org>
parents: 11902
diff changeset
2292 pos.row = get_row_number(&argvars[1], term);
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2293
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2294 if (term->tl_vterm != NULL)
12017
e30f3d1fdea7 patch 8.0.0889: gcc gives warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents: 12011
diff changeset
2295 {
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2296 screen = vterm_obtain_screen(term->tl_vterm);
12017
e30f3d1fdea7 patch 8.0.0889: gcc gives warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents: 12011
diff changeset
2297 p = NULL;
e30f3d1fdea7 patch 8.0.0889: gcc gives warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents: 12011
diff changeset
2298 line = NULL;
e30f3d1fdea7 patch 8.0.0889: gcc gives warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents: 12011
diff changeset
2299 }
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2300 else
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2301 {
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2302 linenr_T lnum = pos.row + term->tl_scrollback_scrolled;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2303
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2304 if (lnum < 0 || lnum >= term->tl_scrollback.ga_len)
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2305 return;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2306 p = ml_get_buf(buf, lnum + 1, FALSE);
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2307 line = (sb_line_T *)term->tl_scrollback.ga_data + lnum;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2308 }
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2309
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2310 for (pos.col = 0; pos.col < term->tl_cols; )
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2311 {
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2312 dict_T *dcell;
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2313 int width;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2314 VTermScreenCellAttrs attrs;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2315 VTermColor fg, bg;
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2316 char_u rgb[8];
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2317 char_u mbs[MB_MAXBYTES * VTERM_MAX_CHARS_PER_CELL + 1];
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2318 int off = 0;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2319 int i;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2320
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2321 if (screen == NULL)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2322 {
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2323 cellattr_T *cellattr;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2324 int len;
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2325
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2326 /* vterm has finished, get the cell from scrollback */
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2327 if (pos.col >= line->sb_cols)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2328 break;
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2329 cellattr = line->sb_cells + pos.col;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2330 width = cellattr->width;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2331 attrs = cellattr->attrs;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2332 fg = cellattr->fg;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2333 bg = cellattr->bg;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2334 len = MB_PTR2LEN(p);
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2335 mch_memmove(mbs, p, len);
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2336 mbs[len] = NUL;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2337 p += len;
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2338 }
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2339 else
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2340 {
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2341 VTermScreenCell cell;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2342 if (vterm_screen_get_cell(screen, pos, &cell) == 0)
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2343 break;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2344 for (i = 0; i < VTERM_MAX_CHARS_PER_CELL; ++i)
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2345 {
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2346 if (cell.chars[i] == 0)
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2347 break;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2348 off += (*utf_char2bytes)((int)cell.chars[i], mbs + off);
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2349 }
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2350 mbs[off] = NUL;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2351 width = cell.width;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2352 attrs = cell.attrs;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2353 fg = cell.fg;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2354 bg = cell.bg;
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2355 }
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2356 dcell = dict_alloc();
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2357 list_append_dict(l, dcell);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2358
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2359 dict_add_nr_str(dcell, "chars", 0, mbs);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2360
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2361 vim_snprintf((char *)rgb, 8, "#%02x%02x%02x",
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2362 fg.red, fg.green, fg.blue);
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2363 dict_add_nr_str(dcell, "fg", 0, rgb);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2364 vim_snprintf((char *)rgb, 8, "#%02x%02x%02x",
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2365 bg.red, bg.green, bg.blue);
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2366 dict_add_nr_str(dcell, "bg", 0, rgb);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2367
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2368 dict_add_nr_str(dcell, "attr",
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2369 cell2attr(attrs, fg, bg), NULL);
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2370 dict_add_nr_str(dcell, "width", width, NULL);
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2371
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2372 ++pos.col;
12009
0d9bfdb3f6f7 patch 8.0.0885: terminal window scrollback is stored inefficiently
Christian Brabandt <cb@256bit.org>
parents: 12007
diff changeset
2373 if (width == 2)
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2374 ++pos.col;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2375 }
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2376 }
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2377
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2378 /*
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2379 * "term_sendkeys(buf, keys)" function
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2380 */
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2381 void
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2382 f_term_sendkeys(typval_T *argvars, typval_T *rettv)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2383 {
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2384 buf_T *buf = term_get_buf(argvars);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2385 char_u *msg;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2386 term_T *term;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2387
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2388 rettv->v_type = VAR_UNKNOWN;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2389 if (buf == NULL)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2390 return;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2391
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2392 msg = get_tv_string_chk(&argvars[1]);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2393 if (msg == NULL)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2394 return;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2395 term = buf->b_term;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2396 if (term->tl_vterm == NULL)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2397 return;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2398
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2399 while (*msg != NUL)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2400 {
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2401 send_keys_to_term(term, PTR2CHAR(msg), FALSE);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2402 msg += MB_PTR2LEN(msg);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2403 }
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2404
11993
92a86fe8adc0 patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 11985
diff changeset
2405 if (!term->tl_normal_mode)
11888
4db6c74df788 patch 8.0.0824: in Terminal mode the cursor and screen gets redrawn
Christian Brabandt <cb@256bit.org>
parents: 11886
diff changeset
2406 {
4db6c74df788 patch 8.0.0824: in Terminal mode the cursor and screen gets redrawn
Christian Brabandt <cb@256bit.org>
parents: 11886
diff changeset
2407 /* TODO: only update once in a while. */
4db6c74df788 patch 8.0.0824: in Terminal mode the cursor and screen gets redrawn
Christian Brabandt <cb@256bit.org>
parents: 11886
diff changeset
2408 update_screen(0);
4db6c74df788 patch 8.0.0824: in Terminal mode the cursor and screen gets redrawn
Christian Brabandt <cb@256bit.org>
parents: 11886
diff changeset
2409 if (buf == curbuf)
4db6c74df788 patch 8.0.0824: in Terminal mode the cursor and screen gets redrawn
Christian Brabandt <cb@256bit.org>
parents: 11886
diff changeset
2410 update_cursor(term, TRUE);
4db6c74df788 patch 8.0.0824: in Terminal mode the cursor and screen gets redrawn
Christian Brabandt <cb@256bit.org>
parents: 11886
diff changeset
2411 }
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2412 }
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2413
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2414 /*
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2415 * "term_start(command, options)" function
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2416 */
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2417 void
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2418 f_term_start(typval_T *argvars, typval_T *rettv)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2419 {
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2420 char_u *cmd = get_tv_string_chk(&argvars[0]);
11939
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2421 jobopt_T opt;
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2422
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2423 if (cmd == NULL)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2424 return;
11939
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2425 init_job_options(&opt);
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2426 /* TODO: allow more job options */
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2427 if (argvars[1].v_type != VAR_UNKNOWN
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2428 && get_job_options(&argvars[1], &opt,
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2429 JO_TIMEOUT_ALL + JO_STOPONEXIT
12056
0498547dace0 patch 8.0.0908: cannot set terminal size with options
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
2430 + JO_EXIT_CB + JO_CLOSE_CALLBACK,
12064
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 12060
diff changeset
2431 JO2_TERM_NAME + JO2_TERM_FINISH + JO2_HIDDEN
12060
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
2432 + JO2_TERM_COLS + JO2_TERM_ROWS + JO2_VERTICAL + JO2_CURWIN
12056
0498547dace0 patch 8.0.0908: cannot set terminal size with options
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
2433 + JO2_CWD + JO2_ENV) == FAIL)
11939
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2434 return;
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2435
12056
0498547dace0 patch 8.0.0908: cannot set terminal size with options
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
2436 if (opt.jo_vertical)
0498547dace0 patch 8.0.0908: cannot set terminal size with options
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
2437 cmdmod.split = WSP_VERT;
12060
a879814b8a37 patch 8.0.0910: cannot create a terminal in the current window
Christian Brabandt <cb@256bit.org>
parents: 12056
diff changeset
2438 term_start(cmd, &opt, FALSE);
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2439
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2440 if (curbuf->b_term != NULL)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2441 rettv->vval.v_number = curbuf->b_fnum;
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2442 }
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2443
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2444 /*
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2445 * "term_wait" function
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2446 */
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2447 void
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2448 f_term_wait(typval_T *argvars, typval_T *rettv UNUSED)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2449 {
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2450 buf_T *buf = term_get_buf(argvars);
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2451
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2452 if (buf == NULL)
11939
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2453 {
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2454 ch_log(NULL, "term_wait(): invalid argument");
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2455 return;
11939
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2456 }
11949
74e45c11b754 patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents: 11947
diff changeset
2457 if (buf->b_term->tl_job == NULL)
74e45c11b754 patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents: 11947
diff changeset
2458 {
74e45c11b754 patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents: 11947
diff changeset
2459 ch_log(NULL, "term_wait(): no job to wait for");
74e45c11b754 patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents: 11947
diff changeset
2460 return;
74e45c11b754 patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents: 11947
diff changeset
2461 }
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2462
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2463 /* Get the job status, this will detect a job that finished. */
11949
74e45c11b754 patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents: 11947
diff changeset
2464 if (STRCMP(job_status(buf->b_term->tl_job), "dead") == 0)
11939
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2465 {
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2466 /* The job is dead, keep reading channel I/O until the channel is
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2467 * closed. */
11949
74e45c11b754 patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents: 11947
diff changeset
2468 ch_log(NULL, "term_wait(): waiting for channel to close");
11939
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2469 while (buf->b_term != NULL && !buf->b_term->tl_channel_closed)
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2470 {
11949
74e45c11b754 patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents: 11947
diff changeset
2471 mch_check_messages();
11939
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2472 parse_queued_messages();
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2473 ui_delay(10L, FALSE);
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2474 }
11949
74e45c11b754 patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents: 11947
diff changeset
2475 mch_check_messages();
11939
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2476 parse_queued_messages();
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2477 }
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2478 else
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2479 {
12007
64b822c4f7ae patch 8.0.0884: can't specify the wait time for term_wait()
Christian Brabandt <cb@256bit.org>
parents: 11993
diff changeset
2480 long wait = 10L;
64b822c4f7ae patch 8.0.0884: can't specify the wait time for term_wait()
Christian Brabandt <cb@256bit.org>
parents: 11993
diff changeset
2481
11949
74e45c11b754 patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents: 11947
diff changeset
2482 mch_check_messages();
11939
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2483 parse_queued_messages();
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2484
12007
64b822c4f7ae patch 8.0.0884: can't specify the wait time for term_wait()
Christian Brabandt <cb@256bit.org>
parents: 11993
diff changeset
2485 /* Wait for some time for any channel I/O. */
64b822c4f7ae patch 8.0.0884: can't specify the wait time for term_wait()
Christian Brabandt <cb@256bit.org>
parents: 11993
diff changeset
2486 if (argvars[1].v_type != VAR_UNKNOWN)
64b822c4f7ae patch 8.0.0884: can't specify the wait time for term_wait()
Christian Brabandt <cb@256bit.org>
parents: 11993
diff changeset
2487 wait = get_tv_number(&argvars[1]);
64b822c4f7ae patch 8.0.0884: can't specify the wait time for term_wait()
Christian Brabandt <cb@256bit.org>
parents: 11993
diff changeset
2488 ui_delay(wait, TRUE);
11949
74e45c11b754 patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents: 11947
diff changeset
2489 mch_check_messages();
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2490
11939
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2491 /* Flushing messages on channels is hopefully sufficient.
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2492 * TODO: is there a better way? */
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2493 parse_queued_messages();
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2494 }
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2495 }
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2496
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2497 # ifdef WIN3264
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2498
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2499 /**************************************
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2500 * 2. MS-Windows implementation.
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2501 */
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents: 11844
diff changeset
2502
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2503 #define WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN 1ul
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2504 #define WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN 2ull
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2505
11774
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
2506 void* (*winpty_config_new)(UINT64, void*);
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2507 void* (*winpty_open)(void*, void*);
11774
edf1a2a247fa patch 8.0.0769: build problems with terminal on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11772
diff changeset
2508 void* (*winpty_spawn_config_new)(UINT64, void*, LPCWSTR, void*, void*, void*);
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2509 BOOL (*winpty_spawn)(void*, void*, HANDLE*, HANDLE*, DWORD*, void*);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2510 void (*winpty_config_set_initial_size)(void*, int, int);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2511 LPCWSTR (*winpty_conin_name)(void*);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2512 LPCWSTR (*winpty_conout_name)(void*);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2513 LPCWSTR (*winpty_conerr_name)(void*);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2514 void (*winpty_free)(void*);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2515 void (*winpty_config_free)(void*);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2516 void (*winpty_spawn_config_free)(void*);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2517 void (*winpty_error_free)(void*);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2518 LPCWSTR (*winpty_error_msg)(void*);
11753
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2519 BOOL (*winpty_set_size)(void*, int, int, void*);
11951
e8b1ef40324a patch 8.0.0855: MS-Windows: can't get tty name of terminal
Christian Brabandt <cb@256bit.org>
parents: 11949
diff changeset
2520 HANDLE (*winpty_agent_process)(void*);
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2521
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2522 #define WINPTY_DLL "winpty.dll"
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2523
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2524 static HINSTANCE hWinPtyDLL = NULL;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2525
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2526 int
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2527 dyn_winpty_init(void)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2528 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2529 int i;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2530 static struct
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2531 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2532 char *name;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2533 FARPROC *ptr;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2534 } winpty_entry[] =
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2535 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2536 {"winpty_conerr_name", (FARPROC*)&winpty_conerr_name},
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2537 {"winpty_config_free", (FARPROC*)&winpty_config_free},
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2538 {"winpty_config_new", (FARPROC*)&winpty_config_new},
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2539 {"winpty_config_set_initial_size", (FARPROC*)&winpty_config_set_initial_size},
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2540 {"winpty_conin_name", (FARPROC*)&winpty_conin_name},
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2541 {"winpty_conout_name", (FARPROC*)&winpty_conout_name},
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2542 {"winpty_error_free", (FARPROC*)&winpty_error_free},
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2543 {"winpty_free", (FARPROC*)&winpty_free},
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2544 {"winpty_open", (FARPROC*)&winpty_open},
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2545 {"winpty_spawn", (FARPROC*)&winpty_spawn},
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2546 {"winpty_spawn_config_free", (FARPROC*)&winpty_spawn_config_free},
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2547 {"winpty_spawn_config_new", (FARPROC*)&winpty_spawn_config_new},
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2548 {"winpty_error_msg", (FARPROC*)&winpty_error_msg},
11753
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2549 {"winpty_set_size", (FARPROC*)&winpty_set_size},
11951
e8b1ef40324a patch 8.0.0855: MS-Windows: can't get tty name of terminal
Christian Brabandt <cb@256bit.org>
parents: 11949
diff changeset
2550 {"winpty_agent_process", (FARPROC*)&winpty_agent_process},
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2551 {NULL, NULL}
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2552 };
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2553
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2554 /* No need to initialize twice. */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2555 if (hWinPtyDLL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2556 return 1;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2557 /* Load winpty.dll */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2558 hWinPtyDLL = vimLoadLib(WINPTY_DLL);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2559 if (!hWinPtyDLL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2560 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2561 EMSG2(_(e_loadlib), WINPTY_DLL);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2562 return 0;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2563 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2564 for (i = 0; winpty_entry[i].name != NULL
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2565 && winpty_entry[i].ptr != NULL; ++i)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2566 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2567 if ((*winpty_entry[i].ptr = (FARPROC)GetProcAddress(hWinPtyDLL,
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2568 winpty_entry[i].name)) == NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2569 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2570 EMSG2(_(e_loadfunc), winpty_entry[i].name);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2571 return 0;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2572 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2573 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2574
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2575 return 1;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2576 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2577
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2578 /*
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2579 * Create a new terminal of "rows" by "cols" cells.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2580 * Store a reference in "term".
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2581 * Return OK or FAIL.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2582 */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2583 static int
11939
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2584 term_and_job_init(term_T *term, int rows, int cols, char_u *cmd, jobopt_T *opt)
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2585 {
11798
4d545cd33f0a patch 8.0.0781: MS-Windows: memory leak when using :terminal
Christian Brabandt <cb@256bit.org>
parents: 11794
diff changeset
2586 WCHAR *p;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2587 channel_T *channel = NULL;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2588 job_T *job = NULL;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2589 DWORD error;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2590 HANDLE jo = NULL, child_process_handle, child_thread_handle;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2591 void *winpty_err;
11798
4d545cd33f0a patch 8.0.0781: MS-Windows: memory leak when using :terminal
Christian Brabandt <cb@256bit.org>
parents: 11794
diff changeset
2592 void *spawn_config = NULL;
11951
e8b1ef40324a patch 8.0.0855: MS-Windows: can't get tty name of terminal
Christian Brabandt <cb@256bit.org>
parents: 11949
diff changeset
2593 char buf[MAX_PATH];
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2594
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2595 if (!dyn_winpty_init())
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2596 return FAIL;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2597
11798
4d545cd33f0a patch 8.0.0781: MS-Windows: memory leak when using :terminal
Christian Brabandt <cb@256bit.org>
parents: 11794
diff changeset
2598 p = enc_to_utf16(cmd, NULL);
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2599 if (p == NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2600 return FAIL;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2601
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2602 job = job_alloc();
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2603 if (job == NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2604 goto failed;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2605
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2606 channel = add_channel();
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2607 if (channel == NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2608 goto failed;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2609
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2610 term->tl_winpty_config = winpty_config_new(0, &winpty_err);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2611 if (term->tl_winpty_config == NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2612 goto failed;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2613
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2614 winpty_config_set_initial_size(term->tl_winpty_config, cols, rows);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2615 term->tl_winpty = winpty_open(term->tl_winpty_config, &winpty_err);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2616 if (term->tl_winpty == NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2617 goto failed;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2618
11933
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
2619 /* TODO: if the command is "NONE" only create a pty. */
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2620 spawn_config = winpty_spawn_config_new(
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2621 WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN |
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2622 WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN,
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2623 NULL,
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2624 p,
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2625 NULL,
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2626 NULL,
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2627 &winpty_err);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2628 if (spawn_config == NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2629 goto failed;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2630
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2631 channel = add_channel();
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2632 if (channel == NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2633 goto failed;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2634
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2635 job = job_alloc();
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2636 if (job == NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2637 goto failed;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2638
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2639 if (!winpty_spawn(term->tl_winpty, spawn_config, &child_process_handle,
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2640 &child_thread_handle, &error, &winpty_err))
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2641 goto failed;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2642
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2643 channel_set_pipes(channel,
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2644 (sock_T) CreateFileW(
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2645 winpty_conin_name(term->tl_winpty),
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2646 GENERIC_WRITE, 0, NULL,
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2647 OPEN_EXISTING, 0, NULL),
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2648 (sock_T) CreateFileW(
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2649 winpty_conout_name(term->tl_winpty),
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2650 GENERIC_READ, 0, NULL,
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2651 OPEN_EXISTING, 0, NULL),
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2652 (sock_T) CreateFileW(
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2653 winpty_conerr_name(term->tl_winpty),
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2654 GENERIC_READ, 0, NULL,
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2655 OPEN_EXISTING, 0, NULL));
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2656
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2657 jo = CreateJobObject(NULL, NULL);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2658 if (jo == NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2659 goto failed;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2660
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2661 if (!AssignProcessToJobObject(jo, child_process_handle))
11798
4d545cd33f0a patch 8.0.0781: MS-Windows: memory leak when using :terminal
Christian Brabandt <cb@256bit.org>
parents: 11794
diff changeset
2662 {
4d545cd33f0a patch 8.0.0781: MS-Windows: memory leak when using :terminal
Christian Brabandt <cb@256bit.org>
parents: 11794
diff changeset
2663 /* Failed, switch the way to terminate process with TerminateProcess. */
4d545cd33f0a patch 8.0.0781: MS-Windows: memory leak when using :terminal
Christian Brabandt <cb@256bit.org>
parents: 11794
diff changeset
2664 CloseHandle(jo);
4d545cd33f0a patch 8.0.0781: MS-Windows: memory leak when using :terminal
Christian Brabandt <cb@256bit.org>
parents: 11794
diff changeset
2665 jo = NULL;
4d545cd33f0a patch 8.0.0781: MS-Windows: memory leak when using :terminal
Christian Brabandt <cb@256bit.org>
parents: 11794
diff changeset
2666 }
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2667
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2668 winpty_spawn_config_free(spawn_config);
11798
4d545cd33f0a patch 8.0.0781: MS-Windows: memory leak when using :terminal
Christian Brabandt <cb@256bit.org>
parents: 11794
diff changeset
2669 vim_free(p);
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2670
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2671 create_vterm(term, rows, cols);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2672
11939
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2673 channel_set_job(channel, job, opt);
11953
fd714bb0ae24 patch 8.0.0856: MS-Windows: terminal job doesn't take options
Christian Brabandt <cb@256bit.org>
parents: 11951
diff changeset
2674 job_set_options(job, opt);
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2675
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2676 job->jv_channel = channel;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2677 job->jv_proc_info.hProcess = child_process_handle;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2678 job->jv_proc_info.dwProcessId = GetProcessId(child_process_handle);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2679 job->jv_job_object = jo;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2680 job->jv_status = JOB_STARTED;
11951
e8b1ef40324a patch 8.0.0855: MS-Windows: can't get tty name of terminal
Christian Brabandt <cb@256bit.org>
parents: 11949
diff changeset
2681 sprintf(buf, "winpty://%lu",
e8b1ef40324a patch 8.0.0855: MS-Windows: can't get tty name of terminal
Christian Brabandt <cb@256bit.org>
parents: 11949
diff changeset
2682 GetProcessId(winpty_agent_process(term->tl_winpty)));
e8b1ef40324a patch 8.0.0855: MS-Windows: can't get tty name of terminal
Christian Brabandt <cb@256bit.org>
parents: 11949
diff changeset
2683 job->jv_tty_name = vim_strsave((char_u*)buf);
11802
b1fd49b4eea7 patch 8.0.0783: job of terminal may be freed too early
Christian Brabandt <cb@256bit.org>
parents: 11798
diff changeset
2684 ++job->jv_refcount;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2685 term->tl_job = job;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2686
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2687 return OK;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2688
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2689 failed:
11798
4d545cd33f0a patch 8.0.0781: MS-Windows: memory leak when using :terminal
Christian Brabandt <cb@256bit.org>
parents: 11794
diff changeset
2690 if (spawn_config != NULL)
4d545cd33f0a patch 8.0.0781: MS-Windows: memory leak when using :terminal
Christian Brabandt <cb@256bit.org>
parents: 11794
diff changeset
2691 winpty_spawn_config_free(spawn_config);
4d545cd33f0a patch 8.0.0781: MS-Windows: memory leak when using :terminal
Christian Brabandt <cb@256bit.org>
parents: 11794
diff changeset
2692 vim_free(p);
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2693 if (channel != NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2694 channel_clear(channel);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2695 if (job != NULL)
11751
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
2696 {
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
2697 job->jv_channel = NULL;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2698 job_cleanup(job);
11751
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
2699 }
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
2700 term->tl_job = NULL;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2701 if (jo != NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2702 CloseHandle(jo);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2703 if (term->tl_winpty != NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2704 winpty_free(term->tl_winpty);
11751
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
2705 term->tl_winpty = NULL;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2706 if (term->tl_winpty_config != NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2707 winpty_config_free(term->tl_winpty_config);
11751
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
2708 term->tl_winpty_config = NULL;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2709 if (winpty_err != NULL)
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2710 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2711 char_u *msg = utf16_to_enc(
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2712 (short_u *)winpty_error_msg(winpty_err), NULL);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2713
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2714 EMSG(msg);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2715 winpty_error_free(winpty_err);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2716 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2717 return FAIL;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2718 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2720 /*
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2721 * Free the terminal emulator part of "term".
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2722 */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2723 static void
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
2724 term_free_vterm(term_T *term)
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2725 {
11751
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
2726 if (term->tl_winpty != NULL)
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
2727 winpty_free(term->tl_winpty);
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
2728 term->tl_winpty = NULL;
11751
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
2729 if (term->tl_winpty_config != NULL)
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
2730 winpty_config_free(term->tl_winpty_config);
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
2731 term->tl_winpty_config = NULL;
11751
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
2732 if (term->tl_vterm != NULL)
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
2733 vterm_free(term->tl_vterm);
11838
e6080ed193f6 patch 8.0.0799: missing semicolon
Christian Brabandt <cb@256bit.org>
parents: 11836
diff changeset
2734 term->tl_vterm = NULL;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2735 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2736
11753
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2737 /*
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2738 * Request size to terminal.
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2739 */
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2740 static void
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2741 term_report_winsize(term_T *term, int rows, int cols)
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2742 {
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2743 winpty_set_size(term->tl_winpty, cols, rows, NULL);
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2744 }
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2745
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2746 # else
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2747
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2748 /**************************************
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2749 * 3. Unix-like implementation.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2750 */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2751
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2752 /*
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2753 * Create a new terminal of "rows" by "cols" cells.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2754 * Start job for "cmd".
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2755 * Store the pointers in "term".
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2756 * Return OK or FAIL.
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2757 */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2758 static int
11939
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2759 term_and_job_init(term_T *term, int rows, int cols, char_u *cmd, jobopt_T *opt)
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2760 {
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2761 typval_T argvars[2];
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2762
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2763 create_vterm(term, rows, cols);
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2764
11933
d033653d3df8 patch 8.0.0846: cannot get the name of the pty of a job
Christian Brabandt <cb@256bit.org>
parents: 11931
diff changeset
2765 /* TODO: if the command is "NONE" only create a pty. */
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2766 argvars[0].v_type = VAR_STRING;
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2767 argvars[0].vval.v_string = cmd;
11939
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2768
ef1febf04d03 patch 8.0.0849: crash when job exit callback wipes the terminal
Christian Brabandt <cb@256bit.org>
parents: 11937
diff changeset
2769 term->tl_job = job_start(argvars, opt);
11802
b1fd49b4eea7 patch 8.0.0783: job of terminal may be freed too early
Christian Brabandt <cb@256bit.org>
parents: 11798
diff changeset
2770 if (term->tl_job != NULL)
b1fd49b4eea7 patch 8.0.0783: job of terminal may be freed too early
Christian Brabandt <cb@256bit.org>
parents: 11798
diff changeset
2771 ++term->tl_job->jv_refcount;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2772
11727
cb1dc90d22cc patch 8.0.0746: when :term fails the job is not properly cleaned up
Christian Brabandt <cb@256bit.org>
parents: 11725
diff changeset
2773 return term->tl_job != NULL
cb1dc90d22cc patch 8.0.0746: when :term fails the job is not properly cleaned up
Christian Brabandt <cb@256bit.org>
parents: 11725
diff changeset
2774 && term->tl_job->jv_channel != NULL
cb1dc90d22cc patch 8.0.0746: when :term fails the job is not properly cleaned up
Christian Brabandt <cb@256bit.org>
parents: 11725
diff changeset
2775 && term->tl_job->jv_status != JOB_FAILED ? OK : FAIL;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2776 }
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2777
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2778 /*
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2779 * Free the terminal emulator part of "term".
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2780 */
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2781 static void
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
2782 term_free_vterm(term_T *term)
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2783 {
11751
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
2784 if (term->tl_vterm != NULL)
a1815c4f8b70 patch 8.0.0758: possible crash when using a terminal window
Christian Brabandt <cb@256bit.org>
parents: 11745
diff changeset
2785 vterm_free(term->tl_vterm);
11834
0cfe4a07c2ad patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents: 11822
diff changeset
2786 term->tl_vterm = NULL;
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2787 }
11753
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2788
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2789 /*
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2790 * Request size to terminal.
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2791 */
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2792 static void
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2793 term_report_winsize(term_T *term, int rows, int cols)
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2794 {
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2795 /* Use an ioctl() to report the new window size to the job. */
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2796 if (term->tl_job != NULL && term->tl_job->jv_channel != NULL)
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2797 {
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2798 int fd = -1;
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2799 int part;
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2800
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2801 for (part = PART_OUT; part < PART_COUNT; ++part)
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2802 {
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2803 fd = term->tl_job->jv_channel->ch_part[part].ch_fd;
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2804 if (isatty(fd))
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2805 break;
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2806 }
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2807 if (part < PART_COUNT && mch_report_winsize(fd, rows, cols) == OK)
12037
85f0f557661e patch 8.0.0899: function name mch_stop_job() is confusing
Christian Brabandt <cb@256bit.org>
parents: 12035
diff changeset
2808 mch_signal_job(term->tl_job, (char_u *)"winch");
11753
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2809 }
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2810 }
f7c2473796b7 patch 8.0.0759: MS-Windows: terminal does not adjust size
Christian Brabandt <cb@256bit.org>
parents: 11751
diff changeset
2811
11719
13ecb3e64399 patch 8.0.0742: terminal feature does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 11715
diff changeset
2812 # endif
11694
8f5840a59b31 patch 8.0.0730: terminal feature only supports Unix-like systems
Christian Brabandt <cb@256bit.org>
parents: 11690
diff changeset
2813
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2814 #endif /* FEAT_TERMINAL */