annotate src/terminal.c @ 19774:00a1b89256ea v8.2.0443

patch 8.2.0443: clipboard code is spread out Commit: https://github.com/vim/vim/commit/45fffdf10b7cb6e59794e76e9b8a2930fcb4b192 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Mar 24 21:42:01 2020 +0100 patch 8.2.0443: clipboard code is spread out Problem: Clipboard code is spread out. Solution: Move clipboard code to its own file. (Yegappan Lakshmanan, closes #5827)
author Bram Moolenaar <Bram@vim.org>
date Tue, 24 Mar 2020 21:45:04 +0100
parents eb4887dd4b60
children d73d982499ae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 *
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 *
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 * Terminal window support, see ":help :terminal".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 *
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 * There are three parts:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 * 1. Generic code for all systems.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 * Uses libvterm for the terminal emulator.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 * 2. The MS-Windows implementation.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 * Uses winpty.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 * 3. The Unix-like implementation.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 * Uses pseudo-tty's (pty's).
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 *
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 * For each terminal one VTerm is constructed. This uses libvterm. A copy of
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 * this library is in the libvterm directory.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 *
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 * When a terminal window is opened, a job is started that will be connected to
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 * the terminal emulator.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 *
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 * If the terminal window has keyboard focus, typed keys are converted to the
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 * terminal encoding and writing to the job over a channel.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 *
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 * If the job produces output, it is written to the terminal emulator. The
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 * terminal emulator invokes callbacks when its screen content changes. The
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 * line range is stored in tl_dirty_row_start and tl_dirty_row_end. Once in a
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 * while, if the terminal window is visible, the screen contents is drawn.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 *
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 * When the job ends the text is put in a buffer. Redrawing then happens from
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 * that buffer, attributes come from the scrollback buffer tl_scrollback.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 * When the buffer is changed it is turned into a normal buffer, the attributes
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 * in tl_scrollback are no longer used.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 #include "vim.h"
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 #if defined(FEAT_TERMINAL) || defined(PROTO)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 #ifndef MIN
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 # define MIN(x,y) ((x) < (y) ? (x) : (y))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 #ifndef MAX
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 # define MAX(x,y) ((x) > (y) ? (x) : (y))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 #include "libvterm/include/vterm.h"
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
54 // This is VTermScreenCell without the characters, thus much smaller.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 typedef struct {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 VTermScreenCellAttrs attrs;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 char width;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
58 VTermColor fg;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
59 VTermColor bg;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 } cellattr_T;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 typedef struct sb_line_S {
15826
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
63 int sb_cols; // can differ per line
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
64 cellattr_T *sb_cells; // allocated
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
65 cellattr_T sb_fill_attr; // for short line
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
66 char_u *sb_text; // for tl_scrollback_postponed
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 } sb_line_T;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15844
diff changeset
69 #ifdef MSWIN
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
70 # ifndef HPCON
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
71 # define HPCON VOID*
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
72 # endif
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
73 # ifndef EXTENDED_STARTUPINFO_PRESENT
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
74 # define EXTENDED_STARTUPINFO_PRESENT 0x00080000
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
75 # endif
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
76 # ifndef PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
77 # define PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE 0x00020016
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
78 # endif
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
79 typedef struct _DYN_STARTUPINFOEXW
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
80 {
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
81 STARTUPINFOW StartupInfo;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
82 LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
83 } DYN_STARTUPINFOEXW, *PDYN_STARTUPINFOEXW;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
84 #endif
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
85
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
86 // typedef term_T in structs.h
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87 struct terminal_S {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88 term_T *tl_next;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
90 VTerm *tl_vterm;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 job_T *tl_job;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92 buf_T *tl_buffer;
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
93 #if defined(FEAT_GUI)
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
94 int tl_system; // when non-zero used for :!cmd output
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
95 int tl_toprow; // row with first line of system terminal
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
96 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
97
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
98 // Set when setting the size of a vterm, reset after redrawing.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
99 int tl_vterm_size_changed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
100
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
101 int tl_normal_mode; // TRUE: Terminal-Normal mode
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
102 int tl_channel_closed;
13888
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
103 int tl_channel_recently_closed; // still need to handle tl_finish
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
104
13476
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
105 int tl_finish;
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
106 #define TL_FINISH_UNSET NUL
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
107 #define TL_FINISH_CLOSE 'c' // ++close or :terminal without argument
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
108 #define TL_FINISH_NOCLOSE 'n' // ++noclose
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
109 #define TL_FINISH_OPEN 'o' // ++open
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
110 char_u *tl_opencmd;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
111 char_u *tl_eof_chars;
18170
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
112 char_u *tl_api; // prefix for terminal API function
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
113
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
114 char_u *tl_arg0_cmd; // To format the status bar
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
115
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15844
diff changeset
116 #ifdef MSWIN
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
117 void *tl_winpty_config;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
118 void *tl_winpty;
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
119
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
120 HPCON tl_conpty;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
121 DYN_STARTUPINFOEXW tl_siex; // Structure that always needs to be hold
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
122
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
123 FILE *tl_out_fd;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
124 #endif
13435
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
125 #if defined(FEAT_SESSION)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
126 char_u *tl_command;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
127 #endif
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
128 char_u *tl_kill;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
129
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
130 // last known vterm size
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
131 int tl_rows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
132 int tl_cols;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
133
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
134 char_u *tl_title; // NULL or allocated
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
135 char_u *tl_status_text; // NULL or allocated
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
136
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
137 // Range of screen rows to update. Zero based.
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
138 int tl_dirty_row_start; // MAX_ROW if nothing dirty
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
139 int tl_dirty_row_end; // row below last one to update
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
140 int tl_dirty_snapshot; // text updated after making snapshot
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
141 #ifdef FEAT_TIMERS
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
142 int tl_timer_set;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
143 proftime_T tl_timer_due;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
144 #endif
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
145 int tl_postponed_scroll; // to be scrolled up
13851
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
146
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
147 garray_T tl_scrollback;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
148 int tl_scrollback_scrolled;
15826
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
149 garray_T tl_scrollback_postponed;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
150
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
151 cellattr_T tl_default_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
152
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
153 linenr_T tl_top_diff_rows; // rows of top diff file or zero
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
154 linenr_T tl_bot_diff_rows; // rows of bottom diff file
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
155
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
156 VTermPos tl_cursor_pos;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
157 int tl_cursor_visible;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
158 int tl_cursor_blink;
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
159 int tl_cursor_shape; // 1: block, 2: underline, 3: bar
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
160 char_u *tl_cursor_color; // NULL or allocated
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
161
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
162 int tl_using_altscreen;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
163 };
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
164
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
165 #define TMODE_ONCE 1 // CTRL-\ CTRL-N used
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
166 #define TMODE_LOOP 2 // CTRL-W N used
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
167
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
168 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
169 * List of all active terminals.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
170 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
171 static term_T *first_term = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
172
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
173 // Terminal active in terminal_loop().
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
174 static term_T *in_terminal_loop = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
175
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15844
diff changeset
176 #ifdef MSWIN
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
177 static BOOL has_winpty = FALSE;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
178 static BOOL has_conpty = FALSE;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
179 #endif
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
180
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
181 #define MAX_ROW 999999 // used for tl_dirty_row_end to update all rows
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
182 #define KEY_BUF_LEN 200
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
183
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
184 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
185 * Functions with separate implementation for MS-Windows and Unix-like systems.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
186 */
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
187 static int term_and_job_init(term_T *term, typval_T *argvar, char **argv, jobopt_T *opt, jobopt_T *orig_opt);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
188 static int create_pty_only(term_T *term, jobopt_T *opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
189 static void term_report_winsize(term_T *term, int rows, int cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
190 static void term_free_vterm(term_T *term);
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
191 #ifdef FEAT_GUI
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
192 static void update_system_term(term_T *term);
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
193 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
194
15826
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
195 static void handle_postponed_scrollback(term_T *term);
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
196
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
197 // The character that we know (or assume) that the terminal expects for the
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
198 // backspace key.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
199 static int term_backspace_char = BS;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
200
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
201 // "Terminal" highlight group colors.
12973
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
202 static int term_default_cterm_fg = -1;
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
203 static int term_default_cterm_bg = -1;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
204
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
205 // Store the last set and the desired cursor properties, so that we only update
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
206 // them when needed. Doing it unnecessary may result in flicker.
13990
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
207 static char_u *last_set_cursor_color = NULL;
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
208 static char_u *desired_cursor_color = NULL;
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
209 static int last_set_cursor_shape = -1;
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
210 static int desired_cursor_shape = -1;
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
211 static int last_set_cursor_blink = -1;
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
212 static int desired_cursor_blink = -1;
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
213
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
214
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
215 ///////////////////////////////////////
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
216 // 1. Generic code for all systems.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
217
13994
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
218 static int
13990
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
219 cursor_color_equal(char_u *lhs_color, char_u *rhs_color)
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
220 {
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
221 if (lhs_color != NULL && rhs_color != NULL)
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
222 return STRCMP(lhs_color, rhs_color) == 0;
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
223 return lhs_color == NULL && rhs_color == NULL;
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
224 }
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
225
13994
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
226 static void
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
227 cursor_color_copy(char_u **to_color, char_u *from_color)
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
228 {
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
229 // Avoid a free & alloc if the value is already right.
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
230 if (cursor_color_equal(*to_color, from_color))
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
231 return;
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
232 vim_free(*to_color);
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
233 *to_color = (from_color == NULL) ? NULL : vim_strsave(from_color);
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
234 }
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
235
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
236 static char_u *
13990
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
237 cursor_color_get(char_u *color)
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
238 {
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
239 return (color == NULL) ? (char_u *)"" : color;
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
240 }
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
241
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
242
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
243 /*
13845
f22db93bd887 patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents: 13835
diff changeset
244 * Parse 'termwinsize' and set "rows" and "cols" for the terminal size in the
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
245 * current window.
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
246 * Sets "rows" and/or "cols" to zero when it should follow the window size.
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
247 * Return TRUE if the size is the minimum size: "24*80".
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
248 */
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
249 static int
13845
f22db93bd887 patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents: 13835
diff changeset
250 parse_termwinsize(win_T *wp, int *rows, int *cols)
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
251 {
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
252 int minsize = FALSE;
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
253
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
254 *rows = 0;
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
255 *cols = 0;
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
256
13742
a34b1323286c patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents: 13720
diff changeset
257 if (*wp->w_p_tws != NUL)
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
258 {
13742
a34b1323286c patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents: 13720
diff changeset
259 char_u *p = vim_strchr(wp->w_p_tws, 'x');
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
260
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
261 // Syntax of value was already checked when it's set.
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
262 if (p == NULL)
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
263 {
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
264 minsize = TRUE;
13742
a34b1323286c patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents: 13720
diff changeset
265 p = vim_strchr(wp->w_p_tws, '*');
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
266 }
13742
a34b1323286c patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents: 13720
diff changeset
267 *rows = atoi((char *)wp->w_p_tws);
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
268 *cols = atoi((char *)p + 1);
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
269 }
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
270 return minsize;
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
271 }
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
272
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
273 /*
13845
f22db93bd887 patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents: 13835
diff changeset
274 * Determine the terminal size from 'termwinsize' and the current window.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
275 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
276 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
277 set_term_and_win_size(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
278 {
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
279 #ifdef FEAT_GUI
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
280 if (term->tl_system)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
281 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
282 // Use the whole screen for the system command. However, it will start
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
283 // at the command line and scroll up as needed, using tl_toprow.
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
284 term->tl_rows = Rows;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
285 term->tl_cols = Columns;
13624
429f0eb87d6f patch 8.0.1684: ml_get errors when using terminal window for shell command
Christian Brabandt <cb@256bit.org>
parents: 13616
diff changeset
286 return;
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
287 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
288 #endif
13845
f22db93bd887 patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents: 13835
diff changeset
289 if (parse_termwinsize(curwin, &term->tl_rows, &term->tl_cols))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
290 {
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
291 if (term->tl_rows != 0)
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
292 term->tl_rows = MAX(term->tl_rows, curwin->w_height);
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
293 if (term->tl_cols != 0)
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
294 term->tl_cols = MAX(term->tl_cols, curwin->w_width);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
295 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
296 if (term->tl_rows == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
297 term->tl_rows = curwin->w_height;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
298 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
299 win_setheight_win(term->tl_rows, curwin);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
300 if (term->tl_cols == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
301 term->tl_cols = curwin->w_width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
302 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
303 win_setwidth_win(term->tl_cols, curwin);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
304 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
305
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
306 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
307 * Initialize job options for a terminal job.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
308 * Caller may overrule some of them.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
309 */
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
310 void
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
311 init_job_options(jobopt_T *opt)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
312 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
313 clear_job_options(opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
314
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
315 opt->jo_mode = MODE_RAW;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
316 opt->jo_out_mode = MODE_RAW;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
317 opt->jo_err_mode = MODE_RAW;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
318 opt->jo_set = JO_MODE | JO_OUT_MODE | JO_ERR_MODE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
319 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
320
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
321 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
322 * Set job options mandatory for a terminal job.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
323 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
324 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
325 setup_job_options(jobopt_T *opt, int rows, int cols)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
326 {
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15844
diff changeset
327 #ifndef MSWIN
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
328 // Win32: Redirecting the job output won't work, thus always connect stdout
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
329 // here.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
330 if (!(opt->jo_set & JO_OUT_IO))
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
331 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
332 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
333 // Connect stdout to the terminal.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
334 opt->jo_io[PART_OUT] = JIO_BUFFER;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
335 opt->jo_io_buf[PART_OUT] = curbuf->b_fnum;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
336 opt->jo_modifiable[PART_OUT] = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
337 opt->jo_set |= JO_OUT_IO + JO_OUT_BUF + JO_OUT_MODIFIABLE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
338 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
339
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15844
diff changeset
340 #ifndef MSWIN
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
341 // Win32: Redirecting the job output won't work, thus always connect stderr
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
342 // here.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
343 if (!(opt->jo_set & JO_ERR_IO))
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
344 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
345 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
346 // Connect stderr to the terminal.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
347 opt->jo_io[PART_ERR] = JIO_BUFFER;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
348 opt->jo_io_buf[PART_ERR] = curbuf->b_fnum;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
349 opt->jo_modifiable[PART_ERR] = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
350 opt->jo_set |= JO_ERR_IO + JO_ERR_BUF + JO_ERR_MODIFIABLE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
351 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
352
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
353 opt->jo_pty = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
354 if ((opt->jo_set2 & JO2_TERM_ROWS) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
355 opt->jo_term_rows = rows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
356 if ((opt->jo_set2 & JO2_TERM_COLS) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
357 opt->jo_term_cols = cols;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
358 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
359
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
360 /*
17186
278583ff5e44 patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
361 * Flush messages on channels.
278583ff5e44 patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
362 */
278583ff5e44 patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
363 static void
278583ff5e44 patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
364 term_flush_messages()
278583ff5e44 patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
365 {
278583ff5e44 patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
366 mch_check_messages();
278583ff5e44 patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
367 parse_queued_messages();
278583ff5e44 patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
368 }
278583ff5e44 patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
369
278583ff5e44 patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
370 /*
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
371 * Close a terminal buffer (and its window). Used when creating the terminal
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
372 * fails.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
373 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
374 static void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
375 term_close_buffer(buf_T *buf, buf_T *old_curbuf)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
376 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
377 free_terminal(buf);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
378 if (old_curbuf != NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
379 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
380 --curbuf->b_nwindows;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
381 curbuf = old_curbuf;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
382 curwin->w_buffer = curbuf;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
383 ++curbuf->b_nwindows;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
384 }
19629
804322d6c6ba patch 8.2.0371: crash with combination of terminal popup and autocmd
Bram Moolenaar <Bram@vim.org>
parents: 19542
diff changeset
385 CHECK_CURBUF;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
386
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
387 // Wiping out the buffer will also close the window and call
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
388 // free_terminal().
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
389 do_buffer(DOBUF_WIPE, DOBUF_FIRST, FORWARD, buf->b_fnum, TRUE);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
390 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
391
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
392 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
393 * Start a terminal window and return its buffer.
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
394 * Use either "argvar" or "argv", the other must be NULL.
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
395 * When "flags" has TERM_START_NOJOB only create the buffer, b_term and open
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
396 * the window.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
397 * Returns NULL when failed.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
398 */
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
399 buf_T *
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
400 term_start(
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
401 typval_T *argvar,
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
402 char **argv,
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
403 jobopt_T *opt,
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
404 int flags)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
405 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
406 exarg_T split_ea;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
407 win_T *old_curwin = curwin;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
408 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
409 buf_T *old_curbuf = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
410 int res;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
411 buf_T *newbuf;
13501
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
412 int vertical = opt->jo_vertical || (cmdmod.split & WSP_VERT);
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
413 jobopt_T orig_opt; // only partly filled
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
414
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
415 if (check_restricted() || check_secure())
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
416 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
417
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
418 if ((opt->jo_set & (JO_IN_IO + JO_OUT_IO + JO_ERR_IO))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
419 == (JO_IN_IO + JO_OUT_IO + JO_ERR_IO)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
420 || (!(opt->jo_set & JO_OUT_IO) && (opt->jo_set & JO_OUT_BUF))
19241
c53dbbf3229b patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents: 18814
diff changeset
421 || (!(opt->jo_set & JO_ERR_IO) && (opt->jo_set & JO_ERR_BUF))
c53dbbf3229b patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents: 18814
diff changeset
422 || (argvar != NULL
c53dbbf3229b patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents: 18814
diff changeset
423 && argvar->v_type == VAR_LIST
c53dbbf3229b patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents: 18814
diff changeset
424 && argvar->vval.v_list != NULL
c53dbbf3229b patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents: 18814
diff changeset
425 && argvar->vval.v_list->lv_first == &range_list_item))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
426 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
427 emsg(_(e_invarg));
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
428 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
429 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
430
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16782
diff changeset
431 term = ALLOC_CLEAR_ONE(term_T);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
432 if (term == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
433 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
434 term->tl_dirty_row_end = MAX_ROW;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
435 term->tl_cursor_visible = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
436 term->tl_cursor_shape = VTERM_PROP_CURSORSHAPE_BLOCK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
437 term->tl_finish = opt->jo_term_finish;
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
438 #ifdef FEAT_GUI
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
439 term->tl_system = (flags & TERM_START_SYSTEM);
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
440 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
441 ga_init2(&term->tl_scrollback, sizeof(sb_line_T), 300);
15826
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
442 ga_init2(&term->tl_scrollback_postponed, sizeof(sb_line_T), 300);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
443
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
444 vim_memset(&split_ea, 0, sizeof(split_ea));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
445 if (opt->jo_curwin)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
446 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
447 // Create a new buffer in the current window.
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
448 if (!can_abandon(curbuf, flags & TERM_START_FORCEIT))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
449 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
450 no_write_message();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
451 vim_free(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
452 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
453 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
454 if (do_ecmd(0, NULL, NULL, &split_ea, ECMD_ONE,
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
455 ECMD_HIDE
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
456 + ((flags & TERM_START_FORCEIT) ? ECMD_FORCEIT : 0),
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
457 curwin) == FAIL)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
458 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
459 vim_free(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
460 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
461 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
462 }
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
463 else if (opt->jo_hidden || (flags & TERM_START_SYSTEM))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
464 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
465 buf_T *buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
466
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
467 // Create a new buffer without a window. Make it the current buffer for
19744
eb4887dd4b60 patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents: 19713
diff changeset
468 // a moment to be able to do the initializations.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
469 buf = buflist_new((char_u *)"", NULL, (linenr_T)0,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
470 BLN_NEW | BLN_LISTED);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
471 if (buf == NULL || ml_open(buf) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
472 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
473 vim_free(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
474 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
475 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
476 old_curbuf = curbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
477 --curbuf->b_nwindows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
478 curbuf = buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
479 curwin->w_buffer = buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
480 ++curbuf->b_nwindows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
481 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
482 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
483 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
484 // Open a new window or tab.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
485 split_ea.cmdidx = CMD_new;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
486 split_ea.cmd = (char_u *)"new";
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
487 split_ea.arg = (char_u *)"";
13501
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
488 if (opt->jo_term_rows > 0 && !vertical)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
489 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
490 split_ea.line2 = opt->jo_term_rows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
491 split_ea.addr_count = 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
492 }
13501
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
493 if (opt->jo_term_cols > 0 && vertical)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
494 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
495 split_ea.line2 = opt->jo_term_cols;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
496 split_ea.addr_count = 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
497 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
498
13501
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
499 if (vertical)
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
500 cmdmod.split |= WSP_VERT;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
501 ex_splitview(&split_ea);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
502 if (curwin == old_curwin)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
503 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
504 // split failed
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
505 vim_free(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
506 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
507 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
508 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
509 term->tl_buffer = curbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
510 curbuf->b_term = term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
511
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
512 if (!opt->jo_hidden)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
513 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
514 // Only one size was taken care of with :new, do the other one. With
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
515 // "curwin" both need to be done.
13501
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
516 if (opt->jo_term_rows > 0 && (opt->jo_curwin || vertical))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
517 win_setheight(opt->jo_term_rows);
13501
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
518 if (opt->jo_term_cols > 0 && (opt->jo_curwin || !vertical))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
519 win_setwidth(opt->jo_term_cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
520 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
521
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
522 // Link the new terminal in the list of active terminals.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
523 term->tl_next = first_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
524 first_term = term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
525
19713
8514e8b7e661 patch 8.2.0413: buffer menu does not handle special buffers properly
Bram Moolenaar <Bram@vim.org>
parents: 19633
diff changeset
526 apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, FALSE, curbuf);
8514e8b7e661 patch 8.2.0413: buffer menu does not handle special buffers properly
Bram Moolenaar <Bram@vim.org>
parents: 19633
diff changeset
527
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
528 if (opt->jo_term_name != NULL)
19744
eb4887dd4b60 patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents: 19713
diff changeset
529 {
eb4887dd4b60 patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents: 19713
diff changeset
530 vim_free(curbuf->b_ffname);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
531 curbuf->b_ffname = vim_strsave(opt->jo_term_name);
19744
eb4887dd4b60 patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents: 19713
diff changeset
532 }
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
533 else if (argv != NULL)
19744
eb4887dd4b60 patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents: 19713
diff changeset
534 {
eb4887dd4b60 patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents: 19713
diff changeset
535 vim_free(curbuf->b_ffname);
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
536 curbuf->b_ffname = vim_strsave((char_u *)"!system");
19744
eb4887dd4b60 patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents: 19713
diff changeset
537 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
538 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
539 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
540 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
541 size_t len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
542 char_u *cmd, *p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
543
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
544 if (argvar->v_type == VAR_STRING)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
545 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
546 cmd = argvar->vval.v_string;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
547 if (cmd == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
548 cmd = (char_u *)"";
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
549 else if (STRCMP(cmd, "NONE") == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
550 cmd = (char_u *)"pty";
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
551 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
552 else if (argvar->v_type != VAR_LIST
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
553 || argvar->vval.v_list == NULL
19241
c53dbbf3229b patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents: 18814
diff changeset
554 || argvar->vval.v_list->lv_len == 0
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15203
diff changeset
555 || (cmd = tv_get_string_chk(
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
556 &argvar->vval.v_list->lv_first->li_tv)) == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
557 cmd = (char_u*)"";
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
558
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
559 len = STRLEN(cmd) + 10;
16782
fc58fee685e2 patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents: 16778
diff changeset
560 p = alloc(len);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
561
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
562 for (i = 0; p != NULL; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
563 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
564 // Prepend a ! to the command name to avoid the buffer name equals
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
565 // the executable, otherwise ":w!" would overwrite it.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
566 if (i == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
567 vim_snprintf((char *)p, len, "!%s", cmd);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
568 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
569 vim_snprintf((char *)p, len, "!%s (%d)", cmd, i);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
570 if (buflist_findname(p) == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
571 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
572 vim_free(curbuf->b_ffname);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
573 curbuf->b_ffname = p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
574 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
575 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
576 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
577 }
19513
274052873790 patch 8.2.0314: short name not set for terminal buffer
Bram Moolenaar <Bram@vim.org>
parents: 19358
diff changeset
578 vim_free(curbuf->b_sfname);
274052873790 patch 8.2.0314: short name not set for terminal buffer
Bram Moolenaar <Bram@vim.org>
parents: 19358
diff changeset
579 curbuf->b_sfname = vim_strsave(curbuf->b_ffname);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
580 curbuf->b_fname = curbuf->b_ffname;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
581
19713
8514e8b7e661 patch 8.2.0413: buffer menu does not handle special buffers properly
Bram Moolenaar <Bram@vim.org>
parents: 19633
diff changeset
582 apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, curbuf);
8514e8b7e661 patch 8.2.0413: buffer menu does not handle special buffers properly
Bram Moolenaar <Bram@vim.org>
parents: 19633
diff changeset
583
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
584 if (opt->jo_term_opencmd != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
585 term->tl_opencmd = vim_strsave(opt->jo_term_opencmd);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
586
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
587 if (opt->jo_eof_chars != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
588 term->tl_eof_chars = vim_strsave(opt->jo_eof_chars);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
589
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
590 set_string_option_direct((char_u *)"buftype", -1,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
591 (char_u *)"terminal", OPT_FREE|OPT_LOCAL, 0);
14449
5faab0545f3c patch 8.1.0238: 'buftype' is cleared when using ":term ++hidden cat"
Christian Brabandt <cb@256bit.org>
parents: 14311
diff changeset
592 // Avoid that 'buftype' is reset when this buffer is entered.
5faab0545f3c patch 8.1.0238: 'buftype' is cleared when using ":term ++hidden cat"
Christian Brabandt <cb@256bit.org>
parents: 14311
diff changeset
593 curbuf->b_p_initialized = TRUE;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
594
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
595 // Mark the buffer as not modifiable. It can only be made modifiable after
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
596 // the job finished.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
597 curbuf->b_p_ma = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
598
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
599 set_term_and_win_size(term);
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15844
diff changeset
600 #ifdef MSWIN
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
601 mch_memmove(orig_opt.jo_io, opt->jo_io, sizeof(orig_opt.jo_io));
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
602 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
603 setup_job_options(opt, term->tl_rows, term->tl_cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
604
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
605 if (flags & TERM_START_NOJOB)
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
606 return curbuf;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
607
13435
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
608 #if defined(FEAT_SESSION)
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
609 // Remember the command for the session file.
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
610 if (opt->jo_term_norestore || argv != NULL)
13435
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
611 term->tl_command = vim_strsave((char_u *)"NONE");
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
612 else if (argvar->v_type == VAR_STRING)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
613 {
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
614 char_u *cmd = argvar->vval.v_string;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
615
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
616 if (cmd != NULL && STRCMP(cmd, p_sh) != 0)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
617 term->tl_command = vim_strsave(cmd);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
618 }
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
619 else if (argvar->v_type == VAR_LIST
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
620 && argvar->vval.v_list != NULL
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
621 && argvar->vval.v_list->lv_len > 0)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
622 {
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
623 garray_T ga;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
624 listitem_T *item;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
625
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
626 ga_init2(&ga, 1, 100);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
627 for (item = argvar->vval.v_list->lv_first;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
628 item != NULL; item = item->li_next)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
629 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15203
diff changeset
630 char_u *s = tv_get_string_chk(&item->li_tv);
13435
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
631 char_u *p;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
632
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
633 if (s == NULL)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
634 break;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
635 p = vim_strsave_fnameescape(s, FALSE);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
636 if (p == NULL)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
637 break;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
638 ga_concat(&ga, p);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
639 vim_free(p);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
640 ga_append(&ga, ' ');
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
641 }
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
642 if (item == NULL)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
643 {
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
644 ga_append(&ga, NUL);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
645 term->tl_command = ga.ga_data;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
646 }
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
647 else
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
648 ga_clear(&ga);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
649 }
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
650 #endif
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
651
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
652 if (opt->jo_term_kill != NULL)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
653 {
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
654 char_u *p = skiptowhite(opt->jo_term_kill);
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
655
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
656 term->tl_kill = vim_strnsave(opt->jo_term_kill, p - opt->jo_term_kill);
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
657 }
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
658
18170
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
659 if (opt->jo_term_api != NULL)
19245
5ed8297121fa patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents: 19241
diff changeset
660 {
5ed8297121fa patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents: 19241
diff changeset
661 char_u *p = skiptowhite(opt->jo_term_api);
5ed8297121fa patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents: 19241
diff changeset
662
5ed8297121fa patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents: 19241
diff changeset
663 term->tl_api = vim_strnsave(opt->jo_term_api, p - opt->jo_term_api);
5ed8297121fa patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents: 19241
diff changeset
664 }
18170
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
665 else
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
666 term->tl_api = vim_strsave((char_u *)"Tapi_");
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
667
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
668 // System dependent: setup the vterm and maybe start the job in it.
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
669 if (argv == NULL
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
670 && argvar->v_type == VAR_STRING
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
671 && argvar->vval.v_string != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
672 && STRCMP(argvar->vval.v_string, "NONE") == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
673 res = create_pty_only(term, opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
674 else
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
675 res = term_and_job_init(term, argvar, argv, opt, &orig_opt);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
676
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
677 newbuf = curbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
678 if (res == OK)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
679 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
680 // Get and remember the size we ended up with. Update the pty.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
681 vterm_get_size(term->tl_vterm, &term->tl_rows, &term->tl_cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
682 term_report_winsize(term, term->tl_rows, term->tl_cols);
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
683 #ifdef FEAT_GUI
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
684 if (term->tl_system)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
685 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
686 // display first line below typed command
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
687 term->tl_toprow = msg_row + 1;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
688 term->tl_dirty_row_end = 0;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
689 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
690 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
691
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
692 // Make sure we don't get stuck on sending keys to the job, it leads to
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
693 // a deadlock if the job is waiting for Vim to read.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
694 channel_set_nonblock(term->tl_job->jv_channel, PART_IN);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
695
13835
8e583c52eb44 patch 8.0.1789: BufWinEnter does not work well for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13829
diff changeset
696 if (old_curbuf != NULL)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
697 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
698 --curbuf->b_nwindows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
699 curbuf = old_curbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
700 curwin->w_buffer = curbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
701 ++curbuf->b_nwindows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
702 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
703 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
704 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
705 {
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
706 term_close_buffer(curbuf, old_curbuf);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
707 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
708 }
13444
9f06f7aca74c patch 8.0.1596: no autocommand specifically for opening a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13438
diff changeset
709
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
710 apply_autocmds(EVENT_TERMINALOPEN, NULL, NULL, FALSE, newbuf);
18450
507348b211b4 patch 8.1.2219: no autocommand for open window with terminal
Bram Moolenaar <Bram@vim.org>
parents: 18420
diff changeset
711 if (!opt->jo_hidden && !(flags & TERM_START_SYSTEM))
507348b211b4 patch 8.1.2219: no autocommand for open window with terminal
Bram Moolenaar <Bram@vim.org>
parents: 18420
diff changeset
712 apply_autocmds(EVENT_TERMINALWINOPEN, NULL, NULL, FALSE, newbuf);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
713 return newbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
714 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
715
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
716 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
717 * ":terminal": open a terminal window and execute a job in it.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
718 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
719 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
720 ex_terminal(exarg_T *eap)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
721 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
722 typval_T argvar[2];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
723 jobopt_T opt;
18514
39b0c28fe495 patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents: 18508
diff changeset
724 int opt_shell = FALSE;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
725 char_u *cmd;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
726 char_u *tofree = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
727
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
728 init_job_options(&opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
729
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
730 cmd = eap->arg;
13219
4b8d89ea9edb patch 8.0.1484: reduntant conditions
Christian Brabandt <cb@256bit.org>
parents: 13206
diff changeset
731 while (*cmd == '+' && *(cmd + 1) == '+')
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
732 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
733 char_u *p, *ep;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
734
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
735 cmd += 2;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
736 p = skiptowhite(cmd);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
737 ep = vim_strchr(cmd, '=');
18170
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
738 if (ep != NULL)
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
739 {
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
740 if (ep < p)
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
741 p = ep;
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
742 else
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
743 ep = NULL;
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
744 }
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
745
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
746 # define OPTARG_HAS(name) ((int)(p - cmd) == sizeof(name) - 1 \
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
747 && STRNICMP(cmd, name, sizeof(name) - 1) == 0)
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
748 if (OPTARG_HAS("close"))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
749 opt.jo_term_finish = 'c';
18170
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
750 else if (OPTARG_HAS("noclose"))
13476
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
751 opt.jo_term_finish = 'n';
18170
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
752 else if (OPTARG_HAS("open"))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
753 opt.jo_term_finish = 'o';
18170
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
754 else if (OPTARG_HAS("curwin"))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
755 opt.jo_curwin = 1;
18170
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
756 else if (OPTARG_HAS("hidden"))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
757 opt.jo_hidden = 1;
18170
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
758 else if (OPTARG_HAS("norestore"))
13435
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
759 opt.jo_term_norestore = 1;
18514
39b0c28fe495 patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents: 18508
diff changeset
760 else if (OPTARG_HAS("shell"))
39b0c28fe495 patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents: 18508
diff changeset
761 opt_shell = TRUE;
18170
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
762 else if (OPTARG_HAS("kill") && ep != NULL)
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
763 {
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
764 opt.jo_set2 |= JO2_TERM_KILL;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
765 opt.jo_term_kill = ep + 1;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
766 p = skiptowhite(cmd);
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
767 }
18170
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
768 else if (OPTARG_HAS("api"))
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
769 {
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
770 opt.jo_set2 |= JO2_TERM_API;
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
771 if (ep != NULL)
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
772 {
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
773 opt.jo_term_api = ep + 1;
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
774 p = skiptowhite(cmd);
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
775 }
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
776 else
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
777 opt.jo_term_api = NULL;
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
778 }
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
779 else if (OPTARG_HAS("rows") && ep != NULL && isdigit(ep[1]))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
780 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
781 opt.jo_set2 |= JO2_TERM_ROWS;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
782 opt.jo_term_rows = atoi((char *)ep + 1);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
783 p = skiptowhite(cmd);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
784 }
18170
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
785 else if (OPTARG_HAS("cols") && ep != NULL && isdigit(ep[1]))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
786 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
787 opt.jo_set2 |= JO2_TERM_COLS;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
788 opt.jo_term_cols = atoi((char *)ep + 1);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
789 p = skiptowhite(cmd);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
790 }
18170
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
791 else if (OPTARG_HAS("eof") && ep != NULL)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
792 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
793 char_u *buf = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
794 char_u *keys;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
795
19245
5ed8297121fa patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents: 19241
diff changeset
796 vim_free(opt.jo_eof_chars);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
797 p = skiptowhite(cmd);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
798 *p = NUL;
18301
506bf60a30a0 patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18279
diff changeset
799 keys = replace_termcodes(ep + 1, &buf,
506bf60a30a0 patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18279
diff changeset
800 REPTERM_FROM_PART | REPTERM_DO_LT | REPTERM_SPECIAL, NULL);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
801 opt.jo_set2 |= JO2_EOF_CHARS;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
802 opt.jo_eof_chars = vim_strsave(keys);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
803 vim_free(buf);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
804 *p = ' ';
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
805 }
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15844
diff changeset
806 #ifdef MSWIN
15746
c017195b121b patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents: 15725
diff changeset
807 else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "type", 4) == 0
c017195b121b patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents: 15725
diff changeset
808 && ep != NULL)
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
809 {
15746
c017195b121b patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents: 15725
diff changeset
810 int tty_type = NUL;
c017195b121b patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents: 15725
diff changeset
811
c017195b121b patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents: 15725
diff changeset
812 p = skiptowhite(cmd);
c017195b121b patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents: 15725
diff changeset
813 if (STRNICMP(ep + 1, "winpty", p - (ep + 1)) == 0)
c017195b121b patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents: 15725
diff changeset
814 tty_type = 'w';
c017195b121b patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents: 15725
diff changeset
815 else if (STRNICMP(ep + 1, "conpty", p - (ep + 1)) == 0)
c017195b121b patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents: 15725
diff changeset
816 tty_type = 'c';
c017195b121b patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents: 15725
diff changeset
817 else
c017195b121b patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents: 15725
diff changeset
818 {
c017195b121b patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents: 15725
diff changeset
819 semsg(e_invargval, "type");
c017195b121b patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents: 15725
diff changeset
820 goto theend;
c017195b121b patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents: 15725
diff changeset
821 }
c017195b121b patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents: 15725
diff changeset
822 opt.jo_set2 |= JO2_TTY_TYPE;
c017195b121b patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents: 15725
diff changeset
823 opt.jo_tty_type = tty_type;
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
824 }
15746
c017195b121b patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents: 15725
diff changeset
825 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
826 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
827 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
828 if (*p)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
829 *p = NUL;
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
830 semsg(_("E181: Invalid attribute: %s"), cmd);
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
831 goto theend;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
832 }
18170
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
833 # undef OPTARG_HAS
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
834 cmd = skipwhite(p);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
835 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
836 if (*cmd == NUL)
13476
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
837 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
838 // Make a copy of 'shell', an autocommand may change the option.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
839 tofree = cmd = vim_strsave(p_sh);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
840
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
841 // default to close when the shell exits
13476
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
842 if (opt.jo_term_finish == NUL)
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
843 opt.jo_term_finish = 'c';
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
844 }
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
845
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
846 if (eap->addr_count > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
847 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
848 // Write lines from current buffer to the job.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
849 opt.jo_set |= JO_IN_IO | JO_IN_BUF | JO_IN_TOP | JO_IN_BOT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
850 opt.jo_io[PART_IN] = JIO_BUFFER;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
851 opt.jo_io_buf[PART_IN] = curbuf->b_fnum;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
852 opt.jo_in_top = eap->line1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
853 opt.jo_in_bot = eap->line2;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
854 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
855
18514
39b0c28fe495 patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents: 18508
diff changeset
856 if (opt_shell && tofree == NULL)
39b0c28fe495 patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents: 18508
diff changeset
857 {
39b0c28fe495 patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents: 18508
diff changeset
858 #ifdef UNIX
39b0c28fe495 patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents: 18508
diff changeset
859 char **argv = NULL;
39b0c28fe495 patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents: 18508
diff changeset
860 char_u *tofree1 = NULL;
39b0c28fe495 patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents: 18508
diff changeset
861 char_u *tofree2 = NULL;
39b0c28fe495 patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents: 18508
diff changeset
862
39b0c28fe495 patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents: 18508
diff changeset
863 // :term ++shell command
39b0c28fe495 patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents: 18508
diff changeset
864 if (unix_build_argv(cmd, &argv, &tofree1, &tofree2) == OK)
39b0c28fe495 patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents: 18508
diff changeset
865 term_start(NULL, argv, &opt, eap->forceit ? TERM_START_FORCEIT : 0);
18595
517bfb2998aa patch 8.1.2291: memory leak when executing command in a terminal
Bram Moolenaar <Bram@vim.org>
parents: 18522
diff changeset
866 vim_free(argv);
18514
39b0c28fe495 patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents: 18508
diff changeset
867 vim_free(tofree1);
39b0c28fe495 patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents: 18508
diff changeset
868 vim_free(tofree2);
18522
dfdc29643c91 patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 18514
diff changeset
869 goto theend;
18514
39b0c28fe495 patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents: 18508
diff changeset
870 #else
18522
dfdc29643c91 patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 18514
diff changeset
871 # ifdef MSWIN
dfdc29643c91 patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 18514
diff changeset
872 long_u cmdlen = STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10;
dfdc29643c91 patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 18514
diff changeset
873 char_u *newcmd;
dfdc29643c91 patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 18514
diff changeset
874
dfdc29643c91 patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 18514
diff changeset
875 newcmd = alloc(cmdlen);
dfdc29643c91 patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 18514
diff changeset
876 if (newcmd == NULL)
dfdc29643c91 patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 18514
diff changeset
877 goto theend;
dfdc29643c91 patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 18514
diff changeset
878 tofree = newcmd;
dfdc29643c91 patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 18514
diff changeset
879 vim_snprintf((char *)newcmd, cmdlen, "%s %s %s", p_sh, p_shcf, cmd);
dfdc29643c91 patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 18514
diff changeset
880 cmd = newcmd;
dfdc29643c91 patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 18514
diff changeset
881 # else
18514
39b0c28fe495 patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents: 18508
diff changeset
882 emsg(_("E279: Sorry, ++shell is not supported on this system"));
18522
dfdc29643c91 patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 18514
diff changeset
883 goto theend;
dfdc29643c91 patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 18514
diff changeset
884 # endif
18514
39b0c28fe495 patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents: 18508
diff changeset
885 #endif
39b0c28fe495 patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents: 18508
diff changeset
886 }
18522
dfdc29643c91 patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 18514
diff changeset
887 argvar[0].v_type = VAR_STRING;
dfdc29643c91 patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 18514
diff changeset
888 argvar[0].vval.v_string = cmd;
dfdc29643c91 patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 18514
diff changeset
889 argvar[1].v_type = VAR_UNKNOWN;
dfdc29643c91 patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 18514
diff changeset
890 term_start(argvar, NULL, &opt, eap->forceit ? TERM_START_FORCEIT : 0);
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
891
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
892 theend:
18522
dfdc29643c91 patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 18514
diff changeset
893 vim_free(tofree);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
894 vim_free(opt.jo_eof_chars);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
895 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
896
13435
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
897 #if defined(FEAT_SESSION) || defined(PROTO)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
898 /*
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
899 * Write a :terminal command to the session file to restore the terminal in
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
900 * window "wp".
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
901 * Return FAIL if writing fails.
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
902 */
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
903 int
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
904 term_write_session(FILE *fd, win_T *wp)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
905 {
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
906 term_T *term = wp->w_buffer->b_term;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
907
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
908 // Create the terminal and run the command. This is not without
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
909 // risk, but let's assume the user only creates a session when this
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
910 // will be OK.
13435
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
911 if (fprintf(fd, "terminal ++curwin ++cols=%d ++rows=%d ",
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
912 term->tl_cols, term->tl_rows) < 0)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
913 return FAIL;
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15844
diff changeset
914 #ifdef MSWIN
15746
c017195b121b patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents: 15725
diff changeset
915 if (fprintf(fd, "++type=%s ", term->tl_job->jv_tty_type) < 0)
c017195b121b patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents: 15725
diff changeset
916 return FAIL;
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
917 #endif
13435
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
918 if (term->tl_command != NULL && fputs((char *)term->tl_command, fd) < 0)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
919 return FAIL;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
920
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
921 return put_eol(fd);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
922 }
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
923
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
924 /*
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
925 * Return TRUE if "buf" has a terminal that should be restored.
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
926 */
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
927 int
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
928 term_should_restore(buf_T *buf)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
929 {
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
930 term_T *term = buf->b_term;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
931
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
932 return term != NULL && (term->tl_command == NULL
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
933 || STRCMP(term->tl_command, "NONE") != 0);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
934 }
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
935 #endif
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
936
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
937 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
938 * Free the scrollback buffer for "term".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
939 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
940 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
941 free_scrollback(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
942 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
943 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
944
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
945 for (i = 0; i < term->tl_scrollback.ga_len; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
946 vim_free(((sb_line_T *)term->tl_scrollback.ga_data + i)->sb_cells);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
947 ga_clear(&term->tl_scrollback);
15826
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
948 for (i = 0; i < term->tl_scrollback_postponed.ga_len; ++i)
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
949 vim_free(((sb_line_T *)term->tl_scrollback_postponed.ga_data + i)->sb_cells);
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
950 ga_clear(&term->tl_scrollback_postponed);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
951 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
952
15675
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
953
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
954 // Terminals that need to be freed soon.
18051
d1e77015f60b patch 8.1.2021: some global functions can be local to the file
Bram Moolenaar <Bram@vim.org>
parents: 18033
diff changeset
955 static term_T *terminals_to_free = NULL;
15675
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
956
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
957 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
958 * Free a terminal and everything it refers to.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
959 * Kills the job if there is one.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
960 * Called when wiping out a buffer.
15675
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
961 * The actual terminal structure is freed later in free_unused_terminals(),
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
962 * because callbacks may wipe out a buffer while the terminal is still
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
963 * referenced.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
964 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
965 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
966 free_terminal(buf_T *buf)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
967 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
968 term_T *term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
969 term_T *tp;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
970
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
971 if (term == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
972 return;
15675
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
973
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
974 // Unlink the terminal form the list of terminals.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
975 if (first_term == term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
976 first_term = term->tl_next;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
977 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
978 for (tp = first_term; tp->tl_next != NULL; tp = tp->tl_next)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
979 if (tp->tl_next == term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
980 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
981 tp->tl_next = term->tl_next;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
982 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
983 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
984
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
985 if (term->tl_job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
986 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
987 if (term->tl_job->jv_status != JOB_ENDED
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
988 && term->tl_job->jv_status != JOB_FINISHED
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
989 && term->tl_job->jv_status != JOB_FAILED)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
990 job_stop(term->tl_job, NULL, "kill");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
991 job_unref(term->tl_job);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
992 }
15675
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
993 term->tl_next = terminals_to_free;
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
994 terminals_to_free = term;
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
995
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
996 buf->b_term = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
997 if (in_terminal_loop == term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
998 in_terminal_loop = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
999 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1000
15675
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1001 void
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1002 free_unused_terminals()
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1003 {
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1004 while (terminals_to_free != NULL)
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1005 {
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1006 term_T *term = terminals_to_free;
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1007
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1008 terminals_to_free = term->tl_next;
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1009
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1010 free_scrollback(term);
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1011
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1012 term_free_vterm(term);
18170
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
1013 vim_free(term->tl_api);
15675
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1014 vim_free(term->tl_title);
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1015 #ifdef FEAT_SESSION
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1016 vim_free(term->tl_command);
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1017 #endif
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1018 vim_free(term->tl_kill);
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1019 vim_free(term->tl_status_text);
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1020 vim_free(term->tl_opencmd);
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1021 vim_free(term->tl_eof_chars);
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
1022 vim_free(term->tl_arg0_cmd);
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15844
diff changeset
1023 #ifdef MSWIN
15675
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1024 if (term->tl_out_fd != NULL)
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1025 fclose(term->tl_out_fd);
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1026 #endif
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1027 vim_free(term->tl_cursor_color);
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1028 vim_free(term);
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1029 }
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1030 }
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1031
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1032 /*
13132
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1033 * Get the part that is connected to the tty. Normally this is PART_IN, but
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1034 * when writing buffer lines to the job it can be another. This makes it
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1035 * possible to do "1,5term vim -".
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1036 */
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1037 static ch_part_T
18139
59bc3cd42cf5 patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents: 18051
diff changeset
1038 get_tty_part(term_T *term UNUSED)
13132
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1039 {
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1040 #ifdef UNIX
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1041 ch_part_T parts[3] = {PART_IN, PART_OUT, PART_ERR};
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1042 int i;
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1043
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1044 for (i = 0; i < 3; ++i)
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1045 {
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1046 int fd = term->tl_job->jv_channel->ch_part[parts[i]].ch_fd;
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1047
15632
d4a6d575e910 patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1048 if (mch_isatty(fd))
13132
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1049 return parts[i];
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1050 }
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1051 #endif
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1052 return PART_IN;
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1053 }
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1054
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1055 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1056 * Write job output "msg[len]" to the vterm.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1057 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1058 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1059 term_write_job_output(term_T *term, char_u *msg, size_t len)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1060 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1061 VTerm *vterm = term->tl_vterm;
13132
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1062 size_t prevlen = vterm_output_get_buffer_current(vterm);
12800
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
1063
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
1064 vterm_input_write(vterm, (char *)msg, len);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1065
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1066 // flush vterm buffer when vterm responded to control sequence
13132
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1067 if (prevlen != vterm_output_get_buffer_current(vterm))
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1068 {
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1069 char buf[KEY_BUF_LEN];
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1070 size_t curlen = vterm_output_read(vterm, buf, KEY_BUF_LEN);
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1071
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1072 if (curlen > 0)
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1073 channel_send(term->tl_job->jv_channel, get_tty_part(term),
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1074 (char_u *)buf, (int)curlen, NULL);
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1075 }
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
1076
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1077 // this invokes the damage callbacks
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1078 vterm_screen_flush_damage(vterm_obtain_screen(vterm));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1079 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1080
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1081 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1082 update_cursor(term_T *term, int redraw)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1083 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1084 if (term->tl_normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1085 return;
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
1086 #ifdef FEAT_GUI
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
1087 if (term->tl_system)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
1088 windgoto(term->tl_cursor_pos.row + term->tl_toprow,
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
1089 term->tl_cursor_pos.col);
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
1090 else
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
1091 #endif
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
1092 setcursor();
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1093 if (redraw)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1094 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1095 if (term->tl_buffer == curbuf && term->tl_cursor_visible)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1096 cursor_on();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1097 out_flush();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1098 #ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1099 if (gui.in_use)
13000
6f98a5fd0c19 patch 8.0.1376: cursor in terminal not always updated
Christian Brabandt <cb@256bit.org>
parents: 12984
diff changeset
1100 {
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1101 gui_update_cursor(FALSE, FALSE);
13000
6f98a5fd0c19 patch 8.0.1376: cursor in terminal not always updated
Christian Brabandt <cb@256bit.org>
parents: 12984
diff changeset
1102 gui_mch_flush();
6f98a5fd0c19 patch 8.0.1376: cursor in terminal not always updated
Christian Brabandt <cb@256bit.org>
parents: 12984
diff changeset
1103 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1104 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1105 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1106 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1107
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1108 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1109 * Invoked when "msg" output from a job was received. Write it to the terminal
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1110 * of "buffer".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1111 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1112 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1113 write_to_term(buf_T *buffer, char_u *msg, channel_T *channel)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1114 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1115 size_t len = STRLEN(msg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1116 term_T *term = buffer->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1117
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15844
diff changeset
1118 #ifdef MSWIN
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1119 // Win32: Cannot redirect output of the job, intercept it here and write to
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1120 // the file.
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
1121 if (term->tl_out_fd != NULL)
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
1122 {
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
1123 ch_log(channel, "Writing %d bytes to output file", (int)len);
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
1124 fwrite(msg, len, 1, term->tl_out_fd);
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
1125 return;
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
1126 }
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
1127 #endif
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
1128
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1129 if (term->tl_vterm == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1130 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1131 ch_log(channel, "NOT writing %d bytes to terminal", (int)len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1132 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1133 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1134 ch_log(channel, "writing %d bytes to terminal", (int)len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1135 term_write_job_output(term, msg, len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1136
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
1137 #ifdef FEAT_GUI
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
1138 if (term->tl_system)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
1139 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1140 // show system output, scrolling up the screen as needed
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
1141 update_system_term(term);
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
1142 update_cursor(term, TRUE);
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
1143 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
1144 else
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
1145 #endif
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1146 // In Terminal-Normal mode we are displaying the buffer, not the terminal
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1147 // contents, thus no screen update is needed.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1148 if (!term->tl_normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1149 {
14117
08b0b6d6cbe7 patch 8.1.0076: command getting cleared with CTRL-W : in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 14109
diff changeset
1150 // Don't use update_screen() when editing the command line, it gets
08b0b6d6cbe7 patch 8.1.0076: command getting cleared with CTRL-W : in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 14109
diff changeset
1151 // cleared.
08b0b6d6cbe7 patch 8.1.0076: command getting cleared with CTRL-W : in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 14109
diff changeset
1152 // TODO: only update once in a while.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1153 ch_log(term->tl_job->jv_channel, "updating screen");
14117
08b0b6d6cbe7 patch 8.1.0076: command getting cleared with CTRL-W : in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 14109
diff changeset
1154 if (buffer == curbuf && (State & CMDLINE) == 0)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1155 {
14117
08b0b6d6cbe7 patch 8.1.0076: command getting cleared with CTRL-W : in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 14109
diff changeset
1156 update_screen(VALID_NO_UPDATE);
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1157 // update_screen() can be slow, check the terminal wasn't closed
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1158 // already
13886
bbf5bdba4a80 patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13878
diff changeset
1159 if (buffer == curbuf && curbuf->b_term != NULL)
bbf5bdba4a80 patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13878
diff changeset
1160 update_cursor(curbuf->b_term, TRUE);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1161 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1162 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1163 redraw_after_callback(TRUE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1164 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1165 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1166
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1167 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1168 * Send a mouse position and click to the vterm
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1169 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1170 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1171 term_send_mouse(VTerm *vterm, int button, int pressed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1172 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1173 VTermModifier mod = VTERM_MOD_NONE;
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
1174 int row = mouse_row - W_WINROW(curwin);
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
1175 int col = mouse_col - curwin->w_wincol;
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
1176
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
1177 #ifdef FEAT_PROP_POPUP
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
1178 if (popup_is_popup(curwin))
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
1179 {
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
1180 row -= popup_top_extra(curwin);
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
1181 col -= popup_left_extra(curwin);
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
1182 }
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
1183 #endif
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
1184 vterm_mouse_move(vterm, row, col, mod);
12865
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12845
diff changeset
1185 if (button != 0)
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12845
diff changeset
1186 vterm_mouse_button(vterm, button, pressed, mod);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1187 return TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1188 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1189
13448
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1190 static int enter_mouse_col = -1;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1191 static int enter_mouse_row = -1;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1192
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1193 /*
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1194 * Handle a mouse click, drag or release.
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1195 * Return TRUE when a mouse event is sent to the terminal.
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1196 */
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1197 static int
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1198 term_mouse_click(VTerm *vterm, int key)
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1199 {
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1200 #if defined(FEAT_CLIPBOARD)
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1201 // For modeless selection mouse drag and release events are ignored, unless
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1202 // they are preceded with a mouse down event
13448
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1203 static int ignore_drag_release = TRUE;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1204 VTermMouseState mouse_state;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1205
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1206 vterm_state_get_mousestate(vterm_obtain_state(vterm), &mouse_state);
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1207 if (mouse_state.flags == 0)
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1208 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1209 // Terminal is not using the mouse, use modeless selection.
13448
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1210 switch (key)
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1211 {
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1212 case K_LEFTDRAG:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1213 case K_LEFTRELEASE:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1214 case K_RIGHTDRAG:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1215 case K_RIGHTRELEASE:
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1216 // Ignore drag and release events when the button-down wasn't
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1217 // seen before.
13448
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1218 if (ignore_drag_release)
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1219 {
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1220 int save_mouse_col, save_mouse_row;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1221
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1222 if (enter_mouse_col < 0)
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1223 break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1224
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1225 // mouse click in the window gave us focus, handle that
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1226 // click now
13448
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1227 save_mouse_col = mouse_col;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1228 save_mouse_row = mouse_row;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1229 mouse_col = enter_mouse_col;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1230 mouse_row = enter_mouse_row;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1231 clip_modeless(MOUSE_LEFT, TRUE, FALSE);
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1232 mouse_col = save_mouse_col;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1233 mouse_row = save_mouse_row;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1234 }
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1235 // FALLTHROUGH
13448
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1236 case K_LEFTMOUSE:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1237 case K_RIGHTMOUSE:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1238 if (key == K_LEFTRELEASE || key == K_RIGHTRELEASE)
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1239 ignore_drag_release = TRUE;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1240 else
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1241 ignore_drag_release = FALSE;
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1242 // Should we call mouse_has() here?
13448
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1243 if (clip_star.available)
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1244 {
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1245 int button, is_click, is_drag;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1246
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1247 button = get_mouse_button(KEY2TERMCAP1(key),
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1248 &is_click, &is_drag);
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1249 if (mouse_model_popup() && button == MOUSE_LEFT
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1250 && (mod_mask & MOD_MASK_SHIFT))
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1251 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1252 // Translate shift-left to right button.
13448
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1253 button = MOUSE_RIGHT;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1254 mod_mask &= ~MOD_MASK_SHIFT;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1255 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1256 clip_modeless(button, is_click, is_drag);
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1257 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1258 break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1259
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1260 case K_MIDDLEMOUSE:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1261 if (clip_star.available)
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1262 insert_reg('*', TRUE);
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1263 break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1264 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1265 enter_mouse_col = -1;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1266 return FALSE;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1267 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1268 #endif
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1269 enter_mouse_col = -1;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1270
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1271 switch (key)
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1272 {
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1273 case K_LEFTMOUSE:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1274 case K_LEFTMOUSE_NM: term_send_mouse(vterm, 1, 1); break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1275 case K_LEFTDRAG: term_send_mouse(vterm, 1, 1); break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1276 case K_LEFTRELEASE:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1277 case K_LEFTRELEASE_NM: term_send_mouse(vterm, 1, 0); break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1278 case K_MOUSEMOVE: term_send_mouse(vterm, 0, 0); break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1279 case K_MIDDLEMOUSE: term_send_mouse(vterm, 2, 1); break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1280 case K_MIDDLEDRAG: term_send_mouse(vterm, 2, 1); break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1281 case K_MIDDLERELEASE: term_send_mouse(vterm, 2, 0); break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1282 case K_RIGHTMOUSE: term_send_mouse(vterm, 3, 1); break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1283 case K_RIGHTDRAG: term_send_mouse(vterm, 3, 1); break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1284 case K_RIGHTRELEASE: term_send_mouse(vterm, 3, 0); break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1285 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1286 return TRUE;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1287 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1288
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1289 /*
18508
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
1290 * Convert typed key "c" with modifiers "modmask" into bytes to send to the
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
1291 * job.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1292 * Return the number of bytes in "buf".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1293 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1294 static int
18508
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
1295 term_convert_key(term_T *term, int c, int modmask, char *buf)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1296 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1297 VTerm *vterm = term->tl_vterm;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1298 VTermKey key = VTERM_KEY_NONE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1299 VTermModifier mod = VTERM_MOD_NONE;
12845
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
1300 int other = FALSE;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1301
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1302 switch (c)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1303 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1304 // don't use VTERM_KEY_ENTER, it may do an unwanted conversion
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1305
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1306 // don't use VTERM_KEY_BACKSPACE, it always
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1307 // becomes 0x7f DEL
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1308 case K_BS: c = term_backspace_char; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1309
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1310 case ESC: key = VTERM_KEY_ESCAPE; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1311 case K_DEL: key = VTERM_KEY_DEL; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1312 case K_DOWN: key = VTERM_KEY_DOWN; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1313 case K_S_DOWN: mod = VTERM_MOD_SHIFT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1314 key = VTERM_KEY_DOWN; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1315 case K_END: key = VTERM_KEY_END; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1316 case K_S_END: mod = VTERM_MOD_SHIFT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1317 key = VTERM_KEY_END; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1318 case K_C_END: mod = VTERM_MOD_CTRL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1319 key = VTERM_KEY_END; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1320 case K_F10: key = VTERM_KEY_FUNCTION(10); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1321 case K_F11: key = VTERM_KEY_FUNCTION(11); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1322 case K_F12: key = VTERM_KEY_FUNCTION(12); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1323 case K_F1: key = VTERM_KEY_FUNCTION(1); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1324 case K_F2: key = VTERM_KEY_FUNCTION(2); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1325 case K_F3: key = VTERM_KEY_FUNCTION(3); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1326 case K_F4: key = VTERM_KEY_FUNCTION(4); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1327 case K_F5: key = VTERM_KEY_FUNCTION(5); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1328 case K_F6: key = VTERM_KEY_FUNCTION(6); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1329 case K_F7: key = VTERM_KEY_FUNCTION(7); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1330 case K_F8: key = VTERM_KEY_FUNCTION(8); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1331 case K_F9: key = VTERM_KEY_FUNCTION(9); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1332 case K_HOME: key = VTERM_KEY_HOME; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1333 case K_S_HOME: mod = VTERM_MOD_SHIFT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1334 key = VTERM_KEY_HOME; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1335 case K_C_HOME: mod = VTERM_MOD_CTRL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1336 key = VTERM_KEY_HOME; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1337 case K_INS: key = VTERM_KEY_INS; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1338 case K_K0: key = VTERM_KEY_KP_0; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1339 case K_K1: key = VTERM_KEY_KP_1; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1340 case K_K2: key = VTERM_KEY_KP_2; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1341 case K_K3: key = VTERM_KEY_KP_3; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1342 case K_K4: key = VTERM_KEY_KP_4; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1343 case K_K5: key = VTERM_KEY_KP_5; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1344 case K_K6: key = VTERM_KEY_KP_6; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1345 case K_K7: key = VTERM_KEY_KP_7; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1346 case K_K8: key = VTERM_KEY_KP_8; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1347 case K_K9: key = VTERM_KEY_KP_9; break;
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1348 case K_KDEL: key = VTERM_KEY_DEL; break; // TODO
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1349 case K_KDIVIDE: key = VTERM_KEY_KP_DIVIDE; break;
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1350 case K_KEND: key = VTERM_KEY_KP_1; break; // TODO
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1351 case K_KENTER: key = VTERM_KEY_KP_ENTER; break;
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1352 case K_KHOME: key = VTERM_KEY_KP_7; break; // TODO
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1353 case K_KINS: key = VTERM_KEY_KP_0; break; // TODO
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1354 case K_KMINUS: key = VTERM_KEY_KP_MINUS; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1355 case K_KMULTIPLY: key = VTERM_KEY_KP_MULT; break;
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1356 case K_KPAGEDOWN: key = VTERM_KEY_KP_3; break; // TODO
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1357 case K_KPAGEUP: key = VTERM_KEY_KP_9; break; // TODO
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1358 case K_KPLUS: key = VTERM_KEY_KP_PLUS; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1359 case K_KPOINT: key = VTERM_KEY_KP_PERIOD; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1360 case K_LEFT: key = VTERM_KEY_LEFT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1361 case K_S_LEFT: mod = VTERM_MOD_SHIFT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1362 key = VTERM_KEY_LEFT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1363 case K_C_LEFT: mod = VTERM_MOD_CTRL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1364 key = VTERM_KEY_LEFT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1365 case K_PAGEDOWN: key = VTERM_KEY_PAGEDOWN; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1366 case K_PAGEUP: key = VTERM_KEY_PAGEUP; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1367 case K_RIGHT: key = VTERM_KEY_RIGHT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1368 case K_S_RIGHT: mod = VTERM_MOD_SHIFT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1369 key = VTERM_KEY_RIGHT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1370 case K_C_RIGHT: mod = VTERM_MOD_CTRL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1371 key = VTERM_KEY_RIGHT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1372 case K_UP: key = VTERM_KEY_UP; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1373 case K_S_UP: mod = VTERM_MOD_SHIFT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1374 key = VTERM_KEY_UP; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1375 case TAB: key = VTERM_KEY_TAB; break;
13294
5fc59833a748 patch 8.0.1521: Shift-Tab does not work in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13292
diff changeset
1376 case K_S_TAB: mod = VTERM_MOD_SHIFT;
5fc59833a748 patch 8.0.1521: Shift-Tab does not work in a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13292
diff changeset
1377 key = VTERM_KEY_TAB; break;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1378
12845
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
1379 case K_MOUSEUP: other = term_send_mouse(vterm, 5, 1); break;
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
1380 case K_MOUSEDOWN: other = term_send_mouse(vterm, 4, 1); break;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1381 case K_MOUSELEFT: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1382 case K_MOUSERIGHT: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1383
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1384 case K_LEFTMOUSE:
13448
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1385 case K_LEFTMOUSE_NM:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1386 case K_LEFTDRAG:
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1387 case K_LEFTRELEASE:
13448
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1388 case K_LEFTRELEASE_NM:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1389 case K_MOUSEMOVE:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1390 case K_MIDDLEMOUSE:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1391 case K_MIDDLEDRAG:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1392 case K_MIDDLERELEASE:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1393 case K_RIGHTMOUSE:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1394 case K_RIGHTDRAG:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1395 case K_RIGHTRELEASE: if (!term_mouse_click(vterm, c))
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1396 return 0;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1397 other = TRUE;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1398 break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1399
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1400 case K_X1MOUSE: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1401 case K_X1DRAG: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1402 case K_X1RELEASE: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1403 case K_X2MOUSE: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1404 case K_X2DRAG: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1405 case K_X2RELEASE: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1406
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1407 case K_IGNORE: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1408 case K_NOP: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1409 case K_UNDO: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1410 case K_HELP: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1411 case K_XF1: key = VTERM_KEY_FUNCTION(1); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1412 case K_XF2: key = VTERM_KEY_FUNCTION(2); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1413 case K_XF3: key = VTERM_KEY_FUNCTION(3); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1414 case K_XF4: key = VTERM_KEY_FUNCTION(4); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1415 case K_SELECT: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1416 #ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1417 case K_VER_SCROLLBAR: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1418 case K_HOR_SCROLLBAR: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1419 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1420 #ifdef FEAT_GUI_TABLINE
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1421 case K_TABLINE: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1422 case K_TABMENU: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1423 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1424 #ifdef FEAT_NETBEANS_INTG
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1425 case K_F21: key = VTERM_KEY_FUNCTION(21); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1426 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1427 #ifdef FEAT_DND
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1428 case K_DROP: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1429 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1430 case K_CURSORHOLD: return 0;
12845
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
1431 case K_PS: vterm_keyboard_start_paste(vterm);
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
1432 other = TRUE;
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
1433 break;
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
1434 case K_PE: vterm_keyboard_end_paste(vterm);
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
1435 other = TRUE;
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
1436 break;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1437 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1438
18279
e8d1f3209dcd patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 18251
diff changeset
1439 // add modifiers for the typed key
18508
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
1440 if (modmask & MOD_MASK_SHIFT)
18301
506bf60a30a0 patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18279
diff changeset
1441 mod |= VTERM_MOD_SHIFT;
18508
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
1442 if (modmask & MOD_MASK_CTRL)
18301
506bf60a30a0 patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18279
diff changeset
1443 mod |= VTERM_MOD_CTRL;
18508
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
1444 if (modmask & (MOD_MASK_ALT | MOD_MASK_META))
18301
506bf60a30a0 patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18279
diff changeset
1445 mod |= VTERM_MOD_ALT;
18279
e8d1f3209dcd patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 18251
diff changeset
1446
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1447 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1448 * Convert special keys to vterm keys:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1449 * - Write keys to vterm: vterm_keyboard_key()
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1450 * - Write output to channel.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1451 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1452 if (key != VTERM_KEY_NONE)
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1453 // Special key, let vterm convert it.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1454 vterm_keyboard_key(vterm, key, mod);
12845
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
1455 else if (!other)
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1456 // Normal character, let vterm convert it.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1457 vterm_keyboard_unichar(vterm, c, mod);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1458
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1459 // Read back the converted escape sequence.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1460 return (int)vterm_output_read(vterm, buf, KEY_BUF_LEN);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1461 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1462
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1463 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1464 * Return TRUE if the job for "term" is still running.
13696
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1465 * If "check_job_status" is TRUE update the job status.
15675
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1466 * NOTE: "term" may be freed by callbacks.
13696
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1467 */
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1468 static int
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1469 term_job_running_check(term_T *term, int check_job_status)
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1470 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1471 // Also consider the job finished when the channel is closed, to avoid a
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1472 // race condition when updating the title.
13696
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1473 if (term != NULL
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1474 && term->tl_job != NULL
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1475 && channel_is_open(term->tl_job->jv_channel))
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1476 {
15675
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1477 job_T *job = term->tl_job;
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1478
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1479 // Careful: Checking the job status may invoked callbacks, which close
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1480 // the buffer and terminate "term". However, "job" will not be freed
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1481 // yet.
13696
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1482 if (check_job_status)
15675
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1483 job_status(job);
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1484 return (job->jv_status == JOB_STARTED
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
1485 || (job->jv_channel != NULL && job->jv_channel->ch_keep_open));
13696
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1486 }
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1487 return FALSE;
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1488 }
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1489
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1490 /*
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1491 * Return TRUE if the job for "term" is still running.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1492 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1493 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1494 term_job_running(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1495 {
13696
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
1496 return term_job_running_check(term, FALSE);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1497 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1498
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1499 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1500 * Return TRUE if "term" has an active channel and used ":term NONE".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1501 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1502 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1503 term_none_open(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1504 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1505 // Also consider the job finished when the channel is closed, to avoid a
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1506 // race condition when updating the title.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1507 return term != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1508 && term->tl_job != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1509 && channel_is_open(term->tl_job->jv_channel)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1510 && term->tl_job->jv_channel->ch_keep_open;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1511 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1512
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1513 /*
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1514 * Used when exiting: kill the job in "buf" if so desired.
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1515 * Return OK when the job finished.
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1516 * Return FAIL when the job is still running.
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1517 */
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1518 int
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1519 term_try_stop_job(buf_T *buf)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1520 {
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1521 int count;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1522 char *how = (char *)buf->b_term->tl_kill;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1523
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1524 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1525 if ((how == NULL || *how == NUL) && (p_confirm || cmdmod.confirm))
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1526 {
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1527 char_u buff[DIALOG_MSG_SIZE];
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1528 int ret;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1529
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1530 dialog_msg(buff, _("Kill job in \"%s\"?"), buf->b_fname);
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1531 ret = vim_dialog_yesnocancel(VIM_QUESTION, NULL, buff, 1);
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1532 if (ret == VIM_YES)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1533 how = "kill";
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1534 else if (ret == VIM_CANCEL)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1535 return FAIL;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1536 }
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1537 #endif
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1538 if (how == NULL || *how == NUL)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1539 return FAIL;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1540
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1541 job_stop(buf->b_term->tl_job, NULL, how);
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1542
15679
d8b4cbb14e1e patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents: 15675
diff changeset
1543 // wait for up to a second for the job to die
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1544 for (count = 0; count < 100; ++count)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1545 {
15679
d8b4cbb14e1e patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents: 15675
diff changeset
1546 job_T *job;
d8b4cbb14e1e patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents: 15675
diff changeset
1547
d8b4cbb14e1e patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents: 15675
diff changeset
1548 // buffer, terminal and job may be cleaned up while waiting
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1549 if (!buf_valid(buf)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1550 || buf->b_term == NULL
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1551 || buf->b_term->tl_job == NULL)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1552 return OK;
15679
d8b4cbb14e1e patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents: 15675
diff changeset
1553 job = buf->b_term->tl_job;
d8b4cbb14e1e patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents: 15675
diff changeset
1554
d8b4cbb14e1e patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents: 15675
diff changeset
1555 // Call job_status() to update jv_status. It may cause the job to be
d8b4cbb14e1e patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents: 15675
diff changeset
1556 // cleaned up but it won't be freed.
d8b4cbb14e1e patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents: 15675
diff changeset
1557 job_status(job);
d8b4cbb14e1e patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents: 15675
diff changeset
1558 if (job->jv_status >= JOB_ENDED)
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1559 return OK;
15679
d8b4cbb14e1e patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents: 15675
diff changeset
1560
18420
3a3efaaa05c5 patch 8.1.2204: crash on exit when closing terminals
Bram Moolenaar <Bram@vim.org>
parents: 18402
diff changeset
1561 ui_delay(10L, TRUE);
17186
278583ff5e44 patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
1562 term_flush_messages();
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1563 }
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1564 return FAIL;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1565 }
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1566
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1567 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1568 * Add the last line of the scrollback buffer to the buffer in the window.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1569 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1570 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1571 add_scrollback_line_to_buffer(term_T *term, char_u *text, int len)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1572 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1573 buf_T *buf = term->tl_buffer;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1574 int empty = (buf->b_ml.ml_flags & ML_EMPTY);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1575 linenr_T lnum = buf->b_ml.ml_line_count;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1576
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15844
diff changeset
1577 #ifdef MSWIN
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1578 if (!enc_utf8 && enc_codepage > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1579 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1580 WCHAR *ret = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1581 int length = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1582
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1583 MultiByteToWideChar_alloc(CP_UTF8, 0, (char*)text, len + 1,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1584 &ret, &length);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1585 if (ret != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1586 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1587 WideCharToMultiByte_alloc(enc_codepage, 0,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1588 ret, length, (char **)&text, &len, 0, 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1589 vim_free(ret);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1590 ml_append_buf(term->tl_buffer, lnum, text, len, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1591 vim_free(text);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1592 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1593 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1594 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1595 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1596 ml_append_buf(term->tl_buffer, lnum, text, len + 1, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1597 if (empty)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1598 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1599 // Delete the empty line that was in the empty buffer.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1600 curbuf = buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1601 ml_delete(1, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1602 curbuf = curwin->w_buffer;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1603 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1604 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1605
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1606 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1607 cell2cellattr(const VTermScreenCell *cell, cellattr_T *attr)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1608 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1609 attr->width = cell->width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1610 attr->attrs = cell->attrs;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1611 attr->fg = cell->fg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1612 attr->bg = cell->bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1613 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1614
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1615 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1616 equal_celattr(cellattr_T *a, cellattr_T *b)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1617 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1618 // Comparing the colors should be sufficient.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1619 return a->fg.red == b->fg.red
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1620 && a->fg.green == b->fg.green
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1621 && a->fg.blue == b->fg.blue
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1622 && a->bg.red == b->bg.red
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1623 && a->bg.green == b->bg.green
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1624 && a->bg.blue == b->bg.blue;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1625 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1626
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1627 /*
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1628 * Add an empty scrollback line to "term". When "lnum" is not zero, add the
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1629 * line at this position. Otherwise at the end.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1630 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1631 static int
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1632 add_empty_scrollback(term_T *term, cellattr_T *fill_attr, int lnum)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1633 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1634 if (ga_grow(&term->tl_scrollback, 1) == OK)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1635 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1636 sb_line_T *line = (sb_line_T *)term->tl_scrollback.ga_data
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1637 + term->tl_scrollback.ga_len;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1638
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1639 if (lnum > 0)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1640 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1641 int i;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1642
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1643 for (i = 0; i < term->tl_scrollback.ga_len - lnum; ++i)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1644 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1645 *line = *(line - 1);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1646 --line;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1647 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1648 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1649 line->sb_cols = 0;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1650 line->sb_cells = NULL;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1651 line->sb_fill_attr = *fill_attr;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1652 ++term->tl_scrollback.ga_len;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1653 return OK;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1654 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1655 return FALSE;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1656 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1657
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1658 /*
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1659 * Remove the terminal contents from the scrollback and the buffer.
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1660 * Used before adding a new scrollback line or updating the buffer for lines
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1661 * displayed in the terminal.
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1662 */
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1663 static void
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1664 cleanup_scrollback(term_T *term)
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1665 {
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1666 sb_line_T *line;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1667 garray_T *gap;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1668
13894
3969c9d3a859 patch 8.0.1818: lines remove from wrong buffer when using terminal window
Christian Brabandt <cb@256bit.org>
parents: 13888
diff changeset
1669 curbuf = term->tl_buffer;
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1670 gap = &term->tl_scrollback;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1671 while (curbuf->b_ml.ml_line_count > term->tl_scrollback_scrolled
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1672 && gap->ga_len > 0)
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1673 {
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1674 ml_delete(curbuf->b_ml.ml_line_count, FALSE);
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1675 line = (sb_line_T *)gap->ga_data + gap->ga_len - 1;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1676 vim_free(line->sb_cells);
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1677 --gap->ga_len;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1678 }
13894
3969c9d3a859 patch 8.0.1818: lines remove from wrong buffer when using terminal window
Christian Brabandt <cb@256bit.org>
parents: 13888
diff changeset
1679 curbuf = curwin->w_buffer;
3969c9d3a859 patch 8.0.1818: lines remove from wrong buffer when using terminal window
Christian Brabandt <cb@256bit.org>
parents: 13888
diff changeset
1680 if (curbuf == term->tl_buffer)
3969c9d3a859 patch 8.0.1818: lines remove from wrong buffer when using terminal window
Christian Brabandt <cb@256bit.org>
parents: 13888
diff changeset
1681 check_cursor();
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1682 }
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1683
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1684 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1685 * Add the current lines of the terminal to scrollback and to the buffer.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1686 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1687 static void
13919
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1688 update_snapshot(term_T *term)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1689 {
13919
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1690 VTermScreen *screen;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1691 int len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1692 int lines_skipped = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1693 VTermPos pos;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1694 VTermScreenCell cell;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1695 cellattr_T fill_attr, new_fill_attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1696 cellattr_T *p;
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1697
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1698 ch_log(term->tl_job == NULL ? NULL : term->tl_job->jv_channel,
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1699 "Adding terminal window snapshot to buffer");
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1700
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1701 // First remove the lines that were appended before, they might be
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1702 // outdated.
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1703 cleanup_scrollback(term);
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1704
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1705 screen = vterm_obtain_screen(term->tl_vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1706 fill_attr = new_fill_attr = term->tl_default_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1707 for (pos.row = 0; pos.row < term->tl_rows; ++pos.row)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1708 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1709 len = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1710 for (pos.col = 0; pos.col < term->tl_cols; ++pos.col)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1711 if (vterm_screen_get_cell(screen, pos, &cell) != 0
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1712 && cell.chars[0] != NUL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1713 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1714 len = pos.col + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1715 new_fill_attr = term->tl_default_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1716 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1717 else
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1718 // Assume the last attr is the filler attr.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1719 cell2cellattr(&cell, &new_fill_attr);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1720
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1721 if (len == 0 && equal_celattr(&new_fill_attr, &fill_attr))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1722 ++lines_skipped;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1723 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1724 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1725 while (lines_skipped > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1726 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1727 // Line was skipped, add an empty line.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1728 --lines_skipped;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1729 if (add_empty_scrollback(term, &fill_attr, 0) == OK)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1730 add_scrollback_line_to_buffer(term, (char_u *)"", 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1731 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1732
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1733 if (len == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1734 p = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1735 else
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16782
diff changeset
1736 p = ALLOC_MULT(cellattr_T, len);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1737 if ((p != NULL || len == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1738 && ga_grow(&term->tl_scrollback, 1) == OK)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1739 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1740 garray_T ga;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1741 int width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1742 sb_line_T *line = (sb_line_T *)term->tl_scrollback.ga_data
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1743 + term->tl_scrollback.ga_len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1744
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1745 ga_init2(&ga, 1, 100);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1746 for (pos.col = 0; pos.col < len; pos.col += width)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1747 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1748 if (vterm_screen_get_cell(screen, pos, &cell) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1749 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1750 width = 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1751 vim_memset(p + pos.col, 0, sizeof(cellattr_T));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1752 if (ga_grow(&ga, 1) == OK)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1753 ga.ga_len += utf_char2bytes(' ',
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1754 (char_u *)ga.ga_data + ga.ga_len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1755 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1756 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1757 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1758 width = cell.width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1759
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1760 cell2cellattr(&cell, &p[pos.col]);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1761
15203
aa877e0b7f62 patch 8.1.0611: crash when using terminal with long composing characters
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
1762 // Each character can be up to 6 bytes.
aa877e0b7f62 patch 8.1.0611: crash when using terminal with long composing characters
Bram Moolenaar <Bram@vim.org>
parents: 15146
diff changeset
1763 if (ga_grow(&ga, VTERM_MAX_CHARS_PER_CELL * 6) == OK)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1764 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1765 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1766 int c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1767
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1768 for (i = 0; (c = cell.chars[i]) > 0 || i == 0; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1769 ga.ga_len += utf_char2bytes(c == NUL ? ' ' : c,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1770 (char_u *)ga.ga_data + ga.ga_len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1771 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1772 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1773 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1774 line->sb_cols = len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1775 line->sb_cells = p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1776 line->sb_fill_attr = new_fill_attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1777 fill_attr = new_fill_attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1778 ++term->tl_scrollback.ga_len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1779
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1780 if (ga_grow(&ga, 1) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1781 add_scrollback_line_to_buffer(term, (char_u *)"", 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1782 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1783 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1784 *((char_u *)ga.ga_data + ga.ga_len) = NUL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1785 add_scrollback_line_to_buffer(term, ga.ga_data, ga.ga_len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1786 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1787 ga_clear(&ga);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1788 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1789 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1790 vim_free(p);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1791 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1792 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1793
15022
f3b4cd98944c patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents: 14960
diff changeset
1794 // Add trailing empty lines.
f3b4cd98944c patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents: 14960
diff changeset
1795 for (pos.row = term->tl_scrollback.ga_len;
f3b4cd98944c patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents: 14960
diff changeset
1796 pos.row < term->tl_scrollback_scrolled + term->tl_cursor_pos.row;
f3b4cd98944c patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents: 14960
diff changeset
1797 ++pos.row)
f3b4cd98944c patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents: 14960
diff changeset
1798 {
f3b4cd98944c patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents: 14960
diff changeset
1799 if (add_empty_scrollback(term, &fill_attr, 0) == OK)
f3b4cd98944c patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents: 14960
diff changeset
1800 add_scrollback_line_to_buffer(term, (char_u *)"", 0);
f3b4cd98944c patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents: 14960
diff changeset
1801 }
f3b4cd98944c patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents: 14960
diff changeset
1802
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1803 term->tl_dirty_snapshot = FALSE;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1804 #ifdef FEAT_TIMERS
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1805 term->tl_timer_set = FALSE;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1806 #endif
13919
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1807 }
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1808
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1809 /*
19542
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1810 * Loop over all windows in the current tab, and also curwin, which is not
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1811 * encountered when using a terminal in a popup window.
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1812 * Return TRUE if "*wp" was set to the next window.
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1813 */
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1814 static int
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1815 for_all_windows_and_curwin(win_T **wp, int *did_curwin)
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1816 {
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1817 if (*wp == NULL)
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1818 *wp = firstwin;
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1819 else if ((*wp)->w_next != NULL)
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1820 *wp = (*wp)->w_next;
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1821 else if (!*did_curwin)
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1822 *wp = curwin;
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1823 else
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1824 return FALSE;
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1825 if (*wp == curwin)
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1826 *did_curwin = TRUE;
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1827 return TRUE;
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1828 }
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1829
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1830 /*
13919
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1831 * If needed, add the current lines of the terminal to scrollback and to the
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1832 * buffer. Called after the job has ended and when switching to
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1833 * Terminal-Normal mode.
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1834 * When "redraw" is TRUE redraw the windows that show the terminal.
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1835 */
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1836 static void
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1837 may_move_terminal_to_buffer(term_T *term, int redraw)
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1838 {
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1839 if (term->tl_vterm == NULL)
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1840 return;
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1841
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1842 // Update the snapshot only if something changes or the buffer does not
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1843 // have all the lines.
13919
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1844 if (term->tl_dirty_snapshot || term->tl_buffer->b_ml.ml_line_count
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1845 <= term->tl_scrollback_scrolled)
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1846 update_snapshot(term);
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1847
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1848 // Obtain the current background color.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1849 vterm_state_get_default_colors(vterm_obtain_state(term->tl_vterm),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1850 &term->tl_default_color.fg, &term->tl_default_color.bg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1851
13919
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1852 if (redraw)
19542
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1853 {
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1854 win_T *wp = NULL;
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1855 int did_curwin = FALSE;
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1856
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1857 while (for_all_windows_and_curwin(&wp, &did_curwin))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1858 {
13900
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1859 if (wp->w_buffer == term->tl_buffer)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1860 {
13900
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1861 wp->w_cursor.lnum = term->tl_buffer->b_ml.ml_line_count;
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1862 wp->w_cursor.col = 0;
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1863 wp->w_valid = 0;
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1864 if (wp->w_cursor.lnum >= wp->w_height)
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1865 {
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1866 linenr_T min_topline = wp->w_cursor.lnum - wp->w_height + 1;
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1867
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1868 if (wp->w_topline < min_topline)
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1869 wp->w_topline = min_topline;
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1870 }
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1871 redraw_win_later(wp, NOT_VALID);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1872 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1873 }
19542
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1874 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1875 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1876
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1877 #if defined(FEAT_TIMERS) || defined(PROTO)
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1878 /*
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1879 * Check if any terminal timer expired. If so, copy text from the terminal to
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1880 * the buffer.
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1881 * Return the time until the next timer will expire.
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1882 */
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1883 int
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1884 term_check_timers(int next_due_arg, proftime_T *now)
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1885 {
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1886 term_T *term;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1887 int next_due = next_due_arg;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1888
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1889 for (term = first_term; term != NULL; term = term->tl_next)
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1890 {
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1891 if (term->tl_timer_set && !term->tl_normal_mode)
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1892 {
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1893 long this_due = proftime_time_left(&term->tl_timer_due, now);
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1894
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1895 if (this_due <= 1)
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1896 {
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1897 term->tl_timer_set = FALSE;
13919
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1898 may_move_terminal_to_buffer(term, FALSE);
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1899 }
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1900 else if (next_due == -1 || next_due > this_due)
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1901 next_due = this_due;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1902 }
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1903 }
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1904
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1905 return next_due;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1906 }
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1907 #endif
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
1908
15826
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
1909 /*
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
1910 * When "normal_mode" is TRUE set the terminal to Terminal-Normal mode,
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
1911 * otherwise end it.
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
1912 */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1913 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1914 set_terminal_mode(term_T *term, int normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1915 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1916 term->tl_normal_mode = normal_mode;
15826
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
1917 if (!normal_mode)
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
1918 handle_postponed_scrollback(term);
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13219
diff changeset
1919 VIM_CLEAR(term->tl_status_text);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1920 if (term->tl_buffer == curbuf)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1921 maketitle();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1922 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1923
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1924 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1925 * Called after the job if finished and Terminal mode is not active:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1926 * Move the vterm contents into the scrollback buffer and free the vterm.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1927 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1928 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1929 cleanup_vterm(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1930 {
15826
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
1931 set_terminal_mode(term, FALSE);
13476
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
1932 if (term->tl_finish != TL_FINISH_CLOSE)
13919
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1933 may_move_terminal_to_buffer(term, TRUE);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1934 term_free_vterm(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1935 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1936
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1937 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1938 * Switch from Terminal-Job mode to Terminal-Normal mode.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1939 * Suspends updating the terminal window.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1940 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1941 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1942 term_enter_normal_mode(void)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1943 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1944 term_T *term = curbuf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1945
13900
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1946 set_terminal_mode(term, TRUE);
f71ed35527eb patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents: 13894
diff changeset
1947
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1948 // Append the current terminal contents to the buffer.
13919
bfca3dbdbf9e patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents: 13906
diff changeset
1949 may_move_terminal_to_buffer(term, TRUE);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1950
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1951 // Move the window cursor to the position of the cursor in the
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1952 // terminal.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1953 curwin->w_cursor.lnum = term->tl_scrollback_scrolled
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1954 + term->tl_cursor_pos.row + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1955 check_cursor();
13935
cc25795aeec6 patch 8.0.1838: cursor in wrong pos when switching to Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13919
diff changeset
1956 if (coladvance(term->tl_cursor_pos.col) == FAIL)
cc25795aeec6 patch 8.0.1838: cursor in wrong pos when switching to Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13919
diff changeset
1957 coladvance(MAXCOL);
19542
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1958 curwin->w_set_curswant = TRUE;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1959
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
1960 // Display the same lines as in the terminal.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1961 curwin->w_topline = term->tl_scrollback_scrolled + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1962 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1963
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1964 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1965 * Returns TRUE if the current window contains a terminal and we are in
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1966 * Terminal-Normal mode.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1967 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1968 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1969 term_in_normal_mode(void)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1970 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1971 term_T *term = curbuf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1972
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1973 return term != NULL && term->tl_normal_mode;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1974 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1975
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1976 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1977 * Switch from Terminal-Normal mode to Terminal-Job mode.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1978 * Restores updating the terminal window.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1979 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1980 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1981 term_enter_job_mode()
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1982 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1983 term_T *term = curbuf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1984
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1985 set_terminal_mode(term, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1986
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1987 if (term->tl_channel_closed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1988 cleanup_vterm(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1989 redraw_buf_and_status_later(curbuf, NOT_VALID);
19542
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1990 #ifdef FEAT_PROP_POPUP
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1991 if (WIN_IS_POPUP(curwin))
19744
eb4887dd4b60 patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents: 19713
diff changeset
1992 redraw_later(NOT_VALID);
19542
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
1993 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1994 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1995
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1996 /*
13344
68c4fc9ae216 patch 8.0.1546: using feedkeys() in a terminal may trigger mappings
Christian Brabandt <cb@256bit.org>
parents: 13335
diff changeset
1997 * Get a key from the user with terminal mode mappings.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1998 * Note: while waiting a terminal may be closed and freed if the channel is
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1999 * closed and ++close was used.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2000 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2001 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2002 term_vgetc()
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2003 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2004 int c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2005 int save_State = State;
18279
e8d1f3209dcd patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 18251
diff changeset
2006 int modify_other_keys =
e8d1f3209dcd patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 18251
diff changeset
2007 vterm_is_modify_other_keys(curbuf->b_term->tl_vterm);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2008
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2009 State = TERMINAL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2010 got_int = FALSE;
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15844
diff changeset
2011 #ifdef MSWIN
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2012 ctrl_break_was_pressed = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2013 #endif
18279
e8d1f3209dcd patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 18251
diff changeset
2014 if (modify_other_keys)
e8d1f3209dcd patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 18251
diff changeset
2015 ++no_reduce_keys;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2016 c = vgetc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2017 got_int = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2018 State = save_State;
18279
e8d1f3209dcd patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 18251
diff changeset
2019 if (modify_other_keys)
e8d1f3209dcd patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 18251
diff changeset
2020 --no_reduce_keys;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2021 return c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2022 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2023
13448
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2024 static int mouse_was_outside = FALSE;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2025
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2026 /*
18508
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2027 * Send key "c" with modifiers "modmask" to terminal.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2028 * Return FAIL when the key needs to be handled in Normal mode.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2029 * Return OK when the key was dropped or sent to the terminal.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2030 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2031 int
18508
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2032 send_keys_to_term(term_T *term, int c, int modmask, int typed)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2033 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2034 char msg[KEY_BUF_LEN];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2035 size_t len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2036 int dragging_outside = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2037
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2038 // Catch keys that need to be handled as in Normal mode.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2039 switch (c)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2040 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2041 case NUL:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2042 case K_ZERO:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2043 if (typed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2044 stuffcharReadbuff(c);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2045 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2046
13849
58b6982ca049 patch 8.0.1796: GUI: click on tab fails when the focus is in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13847
diff changeset
2047 case K_TABLINE:
58b6982ca049 patch 8.0.1796: GUI: click on tab fails when the focus is in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13847
diff changeset
2048 stuffcharReadbuff(c);
58b6982ca049 patch 8.0.1796: GUI: click on tab fails when the focus is in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13847
diff changeset
2049 return FAIL;
58b6982ca049 patch 8.0.1796: GUI: click on tab fails when the focus is in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13847
diff changeset
2050
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2051 case K_IGNORE:
13829
044337cbf854 patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents: 13823
diff changeset
2052 case K_CANCEL: // used for :normal when running out of chars
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2053 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2054
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2055 case K_LEFTDRAG:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2056 case K_MIDDLEDRAG:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2057 case K_RIGHTDRAG:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2058 case K_X1DRAG:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2059 case K_X2DRAG:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2060 dragging_outside = mouse_was_outside;
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2061 // FALLTHROUGH
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2062 case K_LEFTMOUSE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2063 case K_LEFTMOUSE_NM:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2064 case K_LEFTRELEASE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2065 case K_LEFTRELEASE_NM:
12865
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12845
diff changeset
2066 case K_MOUSEMOVE:
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2067 case K_MIDDLEMOUSE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2068 case K_MIDDLERELEASE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2069 case K_RIGHTMOUSE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2070 case K_RIGHTRELEASE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2071 case K_X1MOUSE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2072 case K_X1RELEASE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2073 case K_X2MOUSE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2074 case K_X2RELEASE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2075
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2076 case K_MOUSEUP:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2077 case K_MOUSEDOWN:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2078 case K_MOUSELEFT:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2079 case K_MOUSERIGHT:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2080 {
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2081 int row = mouse_row;
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2082 int col = mouse_col;
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2083
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2084 #ifdef FEAT_PROP_POPUP
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2085 if (popup_is_popup(curwin))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2086 {
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2087 row -= popup_top_extra(curwin);
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2088 col -= popup_left_extra(curwin);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2089 }
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2090 #endif
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2091 if (row < W_WINROW(curwin)
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2092 || row >= (W_WINROW(curwin) + curwin->w_height)
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2093 || col < curwin->w_wincol
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2094 || col >= W_ENDCOL(curwin)
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2095 || dragging_outside)
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2096 {
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2097 // click or scroll outside the current window or on status
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2098 // line or vertical separator
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2099 if (typed)
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2100 {
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2101 stuffcharReadbuff(c);
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2102 mouse_was_outside = TRUE;
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2103 }
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2104 return FAIL;
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2105 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2106 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2107 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2108 if (typed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2109 mouse_was_outside = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2110
18508
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2111 // Convert the typed key to a sequence of bytes for the job.
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2112 len = term_convert_key(term, c, modmask, msg);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2113 if (len > 0)
18508
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2114 // TODO: if FAIL is returned, stop?
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2115 channel_send(term->tl_job->jv_channel, get_tty_part(term),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2116 (char_u *)msg, (int)len, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2117
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2118 return OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2119 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2120
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2121 static void
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2122 position_cursor(win_T *wp, VTermPos *pos, int add_off UNUSED)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2123 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2124 wp->w_wrow = MIN(pos->row, MAX(0, wp->w_height - 1));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2125 wp->w_wcol = MIN(pos->col, MAX(0, wp->w_width - 1));
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2126 #ifdef FEAT_PROP_POPUP
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2127 if (add_off && popup_is_popup(curwin))
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2128 {
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2129 wp->w_wrow += popup_top_extra(curwin);
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2130 wp->w_wcol += popup_left_extra(curwin);
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2131 }
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2132 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2133 wp->w_valid |= (VALID_WCOL|VALID_WROW);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2134 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2135
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2136 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2137 * Handle CTRL-W "": send register contents to the job.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2138 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2139 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2140 term_paste_register(int prev_c UNUSED)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2141 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2142 int c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2143 list_T *l;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2144 listitem_T *item;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2145 long reglen = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2146 int type;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2147
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2148 #ifdef FEAT_CMDL_INFO
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2149 if (add_to_showcmd(prev_c))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2150 if (add_to_showcmd('"'))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2151 out_flush();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2152 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2153 c = term_vgetc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2154 #ifdef FEAT_CMDL_INFO
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2155 clear_showcmd();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2156 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2157 if (!term_use_loop())
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2158 // job finished while waiting for a character
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2159 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2160
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2161 // CTRL-W "= prompt for expression to evaluate.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2162 if (c == '=' && get_expr_register() != '=')
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2163 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2164 if (!term_use_loop())
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2165 // job finished while waiting for a character
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2166 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2167
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2168 l = (list_T *)get_reg_contents(c, GREG_LIST);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2169 if (l != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2170 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2171 type = get_reg_type(c, &reglen);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2172 for (item = l->lv_first; item != NULL; item = item->li_next)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2173 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15203
diff changeset
2174 char_u *s = tv_get_string(&item->li_tv);
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15844
diff changeset
2175 #ifdef MSWIN
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2176 char_u *tmp = s;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2177
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2178 if (!enc_utf8 && enc_codepage > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2179 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2180 WCHAR *ret = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2181 int length = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2182
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2183 MultiByteToWideChar_alloc(enc_codepage, 0, (char *)s,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2184 (int)STRLEN(s), &ret, &length);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2185 if (ret != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2186 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2187 WideCharToMultiByte_alloc(CP_UTF8, 0,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2188 ret, length, (char **)&s, &length, 0, 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2189 vim_free(ret);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2190 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2191 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2192 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2193 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2194 s, (int)STRLEN(s), NULL);
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15844
diff changeset
2195 #ifdef MSWIN
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2196 if (tmp != s)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2197 vim_free(s);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2198 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2199
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2200 if (item->li_next != NULL || type == MLINE)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2201 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2202 (char_u *)"\r", 1, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2203 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2204 list_free(l);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2205 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2206 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2207
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2208 /*
13829
044337cbf854 patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents: 13823
diff changeset
2209 * Return TRUE when waiting for a character in the terminal, the cursor of the
044337cbf854 patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents: 13823
diff changeset
2210 * terminal should be displayed.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2211 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2212 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2213 terminal_is_active()
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2214 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2215 return in_terminal_loop != NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2216 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2217
13829
044337cbf854 patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents: 13823
diff changeset
2218 #if defined(FEAT_GUI) || defined(PROTO)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2219 cursorentry_T *
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2220 term_get_cursor_shape(guicolor_T *fg, guicolor_T *bg)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2221 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2222 term_T *term = in_terminal_loop;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2223 static cursorentry_T entry;
14939
c085c4cd9bba patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents: 14691
diff changeset
2224 int id;
c085c4cd9bba patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents: 14691
diff changeset
2225 guicolor_T term_fg, term_bg;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2226
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2227 vim_memset(&entry, 0, sizeof(entry));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2228 entry.shape = entry.mshape =
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2229 term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_UNDERLINE ? SHAPE_HOR :
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2230 term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_BAR_LEFT ? SHAPE_VER :
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2231 SHAPE_BLOCK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2232 entry.percentage = 20;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2233 if (term->tl_cursor_blink)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2234 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2235 entry.blinkwait = 700;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2236 entry.blinkon = 400;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2237 entry.blinkoff = 250;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2238 }
14939
c085c4cd9bba patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents: 14691
diff changeset
2239
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2240 // The "Terminal" highlight group overrules the defaults.
14939
c085c4cd9bba patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents: 14691
diff changeset
2241 id = syn_name2id((char_u *)"Terminal");
c085c4cd9bba patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents: 14691
diff changeset
2242 if (id != 0)
c085c4cd9bba patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents: 14691
diff changeset
2243 {
c085c4cd9bba patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents: 14691
diff changeset
2244 syn_id2colors(id, &term_fg, &term_bg);
c085c4cd9bba patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents: 14691
diff changeset
2245 *fg = term_bg;
c085c4cd9bba patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents: 14691
diff changeset
2246 }
c085c4cd9bba patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents: 14691
diff changeset
2247 else
c085c4cd9bba patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents: 14691
diff changeset
2248 *fg = gui.back_pixel;
c085c4cd9bba patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents: 14691
diff changeset
2249
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2250 if (term->tl_cursor_color == NULL)
14939
c085c4cd9bba patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents: 14691
diff changeset
2251 {
c085c4cd9bba patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents: 14691
diff changeset
2252 if (id != 0)
c085c4cd9bba patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents: 14691
diff changeset
2253 *bg = term_fg;
c085c4cd9bba patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents: 14691
diff changeset
2254 else
c085c4cd9bba patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents: 14691
diff changeset
2255 *bg = gui.norm_pixel;
c085c4cd9bba patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents: 14691
diff changeset
2256 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2257 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2258 *bg = color_name2handle(term->tl_cursor_color);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2259 entry.name = "n";
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2260 entry.used_for = SHAPE_CURSOR;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2261
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2262 return &entry;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2263 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2264 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2265
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2266 static void
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2267 may_output_cursor_props(void)
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2268 {
13990
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
2269 if (!cursor_color_equal(last_set_cursor_color, desired_cursor_color)
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2270 || last_set_cursor_shape != desired_cursor_shape
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2271 || last_set_cursor_blink != desired_cursor_blink)
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2272 {
13990
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
2273 cursor_color_copy(&last_set_cursor_color, desired_cursor_color);
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2274 last_set_cursor_shape = desired_cursor_shape;
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2275 last_set_cursor_blink = desired_cursor_blink;
13990
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
2276 term_cursor_color(cursor_color_get(desired_cursor_color));
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2277 if (desired_cursor_shape == -1 || desired_cursor_blink == -1)
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2278 // this will restore the initial cursor style, if possible
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2279 ui_cursor_shape_forced(TRUE);
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2280 else
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2281 term_cursor_shape(desired_cursor_shape, desired_cursor_blink);
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2282 }
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2283 }
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2284
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2285 /*
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2286 * Set the cursor color and shape, if not last set to these.
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2287 */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2288 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2289 may_set_cursor_props(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2290 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2291 #ifdef FEAT_GUI
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2292 // For the GUI the cursor properties are obtained with
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2293 // term_get_cursor_shape().
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2294 if (gui.in_use)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2295 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2296 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2297 if (in_terminal_loop == term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2298 {
13990
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
2299 cursor_color_copy(&desired_cursor_color, term->tl_cursor_color);
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2300 desired_cursor_shape = term->tl_cursor_shape;
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2301 desired_cursor_blink = term->tl_cursor_blink;
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2302 may_output_cursor_props();
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2303 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2304 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2305
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2306 /*
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2307 * Reset the desired cursor properties and restore them when needed.
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2308 */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2309 static void
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2310 prepare_restore_cursor_props(void)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2311 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2312 #ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2313 if (gui.in_use)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2314 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2315 #endif
13990
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
2316 cursor_color_copy(&desired_cursor_color, NULL);
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2317 desired_cursor_shape = -1;
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2318 desired_cursor_blink = -1;
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2319 may_output_cursor_props();
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2320 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2321
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2322 /*
13696
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2323 * Returns TRUE if the current window contains a terminal and we are sending
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2324 * keys to the job.
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2325 * If "check_job_status" is TRUE update the job status.
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2326 */
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2327 static int
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2328 term_use_loop_check(int check_job_status)
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2329 {
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2330 term_T *term = curbuf->b_term;
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2331
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2332 return term != NULL
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2333 && !term->tl_normal_mode
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2334 && term->tl_vterm != NULL
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2335 && term_job_running_check(term, check_job_status);
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2336 }
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2337
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2338 /*
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2339 * Returns TRUE if the current window contains a terminal and we are sending
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2340 * keys to the job.
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2341 */
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2342 int
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2343 term_use_loop(void)
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2344 {
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2345 return term_use_loop_check(FALSE);
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2346 }
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2347
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2348 /*
13448
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2349 * Called when entering a window with the mouse. If this is a terminal window
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2350 * we may want to change state.
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2351 */
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2352 void
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2353 term_win_entered()
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2354 {
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2355 term_T *term = curbuf->b_term;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2356
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2357 if (term != NULL)
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2358 {
13696
3b1cfbc70b43 patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents: 13686
diff changeset
2359 if (term_use_loop_check(TRUE))
13448
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2360 {
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2361 reset_VIsual_and_resel();
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2362 if (State & INSERT)
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2363 stop_insert_mode = TRUE;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2364 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2365 mouse_was_outside = FALSE;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2366 enter_mouse_col = mouse_col;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2367 enter_mouse_row = mouse_row;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2368 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2369 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2370
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2371 /*
18508
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2372 * vgetc() may not include CTRL in the key when modify_other_keys is set.
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2373 * Return the Ctrl-key value in that case.
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2374 */
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2375 static int
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2376 raw_c_to_ctrl(int c)
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2377 {
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2378 if ((mod_mask & MOD_MASK_CTRL)
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2379 && ((c >= '`' && c <= 0x7f) || (c >= '@' && c <= '_')))
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2380 return c & 0x1f;
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2381 return c;
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2382 }
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2383
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2384 /*
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2385 * When modify_other_keys is set then do the reverse of raw_c_to_ctrl().
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2386 * May set "mod_mask".
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2387 */
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2388 static int
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2389 ctrl_to_raw_c(int c)
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2390 {
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2391 if (c < 0x20 && vterm_is_modify_other_keys(curbuf->b_term->tl_vterm))
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2392 {
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2393 mod_mask |= MOD_MASK_CTRL;
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2394 return c + '@';
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2395 }
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2396 return c;
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2397 }
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2398
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2399 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2400 * Wait for input and send it to the job.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2401 * When "blocking" is TRUE wait for a character to be typed. Otherwise return
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2402 * when there is no more typahead.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2403 * Return when the start of a CTRL-W command is typed or anything else that
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2404 * should be handled as a Normal mode command.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2405 * Returns OK if a typed character is to be handled in Normal mode, FAIL if
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2406 * the terminal was closed.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2407 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2408 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2409 terminal_loop(int blocking)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2410 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2411 int c;
18279
e8d1f3209dcd patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 18251
diff changeset
2412 int raw_c;
13845
f22db93bd887 patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents: 13835
diff changeset
2413 int termwinkey = 0;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2414 int ret;
12767
4d9cdb1d8bea patch 8.0.1261: program in terminal window gets NL instead of CR
Christian Brabandt <cb@256bit.org>
parents: 12724
diff changeset
2415 #ifdef UNIX
12800
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2416 int tty_fd = curbuf->b_term->tl_job->jv_channel
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2417 ->ch_part[get_tty_part(curbuf->b_term)].ch_fd;
12767
4d9cdb1d8bea patch 8.0.1261: program in terminal window gets NL instead of CR
Christian Brabandt <cb@256bit.org>
parents: 12724
diff changeset
2418 #endif
13906
0ae89b121c58 patch 8.0.1824: Coverity warns for variable that may be uninitialized
Christian Brabandt <cb@256bit.org>
parents: 13900
diff changeset
2419 int restore_cursor = FALSE;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2420
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2421 // Remember the terminal we are sending keys to. However, the terminal
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2422 // might be closed while waiting for a character, e.g. typing "exit" in a
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2423 // shell and ++close was used. Therefore use curbuf->b_term instead of a
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2424 // stored reference.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2425 in_terminal_loop = curbuf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2426
13742
a34b1323286c patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents: 13720
diff changeset
2427 if (*curwin->w_p_twk != NUL)
14109
279465096a16 patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14065
diff changeset
2428 {
13845
f22db93bd887 patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents: 13835
diff changeset
2429 termwinkey = string_to_key(curwin->w_p_twk, TRUE);
14109
279465096a16 patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14065
diff changeset
2430 if (termwinkey == Ctrl_W)
279465096a16 patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14065
diff changeset
2431 termwinkey = 0;
279465096a16 patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14065
diff changeset
2432 }
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2433 position_cursor(curwin, &curbuf->b_term->tl_cursor_pos, TRUE);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2434 may_set_cursor_props(curbuf->b_term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2435
13344
68c4fc9ae216 patch 8.0.1546: using feedkeys() in a terminal may trigger mappings
Christian Brabandt <cb@256bit.org>
parents: 13335
diff changeset
2436 while (blocking || vpeekc_nomap() != NUL)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2437 {
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2438 #ifdef FEAT_GUI
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2439 if (!curbuf->b_term->tl_system)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2440 #endif
15675
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
2441 // TODO: skip screen update when handling a sequence of keys.
01890a3caefd patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents: 15632
diff changeset
2442 // Repeat redrawing in case a message is received while redrawing.
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2443 while (must_redraw != 0)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2444 if (update_screen(0) == FAIL)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2445 break;
13994
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
2446 if (!term_use_loop_check(TRUE) || in_terminal_loop != curbuf->b_term)
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2447 // job finished while redrawing
13886
bbf5bdba4a80 patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13878
diff changeset
2448 break;
bbf5bdba4a80 patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13878
diff changeset
2449
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2450 update_cursor(curbuf->b_term, FALSE);
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2451 restore_cursor = TRUE;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2452
18508
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2453 raw_c = term_vgetc();
13994
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
2454 if (!term_use_loop_check(TRUE) || in_terminal_loop != curbuf->b_term)
12798
5ae0d05e046a patch 8.0.1276: key lost when window closed in exit callback
Christian Brabandt <cb@256bit.org>
parents: 12767
diff changeset
2455 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2456 // Job finished while waiting for a character. Push back the
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2457 // received character.
18508
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2458 if (raw_c != K_IGNORE)
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2459 vungetc(raw_c);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2460 break;
12798
5ae0d05e046a patch 8.0.1276: key lost when window closed in exit callback
Christian Brabandt <cb@256bit.org>
parents: 12767
diff changeset
2461 }
18508
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2462 if (raw_c == K_IGNORE)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2463 continue;
18508
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2464 c = raw_c_to_ctrl(raw_c);
18279
e8d1f3209dcd patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 18251
diff changeset
2465
12800
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2466 #ifdef UNIX
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2467 /*
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2468 * The shell or another program may change the tty settings. Getting
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2469 * them for every typed character is a bit of overhead, but it's needed
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2470 * for the first character typed, e.g. when Vim starts in a shell.
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2471 */
15632
d4a6d575e910 patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
2472 if (mch_isatty(tty_fd))
12800
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2473 {
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2474 ttyinfo_T info;
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2475
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2476 // Get the current backspace character of the pty.
12800
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2477 if (get_tty_info(tty_fd, &info) == OK)
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2478 term_backspace_char = info.backspace;
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2479 }
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2480 #endif
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2481
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15844
diff changeset
2482 #ifdef MSWIN
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2483 // On Windows winpty handles CTRL-C, don't send a CTRL_C_EVENT.
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2484 // Use CTRL-BREAK to kill the job.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2485 if (ctrl_break_was_pressed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2486 mch_signal_job(curbuf->b_term->tl_job, (char_u *)"kill");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2487 #endif
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2488 // Was either CTRL-W (termwinkey) or CTRL-\ pressed?
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2489 // Not in a system terminal.
13845
f22db93bd887 patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents: 13835
diff changeset
2490 if ((c == (termwinkey == 0 ? Ctrl_W : termwinkey) || c == Ctrl_BSL)
13474
8a8daeb057d1 patch 8.0.1611: CTRL-W in system terminal does not go to job
Christian Brabandt <cb@256bit.org>
parents: 13472
diff changeset
2491 #ifdef FEAT_GUI
8a8daeb057d1 patch 8.0.1611: CTRL-W in system terminal does not go to job
Christian Brabandt <cb@256bit.org>
parents: 13472
diff changeset
2492 && !curbuf->b_term->tl_system
8a8daeb057d1 patch 8.0.1611: CTRL-W in system terminal does not go to job
Christian Brabandt <cb@256bit.org>
parents: 13472
diff changeset
2493 #endif
8a8daeb057d1 patch 8.0.1611: CTRL-W in system terminal does not go to job
Christian Brabandt <cb@256bit.org>
parents: 13472
diff changeset
2494 )
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2495 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2496 int prev_c = c;
18508
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2497 int prev_raw_c = raw_c;
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2498 int prev_mod_mask = mod_mask;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2499
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2500 #ifdef FEAT_CMDL_INFO
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2501 if (add_to_showcmd(c))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2502 out_flush();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2503 #endif
18508
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2504 raw_c = term_vgetc();
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2505 c = raw_c_to_ctrl(raw_c);
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2506
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2507 #ifdef FEAT_CMDL_INFO
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2508 clear_showcmd();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2509 #endif
13994
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
2510 if (!term_use_loop_check(TRUE)
411dd50f1daa patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13990
diff changeset
2511 || in_terminal_loop != curbuf->b_term)
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2512 // job finished while waiting for a character
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2513 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2514
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2515 if (prev_c == Ctrl_BSL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2516 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2517 if (c == Ctrl_N)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2518 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2519 // CTRL-\ CTRL-N : go to Terminal-Normal mode.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2520 term_enter_normal_mode();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2521 ret = FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2522 goto theend;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2523 }
18508
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2524 // Send both keys to the terminal, first one here, second one
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2525 // below.
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2526 send_keys_to_term(curbuf->b_term, prev_raw_c, prev_mod_mask,
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2527 TRUE);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2528 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2529 else if (c == Ctrl_C)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2530 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2531 // "CTRL-W CTRL-C" or 'termwinkey' CTRL-C: end the job
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2532 mch_signal_job(curbuf->b_term->tl_job, (char_u *)"kill");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2533 }
14109
279465096a16 patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14065
diff changeset
2534 else if (c == '.')
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2535 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2536 // "CTRL-W .": send CTRL-W to the job
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2537 // "'termwinkey' .": send 'termwinkey' to the job
18508
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2538 raw_c = ctrl_to_raw_c(termwinkey == 0 ? Ctrl_W : termwinkey);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2539 }
14109
279465096a16 patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14065
diff changeset
2540 else if (c == Ctrl_BSL)
13668
6a84e3d2b810 patch 8.0.1706: cannot sent CTRL- to a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13630
diff changeset
2541 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2542 // "CTRL-W CTRL-\": send CTRL-\ to the job
18508
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2543 raw_c = ctrl_to_raw_c(Ctrl_BSL);
13668
6a84e3d2b810 patch 8.0.1706: cannot sent CTRL- to a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13630
diff changeset
2544 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2545 else if (c == 'N')
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2546 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2547 // CTRL-W N : go to Terminal-Normal mode.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2548 term_enter_normal_mode();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2549 ret = FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2550 goto theend;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2551 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2552 else if (c == '"')
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2553 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2554 term_paste_register(prev_c);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2555 continue;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2556 }
13845
f22db93bd887 patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents: 13835
diff changeset
2557 else if (termwinkey == 0 || c != termwinkey)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2558 {
17702
ba18f78c8529 patch 8.1.1848: 'langmap' is not used for CTRL-W command in terminal
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2559 char_u buf[MB_MAXBYTES + 2];
ba18f78c8529 patch 8.1.1848: 'langmap' is not used for CTRL-W command in terminal
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2560
ba18f78c8529 patch 8.1.1848: 'langmap' is not used for CTRL-W command in terminal
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2561 // Put the command into the typeahead buffer, when using the
ba18f78c8529 patch 8.1.1848: 'langmap' is not used for CTRL-W command in terminal
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2562 // stuff buffer KeyStuffed is set and 'langmap' won't be used.
ba18f78c8529 patch 8.1.1848: 'langmap' is not used for CTRL-W command in terminal
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2563 buf[0] = Ctrl_W;
ba18f78c8529 patch 8.1.1848: 'langmap' is not used for CTRL-W command in terminal
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2564 buf[(*mb_char2bytes)(c, buf + 1) + 1] = NUL;
ba18f78c8529 patch 8.1.1848: 'langmap' is not used for CTRL-W command in terminal
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
2565 ins_typebuf(buf, REMAP_NONE, 0, TRUE, FALSE);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2566 ret = OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2567 goto theend;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2568 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2569 }
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15844
diff changeset
2570 # ifdef MSWIN
18508
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2571 if (!enc_utf8 && has_mbyte && raw_c >= 0x80)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2572 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2573 WCHAR wc;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2574 char_u mb[3];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2575
18508
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2576 mb[0] = (unsigned)raw_c >> 8;
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2577 mb[1] = raw_c;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2578 if (MultiByteToWideChar(GetACP(), 0, (char*)mb, 2, &wc, 1) > 0)
18508
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2579 raw_c = wc;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2580 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2581 # endif
18508
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2582 if (send_keys_to_term(curbuf->b_term, raw_c, mod_mask, TRUE) != OK)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2583 {
18508
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
2584 if (raw_c == K_MOUSEMOVE)
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2585 // We are sure to come back here, don't reset the cursor color
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2586 // and shape to avoid flickering.
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2587 restore_cursor = FALSE;
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2588
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2589 ret = OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2590 goto theend;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2591 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2592 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2593 ret = FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2594
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2595 theend:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2596 in_terminal_loop = NULL;
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2597 if (restore_cursor)
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2598 prepare_restore_cursor_props();
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2599
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2600 // Move a snapshot of the screen contents to the buffer, so that completion
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2601 // works in other buffers.
13935
cc25795aeec6 patch 8.0.1838: cursor in wrong pos when switching to Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13919
diff changeset
2602 if (curbuf->b_term != NULL && !curbuf->b_term->tl_normal_mode)
cc25795aeec6 patch 8.0.1838: cursor in wrong pos when switching to Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13919
diff changeset
2603 may_move_terminal_to_buffer(curbuf->b_term, FALSE);
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2604
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2605 return ret;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2606 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2607
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2608 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2609 may_toggle_cursor(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2610 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2611 if (in_terminal_loop == term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2612 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2613 if (term->tl_cursor_visible)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2614 cursor_on();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2615 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2616 cursor_off();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2617 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2618 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2619
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2620 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2621 * Reverse engineer the RGB value into a cterm color index.
12966
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2622 * First color is 1. Return 0 if no match found (default color).
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2623 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2624 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2625 color2index(VTermColor *color, int fg, int *boldp)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2626 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2627 int red = color->red;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2628 int blue = color->blue;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2629 int green = color->green;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2630
12966
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2631 if (color->ansi_index != VTERM_ANSI_INDEX_NONE)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2632 {
16312
46e8430738fa patch 8.1.1161: unreachable code
Bram Moolenaar <Bram@vim.org>
parents: 16283
diff changeset
2633 // The first 16 colors and default: use the ANSI index.
12966
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2634 switch (color->ansi_index)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2635 {
12966
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2636 case 0: return 0;
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2637 case 1: return lookup_color( 0, fg, boldp) + 1; // black
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2638 case 2: return lookup_color( 4, fg, boldp) + 1; // dark red
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2639 case 3: return lookup_color( 2, fg, boldp) + 1; // dark green
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2640 case 4: return lookup_color( 6, fg, boldp) + 1; // brown
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2641 case 5: return lookup_color( 1, fg, boldp) + 1; // dark blue
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2642 case 6: return lookup_color( 5, fg, boldp) + 1; // dark magenta
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2643 case 7: return lookup_color( 3, fg, boldp) + 1; // dark cyan
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2644 case 8: return lookup_color( 8, fg, boldp) + 1; // light grey
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2645 case 9: return lookup_color(12, fg, boldp) + 1; // dark grey
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2646 case 10: return lookup_color(20, fg, boldp) + 1; // red
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2647 case 11: return lookup_color(16, fg, boldp) + 1; // green
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2648 case 12: return lookup_color(24, fg, boldp) + 1; // yellow
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2649 case 13: return lookup_color(14, fg, boldp) + 1; // blue
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2650 case 14: return lookup_color(22, fg, boldp) + 1; // magenta
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2651 case 15: return lookup_color(18, fg, boldp) + 1; // cyan
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2652 case 16: return lookup_color(26, fg, boldp) + 1; // white
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2653 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2654 }
12966
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2655
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2656 if (t_colors >= 256)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2657 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2658 if (red == blue && red == green)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2659 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2660 // 24-color greyscale plus white and black
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2661 static int cutoff[23] = {
12541
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2662 0x0D, 0x17, 0x21, 0x2B, 0x35, 0x3F, 0x49, 0x53, 0x5D, 0x67,
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2663 0x71, 0x7B, 0x85, 0x8F, 0x99, 0xA3, 0xAD, 0xB7, 0xC1, 0xCB,
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2664 0xD5, 0xDF, 0xE9};
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2665 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2666
12541
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2667 if (red < 5)
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2668 return 17; // 00/00/00
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2669 if (red > 245) // ff/ff/ff
12541
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2670 return 232;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2671 for (i = 0; i < 23; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2672 if (red < cutoff[i])
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2673 return i + 233;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2674 return 256;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2675 }
12541
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2676 {
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2677 static int cutoff[5] = {0x2F, 0x73, 0x9B, 0xC3, 0xEB};
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2678 int ri, gi, bi;
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2679
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2680 // 216-color cube
12541
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2681 for (ri = 0; ri < 5; ++ri)
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2682 if (red < cutoff[ri])
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2683 break;
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2684 for (gi = 0; gi < 5; ++gi)
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2685 if (green < cutoff[gi])
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2686 break;
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2687 for (bi = 0; bi < 5; ++bi)
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2688 if (blue < cutoff[bi])
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2689 break;
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2690 return 17 + ri * 36 + gi * 6 + bi;
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2691 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2692 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2693 return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2694 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2695
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2696 /*
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2697 * Convert Vterm attributes to highlight flags.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2698 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2699 static int
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2700 vtermAttr2hl(VTermScreenCellAttrs cellattrs)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2701 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2702 int attr = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2703
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2704 if (cellattrs.bold)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2705 attr |= HL_BOLD;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2706 if (cellattrs.underline)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2707 attr |= HL_UNDERLINE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2708 if (cellattrs.italic)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2709 attr |= HL_ITALIC;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2710 if (cellattrs.strike)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2711 attr |= HL_STRIKETHROUGH;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2712 if (cellattrs.reverse)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2713 attr |= HL_INVERSE;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2714 return attr;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2715 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2716
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2717 /*
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2718 * Store Vterm attributes in "cell" from highlight flags.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2719 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2720 static void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2721 hl2vtermAttr(int attr, cellattr_T *cell)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2722 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2723 vim_memset(&cell->attrs, 0, sizeof(VTermScreenCellAttrs));
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2724 if (attr & HL_BOLD)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2725 cell->attrs.bold = 1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2726 if (attr & HL_UNDERLINE)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2727 cell->attrs.underline = 1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2728 if (attr & HL_ITALIC)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2729 cell->attrs.italic = 1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2730 if (attr & HL_STRIKETHROUGH)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2731 cell->attrs.strike = 1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2732 if (attr & HL_INVERSE)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2733 cell->attrs.reverse = 1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2734 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2735
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2736 /*
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2737 * Convert the attributes of a vterm cell into an attribute index.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2738 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2739 static int
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2740 cell2attr(
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2741 win_T *wp,
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2742 VTermScreenCellAttrs cellattrs,
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2743 VTermColor cellfg,
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2744 VTermColor cellbg)
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2745 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2746 int attr = vtermAttr2hl(cellattrs);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2747
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2748 #ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2749 if (gui.in_use)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2750 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2751 guicolor_T fg, bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2752
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2753 fg = gui_mch_get_rgb_color(cellfg.red, cellfg.green, cellfg.blue);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2754 bg = gui_mch_get_rgb_color(cellbg.red, cellbg.green, cellbg.blue);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2755 return get_gui_attr_idx(attr, fg, bg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2756 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2757 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2758 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2759 #ifdef FEAT_TERMGUICOLORS
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2760 if (p_tgc)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2761 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2762 guicolor_T fg, bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2763
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2764 fg = gui_get_rgb_color_cmn(cellfg.red, cellfg.green, cellfg.blue);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2765 bg = gui_get_rgb_color_cmn(cellbg.red, cellbg.green, cellbg.blue);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2766
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2767 return get_tgc_attr_idx(attr, fg, bg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2768 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2769 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2770 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2771 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2772 int bold = MAYBE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2773 int fg = color2index(&cellfg, TRUE, &bold);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2774 int bg = color2index(&cellbg, FALSE, &bold);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2775
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2776 // Use the 'wincolor' or "Terminal" highlighting for the default
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2777 // colors.
12973
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
2778 if ((fg == 0 || bg == 0) && t_colors >= 16)
12969
a9f6a874b64f patch 8.0.1360: the Terminal highlighting doesn't work in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12966
diff changeset
2779 {
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2780 int wincolor_fg = -1;
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2781 int wincolor_bg = -1;
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2782
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2783 if (wp != NULL && *wp->w_p_wcr != NUL)
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2784 {
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2785 int id = syn_name2id(curwin->w_p_wcr);
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2786
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2787 // Get the 'wincolor' group colors.
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2788 if (id > 0)
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2789 syn_id2cterm_bg(id, &wincolor_fg, &wincolor_bg);
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2790 }
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2791 if (fg == 0)
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2792 {
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2793 if (wincolor_fg >= 0)
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2794 fg = wincolor_fg + 1;
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2795 else if (term_default_cterm_fg >= 0)
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2796 fg = term_default_cterm_fg + 1;
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2797 }
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2798 if (bg == 0)
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2799 {
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2800 if (wincolor_bg >= 0)
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2801 bg = wincolor_bg + 1;
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2802 else if (term_default_cterm_bg >= 0)
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2803 bg = term_default_cterm_bg + 1;
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2804 }
12969
a9f6a874b64f patch 8.0.1360: the Terminal highlighting doesn't work in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12966
diff changeset
2805 }
a9f6a874b64f patch 8.0.1360: the Terminal highlighting doesn't work in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12966
diff changeset
2806
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2807 // with 8 colors set the bold attribute to get a bright foreground
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2808 if (bold == TRUE)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2809 attr |= HL_BOLD;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2810 return get_cterm_attr_idx(attr, fg, bg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2811 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2812 return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2813 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2814
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2815 static void
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2816 set_dirty_snapshot(term_T *term)
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2817 {
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2818 term->tl_dirty_snapshot = TRUE;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2819 #ifdef FEAT_TIMERS
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2820 if (!term->tl_normal_mode)
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2821 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2822 // Update the snapshot after 100 msec of not getting updates.
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2823 profile_setlimit(100L, &term->tl_timer_due);
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2824 term->tl_timer_set = TRUE;
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2825 }
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2826 #endif
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2827 }
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2828
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2829 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2830 handle_damage(VTermRect rect, void *user)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2831 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2832 term_T *term = (term_T *)user;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2833
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2834 term->tl_dirty_row_start = MIN(term->tl_dirty_row_start, rect.start_row);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2835 term->tl_dirty_row_end = MAX(term->tl_dirty_row_end, rect.end_row);
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2836 set_dirty_snapshot(term);
13851
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2837 redraw_buf_later(term->tl_buffer, SOME_VALID);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2838 return 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2839 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2840
13851
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2841 static void
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2842 term_scroll_up(term_T *term, int start_row, int count)
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2843 {
19542
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
2844 win_T *wp = NULL;
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
2845 int did_curwin = FALSE;
13851
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2846 VTermColor fg, bg;
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2847 VTermScreenCellAttrs attr;
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2848 int clear_attr;
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2849
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2850 vim_memset(&attr, 0, sizeof(attr));
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2851
19542
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
2852 while (for_all_windows_and_curwin(&wp, &did_curwin))
13851
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2853 {
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2854 if (wp->w_buffer == term->tl_buffer)
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2855 {
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2856 // Set the color to clear lines with.
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2857 vterm_state_get_default_colors(vterm_obtain_state(term->tl_vterm),
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2858 &fg, &bg);
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2859 clear_attr = cell2attr(wp, attr, fg, bg);
13851
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2860 win_del_lines(wp, start_row, count, FALSE, FALSE, clear_attr);
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2861 }
13851
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2862 }
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2863 }
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2864
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2865 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2866 handle_moverect(VTermRect dest, VTermRect src, void *user)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2867 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2868 term_T *term = (term_T *)user;
13851
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2869 int count = src.start_row - dest.start_row;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2870
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2871 // Scrolling up is done much more efficiently by deleting lines instead of
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2872 // redrawing the text. But avoid doing this multiple times, postpone until
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2873 // the redraw happens.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2874 if (dest.start_col == src.start_col
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2875 && dest.end_col == src.end_col
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2876 && dest.start_row < src.start_row)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2877 {
13851
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2878 if (dest.start_row == 0)
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2879 term->tl_postponed_scroll += count;
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2880 else
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
2881 term_scroll_up(term, dest.start_row, count);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2882 }
12578
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
2883
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
2884 term->tl_dirty_row_start = MIN(term->tl_dirty_row_start, dest.start_row);
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
2885 term->tl_dirty_row_end = MIN(term->tl_dirty_row_end, dest.end_row);
13878
a590029f16a0 patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents: 13864
diff changeset
2886 set_dirty_snapshot(term);
12578
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
2887
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2888 // Note sure if the scrolling will work correctly, let's do a complete
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2889 // redraw later.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2890 redraw_buf_later(term->tl_buffer, NOT_VALID);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2891 return 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2892 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2893
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2894 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2895 handle_movecursor(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2896 VTermPos pos,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2897 VTermPos oldpos UNUSED,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2898 int visible,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2899 void *user)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2900 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2901 term_T *term = (term_T *)user;
19542
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
2902 win_T *wp = NULL;
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
2903 int did_curwin = FALSE;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2904
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2905 term->tl_cursor_pos = pos;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2906 term->tl_cursor_visible = visible;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2907
19542
9e428147e4ee patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents: 19513
diff changeset
2908 while (for_all_windows_and_curwin(&wp, &did_curwin))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2909 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2910 if (wp->w_buffer == term->tl_buffer)
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
2911 position_cursor(wp, &pos, FALSE);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2912 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2913 if (term->tl_buffer == curbuf && !term->tl_normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2914 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2915 may_toggle_cursor(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2916 update_cursor(term, term->tl_cursor_visible);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2917 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2918
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2919 return 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2920 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2921
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2922 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2923 handle_settermprop(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2924 VTermProp prop,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2925 VTermValue *value,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2926 void *user)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2927 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2928 term_T *term = (term_T *)user;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2929
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2930 switch (prop)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2931 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2932 case VTERM_PROP_TITLE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2933 vim_free(term->tl_title);
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
2934 // a blank title isn't useful, make it empty, so that "running" is
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
2935 // displayed
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2936 if (*skipwhite((char_u *)value->string) == NUL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2937 term->tl_title = NULL;
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
2938 // Same as blank
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
2939 else if (term->tl_arg0_cmd != NULL
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
2940 && STRNCMP(term->tl_arg0_cmd, (char_u *)value->string,
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
2941 (int)STRLEN(term->tl_arg0_cmd)) == 0)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
2942 term->tl_title = NULL;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
2943 // Empty corrupted data of winpty
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
2944 else if (STRNCMP(" - ", (char_u *)value->string, 4) == 0)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
2945 term->tl_title = NULL;
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15844
diff changeset
2946 #ifdef MSWIN
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2947 else if (!enc_utf8 && enc_codepage > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2948 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2949 WCHAR *ret = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2950 int length = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2951
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2952 MultiByteToWideChar_alloc(CP_UTF8, 0,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2953 (char*)value->string, (int)STRLEN(value->string),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2954 &ret, &length);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2955 if (ret != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2956 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2957 WideCharToMultiByte_alloc(enc_codepage, 0,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2958 ret, length, (char**)&term->tl_title,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2959 &length, 0, 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2960 vim_free(ret);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2961 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2962 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2963 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2964 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2965 term->tl_title = vim_strsave((char_u *)value->string);
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13219
diff changeset
2966 VIM_CLEAR(term->tl_status_text);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2967 if (term == curbuf->b_term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2968 maketitle();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2969 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2970
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2971 case VTERM_PROP_CURSORVISIBLE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2972 term->tl_cursor_visible = value->boolean;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2973 may_toggle_cursor(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2974 out_flush();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2975 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2976
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2977 case VTERM_PROP_CURSORBLINK:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2978 term->tl_cursor_blink = value->boolean;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2979 may_set_cursor_props(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2980 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2981
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2982 case VTERM_PROP_CURSORSHAPE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2983 term->tl_cursor_shape = value->number;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2984 may_set_cursor_props(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2985 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2986
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2987 case VTERM_PROP_CURSORCOLOR:
13990
017c5462ed5e patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents: 13961
diff changeset
2988 cursor_color_copy(&term->tl_cursor_color, (char_u*)value->string);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2989 may_set_cursor_props(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2990 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2991
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2992 case VTERM_PROP_ALTSCREEN:
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
2993 // TODO: do anything else?
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2994 term->tl_using_altscreen = value->boolean;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2995 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2996
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2997 default:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2998 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2999 }
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3000 // Always return 1, otherwise vterm doesn't store the value internally.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3001 return 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3002 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3003
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3004 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3005 * The job running in the terminal resized the terminal.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3006 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3007 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3008 handle_resize(int rows, int cols, void *user)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3009 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3010 term_T *term = (term_T *)user;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3011 win_T *wp;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3012
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3013 term->tl_rows = rows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3014 term->tl_cols = cols;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3015 if (term->tl_vterm_size_changed)
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3016 // Size was set by vterm_set_size(), don't set the window size.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3017 term->tl_vterm_size_changed = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3018 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3019 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3020 FOR_ALL_WINDOWS(wp)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3021 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3022 if (wp->w_buffer == term->tl_buffer)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3023 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3024 win_setheight_win(rows, wp);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3025 win_setwidth_win(cols, wp);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3026 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3027 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3028 redraw_buf_later(term->tl_buffer, NOT_VALID);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3029 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3030 return 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3031 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3032
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3033 /*
15826
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3034 * If the number of lines that are stored goes over 'termscrollback' then
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3035 * delete the first 10%.
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3036 * "gap" points to tl_scrollback or tl_scrollback_postponed.
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3037 * "update_buffer" is TRUE when the buffer should be updated.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3038 */
15826
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3039 static void
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3040 limit_scrollback(term_T *term, garray_T *gap, int update_buffer)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3041 {
15826
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3042 if (gap->ga_len >= term->tl_buffer->b_p_twsl)
13680
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
3043 {
13742
a34b1323286c patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents: 13720
diff changeset
3044 int todo = term->tl_buffer->b_p_twsl / 10;
13680
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
3045 int i;
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
3046
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
3047 curbuf = term->tl_buffer;
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
3048 for (i = 0; i < todo; ++i)
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
3049 {
15826
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3050 vim_free(((sb_line_T *)gap->ga_data + i)->sb_cells);
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3051 if (update_buffer)
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3052 ml_delete(1, FALSE);
13680
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
3053 }
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
3054 curbuf = curwin->w_buffer;
c32e9628dc30 patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents: 13678
diff changeset
3055
15826
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3056 gap->ga_len -= todo;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3057 mch_memmove(gap->ga_data,
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3058 (sb_line_T *)gap->ga_data + todo,
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3059 sizeof(sb_line_T) * gap->ga_len);
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3060 if (update_buffer)
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3061 term->tl_scrollback_scrolled -= todo;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3062 }
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3063 }
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3064
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3065 /*
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3066 * Handle a line that is pushed off the top of the screen.
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3067 */
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3068 static int
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3069 handle_pushline(int cols, const VTermScreenCell *cells, void *user)
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3070 {
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3071 term_T *term = (term_T *)user;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3072 garray_T *gap;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3073 int update_buffer;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3074
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3075 if (term->tl_normal_mode)
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3076 {
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3077 // In Terminal-Normal mode the user interacts with the buffer, thus we
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3078 // must not change it. Postpone adding the scrollback lines.
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3079 gap = &term->tl_scrollback_postponed;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3080 update_buffer = FALSE;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3081 }
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3082 else
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3083 {
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3084 // First remove the lines that were appended before, the pushed line
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3085 // goes above it.
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3086 cleanup_scrollback(term);
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3087 gap = &term->tl_scrollback;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3088 update_buffer = TRUE;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3089 }
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3090
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3091 limit_scrollback(term, gap, update_buffer);
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3092
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3093 if (ga_grow(gap, 1) == OK)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3094 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3095 cellattr_T *p = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3096 int len = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3097 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3098 int c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3099 int col;
15826
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3100 int text_len;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3101 char_u *text;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3102 sb_line_T *line;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3103 garray_T ga;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3104 cellattr_T fill_attr = term->tl_default_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3105
15826
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3106 // do not store empty cells at the end
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3107 for (i = 0; i < cols; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3108 if (cells[i].chars[0] != 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3109 len = i + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3110 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3111 cell2cellattr(&cells[i], &fill_attr);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3112
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3113 ga_init2(&ga, 1, 100);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3114 if (len > 0)
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16782
diff changeset
3115 p = ALLOC_MULT(cellattr_T, len);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3116 if (p != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3117 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3118 for (col = 0; col < len; col += cells[col].width)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3119 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3120 if (ga_grow(&ga, MB_MAXBYTES) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3121 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3122 ga.ga_len = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3123 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3124 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3125 for (i = 0; (c = cells[col].chars[i]) > 0 || i == 0; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3126 ga.ga_len += utf_char2bytes(c == NUL ? ' ' : c,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3127 (char_u *)ga.ga_data + ga.ga_len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3128 cell2cellattr(&cells[col], &p[col]);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3129 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3130 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3131 if (ga_grow(&ga, 1) == FAIL)
15826
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3132 {
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3133 if (update_buffer)
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3134 text = (char_u *)"";
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3135 else
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3136 text = vim_strsave((char_u *)"");
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3137 text_len = 0;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3138 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3139 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3140 {
15826
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3141 text = ga.ga_data;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3142 text_len = ga.ga_len;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3143 *(text + text_len) = NUL;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3144 }
15826
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3145 if (update_buffer)
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3146 add_scrollback_line_to_buffer(term, text, text_len);
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3147
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3148 line = (sb_line_T *)gap->ga_data + gap->ga_len;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3149 line->sb_cols = len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3150 line->sb_cells = p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3151 line->sb_fill_attr = fill_attr;
15826
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3152 if (update_buffer)
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3153 {
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3154 line->sb_text = NULL;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3155 ++term->tl_scrollback_scrolled;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3156 ga_clear(&ga); // free the text
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3157 }
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3158 else
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3159 {
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3160 line->sb_text = text;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3161 ga_init(&ga); // text is kept in tl_scrollback_postponed
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3162 }
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3163 ++gap->ga_len;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3164 }
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3165 return 0; // ignored
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3166 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3167
15826
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3168 /*
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3169 * Called when leaving Terminal-Normal mode: deal with any scrollback that was
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3170 * received and stored in tl_scrollback_postponed.
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3171 */
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3172 static void
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3173 handle_postponed_scrollback(term_T *term)
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3174 {
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3175 int i;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3176
16026
5b29ab8415df patch 8.1.1018: window cleared when entering Terminal-Normal twice
Bram Moolenaar <Bram@vim.org>
parents: 15953
diff changeset
3177 if (term->tl_scrollback_postponed.ga_len == 0)
5b29ab8415df patch 8.1.1018: window cleared when entering Terminal-Normal twice
Bram Moolenaar <Bram@vim.org>
parents: 15953
diff changeset
3178 return;
5b29ab8415df patch 8.1.1018: window cleared when entering Terminal-Normal twice
Bram Moolenaar <Bram@vim.org>
parents: 15953
diff changeset
3179 ch_log(NULL, "Moving postponed scrollback to scrollback");
5b29ab8415df patch 8.1.1018: window cleared when entering Terminal-Normal twice
Bram Moolenaar <Bram@vim.org>
parents: 15953
diff changeset
3180
15826
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3181 // First remove the lines that were appended before, the pushed lines go
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3182 // above it.
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3183 cleanup_scrollback(term);
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3184
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3185 for (i = 0; i < term->tl_scrollback_postponed.ga_len; ++i)
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3186 {
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3187 char_u *text;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3188 sb_line_T *pp_line;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3189 sb_line_T *line;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3190
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3191 if (ga_grow(&term->tl_scrollback, 1) == FAIL)
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3192 break;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3193 pp_line = (sb_line_T *)term->tl_scrollback_postponed.ga_data + i;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3194
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3195 text = pp_line->sb_text;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3196 if (text == NULL)
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3197 text = (char_u *)"";
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3198 add_scrollback_line_to_buffer(term, text, (int)STRLEN(text));
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3199 vim_free(pp_line->sb_text);
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3200
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3201 line = (sb_line_T *)term->tl_scrollback.ga_data
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3202 + term->tl_scrollback.ga_len;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3203 line->sb_cols = pp_line->sb_cols;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3204 line->sb_cells = pp_line->sb_cells;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3205 line->sb_fill_attr = pp_line->sb_fill_attr;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3206 line->sb_text = NULL;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3207 ++term->tl_scrollback_scrolled;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3208 ++term->tl_scrollback.ga_len;
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3209 }
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3210
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3211 ga_clear(&term->tl_scrollback_postponed);
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3212 limit_scrollback(term, &term->tl_scrollback, TRUE);
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3213 }
1f2edc01e7ed patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents: 15810
diff changeset
3214
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3215 static VTermScreenCallbacks screen_callbacks = {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3216 handle_damage, // damage
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3217 handle_moverect, // moverect
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3218 handle_movecursor, // movecursor
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3219 handle_settermprop, // settermprop
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3220 NULL, // bell
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3221 handle_resize, // resize
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3222 handle_pushline, // sb_pushline
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3223 NULL // sb_popline
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3224 };
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3225
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3226 /*
13888
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3227 * Do the work after the channel of a terminal was closed.
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3228 * Must be called only when updating_screen is FALSE.
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3229 * Returns TRUE when a buffer was closed (list of terminals may have changed).
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3230 */
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3231 static int
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3232 term_after_channel_closed(term_T *term)
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3233 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3234 // Unless in Terminal-Normal mode: clear the vterm.
13888
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3235 if (!term->tl_normal_mode)
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3236 {
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3237 int fnum = term->tl_buffer->b_fnum;
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3238
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3239 cleanup_vterm(term);
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3240
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3241 if (term->tl_finish == TL_FINISH_CLOSE)
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3242 {
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3243 aco_save_T aco;
14459
ecf6c05d8ac3 patch 8.1.0243: using :term ++close ++hidden closes a window
Christian Brabandt <cb@256bit.org>
parents: 14449
diff changeset
3244 int do_set_w_closing = term->tl_buffer->b_nwindows == 0;
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3245 #ifdef FEAT_PROP_POPUP
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3246 win_T *pwin = NULL;
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3247
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3248 // If this was a terminal in a popup window, go back to the
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3249 // previous window.
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3250 if (popup_is_popup(curwin) && curbuf == term->tl_buffer)
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3251 {
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3252 pwin = curwin;
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3253 if (win_valid(prevwin))
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3254 win_enter(prevwin, FALSE);
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3255 }
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3256 else
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3257 #endif
18402
527b7084c556 patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents: 18301
diff changeset
3258 // If this is the last normal window: exit Vim.
527b7084c556 patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents: 18301
diff changeset
3259 if (term->tl_buffer->b_nwindows > 0 && only_one_window())
527b7084c556 patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents: 18301
diff changeset
3260 {
527b7084c556 patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents: 18301
diff changeset
3261 exarg_T ea;
527b7084c556 patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents: 18301
diff changeset
3262
527b7084c556 patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents: 18301
diff changeset
3263 vim_memset(&ea, 0, sizeof(ea));
527b7084c556 patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents: 18301
diff changeset
3264 ex_quit(&ea);
527b7084c556 patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents: 18301
diff changeset
3265 return TRUE;
527b7084c556 patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents: 18301
diff changeset
3266 }
527b7084c556 patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents: 18301
diff changeset
3267
14459
ecf6c05d8ac3 patch 8.1.0243: using :term ++close ++hidden closes a window
Christian Brabandt <cb@256bit.org>
parents: 14449
diff changeset
3268 // ++close or term_finish == "close"
13888
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3269 ch_log(NULL, "terminal job finished, closing window");
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3270 aucmd_prepbuf(&aco, term->tl_buffer);
14459
ecf6c05d8ac3 patch 8.1.0243: using :term ++close ++hidden closes a window
Christian Brabandt <cb@256bit.org>
parents: 14449
diff changeset
3271 // Avoid closing the window if we temporarily use it.
17133
2a9a5e69fb3e patch 8.1.1566: error message when terminal closes in another tab
Bram Moolenaar <Bram@vim.org>
parents: 16912
diff changeset
3272 if (curwin == aucmd_win)
2a9a5e69fb3e patch 8.1.1566: error message when terminal closes in another tab
Bram Moolenaar <Bram@vim.org>
parents: 16912
diff changeset
3273 do_set_w_closing = TRUE;
14459
ecf6c05d8ac3 patch 8.1.0243: using :term ++close ++hidden closes a window
Christian Brabandt <cb@256bit.org>
parents: 14449
diff changeset
3274 if (do_set_w_closing)
ecf6c05d8ac3 patch 8.1.0243: using :term ++close ++hidden closes a window
Christian Brabandt <cb@256bit.org>
parents: 14449
diff changeset
3275 curwin->w_closing = TRUE;
13888
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3276 do_bufdel(DOBUF_WIPE, (char_u *)"", 1, fnum, fnum, FALSE);
14459
ecf6c05d8ac3 patch 8.1.0243: using :term ++close ++hidden closes a window
Christian Brabandt <cb@256bit.org>
parents: 14449
diff changeset
3277 if (do_set_w_closing)
ecf6c05d8ac3 patch 8.1.0243: using :term ++close ++hidden closes a window
Christian Brabandt <cb@256bit.org>
parents: 14449
diff changeset
3278 curwin->w_closing = FALSE;
13888
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3279 aucmd_restbuf(&aco);
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3280 #ifdef FEAT_PROP_POPUP
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3281 if (pwin != NULL)
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3282 popup_close_with_retval(pwin, 0);
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3283 #endif
13888
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3284 return TRUE;
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3285 }
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3286 if (term->tl_finish == TL_FINISH_OPEN
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3287 && term->tl_buffer->b_nwindows == 0)
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3288 {
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3289 char buf[50];
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3290
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3291 // TODO: use term_opencmd
13888
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3292 ch_log(NULL, "terminal job finished, opening window");
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3293 vim_snprintf(buf, sizeof(buf),
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3294 term->tl_opencmd == NULL
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3295 ? "botright sbuf %d"
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3296 : (char *)term->tl_opencmd, fnum);
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3297 do_cmdline_cmd((char_u *)buf);
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3298 }
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3299 else
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3300 ch_log(NULL, "terminal job finished");
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3301 }
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3302
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3303 redraw_buf_and_status_later(term->tl_buffer, NOT_VALID);
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3304 return FALSE;
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3305 }
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3306
19275
2142fb624658 patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19265
diff changeset
3307 #if defined(FEAT_PROP_POPUP) || defined(PROTO)
2142fb624658 patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19265
diff changeset
3308 /*
2142fb624658 patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19265
diff changeset
3309 * If the current window is a terminal in a popup window and the job has
2142fb624658 patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19265
diff changeset
3310 * finished, close the popup window and to back to the previous window.
2142fb624658 patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19265
diff changeset
3311 * Otherwise return FAIL.
2142fb624658 patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19265
diff changeset
3312 */
2142fb624658 patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19265
diff changeset
3313 int
2142fb624658 patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19265
diff changeset
3314 may_close_term_popup(void)
2142fb624658 patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19265
diff changeset
3315 {
2142fb624658 patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19265
diff changeset
3316 if (popup_is_popup(curwin) && curbuf->b_term != NULL
2142fb624658 patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19265
diff changeset
3317 && !term_job_running(curbuf->b_term))
2142fb624658 patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19265
diff changeset
3318 {
2142fb624658 patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19265
diff changeset
3319 win_T *pwin = curwin;
2142fb624658 patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19265
diff changeset
3320
2142fb624658 patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19265
diff changeset
3321 if (win_valid(prevwin))
2142fb624658 patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19265
diff changeset
3322 win_enter(prevwin, FALSE);
2142fb624658 patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19265
diff changeset
3323 popup_close_with_retval(pwin, 0);
2142fb624658 patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19265
diff changeset
3324 return OK;
2142fb624658 patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19265
diff changeset
3325 }
2142fb624658 patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19265
diff changeset
3326 return FAIL;
2142fb624658 patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19265
diff changeset
3327 }
2142fb624658 patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19265
diff changeset
3328 #endif
2142fb624658 patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19265
diff changeset
3329
13888
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3330 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3331 * Called when a channel has been closed.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3332 * If this was a channel for a terminal window then finish it up.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3333 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3334 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3335 term_channel_closed(channel_T *ch)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3336 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3337 term_T *term;
13888
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3338 term_T *next_term;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3339 int did_one = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3340
13888
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3341 for (term = first_term; term != NULL; term = next_term)
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3342 {
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3343 next_term = term->tl_next;
17186
278583ff5e44 patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
3344 if (term->tl_job == ch->ch_job && !term->tl_channel_closed)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3345 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3346 term->tl_channel_closed = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3347 did_one = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3348
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13219
diff changeset
3349 VIM_CLEAR(term->tl_title);
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13219
diff changeset
3350 VIM_CLEAR(term->tl_status_text);
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15844
diff changeset
3351 #ifdef MSWIN
13862
b201372b91a4 patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents: 13860
diff changeset
3352 if (term->tl_out_fd != NULL)
b201372b91a4 patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents: 13860
diff changeset
3353 {
b201372b91a4 patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents: 13860
diff changeset
3354 fclose(term->tl_out_fd);
b201372b91a4 patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents: 13860
diff changeset
3355 term->tl_out_fd = NULL;
b201372b91a4 patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents: 13860
diff changeset
3356 }
b201372b91a4 patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents: 13860
diff changeset
3357 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3358
13888
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3359 if (updating_screen)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3360 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3361 // Cannot open or close windows now. Can happen when
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3362 // 'lazyredraw' is set.
13888
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3363 term->tl_channel_recently_closed = TRUE;
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3364 continue;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3365 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3366
13888
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3367 if (term_after_channel_closed(term))
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3368 next_term = first_term;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3369 }
13888
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3370 }
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3371
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3372 if (did_one)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3373 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3374 redraw_statuslines();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3375
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3376 // Need to break out of vgetc().
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3377 ins_char_typebuf(K_IGNORE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3378 typebuf_was_filled = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3379
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3380 term = curbuf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3381 if (term != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3382 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3383 if (term->tl_job == ch->ch_job)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3384 maketitle();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3385 update_cursor(term, term->tl_cursor_visible);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3386 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3387 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3388 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3389
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3390 /*
13888
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3391 * To be called after resetting updating_screen: handle any terminal where the
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3392 * channel was closed.
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3393 */
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3394 void
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3395 term_check_channel_closed_recently()
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3396 {
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3397 term_T *term;
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3398 term_T *next_term;
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3399
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3400 for (term = first_term; term != NULL; term = next_term)
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3401 {
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3402 next_term = term->tl_next;
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3403 if (term->tl_channel_recently_closed)
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3404 {
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3405 term->tl_channel_recently_closed = FALSE;
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3406 if (term_after_channel_closed(term))
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3407 // start over, the list may have changed
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3408 next_term = first_term;
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3409 }
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3410 }
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3411 }
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3412
81e8e6181aeb patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents: 13886
diff changeset
3413 /*
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3414 * Fill one screen line from a line of the terminal.
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3415 * Advances "pos" to past the last column.
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3416 */
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3417 static void
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3418 term_line2screenline(
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3419 win_T *wp,
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3420 VTermScreen *screen,
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3421 VTermPos *pos,
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3422 int max_col)
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3423 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3424 int off = screen_get_current_line_off();
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3425
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3426 for (pos->col = 0; pos->col < max_col; )
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3427 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3428 VTermScreenCell cell;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3429 int c;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3430
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3431 if (vterm_screen_get_cell(screen, *pos, &cell) == 0)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3432 vim_memset(&cell, 0, sizeof(cell));
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3433
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3434 c = cell.chars[0];
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3435 if (c == NUL)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3436 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3437 ScreenLines[off] = ' ';
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3438 if (enc_utf8)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3439 ScreenLinesUC[off] = NUL;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3440 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3441 else
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3442 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3443 if (enc_utf8)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3444 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3445 int i;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3446
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3447 // composing chars
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3448 for (i = 0; i < Screen_mco
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3449 && i + 1 < VTERM_MAX_CHARS_PER_CELL; ++i)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3450 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3451 ScreenLinesC[i][off] = cell.chars[i + 1];
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3452 if (cell.chars[i + 1] == 0)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3453 break;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3454 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3455 if (c >= 0x80 || (Screen_mco > 0
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3456 && ScreenLinesC[0][off] != 0))
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3457 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3458 ScreenLines[off] = ' ';
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3459 ScreenLinesUC[off] = c;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3460 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3461 else
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3462 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3463 ScreenLines[off] = c;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3464 ScreenLinesUC[off] = NUL;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3465 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3466 }
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15844
diff changeset
3467 #ifdef MSWIN
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3468 else if (has_mbyte && c >= 0x80)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3469 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3470 char_u mb[MB_MAXBYTES+1];
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3471 WCHAR wc = c;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3472
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3473 if (WideCharToMultiByte(GetACP(), 0, &wc, 1,
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3474 (char*)mb, 2, 0, 0) > 1)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3475 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3476 ScreenLines[off] = mb[0];
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3477 ScreenLines[off + 1] = mb[1];
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3478 cell.width = mb_ptr2cells(mb);
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3479 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3480 else
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3481 ScreenLines[off] = c;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3482 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3483 #endif
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3484 else
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3485 ScreenLines[off] = c;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3486 }
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3487 ScreenAttrs[off] = cell2attr(wp, cell.attrs, cell.fg, cell.bg);
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3488
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3489 ++pos->col;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3490 ++off;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3491 if (cell.width == 2)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3492 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3493 if (enc_utf8)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3494 ScreenLinesUC[off] = NUL;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3495
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3496 // don't set the second byte to NUL for a DBCS encoding, it
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3497 // has been set above
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3498 if (enc_utf8 || !has_mbyte)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3499 ScreenLines[off] = NUL;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3500
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3501 ++pos->col;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3502 ++off;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3503 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3504 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3505 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3506
13472
f6a4614edea4 patch 8.0.1610: cannot build without GUI
Christian Brabandt <cb@256bit.org>
parents: 13470
diff changeset
3507 #if defined(FEAT_GUI)
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3508 static void
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3509 update_system_term(term_T *term)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3510 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3511 VTermPos pos;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3512 VTermScreen *screen;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3513
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3514 if (term->tl_vterm == NULL)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3515 return;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3516 screen = vterm_obtain_screen(term->tl_vterm);
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3517
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3518 // Scroll up to make more room for terminal lines if needed.
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3519 while (term->tl_toprow > 0
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3520 && (Rows - term->tl_toprow) < term->tl_dirty_row_end)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3521 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3522 int save_p_more = p_more;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3523
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3524 p_more = FALSE;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3525 msg_row = Rows - 1;
15555
d89c5b339c2a patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents: 15504
diff changeset
3526 msg_puts("\n");
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3527 p_more = save_p_more;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3528 --term->tl_toprow;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3529 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3530
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3531 for (pos.row = term->tl_dirty_row_start; pos.row < term->tl_dirty_row_end
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3532 && pos.row < Rows; ++pos.row)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3533 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3534 if (pos.row < term->tl_rows)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3535 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3536 int max_col = MIN(Columns, term->tl_cols);
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3537
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3538 term_line2screenline(NULL, screen, &pos, max_col);
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3539 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3540 else
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3541 pos.col = 0;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3542
16778
eda4d65f232c patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
3543 screen_line(term->tl_toprow + pos.row, 0, pos.col, Columns, 0);
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3544 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3545
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3546 term->tl_dirty_row_start = MAX_ROW;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3547 term->tl_dirty_row_end = 0;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3548 }
13472
f6a4614edea4 patch 8.0.1610: cannot build without GUI
Christian Brabandt <cb@256bit.org>
parents: 13470
diff changeset
3549 #endif
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3550
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3551 /*
13851
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3552 * Return TRUE if window "wp" is to be redrawn with term_update_window().
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3553 * Returns FALSE when there is no terminal running in this window or it is in
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3554 * Terminal-Normal mode.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3555 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3556 int
13851
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3557 term_do_update_window(win_T *wp)
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3558 {
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3559 term_T *term = wp->w_buffer->b_term;
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3560
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3561 return term != NULL && term->tl_vterm != NULL && !term->tl_normal_mode;
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3562 }
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3563
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3564 /*
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3565 * Called to update a window that contains an active terminal.
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3566 */
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3567 void
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3568 term_update_window(win_T *wp)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3569 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3570 term_T *term = wp->w_buffer->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3571 VTerm *vterm;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3572 VTermScreen *screen;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3573 VTermState *state;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3574 VTermPos pos;
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3575 int rows, cols;
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3576 int newrows, newcols;
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3577 int minsize;
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3578 win_T *twp;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3579
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3580 vterm = term->tl_vterm;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3581 screen = vterm_obtain_screen(vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3582 state = vterm_obtain_state(vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3583
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3584 // We use NOT_VALID on a resize or scroll, redraw everything then. With
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3585 // SOME_VALID only redraw what was marked dirty.
13851
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3586 if (wp->w_redr_type > SOME_VALID)
12590
3c46dcf3b335 patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents: 12578
diff changeset
3587 {
3c46dcf3b335 patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents: 12578
diff changeset
3588 term->tl_dirty_row_start = 0;
3c46dcf3b335 patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents: 12578
diff changeset
3589 term->tl_dirty_row_end = MAX_ROW;
13851
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3590
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3591 if (term->tl_postponed_scroll > 0
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3592 && term->tl_postponed_scroll < term->tl_rows / 3)
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3593 // Scrolling is usually faster than redrawing, when there are only
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3594 // a few lines to scroll.
13851
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3595 term_scroll_up(term, 0, term->tl_postponed_scroll);
3edac4cd1c0a patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents: 13849
diff changeset
3596 term->tl_postponed_scroll = 0;
12590
3c46dcf3b335 patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents: 12578
diff changeset
3597 }
3c46dcf3b335 patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents: 12578
diff changeset
3598
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3599 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3600 * If the window was resized a redraw will be triggered and we get here.
13845
f22db93bd887 patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents: 13835
diff changeset
3601 * Adjust the size of the vterm unless 'termwinsize' specifies a fixed size.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3602 */
13845
f22db93bd887 patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents: 13835
diff changeset
3603 minsize = parse_termwinsize(wp, &rows, &cols);
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3604
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3605 newrows = 99999;
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3606 newcols = 99999;
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3607 for (twp = firstwin; ; twp = twp->w_next)
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3608 {
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3609 // Always use curwin, it may be a popup window.
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3610 win_T *wwp = twp == NULL ? curwin : twp;
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3611
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3612 // When more than one window shows the same terminal, use the
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3613 // smallest size.
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3614 if (wwp->w_buffer == term->tl_buffer)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3615 {
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3616 newrows = MIN(newrows, wwp->w_height);
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3617 newcols = MIN(newcols, wwp->w_width);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3618 }
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3619 if (twp == NULL)
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3620 break;
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3621 }
18162
9c3347b21b89 patch 8.1.2076: crash when trying to put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 18139
diff changeset
3622 if (newrows == 99999 || newcols == 99999)
9c3347b21b89 patch 8.1.2076: crash when trying to put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 18139
diff changeset
3623 return; // safety exit
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3624 newrows = rows == 0 ? newrows : minsize ? MAX(rows, newrows) : rows;
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3625 newcols = cols == 0 ? newcols : minsize ? MAX(cols, newcols) : cols;
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3626
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3627 if (term->tl_rows != newrows || term->tl_cols != newcols)
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3628 {
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3629 term->tl_vterm_size_changed = TRUE;
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3630 vterm_set_size(vterm, newrows, newcols);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3631 ch_log(term->tl_job->jv_channel, "Resizing terminal to %d lines",
13700
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3632 newrows);
b28d679b1843 patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13696
diff changeset
3633 term_report_winsize(term, newrows, newcols);
14311
83b870d9ac4b patch 8.1.0171: typing CTRL-W n in a terminal window causes ml_get error
Christian Brabandt <cb@256bit.org>
parents: 14301
diff changeset
3634
83b870d9ac4b patch 8.1.0171: typing CTRL-W n in a terminal window causes ml_get error
Christian Brabandt <cb@256bit.org>
parents: 14301
diff changeset
3635 // Updating the terminal size will cause the snapshot to be cleared.
83b870d9ac4b patch 8.1.0171: typing CTRL-W n in a terminal window causes ml_get error
Christian Brabandt <cb@256bit.org>
parents: 14301
diff changeset
3636 // When not in terminal_loop() we need to restore it.
83b870d9ac4b patch 8.1.0171: typing CTRL-W n in a terminal window causes ml_get error
Christian Brabandt <cb@256bit.org>
parents: 14301
diff changeset
3637 if (term != in_terminal_loop)
83b870d9ac4b patch 8.1.0171: typing CTRL-W n in a terminal window causes ml_get error
Christian Brabandt <cb@256bit.org>
parents: 14301
diff changeset
3638 may_move_terminal_to_buffer(term, FALSE);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3639 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3640
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3641 // The cursor may have been moved when resizing.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3642 vterm_state_get_cursorpos(state, &pos);
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3643 position_cursor(wp, &pos, FALSE);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3644
12578
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
3645 for (pos.row = term->tl_dirty_row_start; pos.row < term->tl_dirty_row_end
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
3646 && pos.row < wp->w_height; ++pos.row)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3647 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3648 if (pos.row < term->tl_rows)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3649 {
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3650 int max_col = MIN(wp->w_width, term->tl_cols);
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
3651
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3652 term_line2screenline(wp, screen, &pos, max_col);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3653 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3654 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3655 pos.col = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3656
13458
0e7a56b18d61 patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents: 13448
diff changeset
3657 screen_line(wp->w_winrow + pos.row
0e7a56b18d61 patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents: 13448
diff changeset
3658 #ifdef FEAT_MENU
0e7a56b18d61 patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents: 13448
diff changeset
3659 + winbar_height(wp)
0e7a56b18d61 patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents: 13448
diff changeset
3660 #endif
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3661 , wp->w_wincol, pos.col, wp->w_width,
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3662 #ifdef FEAT_PROP_POPUP
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3663 popup_is_popup(wp) ? SLF_POPUP :
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3664 #endif
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3665 0);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3666 }
12578
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
3667 term->tl_dirty_row_start = MAX_ROW;
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
3668 term->tl_dirty_row_end = 0;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3669 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3670
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3671 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3672 * Return TRUE if "wp" is a terminal window where the job has finished.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3673 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3674 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3675 term_is_finished(buf_T *buf)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3676 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3677 return buf->b_term != NULL && buf->b_term->tl_vterm == NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3678 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3679
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3680 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3681 * Return TRUE if "wp" is a terminal window where the job has finished or we
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3682 * are in Terminal-Normal mode, thus we show the buffer contents.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3683 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3684 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3685 term_show_buffer(buf_T *buf)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3686 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3687 term_T *term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3688
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3689 return term != NULL && (term->tl_vterm == NULL || term->tl_normal_mode);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3690 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3691
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3692 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3693 * The current buffer is going to be changed. If there is terminal
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3694 * highlighting remove it now.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3695 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3696 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3697 term_change_in_curbuf(void)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3698 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3699 term_T *term = curbuf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3700
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3701 if (term_is_finished(curbuf) && term->tl_scrollback.ga_len > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3702 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3703 free_scrollback(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3704 redraw_buf_later(term->tl_buffer, NOT_VALID);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3705
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3706 // The buffer is now like a normal buffer, it cannot be easily
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3707 // abandoned when changed.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3708 set_string_option_direct((char_u *)"buftype", -1,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3709 (char_u *)"", OPT_FREE|OPT_LOCAL, 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3710 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3711 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3712
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3713 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3714 * Get the screen attribute for a position in the buffer.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3715 * Use a negative "col" to get the filler background color.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3716 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3717 int
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3718 term_get_attr(win_T *wp, linenr_T lnum, int col)
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3719 {
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3720 buf_T *buf = wp->w_buffer;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3721 term_T *term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3722 sb_line_T *line;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3723 cellattr_T *cellattr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3724
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3725 if (lnum > term->tl_scrollback.ga_len)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3726 cellattr = &term->tl_default_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3727 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3728 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3729 line = (sb_line_T *)term->tl_scrollback.ga_data + lnum - 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3730 if (col < 0 || col >= line->sb_cols)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3731 cellattr = &line->sb_fill_attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3732 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3733 cellattr = line->sb_cells + col;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3734 }
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3735 return cell2attr(wp, cellattr->attrs, cellattr->fg, cellattr->bg);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3736 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3737
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3738 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3739 * Convert a cterm color number 0 - 255 to RGB.
12541
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
3740 * This is compatible with xterm.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3741 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3742 static void
13823
d0d8125ba692 patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13750
diff changeset
3743 cterm_color2vterm(int nr, VTermColor *rgb)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3744 {
13823
d0d8125ba692 patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13750
diff changeset
3745 cterm_color2rgb(nr, &rgb->red, &rgb->green, &rgb->blue, &rgb->ansi_index);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3746 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3747
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3748 /*
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3749 * Initialize term->tl_default_color from the environment.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3750 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3751 static void
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3752 init_default_colors(term_T *term, win_T *wp)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3753 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3754 VTermColor *fg, *bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3755 int fgval, bgval;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3756 int id;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3757
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3758 vim_memset(&term->tl_default_color.attrs, 0, sizeof(VTermScreenCellAttrs));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3759 term->tl_default_color.width = 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3760 fg = &term->tl_default_color.fg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3761 bg = &term->tl_default_color.bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3762
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3763 // Vterm uses a default black background. Set it to white when
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3764 // 'background' is "light".
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3765 if (*p_bg == 'l')
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3766 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3767 fgval = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3768 bgval = 255;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3769 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3770 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3771 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3772 fgval = 255;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3773 bgval = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3774 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3775 fg->red = fg->green = fg->blue = fgval;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3776 bg->red = bg->green = bg->blue = bgval;
12973
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3777 fg->ansi_index = bg->ansi_index = VTERM_ANSI_INDEX_DEFAULT;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3778
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3779 // The 'wincolor' or "Terminal" highlight group overrules the defaults.
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3780 if (wp != NULL && *wp->w_p_wcr != NUL)
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3781 id = syn_name2id(wp->w_p_wcr);
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3782 else
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
3783 id = syn_name2id((char_u *)"Terminal");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3784
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3785 // Use the actual color for the GUI and when 'termguicolors' is set.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3786 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3787 if (0
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3788 # ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3789 || gui.in_use
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3790 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3791 # ifdef FEAT_TERMGUICOLORS
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3792 || p_tgc
13823
d0d8125ba692 patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13750
diff changeset
3793 # ifdef FEAT_VTP
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3794 // Finally get INVALCOLOR on this execution path
13823
d0d8125ba692 patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13750
diff changeset
3795 || (!p_tgc && t_colors >= 256)
d0d8125ba692 patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13750
diff changeset
3796 # endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3797 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3798 )
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3799 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3800 guicolor_T fg_rgb = INVALCOLOR;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3801 guicolor_T bg_rgb = INVALCOLOR;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3802
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3803 if (id != 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3804 syn_id2colors(id, &fg_rgb, &bg_rgb);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3805
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3806 # ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3807 if (gui.in_use)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3808 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3809 if (fg_rgb == INVALCOLOR)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3810 fg_rgb = gui.norm_pixel;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3811 if (bg_rgb == INVALCOLOR)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3812 bg_rgb = gui.back_pixel;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3813 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3814 # ifdef FEAT_TERMGUICOLORS
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3815 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3816 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3817 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3818 # ifdef FEAT_TERMGUICOLORS
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3819 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3820 if (fg_rgb == INVALCOLOR)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3821 fg_rgb = cterm_normal_fg_gui_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3822 if (bg_rgb == INVALCOLOR)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3823 bg_rgb = cterm_normal_bg_gui_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3824 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3825 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3826 if (fg_rgb != INVALCOLOR)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3827 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3828 long_u rgb = GUI_MCH_GET_RGB(fg_rgb);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3829
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3830 fg->red = (unsigned)(rgb >> 16);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3831 fg->green = (unsigned)(rgb >> 8) & 255;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3832 fg->blue = (unsigned)rgb & 255;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3833 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3834 if (bg_rgb != INVALCOLOR)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3835 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3836 long_u rgb = GUI_MCH_GET_RGB(bg_rgb);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3837
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3838 bg->red = (unsigned)(rgb >> 16);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3839 bg->green = (unsigned)(rgb >> 8) & 255;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3840 bg->blue = (unsigned)rgb & 255;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3841 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3842 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3843 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3844 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3845 if (id != 0 && t_colors >= 16)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3846 {
12973
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3847 if (term_default_cterm_fg >= 0)
13823
d0d8125ba692 patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13750
diff changeset
3848 cterm_color2vterm(term_default_cterm_fg, fg);
12973
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3849 if (term_default_cterm_bg >= 0)
13823
d0d8125ba692 patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13750
diff changeset
3850 cterm_color2vterm(term_default_cterm_bg, bg);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3851 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3852 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3853 {
16451
7ae2396cef62 patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents: 16378
diff changeset
3854 #if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3855 int tmp;
12632
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
3856 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3857
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3858 // In an MS-Windows console we know the normal colors.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3859 if (cterm_normal_fg_color > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3860 {
13823
d0d8125ba692 patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13750
diff changeset
3861 cterm_color2vterm(cterm_normal_fg_color - 1, fg);
16451
7ae2396cef62 patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents: 16378
diff changeset
3862 # if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
7ae2396cef62 patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents: 16378
diff changeset
3863 # ifdef VIMDLL
7ae2396cef62 patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents: 16378
diff changeset
3864 if (!gui.in_use)
7ae2396cef62 patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents: 16378
diff changeset
3865 # endif
7ae2396cef62 patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents: 16378
diff changeset
3866 {
7ae2396cef62 patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents: 16378
diff changeset
3867 tmp = fg->red;
7ae2396cef62 patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents: 16378
diff changeset
3868 fg->red = fg->blue;
7ae2396cef62 patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents: 16378
diff changeset
3869 fg->blue = tmp;
7ae2396cef62 patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents: 16378
diff changeset
3870 }
12632
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
3871 # endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3872 }
12634
94566ecb55f0 patch 8.0.1195: can't build on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 12632
diff changeset
3873 # ifdef FEAT_TERMRESPONSE
12632
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
3874 else
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
3875 term_get_fg_color(&fg->red, &fg->green, &fg->blue);
12634
94566ecb55f0 patch 8.0.1195: can't build on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 12632
diff changeset
3876 # endif
12632
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
3877
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3878 if (cterm_normal_bg_color > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3879 {
13823
d0d8125ba692 patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13750
diff changeset
3880 cterm_color2vterm(cterm_normal_bg_color - 1, bg);
16451
7ae2396cef62 patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents: 16378
diff changeset
3881 # if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
7ae2396cef62 patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents: 16378
diff changeset
3882 # ifdef VIMDLL
7ae2396cef62 patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents: 16378
diff changeset
3883 if (!gui.in_use)
7ae2396cef62 patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents: 16378
diff changeset
3884 # endif
7ae2396cef62 patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents: 16378
diff changeset
3885 {
7ae2396cef62 patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents: 16378
diff changeset
3886 tmp = fg->red;
7ae2396cef62 patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents: 16378
diff changeset
3887 fg->red = fg->blue;
7ae2396cef62 patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents: 16378
diff changeset
3888 fg->blue = tmp;
7ae2396cef62 patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents: 16378
diff changeset
3889 }
12632
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
3890 # endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3891 }
12634
94566ecb55f0 patch 8.0.1195: can't build on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 12632
diff changeset
3892 # ifdef FEAT_TERMRESPONSE
12632
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
3893 else
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
3894 term_get_bg_color(&bg->red, &bg->green, &bg->blue);
12634
94566ecb55f0 patch 8.0.1195: can't build on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 12632
diff changeset
3895 # endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3896 }
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3897 }
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3898
13626
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3899 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3900 /*
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3901 * Set the 16 ANSI colors from array of RGB values
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3902 */
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3903 static void
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3904 set_vterm_palette(VTerm *vterm, long_u *rgb)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3905 {
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3906 int index = 0;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3907 VTermState *state = vterm_obtain_state(vterm);
15249
544490b69e1d patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 15217
diff changeset
3908
13626
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3909 for (; index < 16; index++)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3910 {
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3911 VTermColor color;
16283
1298cb5c1f72 patch 8.1.1146: in MS-Windows console colors in a terminal window are wrong
Bram Moolenaar <Bram@vim.org>
parents: 16253
diff changeset
3912
13626
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3913 color.red = (unsigned)(rgb[index] >> 16);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3914 color.green = (unsigned)(rgb[index] >> 8) & 255;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3915 color.blue = (unsigned)rgb[index] & 255;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3916 vterm_state_set_palette_color(state, index, &color);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3917 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3918 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3919
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3920 /*
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3921 * Set the ANSI color palette from a list of colors
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3922 */
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3923 static int
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3924 set_ansi_colors_list(VTerm *vterm, list_T *list)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3925 {
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3926 int n = 0;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3927 long_u rgb[16];
19241
c53dbbf3229b patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents: 18814
diff changeset
3928 listitem_T *li;
c53dbbf3229b patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents: 18814
diff changeset
3929
c53dbbf3229b patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents: 18814
diff changeset
3930 for (li = list->lv_first; li != NULL && n < 16; li = li->li_next, n++)
13626
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3931 {
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3932 char_u *color_name;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3933 guicolor_T guicolor;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3934
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15203
diff changeset
3935 color_name = tv_get_string_chk(&li->li_tv);
13626
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3936 if (color_name == NULL)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3937 return FAIL;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3938
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3939 guicolor = GUI_GET_COLOR(color_name);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3940 if (guicolor == INVALCOLOR)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3941 return FAIL;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3942
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3943 rgb[n] = GUI_MCH_GET_RGB(guicolor);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3944 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3945
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3946 if (n != 16 || li != NULL)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3947 return FAIL;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3948
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3949 set_vterm_palette(vterm, rgb);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3950
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3951 return OK;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3952 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3953
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3954 /*
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3955 * Initialize the ANSI color palette from g:terminal_ansi_colors[0:15]
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3956 */
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3957 static void
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3958 init_vterm_ansi_colors(VTerm *vterm)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3959 {
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3960 dictitem_T *var = find_var((char_u *)"g:terminal_ansi_colors", NULL, TRUE);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3961
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3962 if (var != NULL
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3963 && (var->di_tv.v_type != VAR_LIST
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3964 || var->di_tv.vval.v_list == NULL
19241
c53dbbf3229b patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents: 18814
diff changeset
3965 || var->di_tv.vval.v_list->lv_first == &range_list_item
13626
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3966 || set_ansi_colors_list(vterm, var->di_tv.vval.v_list) == FAIL))
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
3967 semsg(_(e_invarg2), "g:terminal_ansi_colors");
13626
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3968 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3969 #endif
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3970
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3971 /*
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3972 * Handles a "drop" command from the job in the terminal.
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3973 * "item" is the file name, "item->li_next" may have options.
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3974 */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3975 static void
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3976 handle_drop_command(listitem_T *item)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3977 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15203
diff changeset
3978 char_u *fname = tv_get_string(&item->li_tv);
13575
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3979 listitem_T *opt_item = item->li_next;
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3980 int bufnr;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3981 win_T *wp;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3982 tabpage_T *tp;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3983 exarg_T ea;
13575
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3984 char_u *tofree = NULL;
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3985
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3986 bufnr = buflist_add(fname, BLN_LISTED | BLN_NOOPT);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3987 FOR_ALL_TAB_WINDOWS(tp, wp)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3988 {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3989 if (wp->w_buffer->b_fnum == bufnr)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3990 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
3991 // buffer is in a window already, go there
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3992 goto_tabpage_win(tp, wp);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3993 return;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3994 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3995 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3996
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3997 vim_memset(&ea, 0, sizeof(ea));
13575
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3998
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3999 if (opt_item != NULL && opt_item->li_tv.v_type == VAR_DICT
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4000 && opt_item->li_tv.vval.v_dict != NULL)
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4001 {
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4002 dict_T *dict = opt_item->li_tv.vval.v_dict;
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4003 char_u *p;
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4004
15146
7903dce131d4 patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents: 15022
diff changeset
4005 p = dict_get_string(dict, (char_u *)"ff", FALSE);
13575
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4006 if (p == NULL)
15146
7903dce131d4 patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents: 15022
diff changeset
4007 p = dict_get_string(dict, (char_u *)"fileformat", FALSE);
13575
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4008 if (p != NULL)
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4009 {
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4010 if (check_ff_value(p) == FAIL)
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4011 ch_log(NULL, "Invalid ff argument to drop: %s", p);
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4012 else
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4013 ea.force_ff = *p;
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4014 }
15146
7903dce131d4 patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents: 15022
diff changeset
4015 p = dict_get_string(dict, (char_u *)"enc", FALSE);
13575
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4016 if (p == NULL)
15146
7903dce131d4 patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents: 15022
diff changeset
4017 p = dict_get_string(dict, (char_u *)"encoding", FALSE);
13575
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4018 if (p != NULL)
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4019 {
16782
fc58fee685e2 patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents: 16778
diff changeset
4020 ea.cmd = alloc(STRLEN(p) + 12);
13575
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4021 if (ea.cmd != NULL)
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4022 {
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4023 sprintf((char *)ea.cmd, "sbuf ++enc=%s", p);
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4024 ea.force_enc = 11;
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4025 tofree = ea.cmd;
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4026 }
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4027 }
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4028
15146
7903dce131d4 patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents: 15022
diff changeset
4029 p = dict_get_string(dict, (char_u *)"bad", FALSE);
13575
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4030 if (p != NULL)
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4031 get_bad_opt(p, &ea);
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4032
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4033 if (dict_find(dict, (char_u *)"bin", -1) != NULL)
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4034 ea.force_bin = FORCE_BIN;
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4035 if (dict_find(dict, (char_u *)"binary", -1) != NULL)
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4036 ea.force_bin = FORCE_BIN;
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4037 if (dict_find(dict, (char_u *)"nobin", -1) != NULL)
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4038 ea.force_bin = FORCE_NOBIN;
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4039 if (dict_find(dict, (char_u *)"nobinary", -1) != NULL)
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4040 ea.force_bin = FORCE_NOBIN;
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4041 }
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4042
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4043 // open in new window, like ":split fname"
13575
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4044 if (ea.cmd == NULL)
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4045 ea.cmd = (char_u *)"split";
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4046 ea.arg = fname;
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4047 ea.cmdidx = CMD_split;
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4048 ex_splitview(&ea);
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4049
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
4050 vim_free(tofree);
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4051 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4052
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4053 /*
18170
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
4054 * Return TRUE if "func" starts with "pat" and "pat" isn't empty.
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
4055 */
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
4056 static int
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
4057 is_permitted_term_api(char_u *func, char_u *pat)
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
4058 {
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
4059 return pat != NULL && *pat != NUL && STRNICMP(func, pat, STRLEN(pat)) == 0;
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
4060 }
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
4061
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
4062 /*
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4063 * Handles a function call from the job running in a terminal.
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4064 * "item" is the function name, "item->li_next" has the arguments.
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4065 */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4066 static void
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4067 handle_call_command(term_T *term, channel_T *channel, listitem_T *item)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4068 {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4069 char_u *func;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4070 typval_T argvars[2];
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4071 typval_T rettv;
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17186
diff changeset
4072 funcexe_T funcexe;
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4073
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4074 if (item->li_next == NULL)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4075 {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4076 ch_log(channel, "Missing function arguments for call");
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4077 return;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4078 }
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15203
diff changeset
4079 func = tv_get_string(&item->li_tv);
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4080
18170
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
4081 if (!is_permitted_term_api(func, term->tl_api))
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
4082 {
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
4083 ch_log(channel, "Unpermitted function: %s", func);
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4084 return;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4085 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4086
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4087 argvars[0].v_type = VAR_NUMBER;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4088 argvars[0].vval.v_number = term->tl_buffer->b_fnum;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4089 argvars[1] = item->li_next->li_tv;
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17186
diff changeset
4090 vim_memset(&funcexe, 0, sizeof(funcexe));
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17186
diff changeset
4091 funcexe.firstline = 1L;
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17186
diff changeset
4092 funcexe.lastline = 1L;
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17186
diff changeset
4093 funcexe.evaluate = TRUE;
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17186
diff changeset
4094 if (call_func(func, -1, &rettv, 2, argvars, &funcexe) == OK)
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4095 {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4096 clear_tv(&rettv);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4097 ch_log(channel, "Function %s called", func);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4098 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4099 else
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4100 ch_log(channel, "Calling function %s failed", func);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4101 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4102
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4103 /*
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4104 * Called by libvterm when it cannot recognize an OSC sequence.
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4105 * We recognize a terminal API command.
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4106 */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4107 static int
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4108 parse_osc(const char *command, size_t cmdlen, void *user)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4109 {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4110 term_T *term = (term_T *)user;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4111 js_read_T reader;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4112 typval_T tv;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4113 channel_T *channel = term->tl_job == NULL ? NULL
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4114 : term->tl_job->jv_channel;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4115
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4116 // We recognize only OSC 5 1 ; {command}
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4117 if (cmdlen < 3 || STRNCMP(command, "51;", 3) != 0)
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4118 return 0; // not handled
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4119
13577
4cb743db55b3 patch 8.0.1661: warnings from 64 bit compiler
Christian Brabandt <cb@256bit.org>
parents: 13575
diff changeset
4120 reader.js_buf = vim_strnsave((char_u *)command + 3, (int)(cmdlen - 3));
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4121 if (reader.js_buf == NULL)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4122 return 1;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4123 reader.js_fill = NULL;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4124 reader.js_used = 0;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4125 if (json_decode(&reader, &tv, 0) == OK
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4126 && tv.v_type == VAR_LIST
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4127 && tv.vval.v_list != NULL)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4128 {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4129 listitem_T *item = tv.vval.v_list->lv_first;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4130
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4131 if (item == NULL)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4132 ch_log(channel, "Missing command");
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4133 else
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4134 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15203
diff changeset
4135 char_u *cmd = tv_get_string(&item->li_tv);
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4136
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4137 // Make sure an invoked command doesn't delete the buffer (and the
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4138 // terminal) under our fingers.
13720
7d2039b2ecc8 patch 8.0.1732: crash when terminal API call deletes the buffer
Christian Brabandt <cb@256bit.org>
parents: 13700
diff changeset
4139 ++term->tl_buffer->b_locked;
7d2039b2ecc8 patch 8.0.1732: crash when terminal API call deletes the buffer
Christian Brabandt <cb@256bit.org>
parents: 13700
diff changeset
4140
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4141 item = item->li_next;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4142 if (item == NULL)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4143 ch_log(channel, "Missing argument for %s", cmd);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4144 else if (STRCMP(cmd, "drop") == 0)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4145 handle_drop_command(item);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4146 else if (STRCMP(cmd, "call") == 0)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4147 handle_call_command(term, channel, item);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4148 else
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4149 ch_log(channel, "Invalid command received: %s", cmd);
13720
7d2039b2ecc8 patch 8.0.1732: crash when terminal API call deletes the buffer
Christian Brabandt <cb@256bit.org>
parents: 13700
diff changeset
4150 --term->tl_buffer->b_locked;
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4151 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4152 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4153 else
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4154 ch_log(channel, "Invalid JSON received");
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4155
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4156 vim_free(reader.js_buf);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4157 clear_tv(&tv);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4158 return 1;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4159 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4160
16241
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4161 /*
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4162 * Called by libvterm when it cannot recognize a CSI sequence.
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4163 * We recognize the window position report.
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4164 */
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4165 static int
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4166 parse_csi(
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4167 const char *leader UNUSED,
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4168 const long args[],
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4169 int argcount,
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4170 const char *intermed UNUSED,
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4171 char command,
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4172 void *user)
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4173 {
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4174 term_T *term = (term_T *)user;
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4175 char buf[100];
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4176 int len;
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4177 int x = 0;
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4178 int y = 0;
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4179 win_T *wp;
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4180
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4181 // We recognize only CSI 13 t
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4182 if (command != 't' || argcount != 1 || args[0] != 13)
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4183 return 0; // not handled
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4184
16245
e0a6298bd70f patch 8.1.1127: getwinpos() doesn't work in terminal on MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents: 16241
diff changeset
4185 // When getting the window position is not possible or it fails it results
e0a6298bd70f patch 8.1.1127: getwinpos() doesn't work in terminal on MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents: 16241
diff changeset
4186 // in zero/zero.
16253
f28ef3d27f91 patch 8.1.1131: getwinpos() does not work in the MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents: 16245
diff changeset
4187 #if defined(FEAT_GUI) \
f28ef3d27f91 patch 8.1.1131: getwinpos() does not work in the MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents: 16245
diff changeset
4188 || (defined(HAVE_TGETENT) && defined(FEAT_TERMRESPONSE)) \
f28ef3d27f91 patch 8.1.1131: getwinpos() does not work in the MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents: 16245
diff changeset
4189 || defined(MSWIN)
16241
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4190 (void)ui_get_winpos(&x, &y, (varnumber_T)100);
16245
e0a6298bd70f patch 8.1.1127: getwinpos() doesn't work in terminal on MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents: 16241
diff changeset
4191 #endif
16241
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4192
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4193 FOR_ALL_WINDOWS(wp)
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4194 if (wp->w_buffer == term->tl_buffer)
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4195 break;
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4196 if (wp != NULL)
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4197 {
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4198 #ifdef FEAT_GUI
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4199 if (gui.in_use)
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4200 {
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4201 x += wp->w_wincol * gui.char_width;
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4202 y += W_WINROW(wp) * gui.char_height;
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4203 }
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4204 else
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4205 #endif
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4206 {
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4207 // We roughly estimate the position of the terminal window inside
16451
7ae2396cef62 patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents: 16378
diff changeset
4208 // the Vim window by assuming a 10 x 7 character cell.
16241
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4209 x += wp->w_wincol * 7;
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4210 y += W_WINROW(wp) * 10;
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4211 }
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4212 }
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4213
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4214 len = vim_snprintf(buf, 100, "\x1b[3;%d;%dt", x, y);
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4215 channel_send(term->tl_job->jv_channel, get_tty_part(term),
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4216 (char_u *)buf, len, NULL);
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4217 return 1;
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4218 }
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4219
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4220 static VTermParserCallbacks parser_fallbacks = {
16241
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4221 NULL, // text
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4222 NULL, // control
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4223 NULL, // escape
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4224 parse_csi, // csi
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4225 parse_osc, // osc
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4226 NULL, // dcs
c1698187c482 patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
4227 NULL // resize
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4228 };
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4229
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4230 /*
13616
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
4231 * Use Vim's allocation functions for vterm so profiling works.
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
4232 */
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
4233 static void *
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
4234 vterm_malloc(size_t size, void *data UNUSED)
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
4235 {
16768
695d9ef00b03 patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents: 16656
diff changeset
4236 return alloc_clear(size);
13616
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
4237 }
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
4238
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
4239 static void
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
4240 vterm_memfree(void *ptr, void *data UNUSED)
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
4241 {
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
4242 vim_free(ptr);
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
4243 }
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
4244
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
4245 static VTermAllocatorFunctions vterm_allocator = {
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
4246 &vterm_malloc,
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
4247 &vterm_memfree
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
4248 };
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
4249
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
4250 /*
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
4251 * Create a new vterm and initialize it.
15249
544490b69e1d patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 15217
diff changeset
4252 * Return FAIL when out of memory.
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
4253 */
15249
544490b69e1d patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 15217
diff changeset
4254 static int
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
4255 create_vterm(term_T *term, int rows, int cols)
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
4256 {
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
4257 VTerm *vterm;
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
4258 VTermScreen *screen;
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4259 VTermState *state;
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
4260 VTermValue value;
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
4261
13616
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
4262 vterm = vterm_new_with_allocator(rows, cols, &vterm_allocator, NULL);
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
4263 term->tl_vterm = vterm;
15249
544490b69e1d patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 15217
diff changeset
4264 if (vterm == NULL)
544490b69e1d patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 15217
diff changeset
4265 return FAIL;
544490b69e1d patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 15217
diff changeset
4266
544490b69e1d patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 15217
diff changeset
4267 // Allocate screen and state here, so we can bail out if that fails.
544490b69e1d patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 15217
diff changeset
4268 state = vterm_obtain_state(vterm);
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
4269 screen = vterm_obtain_screen(vterm);
15249
544490b69e1d patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 15217
diff changeset
4270 if (state == NULL || screen == NULL)
544490b69e1d patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 15217
diff changeset
4271 {
544490b69e1d patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 15217
diff changeset
4272 vterm_free(vterm);
544490b69e1d patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 15217
diff changeset
4273 return FAIL;
544490b69e1d patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 15217
diff changeset
4274 }
544490b69e1d patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 15217
diff changeset
4275
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
4276 vterm_screen_set_callbacks(screen, &screen_callbacks, term);
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4277 // TODO: depends on 'encoding'.
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
4278 vterm_set_utf8(vterm, 1);
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
4279
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
4280 init_default_colors(term, NULL);
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
4281
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
4282 vterm_state_set_default_colors(
15249
544490b69e1d patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 15217
diff changeset
4283 state,
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
4284 &term->tl_default_color.fg,
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
4285 &term->tl_default_color.bg);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4286
16656
e8c081146788 patch 8.1.1330: using bold attribute in terminal changes the color
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
4287 if (t_colors < 16)
e8c081146788 patch 8.1.1330: using bold attribute in terminal changes the color
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
4288 // Less than 16 colors: assume that bold means using a bright color for
e8c081146788 patch 8.1.1330: using bold attribute in terminal changes the color
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
4289 // the foreground color.
13626
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4290 vterm_state_set_bold_highbright(vterm_obtain_state(vterm), 1);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4291
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4292 // Required to initialize most things.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4293 vterm_screen_reset(screen, 1 /* hard */);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4294
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4295 // Allow using alternate screen.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4296 vterm_screen_enable_altscreen(screen, 1);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4297
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4298 // For unix do not use a blinking cursor. In an xterm this causes the
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4299 // cursor to blink if it's blinking in the xterm.
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4300 // For Windows we respect the system wide setting.
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15844
diff changeset
4301 #ifdef MSWIN
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4302 if (GetCaretBlinkTime() == INFINITE)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4303 value.boolean = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4304 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4305 value.boolean = 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4306 #else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4307 value.boolean = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4308 #endif
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4309 vterm_state_set_termprop(state, VTERM_PROP_CURSORBLINK, &value);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
4310 vterm_state_set_unrecognised_fallbacks(state, &parser_fallbacks, term);
15249
544490b69e1d patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 15217
diff changeset
4311
544490b69e1d patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 15217
diff changeset
4312 return OK;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4313 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4314
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4315 /*
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
4316 * Called when 'wincolor' was set.
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
4317 */
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
4318 void
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
4319 term_update_colors(void)
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
4320 {
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
4321 term_T *term = curwin->w_buffer->b_term;
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
4322
19358
734ca70c1f12 patch 8.2.0237: crash when setting 'wincolor' on finished terminal window
Bram Moolenaar <Bram@vim.org>
parents: 19275
diff changeset
4323 if (term->tl_vterm == NULL)
734ca70c1f12 patch 8.2.0237: crash when setting 'wincolor' on finished terminal window
Bram Moolenaar <Bram@vim.org>
parents: 19275
diff changeset
4324 return;
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
4325 init_default_colors(term, curwin);
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
4326 vterm_state_set_default_colors(
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
4327 vterm_obtain_state(term->tl_vterm),
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
4328 &term->tl_default_color.fg,
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
4329 &term->tl_default_color.bg);
19744
eb4887dd4b60 patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents: 19713
diff changeset
4330
eb4887dd4b60 patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents: 19713
diff changeset
4331 redraw_later(NOT_VALID);
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
4332 }
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
4333
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
4334 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4335 * Return the text to show for the buffer name and status.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4336 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4337 char_u *
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4338 term_get_status_text(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4339 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4340 if (term->tl_status_text == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4341 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4342 char_u *txt;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4343 size_t len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4344
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4345 if (term->tl_normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4346 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4347 if (term_job_running(term))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4348 txt = (char_u *)_("Terminal");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4349 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4350 txt = (char_u *)_("Terminal-finished");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4351 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4352 else if (term->tl_title != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4353 txt = term->tl_title;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4354 else if (term_none_open(term))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4355 txt = (char_u *)_("active");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4356 else if (term_job_running(term))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4357 txt = (char_u *)_("running");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4358 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4359 txt = (char_u *)_("finished");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4360 len = 9 + STRLEN(term->tl_buffer->b_fname) + STRLEN(txt);
16782
fc58fee685e2 patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents: 16778
diff changeset
4361 term->tl_status_text = alloc(len);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4362 if (term->tl_status_text != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4363 vim_snprintf((char *)term->tl_status_text, len, "%s [%s]",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4364 term->tl_buffer->b_fname, txt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4365 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4366 return term->tl_status_text;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4367 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4368
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4369 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4370 * Mark references in jobs of terminals.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4371 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4372 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4373 set_ref_in_term(int copyID)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4374 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4375 int abort = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4376 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4377 typval_T tv;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4378
17151
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 17133
diff changeset
4379 for (term = first_term; !abort && term != NULL; term = term->tl_next)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4380 if (term->tl_job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4381 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4382 tv.v_type = VAR_JOB;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4383 tv.vval.v_job = term->tl_job;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4384 abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4385 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4386 return abort;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4387 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4388
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4389 /*
12973
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
4390 * Cache "Terminal" highlight group colors.
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
4391 */
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
4392 void
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
4393 set_terminal_default_colors(int cterm_fg, int cterm_bg)
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
4394 {
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
4395 term_default_cterm_fg = cterm_fg - 1;
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
4396 term_default_cterm_bg = cterm_bg - 1;
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
4397 }
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
4398
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
4399 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4400 * Get the buffer from the first argument in "argvars".
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4401 * Returns NULL when the buffer is not for a terminal window and logs a message
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4402 * with "where".
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4403 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4404 static buf_T *
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4405 term_get_buf(typval_T *argvars, char *where)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4406 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4407 buf_T *buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4408
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4409 (void)tv_get_number(&argvars[0]); // issue errmsg if type error
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4410 ++emsg_off;
15355
73b153ed5af8 patch 8.1.0685: get_buf_tv() is named inconsistently
Bram Moolenaar <Bram@vim.org>
parents: 15273
diff changeset
4411 buf = tv_get_buf(&argvars[0], FALSE);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4412 --emsg_off;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4413 if (buf == NULL || buf->b_term == NULL)
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4414 {
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4415 ch_log(NULL, "%s: invalid buffer argument", where);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4416 return NULL;
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4417 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4418 return buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4419 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4420
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4421 static int
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4422 same_color(VTermColor *a, VTermColor *b)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4423 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4424 return a->red == b->red
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4425 && a->green == b->green
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4426 && a->blue == b->blue
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4427 && a->ansi_index == b->ansi_index;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4428 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4429
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4430 static void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4431 dump_term_color(FILE *fd, VTermColor *color)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4432 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4433 fprintf(fd, "%02x%02x%02x%d",
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4434 (int)color->red, (int)color->green, (int)color->blue,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4435 (int)color->ansi_index);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4436 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4437
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4438 /*
13329
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
4439 * "term_dumpwrite(buf, filename, options)" function
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4440 *
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4441 * Each screen cell in full is:
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4442 * |{characters}+{attributes}#{fg-color}{color-idx}#{bg-color}{color-idx}
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4443 * {characters} is a space for an empty cell
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4444 * For a double-width character "+" is changed to "*" and the next cell is
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4445 * skipped.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4446 * {attributes} is the decimal value of HL_BOLD + HL_UNDERLINE, etc.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4447 * when "&" use the same as the previous cell.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4448 * {fg-color} is hex RGB, when "&" use the same as the previous cell.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4449 * {bg-color} is hex RGB, when "&" use the same as the previous cell.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4450 * {color-idx} is a number from 0 to 255
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4451 *
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4452 * Screen cell with same width, attributes and color as the previous one:
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4453 * |{characters}
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4454 *
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4455 * To use the color of the previous cell, use "&" instead of {color}-{idx}.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4456 *
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4457 * Repeating the previous screen cell:
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4458 * @{count}
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4459 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4460 void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4461 f_term_dumpwrite(typval_T *argvars, typval_T *rettv UNUSED)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4462 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4463 buf_T *buf = term_get_buf(argvars, "term_dumpwrite()");
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4464 term_T *term;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4465 char_u *fname;
13329
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
4466 int max_height = 0;
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
4467 int max_width = 0;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4468 stat_T st;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4469 FILE *fd;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4470 VTermPos pos;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4471 VTermScreen *screen;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4472 VTermScreenCell prev_cell;
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4473 VTermState *state;
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4474 VTermPos cursor_pos;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4475
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4476 if (check_restricted() || check_secure())
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4477 return;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4478 if (buf == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4479 return;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4480 term = buf->b_term;
14691
e2497d9c51c4 patch 8.1.0358: crash when using term_dumpwrite() after the job finished
Christian Brabandt <cb@256bit.org>
parents: 14625
diff changeset
4481 if (term->tl_vterm == NULL)
e2497d9c51c4 patch 8.1.0358: crash when using term_dumpwrite() after the job finished
Christian Brabandt <cb@256bit.org>
parents: 14625
diff changeset
4482 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
4483 emsg(_("E958: Job already finished"));
14691
e2497d9c51c4 patch 8.1.0358: crash when using term_dumpwrite() after the job finished
Christian Brabandt <cb@256bit.org>
parents: 14625
diff changeset
4484 return;
e2497d9c51c4 patch 8.1.0358: crash when using term_dumpwrite() after the job finished
Christian Brabandt <cb@256bit.org>
parents: 14625
diff changeset
4485 }
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4486
13329
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
4487 if (argvars[2].v_type != VAR_UNKNOWN)
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
4488 {
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
4489 dict_T *d;
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
4490
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
4491 if (argvars[2].v_type != VAR_DICT)
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
4492 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
4493 emsg(_(e_dictreq));
13329
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
4494 return;
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
4495 }
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
4496 d = argvars[2].vval.v_dict;
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
4497 if (d != NULL)
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
4498 {
15146
7903dce131d4 patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents: 15022
diff changeset
4499 max_height = dict_get_number(d, (char_u *)"rows");
7903dce131d4 patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents: 15022
diff changeset
4500 max_width = dict_get_number(d, (char_u *)"columns");
13329
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
4501 }
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
4502 }
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
4503
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15203
diff changeset
4504 fname = tv_get_string_chk(&argvars[1]);
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4505 if (fname == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4506 return;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4507 if (mch_stat((char *)fname, &st) >= 0)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4508 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
4509 semsg(_("E953: File exists: %s"), fname);
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4510 return;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4511 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4512
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4513 if (*fname == NUL || (fd = mch_fopen((char *)fname, WRITEBIN)) == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4514 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
4515 semsg(_(e_notcreate), *fname == NUL ? (char_u *)_("<empty>") : fname);
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4516 return;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4517 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4518
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4519 vim_memset(&prev_cell, 0, sizeof(prev_cell));
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4520
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4521 screen = vterm_obtain_screen(term->tl_vterm);
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4522 state = vterm_obtain_state(term->tl_vterm);
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4523 vterm_state_get_cursorpos(state, &cursor_pos);
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4524
13329
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
4525 for (pos.row = 0; (max_height == 0 || pos.row < max_height)
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
4526 && pos.row < term->tl_rows; ++pos.row)
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4527 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4528 int repeat = 0;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4529
13329
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
4530 for (pos.col = 0; (max_width == 0 || pos.col < max_width)
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
4531 && pos.col < term->tl_cols; ++pos.col)
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4532 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4533 VTermScreenCell cell;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4534 int same_attr;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4535 int same_chars = TRUE;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4536 int i;
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4537 int is_cursor_pos = (pos.col == cursor_pos.col
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4538 && pos.row == cursor_pos.row);
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4539
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4540 if (vterm_screen_get_cell(screen, pos, &cell) == 0)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4541 vim_memset(&cell, 0, sizeof(cell));
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4542
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4543 for (i = 0; i < VTERM_MAX_CHARS_PER_CELL; ++i)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4544 {
13517
d0d66898e98b patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents: 13505
diff changeset
4545 int c = cell.chars[i];
d0d66898e98b patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents: 13505
diff changeset
4546 int pc = prev_cell.chars[i];
d0d66898e98b patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents: 13505
diff changeset
4547
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4548 // For the first character NUL is the same as space.
13517
d0d66898e98b patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents: 13505
diff changeset
4549 if (i == 0)
d0d66898e98b patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents: 13505
diff changeset
4550 {
d0d66898e98b patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents: 13505
diff changeset
4551 c = (c == NUL) ? ' ' : c;
d0d66898e98b patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents: 13505
diff changeset
4552 pc = (pc == NUL) ? ' ' : pc;
d0d66898e98b patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents: 13505
diff changeset
4553 }
14625
cd3f0987c0bc patch 8.1.0326: screen dump does not consider NUL and space equal
Christian Brabandt <cb@256bit.org>
parents: 14459
diff changeset
4554 if (c != pc)
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4555 same_chars = FALSE;
14625
cd3f0987c0bc patch 8.1.0326: screen dump does not consider NUL and space equal
Christian Brabandt <cb@256bit.org>
parents: 14459
diff changeset
4556 if (c == NUL || pc == NUL)
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4557 break;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4558 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4559 same_attr = vtermAttr2hl(cell.attrs)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4560 == vtermAttr2hl(prev_cell.attrs)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4561 && same_color(&cell.fg, &prev_cell.fg)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4562 && same_color(&cell.bg, &prev_cell.bg);
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4563 if (same_chars && cell.width == prev_cell.width && same_attr
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4564 && !is_cursor_pos)
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4565 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4566 ++repeat;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4567 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4568 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4569 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4570 if (repeat > 0)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4571 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4572 fprintf(fd, "@%d", repeat);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4573 repeat = 0;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4574 }
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4575 fputs(is_cursor_pos ? ">" : "|", fd);
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4576
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4577 if (cell.chars[0] == NUL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4578 fputs(" ", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4579 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4580 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4581 char_u charbuf[10];
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4582 int len;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4583
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4584 for (i = 0; i < VTERM_MAX_CHARS_PER_CELL
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4585 && cell.chars[i] != NUL; ++i)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4586 {
13557
4911058c43eb patch 8.0.1652: term_dumpwrite() does not output composing characters
Christian Brabandt <cb@256bit.org>
parents: 13547
diff changeset
4587 len = utf_char2bytes(cell.chars[i], charbuf);
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4588 fwrite(charbuf, len, 1, fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4589 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4590 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4591
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4592 // When only the characters differ we don't write anything, the
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4593 // following "|", "@" or NL will indicate using the same
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4594 // attributes.
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4595 if (cell.width != prev_cell.width || !same_attr)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4596 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4597 if (cell.width == 2)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4598 fputs("*", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4599 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4600 fputs("+", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4601
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4602 if (same_attr)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4603 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4604 fputs("&", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4605 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4606 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4607 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4608 fprintf(fd, "%d", vtermAttr2hl(cell.attrs));
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4609 if (same_color(&cell.fg, &prev_cell.fg))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4610 fputs("&", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4611 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4612 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4613 fputs("#", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4614 dump_term_color(fd, &cell.fg);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4615 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4616 if (same_color(&cell.bg, &prev_cell.bg))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4617 fputs("&", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4618 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4619 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4620 fputs("#", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4621 dump_term_color(fd, &cell.bg);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4622 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4623 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4624 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4625
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4626 prev_cell = cell;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4627 }
15504
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4628
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4629 if (cell.width == 2)
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4630 ++pos.col;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4631 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4632 if (repeat > 0)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4633 fprintf(fd, "@%d", repeat);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4634 fputs("\n", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4635 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4636
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4637 fclose(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4638 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4639
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4640 /*
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4641 * Called when a dump is corrupted. Put a breakpoint here when debugging.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4642 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4643 static void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4644 dump_is_corrupt(garray_T *gap)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4645 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4646 ga_concat(gap, (char_u *)"CORRUPT");
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4647 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4648
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4649 static void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4650 append_cell(garray_T *gap, cellattr_T *cell)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4651 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4652 if (ga_grow(gap, 1) == OK)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4653 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4654 *(((cellattr_T *)gap->ga_data) + gap->ga_len) = *cell;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4655 ++gap->ga_len;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4656 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4657 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4658
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4659 /*
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4660 * Read the dump file from "fd" and append lines to the current buffer.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4661 * Return the cell width of the longest line.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4662 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4663 static int
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4664 read_dump_file(FILE *fd, VTermPos *cursor_pos)
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4665 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4666 int c;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4667 garray_T ga_text;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4668 garray_T ga_cell;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4669 char_u *prev_char = NULL;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4670 int attr = 0;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4671 cellattr_T cell;
15504
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4672 cellattr_T empty_cell;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4673 term_T *term = curbuf->b_term;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4674 int max_cells = 0;
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4675 int start_row = term->tl_scrollback.ga_len;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4676
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4677 ga_init2(&ga_text, 1, 90);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4678 ga_init2(&ga_cell, sizeof(cellattr_T), 90);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4679 vim_memset(&cell, 0, sizeof(cell));
15504
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4680 vim_memset(&empty_cell, 0, sizeof(empty_cell));
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4681 cursor_pos->row = -1;
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4682 cursor_pos->col = -1;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4683
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4684 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4685 for (;;)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4686 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4687 if (c == EOF)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4688 break;
14960
47931abb9f31 patch 8.1.0491: if a terminal dump has CR it is considered corrupt
Bram Moolenaar <Bram@vim.org>
parents: 14939
diff changeset
4689 if (c == '\r')
47931abb9f31 patch 8.1.0491: if a terminal dump has CR it is considered corrupt
Bram Moolenaar <Bram@vim.org>
parents: 14939
diff changeset
4690 {
47931abb9f31 patch 8.1.0491: if a terminal dump has CR it is considered corrupt
Bram Moolenaar <Bram@vim.org>
parents: 14939
diff changeset
4691 // DOS line endings? Ignore.
47931abb9f31 patch 8.1.0491: if a terminal dump has CR it is considered corrupt
Bram Moolenaar <Bram@vim.org>
parents: 14939
diff changeset
4692 c = fgetc(fd);
47931abb9f31 patch 8.1.0491: if a terminal dump has CR it is considered corrupt
Bram Moolenaar <Bram@vim.org>
parents: 14939
diff changeset
4693 }
47931abb9f31 patch 8.1.0491: if a terminal dump has CR it is considered corrupt
Bram Moolenaar <Bram@vim.org>
parents: 14939
diff changeset
4694 else if (c == '\n')
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4695 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4696 // End of a line: append it to the buffer.
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4697 if (ga_text.ga_data == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4698 dump_is_corrupt(&ga_text);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4699 if (ga_grow(&term->tl_scrollback, 1) == OK)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4700 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4701 sb_line_T *line = (sb_line_T *)term->tl_scrollback.ga_data
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4702 + term->tl_scrollback.ga_len;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4703
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4704 if (max_cells < ga_cell.ga_len)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4705 max_cells = ga_cell.ga_len;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4706 line->sb_cols = ga_cell.ga_len;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4707 line->sb_cells = ga_cell.ga_data;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4708 line->sb_fill_attr = term->tl_default_color;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4709 ++term->tl_scrollback.ga_len;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4710 ga_init(&ga_cell);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4711
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4712 ga_append(&ga_text, NUL);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4713 ml_append(curbuf->b_ml.ml_line_count, ga_text.ga_data,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4714 ga_text.ga_len, FALSE);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4715 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4716 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4717 ga_clear(&ga_cell);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4718 ga_text.ga_len = 0;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4719
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4720 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4721 }
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4722 else if (c == '|' || c == '>')
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4723 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4724 int prev_len = ga_text.ga_len;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4725
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4726 if (c == '>')
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4727 {
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4728 if (cursor_pos->row != -1)
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4729 dump_is_corrupt(&ga_text); // duplicate cursor
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4730 cursor_pos->row = term->tl_scrollback.ga_len - start_row;
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4731 cursor_pos->col = ga_cell.ga_len;
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4732 }
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4733
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4734 // normal character(s) followed by "+", "*", "|", "@" or NL
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4735 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4736 if (c != EOF)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4737 ga_append(&ga_text, c);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4738 for (;;)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4739 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4740 c = fgetc(fd);
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4741 if (c == '+' || c == '*' || c == '|' || c == '>' || c == '@'
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4742 || c == EOF || c == '\n')
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4743 break;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4744 ga_append(&ga_text, c);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4745 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4746
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4747 // save the character for repeating it
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4748 vim_free(prev_char);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4749 if (ga_text.ga_data != NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4750 prev_char = vim_strnsave(((char_u *)ga_text.ga_data) + prev_len,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4751 ga_text.ga_len - prev_len);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4752
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4753 if (c == '@' || c == '|' || c == '>' || c == '\n')
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4754 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4755 // use all attributes from previous cell
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4756 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4757 else if (c == '+' || c == '*')
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4758 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4759 int is_bg;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4760
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4761 cell.width = c == '+' ? 1 : 2;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4762
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4763 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4764 if (c == '&')
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4765 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4766 // use same attr as previous cell
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4767 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4768 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4769 else if (isdigit(c))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4770 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4771 // get the decimal attribute
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4772 attr = 0;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4773 while (isdigit(c))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4774 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4775 attr = attr * 10 + (c - '0');
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4776 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4777 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4778 hl2vtermAttr(attr, &cell);
15504
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4779
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4780 // is_bg == 0: fg, is_bg == 1: bg
15504
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4781 for (is_bg = 0; is_bg <= 1; ++is_bg)
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4782 {
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4783 if (c == '&')
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4784 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4785 // use same color as previous cell
15504
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4786 c = fgetc(fd);
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4787 }
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4788 else if (c == '#')
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4789 {
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4790 int red, green, blue, index = 0;
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4791
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4792 c = fgetc(fd);
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4793 red = hex2nr(c);
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4794 c = fgetc(fd);
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4795 red = (red << 4) + hex2nr(c);
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4796 c = fgetc(fd);
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4797 green = hex2nr(c);
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4798 c = fgetc(fd);
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4799 green = (green << 4) + hex2nr(c);
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4800 c = fgetc(fd);
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4801 blue = hex2nr(c);
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4802 c = fgetc(fd);
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4803 blue = (blue << 4) + hex2nr(c);
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4804 c = fgetc(fd);
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4805 if (!isdigit(c))
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4806 dump_is_corrupt(&ga_text);
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4807 while (isdigit(c))
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4808 {
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4809 index = index * 10 + (c - '0');
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4810 c = fgetc(fd);
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4811 }
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4812
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4813 if (is_bg)
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4814 {
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4815 cell.bg.red = red;
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4816 cell.bg.green = green;
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4817 cell.bg.blue = blue;
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4818 cell.bg.ansi_index = index;
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4819 }
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4820 else
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4821 {
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4822 cell.fg.red = red;
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4823 cell.fg.green = green;
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4824 cell.fg.blue = blue;
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4825 cell.fg.ansi_index = index;
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4826 }
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4827 }
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4828 else
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4829 dump_is_corrupt(&ga_text);
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4830 }
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4831 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4832 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4833 dump_is_corrupt(&ga_text);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4834 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4835 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4836 dump_is_corrupt(&ga_text);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4837
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4838 append_cell(&ga_cell, &cell);
15504
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4839 if (cell.width == 2)
247511eadb7a patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4840 append_cell(&ga_cell, &empty_cell);
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4841 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4842 else if (c == '@')
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4843 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4844 if (prev_char == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4845 dump_is_corrupt(&ga_text);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4846 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4847 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4848 int count = 0;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4849
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4850 // repeat previous character, get the count
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4851 for (;;)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4852 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4853 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4854 if (!isdigit(c))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4855 break;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4856 count = count * 10 + (c - '0');
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4857 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4858
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4859 while (count-- > 0)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4860 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4861 ga_concat(&ga_text, prev_char);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4862 append_cell(&ga_cell, &cell);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4863 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4864 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4865 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4866 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4867 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4868 dump_is_corrupt(&ga_text);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4869 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4870 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4871 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4872
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4873 if (ga_text.ga_len > 0)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4874 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4875 // trailing characters after last NL
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4876 dump_is_corrupt(&ga_text);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4877 ga_append(&ga_text, NUL);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4878 ml_append(curbuf->b_ml.ml_line_count, ga_text.ga_data,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4879 ga_text.ga_len, FALSE);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4880 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4881
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4882 ga_clear(&ga_text);
18225
6c3a8312486d patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents: 18170
diff changeset
4883 ga_clear(&ga_cell);
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4884 vim_free(prev_char);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4885
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4886 return max_cells;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4887 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4888
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4889 /*
13579
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4890 * Return an allocated string with at least "text_width" "=" characters and
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4891 * "fname" inserted in the middle.
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4892 */
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4893 static char_u *
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4894 get_separator(int text_width, char_u *fname)
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4895 {
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4896 int width = MAX(text_width, curwin->w_width);
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4897 char_u *textline;
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4898 int fname_size;
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4899 char_u *p = fname;
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4900 int i;
13630
fd3389d64825 patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents: 13626
diff changeset
4901 size_t off;
fd3389d64825 patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents: 13626
diff changeset
4902
fd3389d64825 patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents: 13626
diff changeset
4903 textline = alloc(width + (int)STRLEN(fname) + 1);
13579
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4904 if (textline == NULL)
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4905 return NULL;
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4906
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4907 fname_size = vim_strsize(fname);
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4908 if (fname_size < width - 8)
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4909 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4910 // enough room, don't use the full window width
13579
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4911 width = MAX(text_width, fname_size + 8);
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4912 }
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4913 else if (fname_size > width - 8)
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4914 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4915 // full name doesn't fit, use only the tail
13579
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4916 p = gettail(fname);
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4917 fname_size = vim_strsize(p);
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4918 }
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4919 // skip characters until the name fits
13579
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4920 while (fname_size > width - 8)
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4921 {
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4922 p += (*mb_ptr2len)(p);
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4923 fname_size = vim_strsize(p);
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4924 }
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4925
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4926 for (i = 0; i < (width - fname_size) / 2 - 1; ++i)
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4927 textline[i] = '=';
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4928 textline[i++] = ' ';
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4929
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4930 STRCPY(textline + i, p);
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4931 off = STRLEN(textline);
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4932 textline[off] = ' ';
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4933 for (i = 1; i < (width - fname_size) / 2; ++i)
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4934 textline[off + i] = '=';
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4935 textline[off + i] = NUL;
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4936
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4937 return textline;
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4938 }
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4939
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4940 /*
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4941 * Common for "term_dumpdiff()" and "term_dumpload()".
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4942 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4943 static void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4944 term_load_dump(typval_T *argvars, typval_T *rettv, int do_diff)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4945 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4946 jobopt_T opt;
16912
a5e3509b33ca patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
4947 buf_T *buf = NULL;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4948 char_u buf1[NUMBUFLEN];
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4949 char_u buf2[NUMBUFLEN];
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4950 char_u *fname1;
13300
803294329951 patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents: 13298
diff changeset
4951 char_u *fname2 = NULL;
13501
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4952 char_u *fname_tofree = NULL;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4953 FILE *fd1;
13300
803294329951 patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents: 13298
diff changeset
4954 FILE *fd2 = NULL;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4955 char_u *textline = NULL;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4956
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
4957 // First open the files. If this fails bail out.
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15203
diff changeset
4958 fname1 = tv_get_string_buf_chk(&argvars[0], buf1);
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4959 if (do_diff)
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15203
diff changeset
4960 fname2 = tv_get_string_buf_chk(&argvars[1], buf2);
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4961 if (fname1 == NULL || (do_diff && fname2 == NULL))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4962 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
4963 emsg(_(e_invarg));
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4964 return;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4965 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4966 fd1 = mch_fopen((char *)fname1, READBIN);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4967 if (fd1 == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4968 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
4969 semsg(_(e_notread), fname1);
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4970 return;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4971 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4972 if (do_diff)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4973 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4974 fd2 = mch_fopen((char *)fname2, READBIN);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4975 if (fd2 == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4976 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4977 fclose(fd1);
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
4978 semsg(_(e_notread), fname2);
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4979 return;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4980 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4981 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4982
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4983 init_job_options(&opt);
13501
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4984 if (argvars[do_diff ? 2 : 1].v_type != VAR_UNKNOWN
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4985 && get_job_options(&argvars[do_diff ? 2 : 1], &opt, 0,
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4986 JO2_TERM_NAME + JO2_TERM_COLS + JO2_TERM_ROWS
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4987 + JO2_VERTICAL + JO2_CURWIN + JO2_NORESTORE) == FAIL)
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4988 goto theend;
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4989
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4990 if (opt.jo_term_name == NULL)
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4991 {
13505
a784ef72b617 patch 8.0.1626: compiler warning for possible loss of data
Christian Brabandt <cb@256bit.org>
parents: 13501
diff changeset
4992 size_t len = STRLEN(fname1) + 12;
a784ef72b617 patch 8.0.1626: compiler warning for possible loss of data
Christian Brabandt <cb@256bit.org>
parents: 13501
diff changeset
4993
16782
fc58fee685e2 patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents: 16778
diff changeset
4994 fname_tofree = alloc(len);
13501
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4995 if (fname_tofree != NULL)
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4996 {
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4997 vim_snprintf((char *)fname_tofree, len, "dump diff %s", fname1);
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4998 opt.jo_term_name = fname_tofree;
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4999 }
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
5000 }
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5001
16912
a5e3509b33ca patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5002 if (opt.jo_bufnr_buf != NULL)
a5e3509b33ca patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5003 {
a5e3509b33ca patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5004 win_T *wp = buf_jump_open_win(opt.jo_bufnr_buf);
a5e3509b33ca patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5005
a5e3509b33ca patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5006 // With "bufnr" argument: enter the window with this buffer and make it
a5e3509b33ca patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5007 // empty.
a5e3509b33ca patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5008 if (wp == NULL)
a5e3509b33ca patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5009 semsg(_(e_invarg2), "bufnr");
a5e3509b33ca patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5010 else
a5e3509b33ca patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5011 {
a5e3509b33ca patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5012 buf = curbuf;
a5e3509b33ca patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5013 while (!(curbuf->b_ml.ml_flags & ML_EMPTY))
a5e3509b33ca patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5014 ml_delete((linenr_T)1, FALSE);
18225
6c3a8312486d patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents: 18170
diff changeset
5015 free_scrollback(curbuf->b_term);
16912
a5e3509b33ca patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5016 redraw_later(NOT_VALID);
a5e3509b33ca patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5017 }
a5e3509b33ca patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5018 }
a5e3509b33ca patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5019 else
a5e3509b33ca patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5020 // Create a new terminal window.
a5e3509b33ca patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5021 buf = term_start(&argvars[0], NULL, &opt, TERM_START_NOJOB);
a5e3509b33ca patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
5022
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5023 if (buf != NULL && buf->b_term != NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5024 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5025 int i;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5026 linenr_T bot_lnum;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5027 linenr_T lnum;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5028 term_T *term = buf->b_term;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5029 int width;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5030 int width2;
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
5031 VTermPos cursor_pos1;
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
5032 VTermPos cursor_pos2;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5033
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
5034 init_default_colors(term, NULL);
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
5035
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5036 rettv->vval.v_number = buf->b_fnum;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5037
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5038 // read the files, fill the buffer with the diff
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
5039 width = read_dump_file(fd1, &cursor_pos1);
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
5040
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5041 // position the cursor
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
5042 if (cursor_pos1.row >= 0)
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
5043 {
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
5044 curwin->w_cursor.lnum = cursor_pos1.row + 1;
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
5045 coladvance(cursor_pos1.col);
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
5046 }
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5047
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5048 // Delete the empty line that was in the empty buffer.
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5049 ml_delete(1, FALSE);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5050
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5051 // For term_dumpload() we are done here.
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5052 if (!do_diff)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5053 goto theend;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5054
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5055 term->tl_top_diff_rows = curbuf->b_ml.ml_line_count;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5056
13579
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
5057 textline = get_separator(width, fname1);
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5058 if (textline == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5059 goto theend;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5060 if (add_empty_scrollback(term, &term->tl_default_color, 0) == OK)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5061 ml_append(curbuf->b_ml.ml_line_count, textline, 0, FALSE);
13579
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
5062 vim_free(textline);
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
5063
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
5064 textline = get_separator(width, fname2);
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
5065 if (textline == NULL)
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
5066 goto theend;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5067 if (add_empty_scrollback(term, &term->tl_default_color, 0) == OK)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5068 ml_append(curbuf->b_ml.ml_line_count, textline, 0, FALSE);
13579
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
5069 textline[width] = NUL;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5070
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5071 bot_lnum = curbuf->b_ml.ml_line_count;
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
5072 width2 = read_dump_file(fd2, &cursor_pos2);
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5073 if (width2 > width)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5074 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5075 vim_free(textline);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5076 textline = alloc(width2 + 1);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5077 if (textline == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5078 goto theend;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5079 width = width2;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5080 textline[width] = NUL;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5081 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5082 term->tl_bot_diff_rows = curbuf->b_ml.ml_line_count - bot_lnum;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5083
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5084 for (lnum = 1; lnum <= term->tl_top_diff_rows; ++lnum)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5085 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5086 if (lnum + bot_lnum > curbuf->b_ml.ml_line_count)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5087 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5088 // bottom part has fewer rows, fill with "-"
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5089 for (i = 0; i < width; ++i)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5090 textline[i] = '-';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5091 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5092 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5093 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5094 char_u *line1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5095 char_u *line2;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5096 char_u *p1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5097 char_u *p2;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5098 int col;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5099 sb_line_T *sb_line = (sb_line_T *)term->tl_scrollback.ga_data;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5100 cellattr_T *cellattr1 = (sb_line + lnum - 1)->sb_cells;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5101 cellattr_T *cellattr2 = (sb_line + lnum + bot_lnum - 1)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5102 ->sb_cells;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5103
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5104 // Make a copy, getting the second line will invalidate it.
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5105 line1 = vim_strsave(ml_get(lnum));
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5106 if (line1 == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5107 break;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5108 p1 = line1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5109
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5110 line2 = ml_get(lnum + bot_lnum);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5111 p2 = line2;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5112 for (col = 0; col < width && *p1 != NUL && *p2 != NUL; ++col)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5113 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5114 int len1 = utfc_ptr2len(p1);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5115 int len2 = utfc_ptr2len(p2);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5116
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5117 textline[col] = ' ';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5118 if (len1 != len2 || STRNCMP(p1, p2, len1) != 0)
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5119 // text differs
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5120 textline[col] = 'X';
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
5121 else if (lnum == cursor_pos1.row + 1
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
5122 && col == cursor_pos1.col
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
5123 && (cursor_pos1.row != cursor_pos2.row
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
5124 || cursor_pos1.col != cursor_pos2.col))
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5125 // cursor in first but not in second
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
5126 textline[col] = '>';
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
5127 else if (lnum == cursor_pos2.row + 1
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
5128 && col == cursor_pos2.col
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
5129 && (cursor_pos1.row != cursor_pos2.row
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
5130 || cursor_pos1.col != cursor_pos2.col))
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5131 // cursor in second but not in first
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
5132 textline[col] = '<';
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5133 else if (cellattr1 != NULL && cellattr2 != NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5134 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5135 if ((cellattr1 + col)->width
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5136 != (cellattr2 + col)->width)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5137 textline[col] = 'w';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5138 else if (!same_color(&(cellattr1 + col)->fg,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5139 &(cellattr2 + col)->fg))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5140 textline[col] = 'f';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5141 else if (!same_color(&(cellattr1 + col)->bg,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5142 &(cellattr2 + col)->bg))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5143 textline[col] = 'b';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5144 else if (vtermAttr2hl((cellattr1 + col)->attrs)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5145 != vtermAttr2hl(((cellattr2 + col)->attrs)))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5146 textline[col] = 'a';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5147 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5148 p1 += len1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5149 p2 += len2;
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5150 // TODO: handle different width
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5151 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5152
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5153 while (col < width)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5154 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5155 if (*p1 == NUL && *p2 == NUL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5156 textline[col] = '?';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5157 else if (*p1 == NUL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5158 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5159 textline[col] = '+';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5160 p2 += utfc_ptr2len(p2);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5161 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5162 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5163 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5164 textline[col] = '-';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5165 p1 += utfc_ptr2len(p1);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5166 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5167 ++col;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5168 }
15828
8f112782a2e9 patch 8.1.0921: terminal test sometimes fails; using memory after free
Bram Moolenaar <Bram@vim.org>
parents: 15826
diff changeset
5169
8f112782a2e9 patch 8.1.0921: terminal test sometimes fails; using memory after free
Bram Moolenaar <Bram@vim.org>
parents: 15826
diff changeset
5170 vim_free(line1);
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5171 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5172 if (add_empty_scrollback(term, &term->tl_default_color,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5173 term->tl_top_diff_rows) == OK)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5174 ml_append(term->tl_top_diff_rows + lnum, textline, 0, FALSE);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5175 ++bot_lnum;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5176 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5177
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5178 while (lnum + bot_lnum <= curbuf->b_ml.ml_line_count)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5179 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5180 // bottom part has more rows, fill with "+"
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5181 for (i = 0; i < width; ++i)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5182 textline[i] = '+';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5183 if (add_empty_scrollback(term, &term->tl_default_color,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5184 term->tl_top_diff_rows) == OK)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5185 ml_append(term->tl_top_diff_rows + lnum, textline, 0, FALSE);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5186 ++lnum;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5187 ++bot_lnum;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5188 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5189
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5190 term->tl_cols = width;
13579
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
5191
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5192 // looks better without wrapping
13579
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
5193 curwin->w_p_wrap = 0;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5194 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5195
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5196 theend:
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5197 vim_free(textline);
13501
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
5198 vim_free(fname_tofree);
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5199 fclose(fd1);
13300
803294329951 patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents: 13298
diff changeset
5200 if (fd2 != NULL)
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5201 fclose(fd2);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5202 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5203
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5204 /*
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5205 * If the current buffer shows the output of term_dumpdiff(), swap the top and
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5206 * bottom files.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5207 * Return FAIL when this is not possible.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5208 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5209 int
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5210 term_swap_diff()
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5211 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5212 term_T *term = curbuf->b_term;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5213 linenr_T line_count;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5214 linenr_T top_rows;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5215 linenr_T bot_rows;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5216 linenr_T bot_start;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5217 linenr_T lnum;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5218 char_u *p;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5219 sb_line_T *sb_line;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5220
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5221 if (term == NULL
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5222 || !term_is_finished(curbuf)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5223 || term->tl_top_diff_rows == 0
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5224 || term->tl_scrollback.ga_len == 0)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5225 return FAIL;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5226
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5227 line_count = curbuf->b_ml.ml_line_count;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5228 top_rows = term->tl_top_diff_rows;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5229 bot_rows = term->tl_bot_diff_rows;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5230 bot_start = line_count - bot_rows;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5231 sb_line = (sb_line_T *)term->tl_scrollback.ga_data;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5232
15832
85c94163c4ab patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents: 15828
diff changeset
5233 // move lines from top to above the bottom part
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5234 for (lnum = 1; lnum <= top_rows; ++lnum)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5235 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5236 p = vim_strsave(ml_get(1));
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5237 if (p == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5238 return OK;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5239 ml_append(bot_start, p, 0, FALSE);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5240 ml_delete(1, FALSE);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5241 vim_free(p);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5242 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5243
15832
85c94163c4ab patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents: 15828
diff changeset
5244 // move lines from bottom to the top
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5245 for (lnum = 1; lnum <= bot_rows; ++lnum)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5246 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5247 p = vim_strsave(ml_get(bot_start + lnum));
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5248 if (p == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5249 return OK;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5250 ml_delete(bot_start + lnum, FALSE);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5251 ml_append(lnum - 1, p, 0, FALSE);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5252 vim_free(p);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5253 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5254
15832
85c94163c4ab patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents: 15828
diff changeset
5255 // move top title to bottom
85c94163c4ab patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents: 15828
diff changeset
5256 p = vim_strsave(ml_get(bot_rows + 1));
85c94163c4ab patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents: 15828
diff changeset
5257 if (p == NULL)
85c94163c4ab patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents: 15828
diff changeset
5258 return OK;
85c94163c4ab patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents: 15828
diff changeset
5259 ml_append(line_count - top_rows - 1, p, 0, FALSE);
85c94163c4ab patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents: 15828
diff changeset
5260 ml_delete(bot_rows + 1, FALSE);
85c94163c4ab patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents: 15828
diff changeset
5261 vim_free(p);
85c94163c4ab patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents: 15828
diff changeset
5262
85c94163c4ab patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents: 15828
diff changeset
5263 // move bottom title to top
85c94163c4ab patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents: 15828
diff changeset
5264 p = vim_strsave(ml_get(line_count - top_rows));
85c94163c4ab patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents: 15828
diff changeset
5265 if (p == NULL)
85c94163c4ab patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents: 15828
diff changeset
5266 return OK;
85c94163c4ab patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents: 15828
diff changeset
5267 ml_delete(line_count - top_rows, FALSE);
85c94163c4ab patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents: 15828
diff changeset
5268 ml_append(bot_rows, p, 0, FALSE);
85c94163c4ab patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents: 15828
diff changeset
5269 vim_free(p);
85c94163c4ab patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents: 15828
diff changeset
5270
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5271 if (top_rows == bot_rows)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5272 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5273 // rows counts are equal, can swap cell properties
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5274 for (lnum = 0; lnum < top_rows; ++lnum)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5275 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5276 sb_line_T temp;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5277
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5278 temp = *(sb_line + lnum);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5279 *(sb_line + lnum) = *(sb_line + bot_start + lnum);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5280 *(sb_line + bot_start + lnum) = temp;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5281 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5282 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5283 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5284 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5285 size_t size = sizeof(sb_line_T) * term->tl_scrollback.ga_len;
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16782
diff changeset
5286 sb_line_T *temp = alloc(size);
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5287
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5288 // need to copy cell properties into temp memory
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5289 if (temp != NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5290 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5291 mch_memmove(temp, term->tl_scrollback.ga_data, size);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5292 mch_memmove(term->tl_scrollback.ga_data,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5293 temp + bot_start,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5294 sizeof(sb_line_T) * bot_rows);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5295 mch_memmove((sb_line_T *)term->tl_scrollback.ga_data + bot_rows,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5296 temp + top_rows,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5297 sizeof(sb_line_T) * (line_count - top_rows - bot_rows));
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5298 mch_memmove((sb_line_T *)term->tl_scrollback.ga_data
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5299 + line_count - top_rows,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5300 temp,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5301 sizeof(sb_line_T) * top_rows);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5302 vim_free(temp);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5303 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5304 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5305
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5306 term->tl_top_diff_rows = bot_rows;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5307 term->tl_bot_diff_rows = top_rows;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5308
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5309 update_screen(NOT_VALID);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5310 return OK;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5311 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5312
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5313 /*
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5314 * "term_dumpdiff(filename, filename, options)" function
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5315 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5316 void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5317 f_term_dumpdiff(typval_T *argvars, typval_T *rettv)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5318 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5319 term_load_dump(argvars, rettv, TRUE);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5320 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5321
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5322 /*
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5323 * "term_dumpload(filename, options)" function
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5324 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5325 void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5326 f_term_dumpload(typval_T *argvars, typval_T *rettv)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5327 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5328 term_load_dump(argvars, rettv, FALSE);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5329 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
5330
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5331 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5332 * "term_getaltscreen(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5333 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5334 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5335 f_term_getaltscreen(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5336 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5337 buf_T *buf = term_get_buf(argvars, "term_getaltscreen()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5338
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5339 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5340 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5341 rettv->vval.v_number = buf->b_term->tl_using_altscreen;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5342 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5343
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5344 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5345 * "term_getattr(attr, name)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5346 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5347 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5348 f_term_getattr(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5349 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5350 int attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5351 size_t i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5352 char_u *name;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5353
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5354 static struct {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5355 char *name;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5356 int attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5357 } attrs[] = {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5358 {"bold", HL_BOLD},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5359 {"italic", HL_ITALIC},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5360 {"underline", HL_UNDERLINE},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5361 {"strike", HL_STRIKETHROUGH},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5362 {"reverse", HL_INVERSE},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5363 };
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5364
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15203
diff changeset
5365 attr = tv_get_number(&argvars[0]);
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15203
diff changeset
5366 name = tv_get_string_chk(&argvars[1]);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5367 if (name == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5368 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5369
18033
049a7481d737 patch 8.1.2012: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17702
diff changeset
5370 if (attr > HL_ALL)
049a7481d737 patch 8.1.2012: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17702
diff changeset
5371 attr = syn_attr2attr(attr);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5372 for (i = 0; i < sizeof(attrs)/sizeof(attrs[0]); ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5373 if (STRCMP(name, attrs[i].name) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5374 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5375 rettv->vval.v_number = (attr & attrs[i].attr) != 0 ? 1 : 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5376 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5377 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5378 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5379
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5380 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5381 * "term_getcursor(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5382 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5383 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5384 f_term_getcursor(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5385 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5386 buf_T *buf = term_get_buf(argvars, "term_getcursor()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5387 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5388 list_T *l;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5389 dict_T *d;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5390
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5391 if (rettv_list_alloc(rettv) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5392 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5393 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5394 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5395 term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5396
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5397 l = rettv->vval.v_list;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5398 list_append_number(l, term->tl_cursor_pos.row + 1);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5399 list_append_number(l, term->tl_cursor_pos.col + 1);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5400
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5401 d = dict_alloc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5402 if (d != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5403 {
14301
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 14139
diff changeset
5404 dict_add_number(d, "visible", term->tl_cursor_visible);
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 14139
diff changeset
5405 dict_add_number(d, "blink", blink_state_is_inverted()
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 14139
diff changeset
5406 ? !term->tl_cursor_blink : term->tl_cursor_blink);
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 14139
diff changeset
5407 dict_add_number(d, "shape", term->tl_cursor_shape);
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 14139
diff changeset
5408 dict_add_string(d, "color", cursor_color_get(term->tl_cursor_color));
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5409 list_append_dict(l, d);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5410 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5411 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5412
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5413 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5414 * "term_getjob(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5415 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5416 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5417 f_term_getjob(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5418 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5419 buf_T *buf = term_get_buf(argvars, "term_getjob()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5420
15217
49bc670c3ee9 patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
5421 if (buf == NULL)
49bc670c3ee9 patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
5422 {
49bc670c3ee9 patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
5423 rettv->v_type = VAR_SPECIAL;
49bc670c3ee9 patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
5424 rettv->vval.v_number = VVAL_NULL;
49bc670c3ee9 patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
5425 return;
49bc670c3ee9 patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
5426 }
49bc670c3ee9 patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents: 15211
diff changeset
5427
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5428 rettv->v_type = VAR_JOB;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5429 rettv->vval.v_job = buf->b_term->tl_job;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5430 if (rettv->vval.v_job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5431 ++rettv->vval.v_job->jv_refcount;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5432 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5433
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5434 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5435 get_row_number(typval_T *tv, term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5436 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5437 if (tv->v_type == VAR_STRING
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5438 && tv->vval.v_string != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5439 && STRCMP(tv->vval.v_string, ".") == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5440 return term->tl_cursor_pos.row;
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15203
diff changeset
5441 return (int)tv_get_number(tv) - 1;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5442 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5443
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5444 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5445 * "term_getline(buf, row)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5446 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5447 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5448 f_term_getline(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5449 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5450 buf_T *buf = term_get_buf(argvars, "term_getline()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5451 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5452 int row;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5453
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5454 rettv->v_type = VAR_STRING;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5455 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5456 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5457 term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5458 row = get_row_number(&argvars[1], term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5459
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5460 if (term->tl_vterm == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5461 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5462 linenr_T lnum = row + term->tl_scrollback_scrolled + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5463
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5464 // vterm is finished, get the text from the buffer
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5465 if (lnum > 0 && lnum <= buf->b_ml.ml_line_count)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5466 rettv->vval.v_string = vim_strsave(ml_get_buf(buf, lnum, FALSE));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5467 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5468 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5469 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5470 VTermScreen *screen = vterm_obtain_screen(term->tl_vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5471 VTermRect rect;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5472 int len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5473 char_u *p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5474
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5475 if (row < 0 || row >= term->tl_rows)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5476 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5477 len = term->tl_cols * MB_MAXBYTES + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5478 p = alloc(len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5479 if (p == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5480 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5481 rettv->vval.v_string = p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5482
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5483 rect.start_col = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5484 rect.end_col = term->tl_cols;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5485 rect.start_row = row;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5486 rect.end_row = row + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5487 p[vterm_screen_get_text(screen, (char *)p, len, rect)] = NUL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5488 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5489 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5490
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5491 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5492 * "term_getscrolled(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5493 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5494 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5495 f_term_getscrolled(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5496 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5497 buf_T *buf = term_get_buf(argvars, "term_getscrolled()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5498
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5499 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5500 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5501 rettv->vval.v_number = buf->b_term->tl_scrollback_scrolled;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5502 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5503
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5504 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5505 * "term_getsize(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5506 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5507 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5508 f_term_getsize(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5509 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5510 buf_T *buf = term_get_buf(argvars, "term_getsize()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5511 list_T *l;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5512
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5513 if (rettv_list_alloc(rettv) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5514 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5515 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5516 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5517
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5518 l = rettv->vval.v_list;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5519 list_append_number(l, buf->b_term->tl_rows);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5520 list_append_number(l, buf->b_term->tl_cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5521 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5522
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5523 /*
13678
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
5524 * "term_setsize(buf, rows, cols)" function
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
5525 */
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
5526 void
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
5527 f_term_setsize(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
5528 {
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
5529 buf_T *buf = term_get_buf(argvars, "term_setsize()");
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
5530 term_T *term;
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
5531 varnumber_T rows, cols;
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
5532
13684
1651a4c5c27a patch 8.0.1714: term_setsize() does not give an error in a normal buffer
Christian Brabandt <cb@256bit.org>
parents: 13680
diff changeset
5533 if (buf == NULL)
1651a4c5c27a patch 8.0.1714: term_setsize() does not give an error in a normal buffer
Christian Brabandt <cb@256bit.org>
parents: 13680
diff changeset
5534 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
5535 emsg(_("E955: Not a terminal buffer"));
13684
1651a4c5c27a patch 8.0.1714: term_setsize() does not give an error in a normal buffer
Christian Brabandt <cb@256bit.org>
parents: 13680
diff changeset
5536 return;
1651a4c5c27a patch 8.0.1714: term_setsize() does not give an error in a normal buffer
Christian Brabandt <cb@256bit.org>
parents: 13680
diff changeset
5537 }
1651a4c5c27a patch 8.0.1714: term_setsize() does not give an error in a normal buffer
Christian Brabandt <cb@256bit.org>
parents: 13680
diff changeset
5538 if (buf->b_term->tl_vterm == NULL)
13678
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
5539 return;
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
5540 term = buf->b_term;
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15203
diff changeset
5541 rows = tv_get_number(&argvars[1]);
13678
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
5542 rows = rows <= 0 ? term->tl_rows : rows;
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15203
diff changeset
5543 cols = tv_get_number(&argvars[2]);
13678
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
5544 cols = cols <= 0 ? term->tl_cols : cols;
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
5545 vterm_set_size(term->tl_vterm, rows, cols);
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5546 // handle_resize() will resize the windows
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5547
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5548 // Get and remember the size we ended up with. Update the pty.
13678
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
5549 vterm_get_size(term->tl_vterm, &term->tl_rows, &term->tl_cols);
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
5550 term_report_winsize(term, term->tl_rows, term->tl_cols);
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
5551 }
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
5552
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
5553 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5554 * "term_getstatus(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5555 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5556 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5557 f_term_getstatus(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5558 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5559 buf_T *buf = term_get_buf(argvars, "term_getstatus()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5560 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5561 char_u val[100];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5562
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5563 rettv->v_type = VAR_STRING;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5564 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5565 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5566 term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5567
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5568 if (term_job_running(term))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5569 STRCPY(val, "running");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5570 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5571 STRCPY(val, "finished");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5572 if (term->tl_normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5573 STRCAT(val, ",normal");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5574 rettv->vval.v_string = vim_strsave(val);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5575 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5576
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5577 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5578 * "term_gettitle(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5579 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5580 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5581 f_term_gettitle(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5582 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5583 buf_T *buf = term_get_buf(argvars, "term_gettitle()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5584
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5585 rettv->v_type = VAR_STRING;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5586 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5587 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5588
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5589 if (buf->b_term->tl_title != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5590 rettv->vval.v_string = vim_strsave(buf->b_term->tl_title);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5591 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5592
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5593 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5594 * "term_gettty(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5595 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5596 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5597 f_term_gettty(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5598 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5599 buf_T *buf = term_get_buf(argvars, "term_gettty()");
13864
de8455bd2d05 patch 8.0.1803: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents: 13862
diff changeset
5600 char_u *p = NULL;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5601 int num = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5602
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5603 rettv->v_type = VAR_STRING;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5604 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5605 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5606 if (argvars[1].v_type != VAR_UNKNOWN)
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15203
diff changeset
5607 num = tv_get_number(&argvars[1]);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5608
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5609 switch (num)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5610 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5611 case 0:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5612 if (buf->b_term->tl_job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5613 p = buf->b_term->tl_job->jv_tty_out;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5614 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5615 case 1:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5616 if (buf->b_term->tl_job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5617 p = buf->b_term->tl_job->jv_tty_in;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5618 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5619 default:
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
5620 semsg(_(e_invarg2), tv_get_string(&argvars[1]));
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5621 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5622 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5623 if (p != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5624 rettv->vval.v_string = vim_strsave(p);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5625 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5626
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5627 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5628 * "term_list()" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5629 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5630 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5631 f_term_list(typval_T *argvars UNUSED, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5632 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5633 term_T *tp;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5634 list_T *l;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5635
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5636 if (rettv_list_alloc(rettv) == FAIL || first_term == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5637 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5638
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5639 l = rettv->vval.v_list;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5640 for (tp = first_term; tp != NULL; tp = tp->tl_next)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5641 if (tp != NULL && tp->tl_buffer != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5642 if (list_append_number(l,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5643 (varnumber_T)tp->tl_buffer->b_fnum) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5644 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5645 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5646
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5647 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5648 * "term_scrape(buf, row)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5649 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5650 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5651 f_term_scrape(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5652 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5653 buf_T *buf = term_get_buf(argvars, "term_scrape()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5654 VTermScreen *screen = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5655 VTermPos pos;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5656 list_T *l;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5657 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5658 char_u *p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5659 sb_line_T *line;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5660
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5661 if (rettv_list_alloc(rettv) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5662 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5663 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5664 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5665 term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5666
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5667 l = rettv->vval.v_list;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5668 pos.row = get_row_number(&argvars[1], term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5669
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5670 if (term->tl_vterm != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5671 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5672 screen = vterm_obtain_screen(term->tl_vterm);
15273
19272aa12962 patch 8.1.0645: Coverity warns for possible use of NULL pointer
Bram Moolenaar <Bram@vim.org>
parents: 15249
diff changeset
5673 if (screen == NULL) // can't really happen
19272aa12962 patch 8.1.0645: Coverity warns for possible use of NULL pointer
Bram Moolenaar <Bram@vim.org>
parents: 15249
diff changeset
5674 return;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5675 p = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5676 line = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5677 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5678 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5679 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5680 linenr_T lnum = pos.row + term->tl_scrollback_scrolled;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5681
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5682 if (lnum < 0 || lnum >= term->tl_scrollback.ga_len)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5683 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5684 p = ml_get_buf(buf, lnum + 1, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5685 line = (sb_line_T *)term->tl_scrollback.ga_data + lnum;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5686 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5687
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5688 for (pos.col = 0; pos.col < term->tl_cols; )
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5689 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5690 dict_T *dcell;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5691 int width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5692 VTermScreenCellAttrs attrs;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5693 VTermColor fg, bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5694 char_u rgb[8];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5695 char_u mbs[MB_MAXBYTES * VTERM_MAX_CHARS_PER_CELL + 1];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5696 int off = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5697 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5698
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5699 if (screen == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5700 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5701 cellattr_T *cellattr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5702 int len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5703
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5704 // vterm has finished, get the cell from scrollback
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5705 if (pos.col >= line->sb_cols)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5706 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5707 cellattr = line->sb_cells + pos.col;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5708 width = cellattr->width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5709 attrs = cellattr->attrs;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5710 fg = cellattr->fg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5711 bg = cellattr->bg;
18251
c8a53c0daeed patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18225
diff changeset
5712 len = mb_ptr2len(p);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5713 mch_memmove(mbs, p, len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5714 mbs[len] = NUL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5715 p += len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5716 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5717 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5718 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5719 VTermScreenCell cell;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5720 if (vterm_screen_get_cell(screen, pos, &cell) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5721 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5722 for (i = 0; i < VTERM_MAX_CHARS_PER_CELL; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5723 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5724 if (cell.chars[i] == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5725 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5726 off += (*utf_char2bytes)((int)cell.chars[i], mbs + off);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5727 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5728 mbs[off] = NUL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5729 width = cell.width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5730 attrs = cell.attrs;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5731 fg = cell.fg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5732 bg = cell.bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5733 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5734 dcell = dict_alloc();
13250
fc33325c91c1 patch 8.0.1499: out-of-memory situation not correctly handled
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
5735 if (dcell == NULL)
fc33325c91c1 patch 8.0.1499: out-of-memory situation not correctly handled
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
5736 break;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5737 list_append_dict(l, dcell);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5738
14301
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 14139
diff changeset
5739 dict_add_string(dcell, "chars", mbs);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5740
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5741 vim_snprintf((char *)rgb, 8, "#%02x%02x%02x",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5742 fg.red, fg.green, fg.blue);
14301
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 14139
diff changeset
5743 dict_add_string(dcell, "fg", rgb);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5744 vim_snprintf((char *)rgb, 8, "#%02x%02x%02x",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5745 bg.red, bg.green, bg.blue);
14301
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 14139
diff changeset
5746 dict_add_string(dcell, "bg", rgb);
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 14139
diff changeset
5747
19265
ce8c47ed54e5 patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 19245
diff changeset
5748 dict_add_number(dcell, "attr", cell2attr(NULL, attrs, fg, bg));
14301
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 14139
diff changeset
5749 dict_add_number(dcell, "width", width);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5750
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5751 ++pos.col;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5752 if (width == 2)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5753 ++pos.col;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5754 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5755 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5756
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5757 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5758 * "term_sendkeys(buf, keys)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5759 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5760 void
19633
dd3e5533a7d2 patch 8.2.0373: type of term_sendkeys() is unknown
Bram Moolenaar <Bram@vim.org>
parents: 19629
diff changeset
5761 f_term_sendkeys(typval_T *argvars, typval_T *rettv UNUSED)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5762 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5763 buf_T *buf = term_get_buf(argvars, "term_sendkeys()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5764 char_u *msg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5765 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5766
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5767 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5768 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5769
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15203
diff changeset
5770 msg = tv_get_string_chk(&argvars[1]);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5771 if (msg == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5772 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5773 term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5774 if (term->tl_vterm == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5775 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5776
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5777 while (*msg != NUL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5778 {
14029
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 13996
diff changeset
5779 int c;
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 13996
diff changeset
5780
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 13996
diff changeset
5781 if (*msg == K_SPECIAL && msg[1] != NUL && msg[2] != NUL)
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 13996
diff changeset
5782 {
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 13996
diff changeset
5783 c = TO_SPECIAL(msg[1], msg[2]);
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 13996
diff changeset
5784 msg += 3;
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 13996
diff changeset
5785 }
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 13996
diff changeset
5786 else
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 13996
diff changeset
5787 {
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 13996
diff changeset
5788 c = PTR2CHAR(msg);
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 13996
diff changeset
5789 msg += MB_CPTR2LEN(msg);
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 13996
diff changeset
5790 }
18508
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
5791 send_keys_to_term(term, c, 0, FALSE);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5792 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5793 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5794
13626
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5795 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) || defined(PROTO)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5796 /*
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5797 * "term_getansicolors(buf)" function
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5798 */
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5799 void
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5800 f_term_getansicolors(typval_T *argvars, typval_T *rettv)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5801 {
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5802 buf_T *buf = term_get_buf(argvars, "term_getansicolors()");
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5803 term_T *term;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5804 VTermState *state;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5805 VTermColor color;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5806 char_u hexbuf[10];
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5807 int index;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5808 list_T *list;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5809
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5810 if (rettv_list_alloc(rettv) == FAIL)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5811 return;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5812
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5813 if (buf == NULL)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5814 return;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5815 term = buf->b_term;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5816 if (term->tl_vterm == NULL)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5817 return;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5818
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5819 list = rettv->vval.v_list;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5820 state = vterm_obtain_state(term->tl_vterm);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5821 for (index = 0; index < 16; index++)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5822 {
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5823 vterm_state_get_palette_color(state, index, &color);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5824 sprintf((char *)hexbuf, "#%02x%02x%02x",
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5825 color.red, color.green, color.blue);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5826 if (list_append_string(list, hexbuf, 7) == FAIL)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5827 return;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5828 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5829 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5830
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5831 /*
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5832 * "term_setansicolors(buf, list)" function
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5833 */
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5834 void
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5835 f_term_setansicolors(typval_T *argvars, typval_T *rettv UNUSED)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5836 {
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5837 buf_T *buf = term_get_buf(argvars, "term_setansicolors()");
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5838 term_T *term;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5839
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5840 if (buf == NULL)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5841 return;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5842 term = buf->b_term;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5843 if (term->tl_vterm == NULL)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5844 return;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5845
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5846 if (argvars[1].v_type != VAR_LIST || argvars[1].vval.v_list == NULL)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5847 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
5848 emsg(_(e_listreq));
13626
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5849 return;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5850 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5851
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5852 if (set_ansi_colors_list(term->tl_vterm, argvars[1].vval.v_list) == FAIL)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
5853 emsg(_(e_invarg));
13626
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5854 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5855 #endif
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5856
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5857 /*
18170
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
5858 * "term_setapi(buf, api)" function
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
5859 */
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
5860 void
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
5861 f_term_setapi(typval_T *argvars, typval_T *rettv UNUSED)
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
5862 {
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
5863 buf_T *buf = term_get_buf(argvars, "term_setapi()");
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
5864 term_T *term;
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
5865 char_u *api;
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
5866
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
5867 if (buf == NULL)
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
5868 return;
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
5869 term = buf->b_term;
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
5870 vim_free(term->tl_api);
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
5871 api = tv_get_string_chk(&argvars[1]);
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
5872 if (api != NULL)
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
5873 term->tl_api = vim_strsave(api);
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
5874 else
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
5875 term->tl_api = NULL;
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
5876 }
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
5877
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
5878 /*
13435
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5879 * "term_setrestore(buf, command)" function
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5880 */
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5881 void
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5882 f_term_setrestore(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5883 {
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5884 #if defined(FEAT_SESSION)
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5885 buf_T *buf = term_get_buf(argvars, "term_setrestore()");
13435
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5886 term_T *term;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5887 char_u *cmd;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5888
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5889 if (buf == NULL)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5890 return;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5891 term = buf->b_term;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5892 vim_free(term->tl_command);
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15203
diff changeset
5893 cmd = tv_get_string_chk(&argvars[1]);
13435
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5894 if (cmd != NULL)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5895 term->tl_command = vim_strsave(cmd);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5896 else
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5897 term->tl_command = NULL;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5898 #endif
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5899 }
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5900
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5901 /*
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5902 * "term_setkill(buf, how)" function
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5903 */
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5904 void
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5905 f_term_setkill(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5906 {
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5907 buf_T *buf = term_get_buf(argvars, "term_setkill()");
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5908 term_T *term;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5909 char_u *how;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5910
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5911 if (buf == NULL)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5912 return;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5913 term = buf->b_term;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5914 vim_free(term->tl_kill);
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15203
diff changeset
5915 how = tv_get_string_chk(&argvars[1]);
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5916 if (how != NULL)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5917 term->tl_kill = vim_strsave(how);
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5918 else
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5919 term->tl_kill = NULL;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5920 }
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5921
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5922 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5923 * "term_start(command, options)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5924 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5925 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5926 f_term_start(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5927 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5928 jobopt_T opt;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5929 buf_T *buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5930
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5931 init_job_options(&opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5932 if (argvars[1].v_type != VAR_UNKNOWN
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5933 && get_job_options(&argvars[1], &opt,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5934 JO_TIMEOUT_ALL + JO_STOPONEXIT
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5935 + JO_CALLBACK + JO_OUT_CALLBACK + JO_ERR_CALLBACK
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5936 + JO_EXIT_CB + JO_CLOSE_CALLBACK + JO_OUT_IO,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5937 JO2_TERM_NAME + JO2_TERM_FINISH + JO2_HIDDEN + JO2_TERM_OPENCMD
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5938 + JO2_TERM_COLS + JO2_TERM_ROWS + JO2_VERTICAL + JO2_CURWIN
13435
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
5939 + JO2_CWD + JO2_ENV + JO2_EOF_CHARS
13626
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5940 + JO2_NORESTORE + JO2_TERM_KILL
18170
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 18162
diff changeset
5941 + JO2_ANSI_COLORS + JO2_TTY_TYPE + JO2_TERM_API) == FAIL)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5942 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5943
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
5944 buf = term_start(&argvars[0], NULL, &opt, 0);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5945
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5946 if (buf != NULL && buf->b_term != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5947 rettv->vval.v_number = buf->b_fnum;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5948 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5949
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5950 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5951 * "term_wait" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5952 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5953 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5954 f_term_wait(typval_T *argvars, typval_T *rettv UNUSED)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5955 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5956 buf_T *buf = term_get_buf(argvars, "term_wait()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5957
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5958 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5959 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5960 if (buf->b_term->tl_job == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5961 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5962 ch_log(NULL, "term_wait(): no job to wait for");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5963 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5964 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5965 if (buf->b_term->tl_job->jv_channel == NULL)
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5966 // channel is closed, nothing to do
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5967 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5968
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5969 // Get the job status, this will detect a job that finished.
13219
4b8d89ea9edb patch 8.0.1484: reduntant conditions
Christian Brabandt <cb@256bit.org>
parents: 13206
diff changeset
5970 if (!buf->b_term->tl_job->jv_channel->ch_keep_open
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5971 && STRCMP(job_status(buf->b_term->tl_job), "dead") == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5972 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5973 // The job is dead, keep reading channel I/O until the channel is
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5974 // closed. buf->b_term may become NULL if the terminal was closed while
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5975 // waiting.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5976 ch_log(NULL, "term_wait(): waiting for channel to close");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5977 while (buf->b_term != NULL && !buf->b_term->tl_channel_closed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5978 {
17186
278583ff5e44 patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
5979 term_flush_messages();
278583ff5e44 patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
5980
13996
59121ffd7fce patch 8.1.0016: possible crash in term_wait()
Christian Brabandt <cb@256bit.org>
parents: 13994
diff changeset
5981 ui_delay(10L, FALSE);
12881
1c05b29ab125 patch 8.0.1317: accessing freed memory in term_wait()
Christian Brabandt <cb@256bit.org>
parents: 12865
diff changeset
5982 if (!buf_valid(buf))
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5983 // If the terminal is closed when the channel is closed the
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5984 // buffer disappears.
12881
1c05b29ab125 patch 8.0.1317: accessing freed memory in term_wait()
Christian Brabandt <cb@256bit.org>
parents: 12865
diff changeset
5985 break;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5986 }
17186
278583ff5e44 patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
5987
278583ff5e44 patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
5988 term_flush_messages();
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5989 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5990 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5991 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5992 long wait = 10L;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5993
17186
278583ff5e44 patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
5994 term_flush_messages();
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5995
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
5996 // Wait for some time for any channel I/O.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5997 if (argvars[1].v_type != VAR_UNKNOWN)
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15203
diff changeset
5998 wait = tv_get_number(&argvars[1]);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5999 ui_delay(wait, TRUE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6000
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6001 // Flushing messages on channels is hopefully sufficient.
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6002 // TODO: is there a better way?
17186
278583ff5e44 patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
6003 term_flush_messages();
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6004 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6005 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6006
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6007 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6008 * Called when a channel has sent all the lines to a terminal.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6009 * Send a CTRL-D to mark the end of the text.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6010 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6011 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6012 term_send_eof(channel_T *ch)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6013 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6014 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6015
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6016 for (term = first_term; term != NULL; term = term->tl_next)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6017 if (term->tl_job == ch->ch_job)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6018 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6019 if (term->tl_eof_chars != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6020 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6021 channel_send(ch, PART_IN, term->tl_eof_chars,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6022 (int)STRLEN(term->tl_eof_chars), NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6023 channel_send(ch, PART_IN, (char_u *)"\r", 1, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6024 }
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15844
diff changeset
6025 # ifdef MSWIN
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6026 else
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6027 // Default: CTRL-D
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6028 channel_send(ch, PART_IN, (char_u *)"\004\r", 2, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6029 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6030 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6031 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6032
15555
d89c5b339c2a patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents: 15504
diff changeset
6033 #if defined(FEAT_GUI) || defined(PROTO)
14139
4d3f6bf86bec patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents: 14117
diff changeset
6034 job_T *
4d3f6bf86bec patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents: 14117
diff changeset
6035 term_getjob(term_T *term)
4d3f6bf86bec patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents: 14117
diff changeset
6036 {
4d3f6bf86bec patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents: 14117
diff changeset
6037 return term != NULL ? term->tl_job : NULL;
4d3f6bf86bec patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents: 14117
diff changeset
6038 }
15555
d89c5b339c2a patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents: 15504
diff changeset
6039 #endif
14139
4d3f6bf86bec patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents: 14117
diff changeset
6040
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15844
diff changeset
6041 # if defined(MSWIN) || defined(PROTO)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6042
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6043 ///////////////////////////////////////
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6044 // 2. MS-Windows implementation.
16354
b3bc3ba07bef patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents: 16312
diff changeset
6045 #ifdef PROTO
b3bc3ba07bef patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents: 16312
diff changeset
6046 typedef int COORD;
b3bc3ba07bef patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents: 16312
diff changeset
6047 typedef int DWORD;
b3bc3ba07bef patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents: 16312
diff changeset
6048 typedef int HANDLE;
b3bc3ba07bef patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents: 16312
diff changeset
6049 typedef int *DWORD_PTR;
b3bc3ba07bef patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents: 16312
diff changeset
6050 typedef int HPCON;
b3bc3ba07bef patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents: 16312
diff changeset
6051 typedef int HRESULT;
b3bc3ba07bef patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents: 16312
diff changeset
6052 typedef int LPPROC_THREAD_ATTRIBUTE_LIST;
16378
3d6b282e2d6e patch 8.1.1194: typos and small problems in source files
Bram Moolenaar <Bram@vim.org>
parents: 16354
diff changeset
6053 typedef int SIZE_T;
16354
b3bc3ba07bef patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents: 16312
diff changeset
6054 typedef int PSIZE_T;
b3bc3ba07bef patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents: 16312
diff changeset
6055 typedef int PVOID;
18508
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
6056 typedef int BOOL;
3cd689e9eb7f patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
6057 # define WINAPI
16354
b3bc3ba07bef patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents: 16312
diff changeset
6058 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6059
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6060 HRESULT (WINAPI *pCreatePseudoConsole)(COORD, HANDLE, HANDLE, DWORD, HPCON*);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6061 HRESULT (WINAPI *pResizePseudoConsole)(HPCON, COORD);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6062 HRESULT (WINAPI *pClosePseudoConsole)(HPCON);
15786
ec39beb7e61f patch 8.1.0900: ConPTY many crash with 32-bit build
Bram Moolenaar <Bram@vim.org>
parents: 15746
diff changeset
6063 BOOL (WINAPI *pInitializeProcThreadAttributeList)(LPPROC_THREAD_ATTRIBUTE_LIST, DWORD, DWORD, PSIZE_T);
ec39beb7e61f patch 8.1.0900: ConPTY many crash with 32-bit build
Bram Moolenaar <Bram@vim.org>
parents: 15746
diff changeset
6064 BOOL (WINAPI *pUpdateProcThreadAttribute)(LPPROC_THREAD_ATTRIBUTE_LIST, DWORD, DWORD_PTR, PVOID, SIZE_T, PVOID, PSIZE_T);
ec39beb7e61f patch 8.1.0900: ConPTY many crash with 32-bit build
Bram Moolenaar <Bram@vim.org>
parents: 15746
diff changeset
6065 void (WINAPI *pDeleteProcThreadAttributeList)(LPPROC_THREAD_ATTRIBUTE_LIST);
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6066
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6067 static int
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6068 dyn_conpty_init(int verbose)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6069 {
15844
63e71d195cee patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents: 15832
diff changeset
6070 static HMODULE hKerneldll = NULL;
63e71d195cee patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents: 15832
diff changeset
6071 int i;
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6072 static struct
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6073 {
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6074 char *name;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6075 FARPROC *ptr;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6076 } conpty_entry[] =
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6077 {
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6078 {"CreatePseudoConsole", (FARPROC*)&pCreatePseudoConsole},
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6079 {"ResizePseudoConsole", (FARPROC*)&pResizePseudoConsole},
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6080 {"ClosePseudoConsole", (FARPROC*)&pClosePseudoConsole},
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6081 {"InitializeProcThreadAttributeList",
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6082 (FARPROC*)&pInitializeProcThreadAttributeList},
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6083 {"UpdateProcThreadAttribute",
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6084 (FARPROC*)&pUpdateProcThreadAttribute},
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6085 {"DeleteProcThreadAttributeList",
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6086 (FARPROC*)&pDeleteProcThreadAttributeList},
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6087 {NULL, NULL}
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6088 };
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6089
15804
864ec0dd71b9 patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents: 15786
diff changeset
6090 if (!has_conpty_working())
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6091 {
15844
63e71d195cee patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents: 15832
diff changeset
6092 if (verbose)
63e71d195cee patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents: 15832
diff changeset
6093 emsg(_("E982: ConPTY is not available"));
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6094 return FAIL;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6095 }
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6096
15844
63e71d195cee patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents: 15832
diff changeset
6097 // No need to initialize twice.
63e71d195cee patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents: 15832
diff changeset
6098 if (hKerneldll)
63e71d195cee patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents: 15832
diff changeset
6099 return OK;
63e71d195cee patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents: 15832
diff changeset
6100
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6101 hKerneldll = vimLoadLib("kernel32.dll");
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6102 for (i = 0; conpty_entry[i].name != NULL
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6103 && conpty_entry[i].ptr != NULL; ++i)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6104 {
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6105 if ((*conpty_entry[i].ptr = (FARPROC)GetProcAddress(hKerneldll,
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6106 conpty_entry[i].name)) == NULL)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6107 {
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6108 if (verbose)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6109 semsg(_(e_loadfunc), conpty_entry[i].name);
15844
63e71d195cee patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents: 15832
diff changeset
6110 hKerneldll = NULL;
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6111 return FAIL;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6112 }
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6113 }
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6114
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6115 return OK;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6116 }
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6117
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6118 static int
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6119 conpty_term_and_job_init(
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6120 term_T *term,
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6121 typval_T *argvar,
18139
59bc3cd42cf5 patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents: 18051
diff changeset
6122 char **argv UNUSED,
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6123 jobopt_T *opt,
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6124 jobopt_T *orig_opt)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6125 {
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6126 WCHAR *cmd_wchar = NULL;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6127 WCHAR *cmd_wchar_copy = NULL;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6128 WCHAR *cwd_wchar = NULL;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6129 WCHAR *env_wchar = NULL;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6130 channel_T *channel = NULL;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6131 job_T *job = NULL;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6132 HANDLE jo = NULL;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6133 garray_T ga_cmd, ga_env;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6134 char_u *cmd = NULL;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6135 HRESULT hr;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6136 COORD consize;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6137 SIZE_T breq;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6138 PROCESS_INFORMATION proc_info;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6139 HANDLE i_theirs = NULL;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6140 HANDLE o_theirs = NULL;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6141 HANDLE i_ours = NULL;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6142 HANDLE o_ours = NULL;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6143
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6144 ga_init2(&ga_cmd, (int)sizeof(char*), 20);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6145 ga_init2(&ga_env, (int)sizeof(char*), 20);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6146
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6147 if (argvar->v_type == VAR_STRING)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6148 {
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6149 cmd = argvar->vval.v_string;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6150 }
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6151 else if (argvar->v_type == VAR_LIST)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6152 {
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6153 if (win32_build_cmd(argvar->vval.v_list, &ga_cmd) == FAIL)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6154 goto failed;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6155 cmd = ga_cmd.ga_data;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6156 }
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6157 if (cmd == NULL || *cmd == NUL)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6158 {
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6159 emsg(_(e_invarg));
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6160 goto failed;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6161 }
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6162
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6163 term->tl_arg0_cmd = vim_strsave(cmd);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6164
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6165 cmd_wchar = enc_to_utf16(cmd, NULL);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6166
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6167 if (cmd_wchar != NULL)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6168 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6169 // Request by CreateProcessW
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6170 breq = wcslen(cmd_wchar) + 1 + 1; // Addition of NUL by API
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16782
diff changeset
6171 cmd_wchar_copy = ALLOC_MULT(WCHAR, breq);
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6172 wcsncpy(cmd_wchar_copy, cmd_wchar, breq - 1);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6173 }
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6174
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6175 ga_clear(&ga_cmd);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6176 if (cmd_wchar == NULL)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6177 goto failed;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6178 if (opt->jo_cwd != NULL)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6179 cwd_wchar = enc_to_utf16(opt->jo_cwd, NULL);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6180
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6181 win32_build_env(opt->jo_env, &ga_env, TRUE);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6182 env_wchar = ga_env.ga_data;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6183
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6184 if (!CreatePipe(&i_theirs, &i_ours, NULL, 0))
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6185 goto failed;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6186 if (!CreatePipe(&o_ours, &o_theirs, NULL, 0))
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6187 goto failed;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6188
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6189 consize.X = term->tl_cols;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6190 consize.Y = term->tl_rows;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6191 hr = pCreatePseudoConsole(consize, i_theirs, o_theirs, 0,
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6192 &term->tl_conpty);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6193 if (FAILED(hr))
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6194 goto failed;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6195
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6196 term->tl_siex.StartupInfo.cb = sizeof(term->tl_siex);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6197
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6198 // Set up pipe inheritance safely: Vista or later.
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6199 pInitializeProcThreadAttributeList(NULL, 1, 0, &breq);
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16782
diff changeset
6200 term->tl_siex.lpAttributeList = alloc(breq);
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6201 if (!term->tl_siex.lpAttributeList)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6202 goto failed;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6203 if (!pInitializeProcThreadAttributeList(term->tl_siex.lpAttributeList, 1,
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6204 0, &breq))
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6205 goto failed;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6206 if (!pUpdateProcThreadAttribute(
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6207 term->tl_siex.lpAttributeList, 0,
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6208 PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE, term->tl_conpty,
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6209 sizeof(HPCON), NULL, NULL))
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6210 goto failed;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6211
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6212 channel = add_channel();
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6213 if (channel == NULL)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6214 goto failed;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6215
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6216 job = job_alloc();
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6217 if (job == NULL)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6218 goto failed;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6219 if (argvar->v_type == VAR_STRING)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6220 {
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6221 int argc;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6222
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6223 build_argv_from_string(cmd, &job->jv_argv, &argc);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6224 }
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6225 else
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6226 {
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6227 int argc;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6228
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6229 build_argv_from_list(argvar->vval.v_list, &job->jv_argv, &argc);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6230 }
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6231
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6232 if (opt->jo_set & JO_IN_BUF)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6233 job->jv_in_buf = buflist_findnr(opt->jo_io_buf[PART_IN]);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6234
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6235 if (!CreateProcessW(NULL, cmd_wchar_copy, NULL, NULL, FALSE,
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6236 EXTENDED_STARTUPINFO_PRESENT | CREATE_UNICODE_ENVIRONMENT
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6237 | CREATE_SUSPENDED | CREATE_NEW_PROCESS_GROUP
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6238 | CREATE_DEFAULT_ERROR_MODE,
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6239 env_wchar, cwd_wchar,
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6240 &term->tl_siex.StartupInfo, &proc_info))
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6241 goto failed;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6242
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6243 CloseHandle(i_theirs);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6244 CloseHandle(o_theirs);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6245
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6246 channel_set_pipes(channel,
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6247 (sock_T)i_ours,
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6248 (sock_T)o_ours,
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6249 (sock_T)o_ours);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6250
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6251 // Write lines with CR instead of NL.
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6252 channel->ch_write_text_mode = TRUE;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6253
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6254 // Use to explicitly delete anonymous pipe handle.
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6255 channel->ch_anonymous_pipe = TRUE;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6256
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6257 jo = CreateJobObject(NULL, NULL);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6258 if (jo == NULL)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6259 goto failed;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6260
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6261 if (!AssignProcessToJobObject(jo, proc_info.hProcess))
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6262 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6263 // Failed, switch the way to terminate process with TerminateProcess.
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6264 CloseHandle(jo);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6265 jo = NULL;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6266 }
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6267
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6268 ResumeThread(proc_info.hThread);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6269 CloseHandle(proc_info.hThread);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6270
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6271 vim_free(cmd_wchar);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6272 vim_free(cmd_wchar_copy);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6273 vim_free(cwd_wchar);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6274 vim_free(env_wchar);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6275
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6276 if (create_vterm(term, term->tl_rows, term->tl_cols) == FAIL)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6277 goto failed;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6278
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6279 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6280 if (opt->jo_set2 & JO2_ANSI_COLORS)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6281 set_vterm_palette(term->tl_vterm, opt->jo_ansi_colors);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6282 else
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6283 init_vterm_ansi_colors(term->tl_vterm);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6284 #endif
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6285
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6286 channel_set_job(channel, job, opt);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6287 job_set_options(job, opt);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6288
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6289 job->jv_channel = channel;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6290 job->jv_proc_info = proc_info;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6291 job->jv_job_object = jo;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6292 job->jv_status = JOB_STARTED;
15810
5523665fdf80 patch 8.1.0912: MS-Windows: warning for signed/unsigned
Bram Moolenaar <Bram@vim.org>
parents: 15804
diff changeset
6293 job->jv_tty_type = vim_strsave((char_u *)"conpty");
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6294 ++job->jv_refcount;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6295 term->tl_job = job;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6296
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6297 // Redirecting stdout and stderr doesn't work at the job level. Instead
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6298 // open the file here and handle it in. opt->jo_io was changed in
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6299 // setup_job_options(), use the original flags here.
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6300 if (orig_opt->jo_io[PART_OUT] == JIO_FILE)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6301 {
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6302 char_u *fname = opt->jo_io_name[PART_OUT];
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6303
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6304 ch_log(channel, "Opening output file %s", fname);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6305 term->tl_out_fd = mch_fopen((char *)fname, WRITEBIN);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6306 if (term->tl_out_fd == NULL)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6307 semsg(_(e_notopen), fname);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6308 }
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6309
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6310 return OK;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6311
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6312 failed:
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6313 ga_clear(&ga_cmd);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6314 ga_clear(&ga_env);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6315 vim_free(cmd_wchar);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6316 vim_free(cmd_wchar_copy);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6317 vim_free(cwd_wchar);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6318 if (channel != NULL)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6319 channel_clear(channel);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6320 if (job != NULL)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6321 {
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6322 job->jv_channel = NULL;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6323 job_cleanup(job);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6324 }
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6325 term->tl_job = NULL;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6326 if (jo != NULL)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6327 CloseHandle(jo);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6328
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6329 if (term->tl_siex.lpAttributeList != NULL)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6330 {
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6331 pDeleteProcThreadAttributeList(term->tl_siex.lpAttributeList);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6332 vim_free(term->tl_siex.lpAttributeList);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6333 }
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6334 term->tl_siex.lpAttributeList = NULL;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6335 if (o_theirs != NULL)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6336 CloseHandle(o_theirs);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6337 if (o_ours != NULL)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6338 CloseHandle(o_ours);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6339 if (i_ours != NULL)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6340 CloseHandle(i_ours);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6341 if (i_theirs != NULL)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6342 CloseHandle(i_theirs);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6343 if (term->tl_conpty != NULL)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6344 pClosePseudoConsole(term->tl_conpty);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6345 term->tl_conpty = NULL;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6346 return FAIL;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6347 }
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6348
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6349 static void
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6350 conpty_term_report_winsize(term_T *term, int rows, int cols)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6351 {
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6352 COORD consize;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6353
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6354 consize.X = cols;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6355 consize.Y = rows;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6356 pResizePseudoConsole(term->tl_conpty, consize);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6357 }
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6358
18051
d1e77015f60b patch 8.1.2021: some global functions can be local to the file
Bram Moolenaar <Bram@vim.org>
parents: 18033
diff changeset
6359 static void
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6360 term_free_conpty(term_T *term)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6361 {
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6362 if (term->tl_siex.lpAttributeList != NULL)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6363 {
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6364 pDeleteProcThreadAttributeList(term->tl_siex.lpAttributeList);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6365 vim_free(term->tl_siex.lpAttributeList);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6366 }
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6367 term->tl_siex.lpAttributeList = NULL;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6368 if (term->tl_conpty != NULL)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6369 pClosePseudoConsole(term->tl_conpty);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6370 term->tl_conpty = NULL;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6371 }
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6372
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6373 int
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6374 use_conpty(void)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6375 {
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6376 return has_conpty;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6377 }
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6378
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6379 # ifndef PROTO
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6380
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6381 #define WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN 1ul
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6382 #define WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN 2ull
13206
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
6383 #define WINPTY_MOUSE_MODE_FORCE 2
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6384
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6385 void* (*winpty_config_new)(UINT64, void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6386 void* (*winpty_open)(void*, void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6387 void* (*winpty_spawn_config_new)(UINT64, void*, LPCWSTR, void*, void*, void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6388 BOOL (*winpty_spawn)(void*, void*, HANDLE*, HANDLE*, DWORD*, void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6389 void (*winpty_config_set_mouse_mode)(void*, int);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6390 void (*winpty_config_set_initial_size)(void*, int, int);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6391 LPCWSTR (*winpty_conin_name)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6392 LPCWSTR (*winpty_conout_name)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6393 LPCWSTR (*winpty_conerr_name)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6394 void (*winpty_free)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6395 void (*winpty_config_free)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6396 void (*winpty_spawn_config_free)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6397 void (*winpty_error_free)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6398 LPCWSTR (*winpty_error_msg)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6399 BOOL (*winpty_set_size)(void*, int, int, void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6400 HANDLE (*winpty_agent_process)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6401
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6402 #define WINPTY_DLL "winpty.dll"
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6403
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6404 static HINSTANCE hWinPtyDLL = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6405 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6406
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6407 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6408 dyn_winpty_init(int verbose)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6409 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6410 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6411 static struct
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6412 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6413 char *name;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6414 FARPROC *ptr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6415 } winpty_entry[] =
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6416 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6417 {"winpty_conerr_name", (FARPROC*)&winpty_conerr_name},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6418 {"winpty_config_free", (FARPROC*)&winpty_config_free},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6419 {"winpty_config_new", (FARPROC*)&winpty_config_new},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6420 {"winpty_config_set_mouse_mode",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6421 (FARPROC*)&winpty_config_set_mouse_mode},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6422 {"winpty_config_set_initial_size",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6423 (FARPROC*)&winpty_config_set_initial_size},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6424 {"winpty_conin_name", (FARPROC*)&winpty_conin_name},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6425 {"winpty_conout_name", (FARPROC*)&winpty_conout_name},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6426 {"winpty_error_free", (FARPROC*)&winpty_error_free},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6427 {"winpty_free", (FARPROC*)&winpty_free},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6428 {"winpty_open", (FARPROC*)&winpty_open},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6429 {"winpty_spawn", (FARPROC*)&winpty_spawn},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6430 {"winpty_spawn_config_free", (FARPROC*)&winpty_spawn_config_free},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6431 {"winpty_spawn_config_new", (FARPROC*)&winpty_spawn_config_new},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6432 {"winpty_error_msg", (FARPROC*)&winpty_error_msg},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6433 {"winpty_set_size", (FARPROC*)&winpty_set_size},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6434 {"winpty_agent_process", (FARPROC*)&winpty_agent_process},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6435 {NULL, NULL}
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6436 };
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6437
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6438 // No need to initialize twice.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6439 if (hWinPtyDLL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6440 return OK;
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6441 // Load winpty.dll, prefer using the 'winptydll' option, fall back to just
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6442 // winpty.dll.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6443 if (*p_winptydll != NUL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6444 hWinPtyDLL = vimLoadLib((char *)p_winptydll);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6445 if (!hWinPtyDLL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6446 hWinPtyDLL = vimLoadLib(WINPTY_DLL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6447 if (!hWinPtyDLL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6448 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6449 if (verbose)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
6450 semsg(_(e_loadlib), *p_winptydll != NUL ? p_winptydll
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6451 : (char_u *)WINPTY_DLL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6452 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6453 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6454 for (i = 0; winpty_entry[i].name != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6455 && winpty_entry[i].ptr != NULL; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6456 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6457 if ((*winpty_entry[i].ptr = (FARPROC)GetProcAddress(hWinPtyDLL,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6458 winpty_entry[i].name)) == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6459 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6460 if (verbose)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
6461 semsg(_(e_loadfunc), winpty_entry[i].name);
15844
63e71d195cee patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents: 15832
diff changeset
6462 hWinPtyDLL = NULL;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6463 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6464 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6465 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6466
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6467 return OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6468 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6469
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6470 static int
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6471 winpty_term_and_job_init(
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6472 term_T *term,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6473 typval_T *argvar,
18139
59bc3cd42cf5 patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents: 18051
diff changeset
6474 char **argv UNUSED,
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
6475 jobopt_T *opt,
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
6476 jobopt_T *orig_opt)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6477 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6478 WCHAR *cmd_wchar = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6479 WCHAR *cwd_wchar = NULL;
12724
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
6480 WCHAR *env_wchar = NULL;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6481 channel_T *channel = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6482 job_T *job = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6483 DWORD error;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6484 HANDLE jo = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6485 HANDLE child_process_handle;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6486 HANDLE child_thread_handle;
13111
149347fda678 patch 8.0.1430: crash when term_start() fails
Christian Brabandt <cb@256bit.org>
parents: 13109
diff changeset
6487 void *winpty_err = NULL;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6488 void *spawn_config = NULL;
12724
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
6489 garray_T ga_cmd, ga_env;
13109
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
6490 char_u *cmd = NULL;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6491
13109
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
6492 ga_init2(&ga_cmd, (int)sizeof(char*), 20);
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
6493 ga_init2(&ga_env, (int)sizeof(char*), 20);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6494
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6495 if (argvar->v_type == VAR_STRING)
13109
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
6496 {
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6497 cmd = argvar->vval.v_string;
13109
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
6498 }
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
6499 else if (argvar->v_type == VAR_LIST)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6500 {
12724
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
6501 if (win32_build_cmd(argvar->vval.v_list, &ga_cmd) == FAIL)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6502 goto failed;
12724
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
6503 cmd = ga_cmd.ga_data;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6504 }
13109
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
6505 if (cmd == NULL || *cmd == NUL)
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
6506 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
6507 emsg(_(e_invarg));
13109
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
6508 goto failed;
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
6509 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6510
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6511 term->tl_arg0_cmd = vim_strsave(cmd);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6512
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6513 cmd_wchar = enc_to_utf16(cmd, NULL);
13109
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
6514 ga_clear(&ga_cmd);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6515 if (cmd_wchar == NULL)
13109
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
6516 goto failed;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6517 if (opt->jo_cwd != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6518 cwd_wchar = enc_to_utf16(opt->jo_cwd, NULL);
12907
32531a3eab1f patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents: 12903
diff changeset
6519
32531a3eab1f patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents: 12903
diff changeset
6520 win32_build_env(opt->jo_env, &ga_env, TRUE);
32531a3eab1f patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents: 12903
diff changeset
6521 env_wchar = ga_env.ga_data;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6522
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6523 term->tl_winpty_config = winpty_config_new(0, &winpty_err);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6524 if (term->tl_winpty_config == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6525 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6526
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6527 winpty_config_set_mouse_mode(term->tl_winpty_config,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6528 WINPTY_MOUSE_MODE_FORCE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6529 winpty_config_set_initial_size(term->tl_winpty_config,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6530 term->tl_cols, term->tl_rows);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6531 term->tl_winpty = winpty_open(term->tl_winpty_config, &winpty_err);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6532 if (term->tl_winpty == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6533 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6534
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6535 spawn_config = winpty_spawn_config_new(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6536 WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN |
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6537 WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6538 NULL,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6539 cmd_wchar,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6540 cwd_wchar,
12724
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
6541 env_wchar,
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6542 &winpty_err);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6543 if (spawn_config == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6544 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6545
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6546 channel = add_channel();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6547 if (channel == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6548 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6549
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6550 job = job_alloc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6551 if (job == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6552 goto failed;
13750
3ab6198c1f9a patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents: 13746
diff changeset
6553 if (argvar->v_type == VAR_STRING)
3ab6198c1f9a patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents: 13746
diff changeset
6554 {
3ab6198c1f9a patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents: 13746
diff changeset
6555 int argc;
3ab6198c1f9a patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents: 13746
diff changeset
6556
3ab6198c1f9a patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents: 13746
diff changeset
6557 build_argv_from_string(cmd, &job->jv_argv, &argc);
3ab6198c1f9a patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents: 13746
diff changeset
6558 }
3ab6198c1f9a patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents: 13746
diff changeset
6559 else
3ab6198c1f9a patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents: 13746
diff changeset
6560 {
3ab6198c1f9a patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents: 13746
diff changeset
6561 int argc;
3ab6198c1f9a patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents: 13746
diff changeset
6562
3ab6198c1f9a patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents: 13746
diff changeset
6563 build_argv_from_list(argvar->vval.v_list, &job->jv_argv, &argc);
3ab6198c1f9a patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents: 13746
diff changeset
6564 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6565
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6566 if (opt->jo_set & JO_IN_BUF)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6567 job->jv_in_buf = buflist_findnr(opt->jo_io_buf[PART_IN]);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6568
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6569 if (!winpty_spawn(term->tl_winpty, spawn_config, &child_process_handle,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6570 &child_thread_handle, &error, &winpty_err))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6571 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6572
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6573 channel_set_pipes(channel,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6574 (sock_T)CreateFileW(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6575 winpty_conin_name(term->tl_winpty),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6576 GENERIC_WRITE, 0, NULL,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6577 OPEN_EXISTING, 0, NULL),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6578 (sock_T)CreateFileW(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6579 winpty_conout_name(term->tl_winpty),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6580 GENERIC_READ, 0, NULL,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6581 OPEN_EXISTING, 0, NULL),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6582 (sock_T)CreateFileW(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6583 winpty_conerr_name(term->tl_winpty),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6584 GENERIC_READ, 0, NULL,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6585 OPEN_EXISTING, 0, NULL));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6586
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6587 // Write lines with CR instead of NL.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6588 channel->ch_write_text_mode = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6589
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6590 jo = CreateJobObject(NULL, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6591 if (jo == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6592 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6593
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6594 if (!AssignProcessToJobObject(jo, child_process_handle))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6595 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6596 // Failed, switch the way to terminate process with TerminateProcess.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6597 CloseHandle(jo);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6598 jo = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6599 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6600
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6601 winpty_spawn_config_free(spawn_config);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6602 vim_free(cmd_wchar);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6603 vim_free(cwd_wchar);
13109
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
6604 vim_free(env_wchar);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6605
15249
544490b69e1d patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 15217
diff changeset
6606 if (create_vterm(term, term->tl_rows, term->tl_cols) == FAIL)
544490b69e1d patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 15217
diff changeset
6607 goto failed;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6608
13626
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
6609 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
6610 if (opt->jo_set2 & JO2_ANSI_COLORS)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
6611 set_vterm_palette(term->tl_vterm, opt->jo_ansi_colors);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
6612 else
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
6613 init_vterm_ansi_colors(term->tl_vterm);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
6614 #endif
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
6615
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6616 channel_set_job(channel, job, opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6617 job_set_options(job, opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6618
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6619 job->jv_channel = channel;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6620 job->jv_proc_info.hProcess = child_process_handle;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6621 job->jv_proc_info.dwProcessId = GetProcessId(child_process_handle);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6622 job->jv_job_object = jo;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6623 job->jv_status = JOB_STARTED;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6624 job->jv_tty_in = utf16_to_enc(
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6625 (short_u *)winpty_conin_name(term->tl_winpty), NULL);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6626 job->jv_tty_out = utf16_to_enc(
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6627 (short_u *)winpty_conout_name(term->tl_winpty), NULL);
15810
5523665fdf80 patch 8.1.0912: MS-Windows: warning for signed/unsigned
Bram Moolenaar <Bram@vim.org>
parents: 15804
diff changeset
6628 job->jv_tty_type = vim_strsave((char_u *)"winpty");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6629 ++job->jv_refcount;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6630 term->tl_job = job;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6631
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6632 // Redirecting stdout and stderr doesn't work at the job level. Instead
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6633 // open the file here and handle it in. opt->jo_io was changed in
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6634 // setup_job_options(), use the original flags here.
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
6635 if (orig_opt->jo_io[PART_OUT] == JIO_FILE)
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
6636 {
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
6637 char_u *fname = opt->jo_io_name[PART_OUT];
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
6638
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
6639 ch_log(channel, "Opening output file %s", fname);
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
6640 term->tl_out_fd = mch_fopen((char *)fname, WRITEBIN);
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
6641 if (term->tl_out_fd == NULL)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
6642 semsg(_(e_notopen), fname);
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
6643 }
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
6644
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6645 return OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6646
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6647 failed:
13109
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
6648 ga_clear(&ga_cmd);
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
6649 ga_clear(&ga_env);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6650 vim_free(cmd_wchar);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6651 vim_free(cwd_wchar);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6652 if (spawn_config != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6653 winpty_spawn_config_free(spawn_config);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6654 if (channel != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6655 channel_clear(channel);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6656 if (job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6657 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6658 job->jv_channel = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6659 job_cleanup(job);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6660 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6661 term->tl_job = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6662 if (jo != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6663 CloseHandle(jo);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6664 if (term->tl_winpty != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6665 winpty_free(term->tl_winpty);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6666 term->tl_winpty = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6667 if (term->tl_winpty_config != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6668 winpty_config_free(term->tl_winpty_config);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6669 term->tl_winpty_config = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6670 if (winpty_err != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6671 {
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6672 char *msg = (char *)utf16_to_enc(
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6673 (short_u *)winpty_error_msg(winpty_err), NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6674
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15355
diff changeset
6675 emsg(msg);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6676 winpty_error_free(winpty_err);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6677 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6678 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6679 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6680
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6681 /*
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6682 * Create a new terminal of "rows" by "cols" cells.
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6683 * Store a reference in "term".
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6684 * Return OK or FAIL.
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6685 */
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6686 static int
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6687 term_and_job_init(
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6688 term_T *term,
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6689 typval_T *argvar,
18514
39b0c28fe495 patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents: 18508
diff changeset
6690 char **argv,
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6691 jobopt_T *opt,
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6692 jobopt_T *orig_opt)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6693 {
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6694 int use_winpty = FALSE;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6695 int use_conpty = FALSE;
15746
c017195b121b patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents: 15725
diff changeset
6696 int tty_type = *p_twt;
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6697
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6698 has_winpty = dyn_winpty_init(FALSE) != FAIL ? TRUE : FALSE;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6699 has_conpty = dyn_conpty_init(FALSE) != FAIL ? TRUE : FALSE;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6700
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6701 if (!has_winpty && !has_conpty)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6702 // If neither is available give the errors for winpty, since when
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6703 // conpty is not available it can't be installed either.
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6704 return dyn_winpty_init(TRUE);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6705
15746
c017195b121b patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents: 15725
diff changeset
6706 if (opt->jo_tty_type != NUL)
c017195b121b patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents: 15725
diff changeset
6707 tty_type = opt->jo_tty_type;
c017195b121b patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents: 15725
diff changeset
6708
c017195b121b patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents: 15725
diff changeset
6709 if (tty_type == NUL)
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6710 {
15804
864ec0dd71b9 patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents: 15786
diff changeset
6711 if (has_conpty && (is_conpty_stable() || !has_winpty))
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6712 use_conpty = TRUE;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6713 else if (has_winpty)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6714 use_winpty = TRUE;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6715 // else: error
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6716 }
15746
c017195b121b patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents: 15725
diff changeset
6717 else if (tty_type == 'w') // winpty
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6718 {
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6719 if (has_winpty)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6720 use_winpty = TRUE;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6721 }
15746
c017195b121b patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents: 15725
diff changeset
6722 else if (tty_type == 'c') // conpty
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6723 {
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6724 if (has_conpty)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6725 use_conpty = TRUE;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6726 else
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6727 return dyn_conpty_init(TRUE);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6728 }
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6729
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6730 if (use_conpty)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6731 return conpty_term_and_job_init(term, argvar, argv, opt, orig_opt);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6732
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6733 if (use_winpty)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6734 return winpty_term_and_job_init(term, argvar, argv, opt, orig_opt);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6735
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6736 // error
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6737 return dyn_winpty_init(TRUE);
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6738 }
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6739
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6740 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6741 create_pty_only(term_T *term, jobopt_T *options)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6742 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6743 HANDLE hPipeIn = INVALID_HANDLE_VALUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6744 HANDLE hPipeOut = INVALID_HANDLE_VALUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6745 char in_name[80], out_name[80];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6746 channel_T *channel = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6747
15249
544490b69e1d patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 15217
diff changeset
6748 if (create_vterm(term, term->tl_rows, term->tl_cols) == FAIL)
544490b69e1d patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 15217
diff changeset
6749 return FAIL;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6750
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6751 vim_snprintf(in_name, sizeof(in_name), "\\\\.\\pipe\\vim-%d-in-%d",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6752 GetCurrentProcessId(),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6753 curbuf->b_fnum);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6754 hPipeIn = CreateNamedPipe(in_name, PIPE_ACCESS_OUTBOUND,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6755 PIPE_TYPE_MESSAGE | PIPE_NOWAIT,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6756 PIPE_UNLIMITED_INSTANCES,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6757 0, 0, NMPWAIT_NOWAIT, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6758 if (hPipeIn == INVALID_HANDLE_VALUE)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6759 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6760
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6761 vim_snprintf(out_name, sizeof(out_name), "\\\\.\\pipe\\vim-%d-out-%d",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6762 GetCurrentProcessId(),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6763 curbuf->b_fnum);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6764 hPipeOut = CreateNamedPipe(out_name, PIPE_ACCESS_INBOUND,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6765 PIPE_TYPE_MESSAGE | PIPE_NOWAIT,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6766 PIPE_UNLIMITED_INSTANCES,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6767 0, 0, 0, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6768 if (hPipeOut == INVALID_HANDLE_VALUE)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6769 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6770
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6771 ConnectNamedPipe(hPipeIn, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6772 ConnectNamedPipe(hPipeOut, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6773
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6774 term->tl_job = job_alloc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6775 if (term->tl_job == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6776 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6777 ++term->tl_job->jv_refcount;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6778
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6779 // behave like the job is already finished
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6780 term->tl_job->jv_status = JOB_FINISHED;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6781
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6782 channel = add_channel();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6783 if (channel == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6784 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6785 term->tl_job->jv_channel = channel;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6786 channel->ch_keep_open = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6787 channel->ch_named_pipe = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6788
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6789 channel_set_pipes(channel,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6790 (sock_T)hPipeIn,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6791 (sock_T)hPipeOut,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6792 (sock_T)hPipeOut);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6793 channel_set_job(channel, term->tl_job, options);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6794 term->tl_job->jv_tty_in = vim_strsave((char_u*)in_name);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6795 term->tl_job->jv_tty_out = vim_strsave((char_u*)out_name);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6796
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6797 return OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6798
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6799 failed:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6800 if (hPipeIn != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6801 CloseHandle(hPipeIn);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6802 if (hPipeOut != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6803 CloseHandle(hPipeOut);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6804 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6805 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6806
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6807 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6808 * Free the terminal emulator part of "term".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6809 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6810 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6811 term_free_vterm(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6812 {
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6813 term_free_conpty(term);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6814 if (term->tl_winpty != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6815 winpty_free(term->tl_winpty);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6816 term->tl_winpty = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6817 if (term->tl_winpty_config != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6818 winpty_config_free(term->tl_winpty_config);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6819 term->tl_winpty_config = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6820 if (term->tl_vterm != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6821 vterm_free(term->tl_vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6822 term->tl_vterm = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6823 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6824
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6825 /*
13678
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
6826 * Report the size to the terminal.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6827 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6828 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6829 term_report_winsize(term_T *term, int rows, int cols)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6830 {
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6831 if (term->tl_conpty)
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6832 conpty_term_report_winsize(term, rows, cols);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6833 if (term->tl_winpty)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6834 winpty_set_size(term->tl_winpty, cols, rows, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6835 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6836
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6837 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6838 terminal_enabled(void)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6839 {
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6840 return dyn_winpty_init(FALSE) == OK || dyn_conpty_init(FALSE) == OK;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6841 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6842
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6843 # else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6844
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6845 ///////////////////////////////////////
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6846 // 3. Unix-like implementation.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6847
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6848 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6849 * Create a new terminal of "rows" by "cols" cells.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6850 * Start job for "cmd".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6851 * Store the pointers in "term".
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
6852 * When "argv" is not NULL then "argvar" is not used.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6853 * Return OK or FAIL.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6854 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6855 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6856 term_and_job_init(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6857 term_T *term,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6858 typval_T *argvar,
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
6859 char **argv,
13860
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
6860 jobopt_T *opt,
7f892e37b017 patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents: 13851
diff changeset
6861 jobopt_T *orig_opt UNUSED)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6862 {
15725
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6863 term->tl_arg0_cmd = NULL;
a3e2e7948ee4 patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents: 15679
diff changeset
6864
15249
544490b69e1d patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 15217
diff changeset
6865 if (create_vterm(term, term->tl_rows, term->tl_cols) == FAIL)
544490b69e1d patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 15217
diff changeset
6866 return FAIL;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6867
13626
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
6868 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
6869 if (opt->jo_set2 & JO2_ANSI_COLORS)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
6870 set_vterm_palette(term->tl_vterm, opt->jo_ansi_colors);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
6871 else
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
6872 init_vterm_ansi_colors(term->tl_vterm);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
6873 #endif
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
6874
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6875 // This may change a string in "argvar".
19245
5ed8297121fa patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents: 19241
diff changeset
6876 term->tl_job = job_start(argvar, argv, opt, &term->tl_job);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6877 if (term->tl_job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6878 ++term->tl_job->jv_refcount;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6879
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6880 return term->tl_job != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6881 && term->tl_job->jv_channel != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6882 && term->tl_job->jv_status != JOB_FAILED ? OK : FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6883 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6884
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6885 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6886 create_pty_only(term_T *term, jobopt_T *opt)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6887 {
15249
544490b69e1d patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 15217
diff changeset
6888 if (create_vterm(term, term->tl_rows, term->tl_cols) == FAIL)
544490b69e1d patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 15217
diff changeset
6889 return FAIL;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6890
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6891 term->tl_job = job_alloc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6892 if (term->tl_job == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6893 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6894 ++term->tl_job->jv_refcount;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6895
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6896 // behave like the job is already finished
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6897 term->tl_job->jv_status = JOB_FINISHED;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6898
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6899 return mch_create_pty_channel(term->tl_job, opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6900 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6901
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6902 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6903 * Free the terminal emulator part of "term".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6904 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6905 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6906 term_free_vterm(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6907 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6908 if (term->tl_vterm != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6909 vterm_free(term->tl_vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6910 term->tl_vterm = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6911 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6912
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6913 /*
13678
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
6914 * Report the size to the terminal.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6915 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6916 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6917 term_report_winsize(term_T *term, int rows, int cols)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6918 {
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6919 // Use an ioctl() to report the new window size to the job.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6920 if (term->tl_job != NULL && term->tl_job->jv_channel != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6921 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6922 int fd = -1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6923 int part;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6924
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6925 for (part = PART_OUT; part < PART_COUNT; ++part)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6926 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6927 fd = term->tl_job->jv_channel->ch_part[part].ch_fd;
15632
d4a6d575e910 patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
6928 if (mch_isatty(fd))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6929 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6930 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6931 if (part < PART_COUNT && mch_report_winsize(fd, rows, cols) == OK)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6932 mch_signal_job(term->tl_job, (char_u *)"winch");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6933 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6934 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6935
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6936 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6937
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18595
diff changeset
6938 #endif // FEAT_TERMINAL