annotate src/terminal.c @ 13678:39fcaaa973db v8.0.1711

patch 8.0.1711: term_setsize() is not implemented yet commit https://github.com/vim/vim/commit/a42d363bac8a581afe769c370db70cf833767c41 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Apr 14 17:05:38 2018 +0200 patch 8.0.1711: term_setsize() is not implemented yet Problem: Term_setsize() is not implemented yet. Solution: Implement it.
author Christian Brabandt <cb@256bit.org>
date Sat, 14 Apr 2018 17:15:05 +0200
parents 6a84e3d2b810
children c32e9628dc30
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 * TODO:
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
41 * - Win32: Make terminal used for :!cmd in the GUI work better. Allow for
13579
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
42 * redirection. Probably in call to channel_set_pipes().
13626
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
43 * - add an optional limit for the scrollback size. When reaching it remove
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
44 * 10% at the start.
13444
9f06f7aca74c patch 8.0.1596: no autocommand specifically for opening a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13438
diff changeset
45 * - Copy text in the vterm to the Vim buffer once in a while, so that
9f06f7aca74c patch 8.0.1596: no autocommand specifically for opening a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13438
diff changeset
46 * completion works.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 * - in GUI vertical split causes problems. Cursor is flickering. (Hirohito
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 * Higashi, 2017 Sep 19)
12578
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
49 * - after resizing windows overlap. (Boris Staletic, #2164)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 * - Redirecting output does not work on MS-Windows, Test_terminal_redir_file()
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 * is disabled.
12541
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
52 * - cursor blinks in terminal on widows with a timer. (xtal8, #2142)
12724
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
53 * - Termdebug does not work when Vim build with mzscheme. gdb hangs.
12541
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
54 * - MS-Windows GUI: WinBar has tearoff item
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 * - MS-Windows GUI: still need to type a key after shell exits? #1924
12865
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12845
diff changeset
56 * - After executing a shell command the status line isn't redraw.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 * - add test for giving error for invalid 'termsize' value.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 * - support minimal size when 'termsize' is "rows*cols".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59 * - support minimal size when 'termsize' is empty?
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 * - GUI: when using tabs, focus in terminal, click on tab does not work.
12632
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
61 * - Redrawing is slow with Athena and Motif. Also other GUI? (Ramel Eshed)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 * - For the GUI fill termios with default values, perhaps like pangoterm:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 * http://bazaar.launchpad.net/~leonerd/pangoterm/trunk/view/head:/main.c#L134
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 * - when 'encoding' is not utf-8, or the job is using another encoding, setup
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 * conversions.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 #include "vim.h"
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 #if defined(FEAT_TERMINAL) || defined(PROTO)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 #ifndef MIN
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73 # define MIN(x,y) ((x) < (y) ? (x) : (y))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75 #ifndef MAX
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
76 # define MAX(x,y) ((x) > (y) ? (x) : (y))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
77 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 #include "libvterm/include/vterm.h"
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 /* This is VTermScreenCell without the characters, thus much smaller. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82 typedef struct {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83 VTermScreenCellAttrs attrs;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 char width;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
85 VTermColor fg;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
86 VTermColor bg;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87 } cellattr_T;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89 typedef struct sb_line_S {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
90 int sb_cols; /* can differ per line */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 cellattr_T *sb_cells; /* allocated */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92 cellattr_T sb_fill_attr; /* for short line */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 } sb_line_T;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
94
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
95 /* typedef term_T in structs.h */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
96 struct terminal_S {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
97 term_T *tl_next;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
98
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
99 VTerm *tl_vterm;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
100 job_T *tl_job;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
101 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
102 #if defined(FEAT_GUI)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
103 int tl_system; /* when non-zero used for :!cmd output */
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
104 int tl_toprow; /* row with first line of system terminal */
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
105 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
106
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
107 /* Set when setting the size of a vterm, reset after redrawing. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
108 int tl_vterm_size_changed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
109
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
110 /* used when tl_job is NULL and only a pty was created */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
111 int tl_tty_fd;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
112 char_u *tl_tty_in;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
113 char_u *tl_tty_out;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
114
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
115 int tl_normal_mode; /* TRUE: Terminal-Normal mode */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
116 int tl_channel_closed;
13476
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
117 int tl_finish;
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
118 #define TL_FINISH_UNSET NUL
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
119 #define TL_FINISH_CLOSE 'c' /* ++close or :terminal without argument */
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
120 #define TL_FINISH_NOCLOSE 'n' /* ++noclose */
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
121 #define TL_FINISH_OPEN 'o' /* ++open */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
122 char_u *tl_opencmd;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
123 char_u *tl_eof_chars;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
124
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
125 #ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
126 void *tl_winpty_config;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
127 void *tl_winpty;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
128 #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
129 #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
130 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
131 #endif
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
132 char_u *tl_kill;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
133
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
134 /* last known vterm size */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
135 int tl_rows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
136 int tl_cols;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
137 /* vterm size does not follow window size */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
138 int tl_rows_fixed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
139 int tl_cols_fixed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
140
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
141 char_u *tl_title; /* NULL or allocated */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
142 char_u *tl_status_text; /* NULL or allocated */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
143
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
144 /* Range of screen rows to update. Zero based. */
12578
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
145 int tl_dirty_row_start; /* MAX_ROW if nothing dirty */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
146 int tl_dirty_row_end; /* row below last one to update */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
147
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
148 garray_T tl_scrollback;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
149 int tl_scrollback_scrolled;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
150 cellattr_T tl_default_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
151
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
152 linenr_T tl_top_diff_rows; /* rows of top diff file or zero */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
153 linenr_T tl_bot_diff_rows; /* rows of bottom diff file */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
154
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
155 VTermPos tl_cursor_pos;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
156 int tl_cursor_visible;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
157 int tl_cursor_blink;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
158 int tl_cursor_shape; /* 1: block, 2: underline, 3: bar */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
159 char_u *tl_cursor_color; /* NULL or allocated */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
160
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
161 int tl_using_altscreen;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
162 };
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 #define TMODE_ONCE 1 /* CTRL-\ CTRL-N used */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
165 #define TMODE_LOOP 2 /* CTRL-W N used */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
166
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 * List of all active terminals.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
169 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
170 static term_T *first_term = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
171
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
172 /* Terminal active in terminal_loop(). */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
173 static term_T *in_terminal_loop = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
174
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
175 #define MAX_ROW 999999 /* used for tl_dirty_row_end to update all rows */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
176 #define KEY_BUF_LEN 200
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
177
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
178 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
179 * Functions with separate implementation for MS-Windows and Unix-like systems.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
180 */
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
181 static int term_and_job_init(term_T *term, typval_T *argvar, char **argv, jobopt_T *opt);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
182 static int create_pty_only(term_T *term, jobopt_T *opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
183 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
184 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
185 #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
186 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
187 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
188
12800
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
189 /* The character that we know (or assume) that the terminal expects for the
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
190 * backspace key. */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
191 static int term_backspace_char = BS;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
192
12973
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
193 /* "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
194 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
195 static int term_default_cterm_bg = -1;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
196
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
197 /* Store the last set and the desired cursor properties, so that we only update
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
198 * them when needed. Doing it unnecessary may result in flicker. */
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
199 static char_u *last_set_cursor_color = (char_u *)"";
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
200 static char_u *desired_cursor_color = (char_u *)"";
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
201 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
202 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
203 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
204 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
205
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
206
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
207 /**************************************
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
208 * 1. Generic code for all systems.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
209 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
210
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
211 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
212 * Determine the terminal size from 'termsize' and the current window.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
213 * Assumes term->tl_rows and term->tl_cols are zero.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
214 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
215 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
216 set_term_and_win_size(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
217 {
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
218 #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
219 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
220 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
221 /* Use the whole screen for the system command. However, it will start
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
222 * at the command line and scroll up as needed, using tl_toprow. */
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
223 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
224 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
225 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
226 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
227 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
228 if (*curwin->w_p_tms != NUL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
229 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
230 char_u *p = vim_strchr(curwin->w_p_tms, 'x') + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
231
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
232 term->tl_rows = atoi((char *)curwin->w_p_tms);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
233 term->tl_cols = atoi((char *)p);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
234 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
235 if (term->tl_rows == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
236 term->tl_rows = curwin->w_height;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
237 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
238 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
239 win_setheight_win(term->tl_rows, curwin);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
240 term->tl_rows_fixed = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
241 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
242 if (term->tl_cols == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
243 term->tl_cols = curwin->w_width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
244 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
245 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
246 win_setwidth_win(term->tl_cols, curwin);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
247 term->tl_cols_fixed = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
248 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
249 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
250
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
251 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
252 * Initialize job options for a terminal job.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
253 * Caller may overrule some of them.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
254 */
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
255 void
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
256 init_job_options(jobopt_T *opt)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
257 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
258 clear_job_options(opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
259
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
260 opt->jo_mode = MODE_RAW;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
261 opt->jo_out_mode = MODE_RAW;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
262 opt->jo_err_mode = MODE_RAW;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
263 opt->jo_set = JO_MODE | JO_OUT_MODE | JO_ERR_MODE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
264 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
265
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
266 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
267 * Set job options mandatory for a terminal job.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
268 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
269 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
270 setup_job_options(jobopt_T *opt, int rows, int cols)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
271 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
272 if (!(opt->jo_set & JO_OUT_IO))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
273 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
274 /* Connect stdout to the terminal. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
275 opt->jo_io[PART_OUT] = JIO_BUFFER;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
276 opt->jo_io_buf[PART_OUT] = curbuf->b_fnum;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
277 opt->jo_modifiable[PART_OUT] = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
278 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
279 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
280
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
281 if (!(opt->jo_set & JO_ERR_IO))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
282 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
283 /* Connect stderr to the terminal. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
284 opt->jo_io[PART_ERR] = JIO_BUFFER;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
285 opt->jo_io_buf[PART_ERR] = curbuf->b_fnum;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
286 opt->jo_modifiable[PART_ERR] = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
287 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
288 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
289
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
290 opt->jo_pty = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
291 if ((opt->jo_set2 & JO2_TERM_ROWS) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
292 opt->jo_term_rows = rows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
293 if ((opt->jo_set2 & JO2_TERM_COLS) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
294 opt->jo_term_cols = cols;
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
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
297 /*
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
298 * 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
299 * fails.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
300 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
301 static void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
302 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
303 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
304 free_terminal(buf);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
305 if (old_curbuf != NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
306 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
307 --curbuf->b_nwindows;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
308 curbuf = old_curbuf;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
309 curwin->w_buffer = curbuf;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
310 ++curbuf->b_nwindows;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
311 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
312
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
313 /* Wiping out the buffer will also close the window and call
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
314 * free_terminal(). */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
315 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
316 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
317
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
318 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
319 * 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
320 * 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
321 * 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
322 * the window.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
323 * Returns NULL when failed.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
324 */
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
325 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
326 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
327 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
328 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
329 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
330 int flags)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
331 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
332 exarg_T split_ea;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
333 win_T *old_curwin = curwin;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
334 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
335 buf_T *old_curbuf = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
336 int res;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
337 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
338 int vertical = opt->jo_vertical || (cmdmod.split & WSP_VERT);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
339
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
340 if (check_restricted() || check_secure())
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
341 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
342
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
343 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
344 == (JO_IN_IO + JO_OUT_IO + JO_ERR_IO)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
345 || (!(opt->jo_set & JO_OUT_IO) && (opt->jo_set & JO_OUT_BUF))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
346 || (!(opt->jo_set & JO_ERR_IO) && (opt->jo_set & JO_ERR_BUF)))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
347 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
348 EMSG(_(e_invarg));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
349 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
350 }
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 term = (term_T *)alloc_clear(sizeof(term_T));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
353 if (term == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
354 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
355 term->tl_dirty_row_end = MAX_ROW;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
356 term->tl_cursor_visible = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
357 term->tl_cursor_shape = VTERM_PROP_CURSORSHAPE_BLOCK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
358 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
359 #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
360 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
361 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
362 ga_init2(&term->tl_scrollback, sizeof(sb_line_T), 300);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
363
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
364 vim_memset(&split_ea, 0, sizeof(split_ea));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
365 if (opt->jo_curwin)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
366 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
367 /* 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
368 if (!can_abandon(curbuf, flags & TERM_START_FORCEIT))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
369 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
370 no_write_message();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
371 vim_free(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
372 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
373 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
374 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
375 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
376 + ((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
377 curwin) == FAIL)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
378 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
379 vim_free(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
380 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
381 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
382 }
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
383 else if (opt->jo_hidden || (flags & TERM_START_SYSTEM))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
384 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
385 buf_T *buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
386
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
387 /* Create a new buffer without a window. Make it the current buffer for
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
388 * a moment to be able to do the initialisations. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
389 buf = buflist_new((char_u *)"", NULL, (linenr_T)0,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
390 BLN_NEW | BLN_LISTED);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
391 if (buf == NULL || ml_open(buf) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
392 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
393 vim_free(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
394 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
395 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
396 old_curbuf = curbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
397 --curbuf->b_nwindows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
398 curbuf = buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
399 curwin->w_buffer = buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
400 ++curbuf->b_nwindows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
401 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
402 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
403 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
404 /* Open a new window or tab. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
405 split_ea.cmdidx = CMD_new;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
406 split_ea.cmd = (char_u *)"new";
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
407 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
408 if (opt->jo_term_rows > 0 && !vertical)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
409 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
410 split_ea.line2 = opt->jo_term_rows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
411 split_ea.addr_count = 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
412 }
13501
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
413 if (opt->jo_term_cols > 0 && vertical)
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 split_ea.line2 = opt->jo_term_cols;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
416 split_ea.addr_count = 1;
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
13501
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
419 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
420 cmdmod.split |= WSP_VERT;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
421 ex_splitview(&split_ea);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
422 if (curwin == old_curwin)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
423 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
424 /* split failed */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
425 vim_free(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
426 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
427 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
428 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
429 term->tl_buffer = curbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
430 curbuf->b_term = term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
431
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
432 if (!opt->jo_hidden)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
433 {
13304
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents: 13300
diff changeset
434 /* Only one size was taken care of with :new, do the other one. With
013c44d9dc09 patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents: 13300
diff changeset
435 * "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
436 if (opt->jo_term_rows > 0 && (opt->jo_curwin || vertical))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
437 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
438 if (opt->jo_term_cols > 0 && (opt->jo_curwin || !vertical))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
439 win_setwidth(opt->jo_term_cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
440 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
441
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
442 /* Link the new terminal in the list of active terminals. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
443 term->tl_next = first_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
444 first_term = term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
445
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
446 if (opt->jo_term_name != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
447 curbuf->b_ffname = vim_strsave(opt->jo_term_name);
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
448 else if (argv != NULL)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
449 curbuf->b_ffname = vim_strsave((char_u *)"!system");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
450 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
451 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
452 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
453 size_t len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
454 char_u *cmd, *p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
455
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
456 if (argvar->v_type == VAR_STRING)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
457 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
458 cmd = argvar->vval.v_string;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
459 if (cmd == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
460 cmd = (char_u *)"";
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
461 else if (STRCMP(cmd, "NONE") == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
462 cmd = (char_u *)"pty";
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
463 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
464 else if (argvar->v_type != VAR_LIST
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
465 || argvar->vval.v_list == NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
466 || argvar->vval.v_list->lv_len < 1
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
467 || (cmd = get_tv_string_chk(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
468 &argvar->vval.v_list->lv_first->li_tv)) == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
469 cmd = (char_u*)"";
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
470
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
471 len = STRLEN(cmd) + 10;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
472 p = alloc((int)len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
473
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
474 for (i = 0; p != NULL; ++i)
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 /* Prepend a ! to the command name to avoid the buffer name equals
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
477 * the executable, otherwise ":w!" would overwrite it. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
478 if (i == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
479 vim_snprintf((char *)p, len, "!%s", cmd);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
480 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
481 vim_snprintf((char *)p, len, "!%s (%d)", cmd, i);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
482 if (buflist_findname(p) == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
483 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
484 vim_free(curbuf->b_ffname);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
485 curbuf->b_ffname = p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
486 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
487 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
488 }
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 curbuf->b_fname = curbuf->b_ffname;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
491
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
492 if (opt->jo_term_opencmd != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
493 term->tl_opencmd = vim_strsave(opt->jo_term_opencmd);
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 if (opt->jo_eof_chars != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
496 term->tl_eof_chars = vim_strsave(opt->jo_eof_chars);
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 set_string_option_direct((char_u *)"buftype", -1,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
499 (char_u *)"terminal", OPT_FREE|OPT_LOCAL, 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
500
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
501 /* Mark the buffer as not modifiable. It can only be made modifiable after
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
502 * the job finished. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
503 curbuf->b_p_ma = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
504
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
505 set_term_and_win_size(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
506 setup_job_options(opt, term->tl_rows, term->tl_cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
507
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
508 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
509 return curbuf;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
510
13435
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
511 #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
512 /* 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
513 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
514 {
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
515 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
516 }
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
517 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
518 {
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
519 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
520
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
521 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
522 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
523 }
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
524 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
525 && 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
526 && 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
527 {
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
528 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
529 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
530
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
531 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
532 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
533 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
534 {
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
535 char_u *s = get_tv_string_chk(&item->li_tv);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
536 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
537
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
538 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
539 break;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
540 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
541 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
542 break;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
543 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
544 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
545 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
546 }
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
547 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
548 {
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
549 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
550 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
551 }
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
552 else
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
553 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
554 }
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
555 #endif
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
556
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
557 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
558 {
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
559 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
560
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
561 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
562 }
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
563
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
564 /* 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
565 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
566 && argvar->v_type == VAR_STRING
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
567 && argvar->vval.v_string != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
568 && STRCMP(argvar->vval.v_string, "NONE") == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
569 res = create_pty_only(term, opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
570 else
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
571 res = term_and_job_init(term, argvar, argv, opt);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
572
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
573 newbuf = curbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
574 if (res == OK)
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 /* Get and remember the size we ended up with. Update the pty. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
577 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
578 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
579 #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
580 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
581 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
582 /* display first line below typed command */
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
583 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
584 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
585 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
586 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
587
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
588 /* Make sure we don't get stuck on sending keys to the job, it leads to
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
589 * a deadlock if the job is waiting for Vim to read. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
590 channel_set_nonblock(term->tl_job->jv_channel, PART_IN);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
591
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
592 if (old_curbuf == NULL)
13282
8db0345053b9 patch 8.0.1515: BufWinEnter event fired when opening hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 13250
diff changeset
593 {
8db0345053b9 patch 8.0.1515: BufWinEnter event fired when opening hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 13250
diff changeset
594 ++curbuf->b_locked;
8db0345053b9 patch 8.0.1515: BufWinEnter event fired when opening hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 13250
diff changeset
595 apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf);
8db0345053b9 patch 8.0.1515: BufWinEnter event fired when opening hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 13250
diff changeset
596 --curbuf->b_locked;
8db0345053b9 patch 8.0.1515: BufWinEnter event fired when opening hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 13250
diff changeset
597 }
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
598 else
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
599 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
600 --curbuf->b_nwindows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
601 curbuf = old_curbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
602 curwin->w_buffer = curbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
603 ++curbuf->b_nwindows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
604 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
605 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
606 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
607 {
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
608 term_close_buffer(curbuf, old_curbuf);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
609 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
610 }
13444
9f06f7aca74c patch 8.0.1596: no autocommand specifically for opening a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13438
diff changeset
611
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
612 apply_autocmds(EVENT_TERMINALOPEN, NULL, NULL, FALSE, newbuf);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
613 return newbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
614 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
615
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
616 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
617 * ":terminal": open a terminal window and execute a job in it.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
618 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
619 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
620 ex_terminal(exarg_T *eap)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
621 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
622 typval_T argvar[2];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
623 jobopt_T opt;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
624 char_u *cmd;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
625 char_u *tofree = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
626
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
627 init_job_options(&opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
628
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
629 cmd = eap->arg;
13219
4b8d89ea9edb patch 8.0.1484: reduntant conditions
Christian Brabandt <cb@256bit.org>
parents: 13206
diff changeset
630 while (*cmd == '+' && *(cmd + 1) == '+')
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
631 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
632 char_u *p, *ep;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
633
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
634 cmd += 2;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
635 p = skiptowhite(cmd);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
636 ep = vim_strchr(cmd, '=');
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
637 if (ep != NULL && ep < p)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
638 p = ep;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
639
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
640 if ((int)(p - cmd) == 5 && STRNICMP(cmd, "close", 5) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
641 opt.jo_term_finish = 'c';
13476
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
642 else if ((int)(p - cmd) == 7 && STRNICMP(cmd, "noclose", 7) == 0)
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
643 opt.jo_term_finish = 'n';
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
644 else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "open", 4) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
645 opt.jo_term_finish = 'o';
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
646 else if ((int)(p - cmd) == 6 && STRNICMP(cmd, "curwin", 6) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
647 opt.jo_curwin = 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
648 else if ((int)(p - cmd) == 6 && STRNICMP(cmd, "hidden", 6) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
649 opt.jo_hidden = 1;
13435
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
650 else if ((int)(p - cmd) == 9 && STRNICMP(cmd, "norestore", 9) == 0)
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
651 opt.jo_term_norestore = 1;
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
652 else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "kill", 4) == 0
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
653 && ep != NULL)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
654 {
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
655 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
656 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
657 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
658 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
659 else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "rows", 4) == 0
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
660 && ep != NULL && isdigit(ep[1]))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
661 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
662 opt.jo_set2 |= JO2_TERM_ROWS;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
663 opt.jo_term_rows = atoi((char *)ep + 1);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
664 p = skiptowhite(cmd);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
665 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
666 else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "cols", 4) == 0
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
667 && ep != NULL && isdigit(ep[1]))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
668 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
669 opt.jo_set2 |= JO2_TERM_COLS;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
670 opt.jo_term_cols = atoi((char *)ep + 1);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
671 p = skiptowhite(cmd);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
672 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
673 else if ((int)(p - cmd) == 3 && STRNICMP(cmd, "eof", 3) == 0
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
674 && ep != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
675 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
676 char_u *buf = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
677 char_u *keys;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
678
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
679 p = skiptowhite(cmd);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
680 *p = NUL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
681 keys = replace_termcodes(ep + 1, &buf, TRUE, TRUE, TRUE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
682 opt.jo_set2 |= JO2_EOF_CHARS;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
683 opt.jo_eof_chars = vim_strsave(keys);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
684 vim_free(buf);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
685 *p = ' ';
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
686 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
687 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
688 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
689 if (*p)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
690 *p = NUL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
691 EMSG2(_("E181: Invalid attribute: %s"), cmd);
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
692 goto theend;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
693 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
694 cmd = skipwhite(p);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
695 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
696 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
697 {
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
698 /* Make a copy of 'shell', an autocommand may change the option. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
699 tofree = cmd = vim_strsave(p_sh);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
700
13476
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
701 /* default to close when the shell exits */
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
702 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
703 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
704 }
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
705
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
706 if (eap->addr_count > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
707 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
708 /* Write lines from current buffer to the job. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
709 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
710 opt.jo_io[PART_IN] = JIO_BUFFER;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
711 opt.jo_io_buf[PART_IN] = curbuf->b_fnum;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
712 opt.jo_in_top = eap->line1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
713 opt.jo_in_bot = eap->line2;
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 argvar[0].v_type = VAR_STRING;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
717 argvar[0].vval.v_string = cmd;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
718 argvar[1].v_type = VAR_UNKNOWN;
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
719 term_start(argvar, NULL, &opt, eap->forceit ? TERM_START_FORCEIT : 0);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
720 vim_free(tofree);
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
721
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
722 theend:
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
723 vim_free(opt.jo_eof_chars);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
724 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
725
13435
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
726 #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
727 /*
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
728 * 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
729 * 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
730 * 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
731 */
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
732 int
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
733 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
734 {
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
735 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
736
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
737 /* Create the terminal and run the command. This is not without
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
738 * risk, but let's assume the user only creates a session when this
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
739 * will be OK. */
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
740 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
741 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
742 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
743 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
744 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
745
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
746 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
747 }
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
748
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
749 /*
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
750 * 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
751 */
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
752 int
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
753 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
754 {
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
755 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
756
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
757 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
758 || 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
759 }
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
760 #endif
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
761
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
762 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
763 * Free the scrollback buffer for "term".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
764 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
765 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
766 free_scrollback(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
767 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
768 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
769
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
770 for (i = 0; i < term->tl_scrollback.ga_len; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
771 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
772 ga_clear(&term->tl_scrollback);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
773 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
774
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
775 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
776 * Free a terminal and everything it refers to.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
777 * Kills the job if there is one.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
778 * Called when wiping out a buffer.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
779 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
780 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
781 free_terminal(buf_T *buf)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
782 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
783 term_T *term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
784 term_T *tp;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
785
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
786 if (term == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
787 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
788 if (first_term == term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
789 first_term = term->tl_next;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
790 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
791 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
792 if (tp->tl_next == term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
793 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
794 tp->tl_next = term->tl_next;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
795 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
796 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
797
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
798 if (term->tl_job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
799 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
800 if (term->tl_job->jv_status != JOB_ENDED
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
801 && 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
802 && term->tl_job->jv_status != JOB_FAILED)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
803 job_stop(term->tl_job, NULL, "kill");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
804 job_unref(term->tl_job);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
805 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
806
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
807 free_scrollback(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
808
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
809 term_free_vterm(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
810 vim_free(term->tl_title);
13435
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
811 #ifdef FEAT_SESSION
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
812 vim_free(term->tl_command);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
813 #endif
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
814 vim_free(term->tl_kill);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
815 vim_free(term->tl_status_text);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
816 vim_free(term->tl_opencmd);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
817 vim_free(term->tl_eof_chars);
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
818 if (desired_cursor_color == term->tl_cursor_color)
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
819 desired_cursor_color = (char_u *)"";
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
820 vim_free(term->tl_cursor_color);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
821 vim_free(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
822 buf->b_term = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
823 if (in_terminal_loop == term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
824 in_terminal_loop = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
825 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
826
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
827 /*
13132
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
828 * 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
829 * 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
830 * 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
831 */
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
832 static ch_part_T
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
833 get_tty_part(term_T *term)
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
834 {
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
835 #ifdef UNIX
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
836 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
837 int i;
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
838
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
839 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
840 {
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
841 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
842
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
843 if (isatty(fd))
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
844 return parts[i];
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
845 }
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
846 #endif
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
847 return PART_IN;
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
848 }
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
849
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
850 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
851 * Write job output "msg[len]" to the vterm.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
852 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
853 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
854 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
855 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
856 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
857 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
858
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
859 vterm_input_write(vterm, (char *)msg, len);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
860
13132
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
861 /* flush vterm buffer when vterm responded to control sequence */
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
862 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
863 {
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
864 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
865 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
866
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
867 if (curlen > 0)
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
868 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
869 (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
870 }
fe0cec169589 patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents: 13111
diff changeset
871
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
872 /* this invokes the damage callbacks */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
873 vterm_screen_flush_damage(vterm_obtain_screen(vterm));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
874 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
875
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
876 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
877 update_cursor(term_T *term, int redraw)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
878 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
879 if (term->tl_normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
880 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
881 #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
882 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
883 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
884 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
885 else
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
886 #endif
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
887 setcursor();
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
888 if (redraw)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
889 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
890 if (term->tl_buffer == curbuf && term->tl_cursor_visible)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
891 cursor_on();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
892 out_flush();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
893 #ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
894 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
895 {
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
896 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
897 gui_mch_flush();
6f98a5fd0c19 patch 8.0.1376: cursor in terminal not always updated
Christian Brabandt <cb@256bit.org>
parents: 12984
diff changeset
898 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
899 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
900 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
901 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
902
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
903 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
904 * 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
905 * of "buffer".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
906 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
907 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
908 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
909 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
910 size_t len = STRLEN(msg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
911 term_T *term = buffer->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
912
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
913 if (term->tl_vterm == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
914 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
915 ch_log(channel, "NOT writing %d bytes to terminal", (int)len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
916 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
917 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
918 ch_log(channel, "writing %d bytes to terminal", (int)len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
919 term_write_job_output(term, msg, len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
920
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
921 #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
922 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
923 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
924 /* show system output, scrolling up the screen as needed */
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
925 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
926 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
927 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
928 else
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
929 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
930 /* In Terminal-Normal mode we are displaying the buffer, not the terminal
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
931 * contents, thus no screen update is needed. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
932 if (!term->tl_normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
933 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
934 /* TODO: only update once in a while. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
935 ch_log(term->tl_job->jv_channel, "updating screen");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
936 if (buffer == curbuf)
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 update_screen(0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
939 update_cursor(term, TRUE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
940 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
941 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
942 redraw_after_callback(TRUE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
943 }
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
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
946 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
947 * Send a mouse position and click to the vterm
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
948 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
949 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
950 term_send_mouse(VTerm *vterm, int button, int pressed)
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 VTermModifier mod = VTERM_MOD_NONE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
953
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
954 vterm_mouse_move(vterm, mouse_row - W_WINROW(curwin),
12513
3ca08bf99396 patch 8.0.1135: W_WINCOL() is always the same
Christian Brabandt <cb@256bit.org>
parents: 12509
diff changeset
955 mouse_col - curwin->w_wincol, mod);
12865
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12845
diff changeset
956 if (button != 0)
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12845
diff changeset
957 vterm_mouse_button(vterm, button, pressed, mod);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
958 return TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
959 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
960
13448
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
961 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
962 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
963
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
964 /*
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
965 * 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
966 * 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
967 */
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
968 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
969 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
970 {
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
971 #if defined(FEAT_CLIPBOARD)
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
972 /* For modeless selection mouse drag and release events are ignored, unless
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
973 * they are preceded with a mouse down event */
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
974 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
975 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
976
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
977 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
978 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
979 {
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
980 /* Terminal is not using the mouse, use modeless selection. */
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
981 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
982 {
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
983 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
984 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
985 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
986 case K_RIGHTRELEASE:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
987 /* Ignore drag and release events when the button-down wasn't
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
988 * seen before. */
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
989 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
990 {
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
991 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
992
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
993 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
994 break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
995
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
996 /* mouse click in the window gave us focus, handle that
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
997 * click now */
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
998 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
999 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
1000 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
1001 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
1002 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
1003 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
1004 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
1005 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1006 /* FALLTHROUGH */
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1007 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
1008 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
1009 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
1010 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
1011 else
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1012 ignore_drag_release = FALSE;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1013 /* Should we call mouse_has() here? */
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1014 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
1015 {
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1016 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
1017
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1018 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
1019 &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
1020 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
1021 && (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
1022 {
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1023 /* Translate shift-left to right button. */
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1024 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
1025 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
1026 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1027 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
1028 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1029 break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1030
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1031 case K_MIDDLEMOUSE:
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1032 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
1033 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
1034 break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1035 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1036 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
1037 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
1038 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1039 #endif
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1040 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
1041
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1042 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
1043 {
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1044 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
1045 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
1046 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
1047 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
1048 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
1049 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
1050 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
1051 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
1052 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
1053 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
1054 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
1055 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
1056 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1057 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
1058 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1059
12502
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 * Convert typed key "c" into bytes to send to the job.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1062 * Return the number of bytes in "buf".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1063 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1064 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1065 term_convert_key(term_T *term, int c, char *buf)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1066 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1067 VTerm *vterm = term->tl_vterm;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1068 VTermKey key = VTERM_KEY_NONE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1069 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
1070 int other = FALSE;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1071
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1072 switch (c)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1073 {
12800
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
1074 /* don't use VTERM_KEY_ENTER, it may do an unwanted conversion */
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
1075
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1076 /* don't use VTERM_KEY_BACKSPACE, it always
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1077 * becomes 0x7f DEL */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1078 case K_BS: c = term_backspace_char; break;
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 case ESC: key = VTERM_KEY_ESCAPE; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1081 case K_DEL: key = VTERM_KEY_DEL; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1082 case K_DOWN: key = VTERM_KEY_DOWN; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1083 case K_S_DOWN: mod = VTERM_MOD_SHIFT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1084 key = VTERM_KEY_DOWN; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1085 case K_END: key = VTERM_KEY_END; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1086 case K_S_END: mod = VTERM_MOD_SHIFT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1087 key = VTERM_KEY_END; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1088 case K_C_END: mod = VTERM_MOD_CTRL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1089 key = VTERM_KEY_END; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1090 case K_F10: key = VTERM_KEY_FUNCTION(10); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1091 case K_F11: key = VTERM_KEY_FUNCTION(11); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1092 case K_F12: key = VTERM_KEY_FUNCTION(12); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1093 case K_F1: key = VTERM_KEY_FUNCTION(1); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1094 case K_F2: key = VTERM_KEY_FUNCTION(2); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1095 case K_F3: key = VTERM_KEY_FUNCTION(3); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1096 case K_F4: key = VTERM_KEY_FUNCTION(4); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1097 case K_F5: key = VTERM_KEY_FUNCTION(5); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1098 case K_F6: key = VTERM_KEY_FUNCTION(6); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1099 case K_F7: key = VTERM_KEY_FUNCTION(7); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1100 case K_F8: key = VTERM_KEY_FUNCTION(8); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1101 case K_F9: key = VTERM_KEY_FUNCTION(9); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1102 case K_HOME: key = VTERM_KEY_HOME; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1103 case K_S_HOME: mod = VTERM_MOD_SHIFT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1104 key = VTERM_KEY_HOME; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1105 case K_C_HOME: mod = VTERM_MOD_CTRL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1106 key = VTERM_KEY_HOME; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1107 case K_INS: key = VTERM_KEY_INS; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1108 case K_K0: key = VTERM_KEY_KP_0; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1109 case K_K1: key = VTERM_KEY_KP_1; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1110 case K_K2: key = VTERM_KEY_KP_2; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1111 case K_K3: key = VTERM_KEY_KP_3; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1112 case K_K4: key = VTERM_KEY_KP_4; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1113 case K_K5: key = VTERM_KEY_KP_5; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1114 case K_K6: key = VTERM_KEY_KP_6; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1115 case K_K7: key = VTERM_KEY_KP_7; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1116 case K_K8: key = VTERM_KEY_KP_8; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1117 case K_K9: key = VTERM_KEY_KP_9; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1118 case K_KDEL: key = VTERM_KEY_DEL; break; /* TODO */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1119 case K_KDIVIDE: key = VTERM_KEY_KP_DIVIDE; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1120 case K_KEND: key = VTERM_KEY_KP_1; break; /* TODO */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1121 case K_KENTER: key = VTERM_KEY_KP_ENTER; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1122 case K_KHOME: key = VTERM_KEY_KP_7; break; /* TODO */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1123 case K_KINS: key = VTERM_KEY_KP_0; break; /* TODO */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1124 case K_KMINUS: key = VTERM_KEY_KP_MINUS; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1125 case K_KMULTIPLY: key = VTERM_KEY_KP_MULT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1126 case K_KPAGEDOWN: key = VTERM_KEY_KP_3; break; /* TODO */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1127 case K_KPAGEUP: key = VTERM_KEY_KP_9; break; /* TODO */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1128 case K_KPLUS: key = VTERM_KEY_KP_PLUS; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1129 case K_KPOINT: key = VTERM_KEY_KP_PERIOD; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1130 case K_LEFT: key = VTERM_KEY_LEFT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1131 case K_S_LEFT: mod = VTERM_MOD_SHIFT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1132 key = VTERM_KEY_LEFT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1133 case K_C_LEFT: mod = VTERM_MOD_CTRL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1134 key = VTERM_KEY_LEFT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1135 case K_PAGEDOWN: key = VTERM_KEY_PAGEDOWN; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1136 case K_PAGEUP: key = VTERM_KEY_PAGEUP; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1137 case K_RIGHT: key = VTERM_KEY_RIGHT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1138 case K_S_RIGHT: mod = VTERM_MOD_SHIFT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1139 key = VTERM_KEY_RIGHT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1140 case K_C_RIGHT: mod = VTERM_MOD_CTRL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1141 key = VTERM_KEY_RIGHT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1142 case K_UP: key = VTERM_KEY_UP; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1143 case K_S_UP: mod = VTERM_MOD_SHIFT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1144 key = VTERM_KEY_UP; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1145 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
1146 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
1147 key = VTERM_KEY_TAB; break;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1148
12845
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
1149 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
1150 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
1151 case K_MOUSELEFT: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1152 case K_MOUSERIGHT: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1153
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1154 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
1155 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
1156 case K_LEFTDRAG:
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1157 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
1158 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
1159 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
1160 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
1161 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
1162 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
1163 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
1164 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
1165 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
1166 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
1167 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
1168 break;
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1169
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1170 case K_X1MOUSE: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1171 case K_X1DRAG: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1172 case K_X1RELEASE: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1173 case K_X2MOUSE: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1174 case K_X2DRAG: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1175 case K_X2RELEASE: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1176
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1177 case K_IGNORE: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1178 case K_NOP: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1179 case K_UNDO: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1180 case K_HELP: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1181 case K_XF1: key = VTERM_KEY_FUNCTION(1); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1182 case K_XF2: key = VTERM_KEY_FUNCTION(2); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1183 case K_XF3: key = VTERM_KEY_FUNCTION(3); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1184 case K_XF4: key = VTERM_KEY_FUNCTION(4); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1185 case K_SELECT: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1186 #ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1187 case K_VER_SCROLLBAR: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1188 case K_HOR_SCROLLBAR: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1189 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1190 #ifdef FEAT_GUI_TABLINE
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1191 case K_TABLINE: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1192 case K_TABMENU: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1193 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1194 #ifdef FEAT_NETBEANS_INTG
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1195 case K_F21: key = VTERM_KEY_FUNCTION(21); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1196 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1197 #ifdef FEAT_DND
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1198 case K_DROP: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1199 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1200 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
1201 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
1202 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
1203 break;
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
1204 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
1205 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
1206 break;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1207 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1208
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1209 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1210 * Convert special keys to vterm keys:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1211 * - Write keys to vterm: vterm_keyboard_key()
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1212 * - Write output to channel.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1213 * TODO: use mod_mask
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1214 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1215 if (key != VTERM_KEY_NONE)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1216 /* Special key, let vterm convert it. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1217 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
1218 else if (!other)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1219 /* Normal character, let vterm convert it. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1220 vterm_keyboard_unichar(vterm, c, mod);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1221
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1222 /* Read back the converted escape sequence. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1223 return (int)vterm_output_read(vterm, buf, KEY_BUF_LEN);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1224 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1225
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1226 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1227 * Return TRUE if the job for "term" is still running.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1228 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1229 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1230 term_job_running(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1231 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1232 /* Also consider the job finished when the channel is closed, to avoid a
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1233 * race condition when updating the title. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1234 return term != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1235 && term->tl_job != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1236 && channel_is_open(term->tl_job->jv_channel)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1237 && (term->tl_job->jv_status == JOB_STARTED
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1238 || term->tl_job->jv_channel->ch_keep_open);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1239 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1240
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1241 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1242 * 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
1243 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1244 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1245 term_none_open(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1246 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1247 /* Also consider the job finished when the channel is closed, to avoid a
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1248 * race condition when updating the title. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1249 return term != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1250 && term->tl_job != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1251 && channel_is_open(term->tl_job->jv_channel)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1252 && term->tl_job->jv_channel->ch_keep_open;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1253 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1254
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1255 /*
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1256 * 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
1257 * 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
1258 * 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
1259 */
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1260 int
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1261 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
1262 {
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1263 int count;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1264 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
1265
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1266 #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
1267 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
1268 {
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1269 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
1270 int ret;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1271
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1272 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
1273 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
1274 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
1275 how = "kill";
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1276 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
1277 return FAIL;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1278 }
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1279 #endif
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1280 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
1281 return FAIL;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1282
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1283 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
1284
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1285 /* wait for up to a second for the job to die */
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1286 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
1287 {
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1288 /* buffer, terminal and job may be cleaned up while waiting */
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1289 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
1290 || 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
1291 || 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
1292 return OK;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1293
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1294 /* call job_status() to update jv_status */
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1295 job_status(buf->b_term->tl_job);
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1296 if (buf->b_term->tl_job->jv_status >= JOB_ENDED)
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1297 return OK;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1298 ui_delay(10L, FALSE);
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1299 mch_check_messages();
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1300 parse_queued_messages();
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1301 }
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1302 return FAIL;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1303 }
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1304
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
1305 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1306 * 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
1307 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1308 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1309 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
1310 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1311 buf_T *buf = term->tl_buffer;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1312 int empty = (buf->b_ml.ml_flags & ML_EMPTY);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1313 linenr_T lnum = buf->b_ml.ml_line_count;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1314
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1315 #ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1316 if (!enc_utf8 && enc_codepage > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1317 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1318 WCHAR *ret = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1319 int length = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1320
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1321 MultiByteToWideChar_alloc(CP_UTF8, 0, (char*)text, len + 1,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1322 &ret, &length);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1323 if (ret != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1324 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1325 WideCharToMultiByte_alloc(enc_codepage, 0,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1326 ret, length, (char **)&text, &len, 0, 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1327 vim_free(ret);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1328 ml_append_buf(term->tl_buffer, lnum, text, len, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1329 vim_free(text);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1330 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1331 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1332 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1333 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1334 ml_append_buf(term->tl_buffer, lnum, text, len + 1, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1335 if (empty)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1336 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1337 /* Delete the empty line that was in the empty buffer. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1338 curbuf = buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1339 ml_delete(1, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1340 curbuf = curwin->w_buffer;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1341 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1342 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1343
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1344 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1345 cell2cellattr(const VTermScreenCell *cell, cellattr_T *attr)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1346 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1347 attr->width = cell->width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1348 attr->attrs = cell->attrs;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1349 attr->fg = cell->fg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1350 attr->bg = cell->bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1351 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1352
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1353 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1354 equal_celattr(cellattr_T *a, cellattr_T *b)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1355 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1356 /* Comparing the colors should be sufficient. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1357 return a->fg.red == b->fg.red
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1358 && a->fg.green == b->fg.green
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1359 && a->fg.blue == b->fg.blue
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1360 && a->bg.red == b->bg.red
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1361 && a->bg.green == b->bg.green
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1362 && a->bg.blue == b->bg.blue;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1363 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1364
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1365 /*
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1366 * 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
1367 * 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
1368 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1369 static int
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1370 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
1371 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1372 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
1373 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1374 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
1375 + 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
1376
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1377 if (lnum > 0)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1378 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1379 int i;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1380
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1381 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
1382 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1383 *line = *(line - 1);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1384 --line;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1385 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1386 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1387 line->sb_cols = 0;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1388 line->sb_cells = NULL;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1389 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
1390 ++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
1391 return OK;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1392 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1393 return FALSE;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1394 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1395
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1396 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1397 * 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
1398 * Called after the job has ended and when switching to Terminal-Normal mode.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1399 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1400 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1401 move_terminal_to_buffer(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1402 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1403 win_T *wp;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1404 int len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1405 int lines_skipped = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1406 VTermPos pos;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1407 VTermScreenCell cell;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1408 cellattr_T fill_attr, new_fill_attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1409 cellattr_T *p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1410 VTermScreen *screen;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1411
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1412 if (term->tl_vterm == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1413 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1414 screen = vterm_obtain_screen(term->tl_vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1415 fill_attr = new_fill_attr = term->tl_default_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1416
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1417 for (pos.row = 0; pos.row < term->tl_rows; ++pos.row)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1418 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1419 len = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1420 for (pos.col = 0; pos.col < term->tl_cols; ++pos.col)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1421 if (vterm_screen_get_cell(screen, pos, &cell) != 0
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1422 && cell.chars[0] != NUL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1423 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1424 len = pos.col + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1425 new_fill_attr = term->tl_default_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1426 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1427 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1428 /* Assume the last attr is the filler attr. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1429 cell2cellattr(&cell, &new_fill_attr);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1430
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1431 if (len == 0 && equal_celattr(&new_fill_attr, &fill_attr))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1432 ++lines_skipped;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1433 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1434 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1435 while (lines_skipped > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1436 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1437 /* Line was skipped, add an empty line. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1438 --lines_skipped;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
1439 if (add_empty_scrollback(term, &fill_attr, 0) == OK)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1440 add_scrollback_line_to_buffer(term, (char_u *)"", 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1441 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1442
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1443 if (len == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1444 p = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1445 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1446 p = (cellattr_T *)alloc((int)sizeof(cellattr_T) * len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1447 if ((p != NULL || len == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1448 && ga_grow(&term->tl_scrollback, 1) == OK)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1449 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1450 garray_T ga;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1451 int width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1452 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
1453 + term->tl_scrollback.ga_len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1454
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1455 ga_init2(&ga, 1, 100);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1456 for (pos.col = 0; pos.col < len; pos.col += width)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1457 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1458 if (vterm_screen_get_cell(screen, pos, &cell) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1459 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1460 width = 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1461 vim_memset(p + pos.col, 0, sizeof(cellattr_T));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1462 if (ga_grow(&ga, 1) == OK)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1463 ga.ga_len += utf_char2bytes(' ',
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1464 (char_u *)ga.ga_data + ga.ga_len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1465 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1466 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1467 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1468 width = cell.width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1469
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1470 cell2cellattr(&cell, &p[pos.col]);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1471
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1472 if (ga_grow(&ga, MB_MAXBYTES) == OK)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1473 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1474 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1475 int c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1476
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1477 for (i = 0; (c = cell.chars[i]) > 0 || i == 0; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1478 ga.ga_len += utf_char2bytes(c == NUL ? ' ' : c,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1479 (char_u *)ga.ga_data + ga.ga_len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1480 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1481 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1482 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1483 line->sb_cols = len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1484 line->sb_cells = p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1485 line->sb_fill_attr = new_fill_attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1486 fill_attr = new_fill_attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1487 ++term->tl_scrollback.ga_len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1488
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1489 if (ga_grow(&ga, 1) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1490 add_scrollback_line_to_buffer(term, (char_u *)"", 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1491 else
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 *((char_u *)ga.ga_data + ga.ga_len) = NUL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1494 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
1495 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1496 ga_clear(&ga);
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 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1499 vim_free(p);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1500 }
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
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1503 /* Obtain the current background color. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1504 vterm_state_get_default_colors(vterm_obtain_state(term->tl_vterm),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1505 &term->tl_default_color.fg, &term->tl_default_color.bg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1506
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1507 FOR_ALL_WINDOWS(wp)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1508 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1509 if (wp->w_buffer == term->tl_buffer)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1510 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1511 wp->w_cursor.lnum = term->tl_buffer->b_ml.ml_line_count;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1512 wp->w_cursor.col = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1513 wp->w_valid = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1514 if (wp->w_cursor.lnum >= wp->w_height)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1515 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1516 linenr_T min_topline = wp->w_cursor.lnum - wp->w_height + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1517
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1518 if (wp->w_topline < min_topline)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1519 wp->w_topline = min_topline;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1520 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1521 redraw_win_later(wp, NOT_VALID);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1522 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1523 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1524 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1525
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1526 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1527 set_terminal_mode(term_T *term, int normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1528 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1529 term->tl_normal_mode = normal_mode;
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13219
diff changeset
1530 VIM_CLEAR(term->tl_status_text);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1531 if (term->tl_buffer == curbuf)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1532 maketitle();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1533 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1534
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1535 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1536 * 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
1537 * 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
1538 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1539 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1540 cleanup_vterm(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1541 {
13476
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
1542 if (term->tl_finish != TL_FINISH_CLOSE)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1543 move_terminal_to_buffer(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1544 term_free_vterm(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1545 set_terminal_mode(term, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1546 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1547
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1548 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1549 * Switch from Terminal-Job mode to Terminal-Normal mode.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1550 * Suspends updating the terminal window.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1551 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1552 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1553 term_enter_normal_mode(void)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1554 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1555 term_T *term = curbuf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1556
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1557 /* Append the current terminal contents to the buffer. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1558 move_terminal_to_buffer(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1559
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1560 set_terminal_mode(term, TRUE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1561
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1562 /* Move the window cursor to the position of the cursor in the
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1563 * terminal. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1564 curwin->w_cursor.lnum = term->tl_scrollback_scrolled
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1565 + term->tl_cursor_pos.row + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1566 check_cursor();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1567 coladvance(term->tl_cursor_pos.col);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1568
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1569 /* Display the same lines as in the terminal. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1570 curwin->w_topline = term->tl_scrollback_scrolled + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1571 }
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 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1574 * 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
1575 * Terminal-Normal mode.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1576 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1577 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1578 term_in_normal_mode(void)
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 term_T *term = curbuf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1581
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1582 return term != NULL && term->tl_normal_mode;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1583 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1584
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1585 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1586 * Switch from Terminal-Normal mode to Terminal-Job mode.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1587 * Restores updating the terminal window.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1588 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1589 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1590 term_enter_job_mode()
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1591 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1592 term_T *term = curbuf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1593 sb_line_T *line;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1594 garray_T *gap;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1595
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1596 /* Remove the terminal contents from the scrollback and the buffer. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1597 gap = &term->tl_scrollback;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1598 while (curbuf->b_ml.ml_line_count > term->tl_scrollback_scrolled
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1599 && gap->ga_len > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1600 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1601 ml_delete(curbuf->b_ml.ml_line_count, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1602 line = (sb_line_T *)gap->ga_data + gap->ga_len - 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1603 vim_free(line->sb_cells);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1604 --gap->ga_len;
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 check_cursor();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1607
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1608 set_terminal_mode(term, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1609
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1610 if (term->tl_channel_closed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1611 cleanup_vterm(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1612 redraw_buf_and_status_later(curbuf, NOT_VALID);
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 /*
13344
68c4fc9ae216 patch 8.0.1546: using feedkeys() in a terminal may trigger mappings
Christian Brabandt <cb@256bit.org>
parents: 13335
diff changeset
1616 * Get a key from the user with terminal mode mappings.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1617 * 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
1618 * closed and ++close was used.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1619 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1620 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1621 term_vgetc()
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1622 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1623 int c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1624 int save_State = State;
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 State = TERMINAL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1627 got_int = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1628 #ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1629 ctrl_break_was_pressed = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1630 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1631 c = vgetc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1632 got_int = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1633 State = save_State;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1634 return c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1635 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1636
13448
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1637 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
1638
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1639 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1640 * Send keys to terminal.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1641 * 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
1642 * 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
1643 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1644 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1645 send_keys_to_term(term_T *term, int c, int typed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1646 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1647 char msg[KEY_BUF_LEN];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1648 size_t len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1649 int dragging_outside = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1650
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1651 /* Catch keys that need to be handled as in Normal mode. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1652 switch (c)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1653 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1654 case NUL:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1655 case K_ZERO:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1656 if (typed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1657 stuffcharReadbuff(c);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1658 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1659
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1660 case K_IGNORE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1661 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1662
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1663 case K_LEFTDRAG:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1664 case K_MIDDLEDRAG:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1665 case K_RIGHTDRAG:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1666 case K_X1DRAG:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1667 case K_X2DRAG:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1668 dragging_outside = mouse_was_outside;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1669 /* FALLTHROUGH */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1670 case K_LEFTMOUSE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1671 case K_LEFTMOUSE_NM:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1672 case K_LEFTRELEASE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1673 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
1674 case K_MOUSEMOVE:
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1675 case K_MIDDLEMOUSE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1676 case K_MIDDLERELEASE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1677 case K_RIGHTMOUSE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1678 case K_RIGHTRELEASE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1679 case K_X1MOUSE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1680 case K_X1RELEASE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1681 case K_X2MOUSE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1682 case K_X2RELEASE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1683
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1684 case K_MOUSEUP:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1685 case K_MOUSEDOWN:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1686 case K_MOUSELEFT:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1687 case K_MOUSERIGHT:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1688 if (mouse_row < W_WINROW(curwin)
12984
fc0d4a036654 patch 8.0.1368: cannot drag status or separator of new terminal window
Christian Brabandt <cb@256bit.org>
parents: 12973
diff changeset
1689 || mouse_row >= (W_WINROW(curwin) + curwin->w_height)
12513
3ca08bf99396 patch 8.0.1135: W_WINCOL() is always the same
Christian Brabandt <cb@256bit.org>
parents: 12509
diff changeset
1690 || mouse_col < curwin->w_wincol
12984
fc0d4a036654 patch 8.0.1368: cannot drag status or separator of new terminal window
Christian Brabandt <cb@256bit.org>
parents: 12973
diff changeset
1691 || mouse_col >= W_ENDCOL(curwin)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1692 || dragging_outside)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1693 {
12984
fc0d4a036654 patch 8.0.1368: cannot drag status or separator of new terminal window
Christian Brabandt <cb@256bit.org>
parents: 12973
diff changeset
1694 /* click or scroll outside the current window or on status line
fc0d4a036654 patch 8.0.1368: cannot drag status or separator of new terminal window
Christian Brabandt <cb@256bit.org>
parents: 12973
diff changeset
1695 * or vertical separator */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1696 if (typed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1697 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1698 stuffcharReadbuff(c);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1699 mouse_was_outside = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1700 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1701 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1702 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1703 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1704 if (typed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1705 mouse_was_outside = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1706
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1707 /* Convert the typed key to a sequence of bytes for the job. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1708 len = term_convert_key(term, c, msg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1709 if (len > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1710 /* TODO: if FAIL is returned, stop? */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1711 channel_send(term->tl_job->jv_channel, get_tty_part(term),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1712 (char_u *)msg, (int)len, NULL);
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 return OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1715 }
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 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1718 position_cursor(win_T *wp, VTermPos *pos)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1719 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1720 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
1721 wp->w_wcol = MIN(pos->col, MAX(0, wp->w_width - 1));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1722 wp->w_valid |= (VALID_WCOL|VALID_WROW);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1723 }
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 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1726 * Handle CTRL-W "": send register contents to the job.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1727 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1728 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1729 term_paste_register(int prev_c UNUSED)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1730 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1731 int c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1732 list_T *l;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1733 listitem_T *item;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1734 long reglen = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1735 int type;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1736
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1737 #ifdef FEAT_CMDL_INFO
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1738 if (add_to_showcmd(prev_c))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1739 if (add_to_showcmd('"'))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1740 out_flush();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1741 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1742 c = term_vgetc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1743 #ifdef FEAT_CMDL_INFO
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1744 clear_showcmd();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1745 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1746 if (!term_use_loop())
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1747 /* job finished while waiting for a character */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1748 return;
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 /* CTRL-W "= prompt for expression to evaluate. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1751 if (c == '=' && get_expr_register() != '=')
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1752 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1753 if (!term_use_loop())
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1754 /* job finished while waiting for a character */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1755 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1756
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1757 l = (list_T *)get_reg_contents(c, GREG_LIST);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1758 if (l != NULL)
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 type = get_reg_type(c, &reglen);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1761 for (item = l->lv_first; item != NULL; item = item->li_next)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1762 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1763 char_u *s = get_tv_string(&item->li_tv);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1764 #ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1765 char_u *tmp = s;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1766
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1767 if (!enc_utf8 && enc_codepage > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1768 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1769 WCHAR *ret = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1770 int length = 0;
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 MultiByteToWideChar_alloc(enc_codepage, 0, (char *)s,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1773 (int)STRLEN(s), &ret, &length);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1774 if (ret != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1775 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1776 WideCharToMultiByte_alloc(CP_UTF8, 0,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1777 ret, length, (char **)&s, &length, 0, 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1778 vim_free(ret);
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 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1781 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1782 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1783 s, (int)STRLEN(s), NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1784 #ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1785 if (tmp != s)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1786 vim_free(s);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1787 #endif
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 if (item->li_next != NULL || type == MLINE)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1790 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1791 (char_u *)"\r", 1, NULL);
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 list_free(l);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1794 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1795 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1796
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1797 #if defined(FEAT_GUI) || defined(PROTO)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1798 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1799 * Return TRUE when the cursor of the terminal should be displayed.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1800 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1801 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1802 terminal_is_active()
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1803 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1804 return in_terminal_loop != NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1805 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1806
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1807 cursorentry_T *
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1808 term_get_cursor_shape(guicolor_T *fg, guicolor_T *bg)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1809 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1810 term_T *term = in_terminal_loop;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1811 static cursorentry_T entry;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1812
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1813 vim_memset(&entry, 0, sizeof(entry));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1814 entry.shape = entry.mshape =
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1815 term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_UNDERLINE ? SHAPE_HOR :
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1816 term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_BAR_LEFT ? SHAPE_VER :
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1817 SHAPE_BLOCK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1818 entry.percentage = 20;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1819 if (term->tl_cursor_blink)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1820 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1821 entry.blinkwait = 700;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1822 entry.blinkon = 400;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1823 entry.blinkoff = 250;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1824 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1825 *fg = gui.back_pixel;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1826 if (term->tl_cursor_color == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1827 *bg = gui.norm_pixel;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1828 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1829 *bg = color_name2handle(term->tl_cursor_color);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1830 entry.name = "n";
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1831 entry.used_for = SHAPE_CURSOR;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1832
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1833 return &entry;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1834 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1835 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1836
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
1837 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
1838 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
1839 {
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1840 if (STRCMP(last_set_cursor_color, desired_cursor_color) != 0
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1841 || 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
1842 || 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
1843 {
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1844 last_set_cursor_color = desired_cursor_color;
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1845 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
1846 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
1847 term_cursor_color(desired_cursor_color);
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1848 if (desired_cursor_shape == -1 || desired_cursor_blink == -1)
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1849 /* this will restore the initial cursor style, if possible */
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1850 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
1851 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
1852 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
1853 }
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1854 }
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1855
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1856 /*
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1857 * 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
1858 */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1859 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1860 may_set_cursor_props(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1861 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1862 #ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1863 /* For the GUI the cursor properties are obtained with
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1864 * term_get_cursor_shape(). */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1865 if (gui.in_use)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1866 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1867 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1868 if (in_terminal_loop == term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1869 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1870 if (term->tl_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
1871 desired_cursor_color = term->tl_cursor_color;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1872 else
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
1873 desired_cursor_color = (char_u *)"";
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1874 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
1875 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
1876 may_output_cursor_props();
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1877 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1878 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1879
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
1880 /*
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1881 * 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
1882 */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1883 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
1884 prepare_restore_cursor_props(void)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1885 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1886 #ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1887 if (gui.in_use)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1888 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1889 #endif
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
1890 desired_cursor_color = (char_u *)"";
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
1891 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
1892 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
1893 may_output_cursor_props();
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1894 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1895
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1896 /*
13448
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1897 * 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
1898 * 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
1899 */
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1900 void
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1901 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
1902 {
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1903 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
1904
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1905 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
1906 {
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1907 if (term_use_loop())
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1908 {
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1909 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
1910 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
1911 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
1912 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1913 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
1914 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
1915 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
1916 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1917 }
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1918
a62b0bbc8834 patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
1919 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1920 * Returns TRUE if the current window contains a terminal and we are sending
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1921 * keys to the job.
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 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1924 term_use_loop(void)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1925 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1926 term_T *term = curbuf->b_term;
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 return term != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1929 && !term->tl_normal_mode
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1930 && term->tl_vterm != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1931 && term_job_running(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1932 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1933
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1934 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1935 * Wait for input and send it to the job.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1936 * 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
1937 * when there is no more typahead.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1938 * 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
1939 * should be handled as a Normal mode command.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1940 * 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
1941 * the terminal was closed.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1942 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1943 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1944 terminal_loop(int blocking)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1945 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1946 int c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1947 int termkey = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1948 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
1949 #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
1950 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
1951 ->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
1952 #endif
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
1953 int restore_cursor;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1954
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1955 /* Remember the terminal we are sending keys to. However, the terminal
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1956 * might be closed while waiting for a character, e.g. typing "exit" in a
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1957 * shell and ++close was used. Therefore use curbuf->b_term instead of a
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1958 * stored reference. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1959 in_terminal_loop = curbuf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1960
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1961 if (*curwin->w_p_tk != NUL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1962 termkey = string_to_key(curwin->w_p_tk, TRUE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1963 position_cursor(curwin, &curbuf->b_term->tl_cursor_pos);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1964 may_set_cursor_props(curbuf->b_term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1965
13344
68c4fc9ae216 patch 8.0.1546: using feedkeys() in a terminal may trigger mappings
Christian Brabandt <cb@256bit.org>
parents: 13335
diff changeset
1966 while (blocking || vpeekc_nomap() != NUL)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1967 {
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
1968 #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
1969 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
1970 #endif
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
1971 /* TODO: skip screen update when handling a sequence of keys. */
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
1972 /* Repeat redrawing in case a message is received while redrawing.
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
1973 */
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
1974 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
1975 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
1976 break;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1977 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
1978 restore_cursor = TRUE;
12502
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 c = term_vgetc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1981 if (!term_use_loop())
12798
5ae0d05e046a patch 8.0.1276: key lost when window closed in exit callback
Christian Brabandt <cb@256bit.org>
parents: 12767
diff changeset
1982 {
12800
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
1983 /* Job finished while waiting for a character. Push back the
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
1984 * received character. */
12798
5ae0d05e046a patch 8.0.1276: key lost when window closed in exit callback
Christian Brabandt <cb@256bit.org>
parents: 12767
diff changeset
1985 if (c != K_IGNORE)
5ae0d05e046a patch 8.0.1276: key lost when window closed in exit callback
Christian Brabandt <cb@256bit.org>
parents: 12767
diff changeset
1986 vungetc(c);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1987 break;
12798
5ae0d05e046a patch 8.0.1276: key lost when window closed in exit callback
Christian Brabandt <cb@256bit.org>
parents: 12767
diff changeset
1988 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1989 if (c == K_IGNORE)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1990 continue;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1991
12800
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
1992 #ifdef UNIX
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
1993 /*
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
1994 * 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
1995 * 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
1996 * 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
1997 */
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
1998 if (isatty(tty_fd))
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
1999 {
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2000 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
2001
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2002 /* Get the current backspace character of the pty. */
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2003 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
2004 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
2005 }
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2006 #endif
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
2007
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2008 #ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2009 /* On Windows winpty handles CTRL-C, don't send a CTRL_C_EVENT.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2010 * Use CTRL-BREAK to kill the job. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2011 if (ctrl_break_was_pressed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2012 mch_signal_job(curbuf->b_term->tl_job, (char_u *)"kill");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2013 #endif
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
2014 /* Was either CTRL-W (termkey) or CTRL-\ pressed?
8a8daeb057d1 patch 8.0.1611: CTRL-W in system terminal does not go to job
Christian Brabandt <cb@256bit.org>
parents: 13472
diff changeset
2015 * Not in a system terminal. */
8a8daeb057d1 patch 8.0.1611: CTRL-W in system terminal does not go to job
Christian Brabandt <cb@256bit.org>
parents: 13472
diff changeset
2016 if ((c == (termkey == 0 ? Ctrl_W : termkey) || c == Ctrl_BSL)
8a8daeb057d1 patch 8.0.1611: CTRL-W in system terminal does not go to job
Christian Brabandt <cb@256bit.org>
parents: 13472
diff changeset
2017 #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
2018 && !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
2019 #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
2020 )
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2021 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2022 int prev_c = c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2023
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2024 #ifdef FEAT_CMDL_INFO
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2025 if (add_to_showcmd(c))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2026 out_flush();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2027 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2028 c = term_vgetc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2029 #ifdef FEAT_CMDL_INFO
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2030 clear_showcmd();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2031 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2032 if (!term_use_loop())
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2033 /* job finished while waiting for a character */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2034 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2035
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2036 if (prev_c == Ctrl_BSL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2037 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2038 if (c == Ctrl_N)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2039 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2040 /* CTRL-\ CTRL-N : go to Terminal-Normal mode. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2041 term_enter_normal_mode();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2042 ret = FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2043 goto theend;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2044 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2045 /* Send both keys to the terminal. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2046 send_keys_to_term(curbuf->b_term, prev_c, TRUE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2047 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2048 else if (c == Ctrl_C)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2049 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2050 /* "CTRL-W CTRL-C" or 'termkey' CTRL-C: end the job */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2051 mch_signal_job(curbuf->b_term->tl_job, (char_u *)"kill");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2052 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2053 else if (termkey == 0 && c == '.')
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 /* "CTRL-W .": send CTRL-W to the job */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2056 c = Ctrl_W;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2057 }
13668
6a84e3d2b810 patch 8.0.1706: cannot sent CTRL- to a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13630
diff changeset
2058 else if (termkey == 0 && c == Ctrl_BSL)
6a84e3d2b810 patch 8.0.1706: cannot sent CTRL- to a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13630
diff changeset
2059 {
6a84e3d2b810 patch 8.0.1706: cannot sent CTRL- to a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13630
diff changeset
2060 /* "CTRL-W CTRL-\": send CTRL-\ to the job */
6a84e3d2b810 patch 8.0.1706: cannot sent CTRL- to a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13630
diff changeset
2061 c = Ctrl_BSL;
6a84e3d2b810 patch 8.0.1706: cannot sent CTRL- to a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13630
diff changeset
2062 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2063 else if (c == 'N')
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2064 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2065 /* CTRL-W N : go to Terminal-Normal mode. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2066 term_enter_normal_mode();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2067 ret = FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2068 goto theend;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2069 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2070 else if (c == '"')
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2071 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2072 term_paste_register(prev_c);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2073 continue;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2074 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2075 else if (termkey == 0 || c != termkey)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2076 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2077 stuffcharReadbuff(Ctrl_W);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2078 stuffcharReadbuff(c);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2079 ret = OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2080 goto theend;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2081 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2082 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2083 # ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2084 if (!enc_utf8 && has_mbyte && c >= 0x80)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2085 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2086 WCHAR wc;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2087 char_u mb[3];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2088
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2089 mb[0] = (unsigned)c >> 8;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2090 mb[1] = c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2091 if (MultiByteToWideChar(GetACP(), 0, (char*)mb, 2, &wc, 1) > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2092 c = wc;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2093 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2094 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2095 if (send_keys_to_term(curbuf->b_term, c, TRUE) != OK)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2096 {
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
2097 if (c == K_MOUSEMOVE)
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2098 /* We are sure to come back here, don't reset the cursor color
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2099 * and shape to avoid flickering. */
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2100 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
2101
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2102 ret = OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2103 goto theend;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2104 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2105 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2106 ret = FAIL;
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 theend:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2109 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
2110 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
2111 prepare_restore_cursor_props();
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2112 return ret;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2113 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2114
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2115 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2116 * Called when a job has finished.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2117 * This updates the title and status, but does not close the vterm, because
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2118 * there might still be pending output in the channel.
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 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2121 term_job_ended(job_T *job)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2122 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2123 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2124 int did_one = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2125
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2126 for (term = first_term; term != NULL; term = term->tl_next)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2127 if (term->tl_job == job)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2128 {
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13219
diff changeset
2129 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
2130 VIM_CLEAR(term->tl_status_text);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2131 redraw_buf_and_status_later(term->tl_buffer, VALID);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2132 did_one = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2133 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2134 if (did_one)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2135 redraw_statuslines();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2136 if (curbuf->b_term != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2137 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2138 if (curbuf->b_term->tl_job == job)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2139 maketitle();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2140 update_cursor(curbuf->b_term, TRUE);
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 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2143
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2144 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2145 may_toggle_cursor(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2146 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2147 if (in_terminal_loop == term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2148 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2149 if (term->tl_cursor_visible)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2150 cursor_on();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2151 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2152 cursor_off();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2153 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2154 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2155
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2156 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2157 * 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
2158 * 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
2159 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2160 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2161 color2index(VTermColor *color, int fg, int *boldp)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2162 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2163 int red = color->red;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2164 int blue = color->blue;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2165 int green = color->green;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2166
12966
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2167 if (color->ansi_index != VTERM_ANSI_INDEX_NONE)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2168 {
12966
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2169 /* First 16 colors and default: use the ANSI index, because these
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2170 * colors can be redefined. */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2171 if (t_colors >= 16)
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2172 return color->ansi_index;
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2173 switch (color->ansi_index)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2174 {
12966
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2175 case 0: return 0;
13329
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
2176 case 1: return lookup_color( 0, fg, boldp) + 1; /* black */
12966
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2177 case 2: return lookup_color( 4, fg, boldp) + 1; /* dark red */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2178 case 3: return lookup_color( 2, fg, boldp) + 1; /* dark green */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2179 case 4: return lookup_color( 6, fg, boldp) + 1; /* brown */
13668
6a84e3d2b810 patch 8.0.1706: cannot sent CTRL- to a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13630
diff changeset
2180 case 5: return lookup_color( 1, fg, boldp) + 1; /* dark blue */
12966
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2181 case 6: return lookup_color( 5, fg, boldp) + 1; /* dark magenta */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2182 case 7: return lookup_color( 3, fg, boldp) + 1; /* dark cyan */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2183 case 8: return lookup_color( 8, fg, boldp) + 1; /* light grey */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2184 case 9: return lookup_color(12, fg, boldp) + 1; /* dark grey */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2185 case 10: return lookup_color(20, fg, boldp) + 1; /* red */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2186 case 11: return lookup_color(16, fg, boldp) + 1; /* green */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2187 case 12: return lookup_color(24, fg, boldp) + 1; /* yellow */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2188 case 13: return lookup_color(14, fg, boldp) + 1; /* blue */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2189 case 14: return lookup_color(22, fg, boldp) + 1; /* magenta */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2190 case 15: return lookup_color(18, fg, boldp) + 1; /* cyan */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2191 case 16: return lookup_color(26, fg, boldp) + 1; /* white */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2192 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2193 }
12966
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2194
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2195 if (t_colors >= 256)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2196 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2197 if (red == blue && red == green)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2198 {
12541
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2199 /* 24-color greyscale plus white and black */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2200 static int cutoff[23] = {
12541
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2201 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
2202 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
2203 0xD5, 0xDF, 0xE9};
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2204 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2205
12541
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2206 if (red < 5)
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2207 return 17; /* 00/00/00 */
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2208 if (red > 245) /* ff/ff/ff */
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2209 return 232;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2210 for (i = 0; i < 23; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2211 if (red < cutoff[i])
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2212 return i + 233;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2213 return 256;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2214 }
12541
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2215 {
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2216 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
2217 int ri, gi, bi;
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2218
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2219 /* 216-color cube */
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2220 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
2221 if (red < cutoff[ri])
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2222 break;
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2223 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
2224 if (green < cutoff[gi])
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2225 break;
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2226 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
2227 if (blue < cutoff[bi])
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2228 break;
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2229 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
2230 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2231 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2232 return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2233 }
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 /*
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2236 * Convert Vterm attributes to highlight flags.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2237 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2238 static int
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2239 vtermAttr2hl(VTermScreenCellAttrs cellattrs)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2240 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2241 int attr = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2242
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2243 if (cellattrs.bold)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2244 attr |= HL_BOLD;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2245 if (cellattrs.underline)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2246 attr |= HL_UNDERLINE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2247 if (cellattrs.italic)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2248 attr |= HL_ITALIC;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2249 if (cellattrs.strike)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2250 attr |= HL_STRIKETHROUGH;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2251 if (cellattrs.reverse)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2252 attr |= HL_INVERSE;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2253 return attr;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2254 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2255
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2256 /*
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2257 * 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
2258 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2259 static void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2260 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
2261 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2262 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
2263 if (attr & HL_BOLD)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2264 cell->attrs.bold = 1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2265 if (attr & HL_UNDERLINE)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2266 cell->attrs.underline = 1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2267 if (attr & HL_ITALIC)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2268 cell->attrs.italic = 1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2269 if (attr & HL_STRIKETHROUGH)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2270 cell->attrs.strike = 1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2271 if (attr & HL_INVERSE)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2272 cell->attrs.reverse = 1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2273 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2274
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2275 /*
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2276 * 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
2277 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2278 static int
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2279 cell2attr(VTermScreenCellAttrs cellattrs, VTermColor cellfg, VTermColor cellbg)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2280 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
2281 int attr = vtermAttr2hl(cellattrs);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2282
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2283 #ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2284 if (gui.in_use)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2285 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2286 guicolor_T fg, bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2287
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2288 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
2289 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
2290 return get_gui_attr_idx(attr, fg, bg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2291 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2292 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2293 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2294 #ifdef FEAT_TERMGUICOLORS
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2295 if (p_tgc)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2296 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2297 guicolor_T fg, bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2298
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2299 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
2300 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
2301
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2302 return get_tgc_attr_idx(attr, fg, bg);
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 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2305 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2306 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2307 int bold = MAYBE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2308 int fg = color2index(&cellfg, TRUE, &bold);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2309 int bg = color2index(&cellbg, FALSE, &bold);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2310
12969
a9f6a874b64f patch 8.0.1360: the Terminal highlighting doesn't work in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12966
diff changeset
2311 /* Use the "Terminal" highlighting for the default colors. */
12973
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
2312 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
2313 {
12973
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
2314 if (fg == 0 && term_default_cterm_fg >= 0)
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
2315 fg = term_default_cterm_fg + 1;
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
2316 if (bg == 0 && term_default_cterm_bg >= 0)
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
2317 bg = term_default_cterm_bg + 1;
12969
a9f6a874b64f patch 8.0.1360: the Terminal highlighting doesn't work in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12966
diff changeset
2318 }
a9f6a874b64f patch 8.0.1360: the Terminal highlighting doesn't work in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12966
diff changeset
2319
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2320 /* with 8 colors set the bold attribute to get a bright foreground */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2321 if (bold == TRUE)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2322 attr |= HL_BOLD;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2323 return get_cterm_attr_idx(attr, fg, bg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2324 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2325 return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2326 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2327
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2328 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2329 handle_damage(VTermRect rect, void *user)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2330 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2331 term_T *term = (term_T *)user;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2332
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2333 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
2334 term->tl_dirty_row_end = MAX(term->tl_dirty_row_end, rect.end_row);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2335 redraw_buf_later(term->tl_buffer, NOT_VALID);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2336 return 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2337 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2338
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2339 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2340 handle_moverect(VTermRect dest, VTermRect src, void *user)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2341 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2342 term_T *term = (term_T *)user;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2343
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2344 /* Scrolling up is done much more efficiently by deleting lines instead of
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2345 * redrawing the text. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2346 if (dest.start_col == src.start_col
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2347 && dest.end_col == src.end_col
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2348 && dest.start_row < src.start_row)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2349 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2350 win_T *wp;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2351 VTermColor fg, bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2352 VTermScreenCellAttrs attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2353 int clear_attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2354
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2355 /* Set the color to clear lines with. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2356 vterm_state_get_default_colors(vterm_obtain_state(term->tl_vterm),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2357 &fg, &bg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2358 vim_memset(&attr, 0, sizeof(attr));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2359 clear_attr = cell2attr(attr, fg, bg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2360
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2361 FOR_ALL_WINDOWS(wp)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2362 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2363 if (wp->w_buffer == term->tl_buffer)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2364 win_del_lines(wp, dest.start_row,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2365 src.start_row - dest.start_row, FALSE, FALSE,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2366 clear_attr);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2367 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2368 }
12578
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
2369
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
2370 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
2371 term->tl_dirty_row_end = MIN(term->tl_dirty_row_end, dest.end_row);
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
2372
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2373 redraw_buf_later(term->tl_buffer, NOT_VALID);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2374 return 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2375 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2376
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2377 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2378 handle_movecursor(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2379 VTermPos pos,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2380 VTermPos oldpos UNUSED,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2381 int visible,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2382 void *user)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2383 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2384 term_T *term = (term_T *)user;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2385 win_T *wp;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2386
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2387 term->tl_cursor_pos = pos;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2388 term->tl_cursor_visible = visible;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2389
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2390 FOR_ALL_WINDOWS(wp)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2391 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2392 if (wp->w_buffer == term->tl_buffer)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2393 position_cursor(wp, &pos);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2394 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2395 if (term->tl_buffer == curbuf && !term->tl_normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2396 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2397 may_toggle_cursor(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2398 update_cursor(term, term->tl_cursor_visible);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2399 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2400
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2401 return 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2402 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2403
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2404 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2405 handle_settermprop(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2406 VTermProp prop,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2407 VTermValue *value,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2408 void *user)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2409 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2410 term_T *term = (term_T *)user;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2411
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2412 switch (prop)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2413 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2414 case VTERM_PROP_TITLE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2415 vim_free(term->tl_title);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2416 /* a blank title isn't useful, make it empty, so that "running" is
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2417 * displayed */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2418 if (*skipwhite((char_u *)value->string) == NUL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2419 term->tl_title = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2420 #ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2421 else if (!enc_utf8 && enc_codepage > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2422 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2423 WCHAR *ret = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2424 int length = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2425
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2426 MultiByteToWideChar_alloc(CP_UTF8, 0,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2427 (char*)value->string, (int)STRLEN(value->string),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2428 &ret, &length);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2429 if (ret != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2430 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2431 WideCharToMultiByte_alloc(enc_codepage, 0,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2432 ret, length, (char**)&term->tl_title,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2433 &length, 0, 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2434 vim_free(ret);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2435 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2436 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2437 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2438 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2439 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
2440 VIM_CLEAR(term->tl_status_text);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2441 if (term == curbuf->b_term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2442 maketitle();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2443 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2444
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2445 case VTERM_PROP_CURSORVISIBLE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2446 term->tl_cursor_visible = value->boolean;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2447 may_toggle_cursor(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2448 out_flush();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2449 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2450
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2451 case VTERM_PROP_CURSORBLINK:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2452 term->tl_cursor_blink = value->boolean;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2453 may_set_cursor_props(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2454 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2455
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2456 case VTERM_PROP_CURSORSHAPE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2457 term->tl_cursor_shape = value->number;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2458 may_set_cursor_props(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2459 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2460
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2461 case VTERM_PROP_CURSORCOLOR:
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
2462 if (desired_cursor_color == term->tl_cursor_color)
53f0c469dfc6 patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents: 13132
diff changeset
2463 desired_cursor_color = (char_u *)"";
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2464 vim_free(term->tl_cursor_color);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2465 if (*value->string == NUL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2466 term->tl_cursor_color = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2467 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2468 term->tl_cursor_color = vim_strsave((char_u *)value->string);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2469 may_set_cursor_props(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2470 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2471
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2472 case VTERM_PROP_ALTSCREEN:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2473 /* TODO: do anything else? */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2474 term->tl_using_altscreen = value->boolean;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2475 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2476
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2477 default:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2478 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2479 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2480 /* Always return 1, otherwise vterm doesn't store the value internally. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2481 return 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2482 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2483
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2484 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2485 * The job running in the terminal resized the terminal.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2486 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2487 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2488 handle_resize(int rows, int cols, void *user)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2489 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2490 term_T *term = (term_T *)user;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2491 win_T *wp;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2492
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2493 term->tl_rows = rows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2494 term->tl_cols = cols;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2495 if (term->tl_vterm_size_changed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2496 /* Size was set by vterm_set_size(), don't set the window size. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2497 term->tl_vterm_size_changed = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2498 else
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 FOR_ALL_WINDOWS(wp)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2501 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2502 if (wp->w_buffer == term->tl_buffer)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2503 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2504 win_setheight_win(rows, wp);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2505 win_setwidth_win(cols, wp);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2506 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2507 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2508 redraw_buf_later(term->tl_buffer, NOT_VALID);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2509 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2510 return 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2511 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2512
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2513 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2514 * Handle a line that is pushed off the top of the screen.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2515 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2516 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2517 handle_pushline(int cols, const VTermScreenCell *cells, void *user)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2518 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2519 term_T *term = (term_T *)user;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2520
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2521 /* TODO: Limit the number of lines that are stored. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2522 if (ga_grow(&term->tl_scrollback, 1) == OK)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2523 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2524 cellattr_T *p = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2525 int len = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2526 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2527 int c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2528 int col;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2529 sb_line_T *line;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2530 garray_T ga;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2531 cellattr_T fill_attr = term->tl_default_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2532
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2533 /* do not store empty cells at the end */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2534 for (i = 0; i < cols; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2535 if (cells[i].chars[0] != 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2536 len = i + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2537 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2538 cell2cellattr(&cells[i], &fill_attr);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2539
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2540 ga_init2(&ga, 1, 100);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2541 if (len > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2542 p = (cellattr_T *)alloc((int)sizeof(cellattr_T) * len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2543 if (p != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2544 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2545 for (col = 0; col < len; col += cells[col].width)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2546 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2547 if (ga_grow(&ga, MB_MAXBYTES) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2548 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2549 ga.ga_len = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2550 break;
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 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
2553 ga.ga_len += utf_char2bytes(c == NUL ? ' ' : c,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2554 (char_u *)ga.ga_data + ga.ga_len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2555 cell2cellattr(&cells[col], &p[col]);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2556 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2557 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2558 if (ga_grow(&ga, 1) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2559 add_scrollback_line_to_buffer(term, (char_u *)"", 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2560 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2561 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2562 *((char_u *)ga.ga_data + ga.ga_len) = NUL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2563 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
2564 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2565 ga_clear(&ga);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2566
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2567 line = (sb_line_T *)term->tl_scrollback.ga_data
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2568 + term->tl_scrollback.ga_len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2569 line->sb_cols = len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2570 line->sb_cells = p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2571 line->sb_fill_attr = fill_attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2572 ++term->tl_scrollback.ga_len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2573 ++term->tl_scrollback_scrolled;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2574 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2575 return 0; /* ignored */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2576 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2577
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2578 static VTermScreenCallbacks screen_callbacks = {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2579 handle_damage, /* damage */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2580 handle_moverect, /* moverect */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2581 handle_movecursor, /* movecursor */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2582 handle_settermprop, /* settermprop */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2583 NULL, /* bell */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2584 handle_resize, /* resize */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2585 handle_pushline, /* sb_pushline */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2586 NULL /* sb_popline */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2587 };
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2588
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2589 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2590 * Called when a channel has been closed.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2591 * 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
2592 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2593 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2594 term_channel_closed(channel_T *ch)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2595 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2596 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2597 int did_one = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2598
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2599 for (term = first_term; term != NULL; term = term->tl_next)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2600 if (term->tl_job == ch->ch_job)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2601 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2602 term->tl_channel_closed = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2603 did_one = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2604
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13219
diff changeset
2605 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
2606 VIM_CLEAR(term->tl_status_text);
12502
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 /* Unless in Terminal-Normal mode: clear the vterm. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2609 if (!term->tl_normal_mode)
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 int fnum = term->tl_buffer->b_fnum;
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 cleanup_vterm(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2614
13476
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
2615 if (term->tl_finish == TL_FINISH_CLOSE)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2616 {
12903
411a30bd7e8a patch 8.0.1328: trouble when using ":term ++close" with autocmd
Christian Brabandt <cb@256bit.org>
parents: 12893
diff changeset
2617 aco_save_T aco;
411a30bd7e8a patch 8.0.1328: trouble when using ":term ++close" with autocmd
Christian Brabandt <cb@256bit.org>
parents: 12893
diff changeset
2618
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2619 /* ++close or term_finish == "close" */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2620 ch_log(NULL, "terminal job finished, closing window");
12903
411a30bd7e8a patch 8.0.1328: trouble when using ":term ++close" with autocmd
Christian Brabandt <cb@256bit.org>
parents: 12893
diff changeset
2621 aucmd_prepbuf(&aco, term->tl_buffer);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2622 do_bufdel(DOBUF_WIPE, (char_u *)"", 1, fnum, fnum, FALSE);
12903
411a30bd7e8a patch 8.0.1328: trouble when using ":term ++close" with autocmd
Christian Brabandt <cb@256bit.org>
parents: 12893
diff changeset
2623 aucmd_restbuf(&aco);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2624 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2625 }
13476
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
2626 if (term->tl_finish == TL_FINISH_OPEN
d130044d4f1f patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents: 13474
diff changeset
2627 && term->tl_buffer->b_nwindows == 0)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2628 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2629 char buf[50];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2630
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2631 /* TODO: use term_opencmd */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2632 ch_log(NULL, "terminal job finished, opening window");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2633 vim_snprintf(buf, sizeof(buf),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2634 term->tl_opencmd == NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2635 ? "botright sbuf %d"
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2636 : (char *)term->tl_opencmd, fnum);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2637 do_cmdline_cmd((char_u *)buf);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2638 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2639 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2640 ch_log(NULL, "terminal job finished");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2641 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2642
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2643 redraw_buf_and_status_later(term->tl_buffer, NOT_VALID);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2644 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2645 if (did_one)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2646 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2647 redraw_statuslines();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2648
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2649 /* Need to break out of vgetc(). */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2650 ins_char_typebuf(K_IGNORE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2651 typebuf_was_filled = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2652
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2653 term = curbuf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2654 if (term != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2655 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2656 if (term->tl_job == ch->ch_job)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2657 maketitle();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2658 update_cursor(term, term->tl_cursor_visible);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2659 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2660 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2661 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2662
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2663 /*
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2664 * 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
2665 * 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
2666 */
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2667 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
2668 term_line2screenline(VTermScreen *screen, VTermPos *pos, int max_col)
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2669 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2670 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
2671
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2672 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
2673 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2674 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
2675 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
2676
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2677 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
2678 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
2679
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2680 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
2681 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
2682 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2683 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
2684 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
2685 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
2686 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2687 else
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2688 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2689 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
2690 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2691 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
2692
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2693 /* composing chars */
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2694 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
2695 && 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
2696 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2697 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
2698 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
2699 break;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2700 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2701 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
2702 && 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
2703 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2704 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
2705 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
2706 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2707 else
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2708 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2709 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
2710 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
2711 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2712 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2713 #ifdef WIN3264
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2714 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
2715 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2716 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
2717 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
2718
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2719 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
2720 (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
2721 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2722 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
2723 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
2724 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
2725 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2726 else
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2727 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
2728 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2729 #endif
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2730 else
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2731 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
2732 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2733 ScreenAttrs[off] = cell2attr(cell.attrs, cell.fg, cell.bg);
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2734
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2735 ++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
2736 ++off;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2737 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
2738 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2739 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
2740 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
2741
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2742 /* don't set the second byte to NUL for a DBCS encoding, it
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2743 * has been set above */
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2744 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
2745 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
2746
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2747 ++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
2748 ++off;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2749 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2750 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2751 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2752
13472
f6a4614edea4 patch 8.0.1610: cannot build without GUI
Christian Brabandt <cb@256bit.org>
parents: 13470
diff changeset
2753 #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
2754 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
2755 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
2756 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2757 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
2758 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
2759
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2760 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
2761 return;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2762 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
2763
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2764 /* Scroll up to make more room for terminal lines if needed. */
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2765 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
2766 && (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
2767 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2768 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
2769
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2770 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
2771 msg_row = Rows - 1;
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2772 msg_puts((char_u *)"\n");
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2773 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
2774 --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
2775 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2776
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2777 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
2778 && 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
2779 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2780 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
2781 {
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2782 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
2783
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2784 term_line2screenline(screen, &pos, max_col);
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2785 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2786 else
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2787 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
2788
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2789 screen_line(term->tl_toprow + pos.row, 0, pos.col, Columns, FALSE);
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2790 }
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2791
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2792 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
2793 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
2794 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
2795 }
13472
f6a4614edea4 patch 8.0.1610: cannot build without GUI
Christian Brabandt <cb@256bit.org>
parents: 13470
diff changeset
2796 #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
2797
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2798 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2799 * Called to update a window that contains an active terminal.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2800 * Returns FAIL when there is no terminal running in this window or in
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2801 * Terminal-Normal mode.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2802 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2803 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2804 term_update_window(win_T *wp)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2805 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2806 term_T *term = wp->w_buffer->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2807 VTerm *vterm;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2808 VTermScreen *screen;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2809 VTermState *state;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2810 VTermPos pos;
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 if (term == NULL || term->tl_vterm == NULL || term->tl_normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2813 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2814
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2815 vterm = term->tl_vterm;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2816 screen = vterm_obtain_screen(vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2817 state = vterm_obtain_state(vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2818
12598
97a2f34962ee patch 8.0.1177: in a terminal window the popup menu is not cleared
Christian Brabandt <cb@256bit.org>
parents: 12590
diff changeset
2819 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
2820 {
3c46dcf3b335 patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents: 12578
diff changeset
2821 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
2822 term->tl_dirty_row_end = MAX_ROW;
3c46dcf3b335 patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents: 12578
diff changeset
2823 }
3c46dcf3b335 patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents: 12578
diff changeset
2824
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2825 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2826 * If the window was resized a redraw will be triggered and we get here.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2827 * Adjust the size of the vterm unless 'termsize' specifies a fixed size.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2828 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2829 if ((!term->tl_rows_fixed && term->tl_rows != wp->w_height)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2830 || (!term->tl_cols_fixed && term->tl_cols != wp->w_width))
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 int rows = term->tl_rows_fixed ? term->tl_rows : wp->w_height;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2833 int cols = term->tl_cols_fixed ? term->tl_cols : wp->w_width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2834 win_T *twp;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2835
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2836 FOR_ALL_WINDOWS(twp)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2837 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2838 /* When more than one window shows the same terminal, use the
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2839 * smallest size. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2840 if (twp->w_buffer == term->tl_buffer)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2841 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2842 if (!term->tl_rows_fixed && rows > twp->w_height)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2843 rows = twp->w_height;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2844 if (!term->tl_cols_fixed && cols > twp->w_width)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2845 cols = twp->w_width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2846 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2847 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2848
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2849 term->tl_vterm_size_changed = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2850 vterm_set_size(vterm, rows, cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2851 ch_log(term->tl_job->jv_channel, "Resizing terminal to %d lines",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2852 rows);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2853 term_report_winsize(term, rows, cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2854 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2855
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2856 /* The cursor may have been moved when resizing. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2857 vterm_state_get_cursorpos(state, &pos);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2858 position_cursor(wp, &pos);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2859
12578
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
2860 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
2861 && pos.row < wp->w_height; ++pos.row)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2862 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2863 if (pos.row < term->tl_rows)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2864 {
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2865 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
2866
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
2867 term_line2screenline(screen, &pos, max_col);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2868 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2869 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2870 pos.col = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2871
13458
0e7a56b18d61 patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents: 13448
diff changeset
2872 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
2873 #ifdef FEAT_MENU
0e7a56b18d61 patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents: 13448
diff changeset
2874 + winbar_height(wp)
0e7a56b18d61 patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents: 13448
diff changeset
2875 #endif
0e7a56b18d61 patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents: 13448
diff changeset
2876 , wp->w_wincol, pos.col, wp->w_width, FALSE);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2877 }
12578
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
2878 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
2879 term->tl_dirty_row_end = 0;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2880
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2881 return OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2882 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2883
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2884 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2885 * 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
2886 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2887 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2888 term_is_finished(buf_T *buf)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2889 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2890 return buf->b_term != NULL && buf->b_term->tl_vterm == NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2891 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2892
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 * 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
2895 * are in Terminal-Normal mode, thus we show the buffer contents.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2896 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2897 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2898 term_show_buffer(buf_T *buf)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2899 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2900 term_T *term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2901
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2902 return term != NULL && (term->tl_vterm == NULL || term->tl_normal_mode);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2903 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2904
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2905 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2906 * 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
2907 * highlighting remove it now.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2908 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2909 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2910 term_change_in_curbuf(void)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2911 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2912 term_T *term = curbuf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2913
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2914 if (term_is_finished(curbuf) && term->tl_scrollback.ga_len > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2915 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2916 free_scrollback(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2917 redraw_buf_later(term->tl_buffer, NOT_VALID);
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 /* The buffer is now like a normal buffer, it cannot be easily
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2920 * abandoned when changed. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2921 set_string_option_direct((char_u *)"buftype", -1,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2922 (char_u *)"", OPT_FREE|OPT_LOCAL, 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2923 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2924 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2925
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2926 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2927 * Get the screen attribute for a position in the buffer.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2928 * Use a negative "col" to get the filler background color.
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 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2931 term_get_attr(buf_T *buf, linenr_T lnum, int col)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2932 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2933 term_T *term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2934 sb_line_T *line;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2935 cellattr_T *cellattr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2936
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2937 if (lnum > term->tl_scrollback.ga_len)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2938 cellattr = &term->tl_default_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2939 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2940 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2941 line = (sb_line_T *)term->tl_scrollback.ga_data + lnum - 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2942 if (col < 0 || col >= line->sb_cols)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2943 cellattr = &line->sb_fill_attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2944 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2945 cellattr = line->sb_cells + col;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2946 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2947 return cell2attr(cellattr->attrs, cellattr->fg, cellattr->bg);
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
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2950 static VTermColor ansi_table[16] = {
12966
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2951 { 0, 0, 0, 1}, /* black */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2952 {224, 0, 0, 2}, /* dark red */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2953 { 0, 224, 0, 3}, /* dark green */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2954 {224, 224, 0, 4}, /* dark yellow / brown */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2955 { 0, 0, 224, 5}, /* dark blue */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2956 {224, 0, 224, 6}, /* dark magenta */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2957 { 0, 224, 224, 7}, /* dark cyan */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2958 {224, 224, 224, 8}, /* light grey */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2959
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2960 {128, 128, 128, 9}, /* dark grey */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2961 {255, 64, 64, 10}, /* light red */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2962 { 64, 255, 64, 11}, /* light green */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2963 {255, 255, 64, 12}, /* yellow */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2964 { 64, 64, 255, 13}, /* light blue */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2965 {255, 64, 255, 14}, /* light magenta */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2966 { 64, 255, 255, 15}, /* light cyan */
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
2967 {255, 255, 255, 16}, /* white */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2968 };
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2969
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2970 static int cube_value[] = {
12541
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2971 0x00, 0x5F, 0x87, 0xAF, 0xD7, 0xFF
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2972 };
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2973
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2974 static int grey_ramp[] = {
12541
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2975 0x08, 0x12, 0x1C, 0x26, 0x30, 0x3A, 0x44, 0x4E, 0x58, 0x62, 0x6C, 0x76,
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2976 0x80, 0x8A, 0x94, 0x9E, 0xA8, 0xB2, 0xBC, 0xC6, 0xD0, 0xDA, 0xE4, 0xEE
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2977 };
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2978
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2979 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2980 * 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
2981 * This is compatible with xterm.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2982 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2983 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2984 cterm_color2rgb(int nr, VTermColor *rgb)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2985 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2986 int idx;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2987
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2988 if (nr < 16)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2989 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2990 *rgb = ansi_table[nr];
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 else if (nr < 232)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2993 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2994 /* 216 color cube */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2995 idx = nr - 16;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2996 rgb->blue = cube_value[idx % 6];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2997 rgb->green = cube_value[idx / 6 % 6];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2998 rgb->red = cube_value[idx / 36 % 6];
12973
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
2999 rgb->ansi_index = VTERM_ANSI_INDEX_NONE;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3000 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3001 else if (nr < 256)
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 /* 24 grey scale ramp */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3004 idx = nr - 232;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3005 rgb->blue = grey_ramp[idx];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3006 rgb->green = grey_ramp[idx];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3007 rgb->red = grey_ramp[idx];
12973
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3008 rgb->ansi_index = VTERM_ANSI_INDEX_NONE;
12502
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 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3011
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3012 /*
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3013 * Initialize term->tl_default_color from the environment.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3014 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3015 static void
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3016 init_default_colors(term_T *term)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3017 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3018 VTermColor *fg, *bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3019 int fgval, bgval;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3020 int id;
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 vim_memset(&term->tl_default_color.attrs, 0, sizeof(VTermScreenCellAttrs));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3023 term->tl_default_color.width = 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3024 fg = &term->tl_default_color.fg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3025 bg = &term->tl_default_color.bg;
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 /* Vterm uses a default black background. Set it to white when
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3028 * 'background' is "light". */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3029 if (*p_bg == 'l')
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3030 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3031 fgval = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3032 bgval = 255;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3033 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3034 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3035 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3036 fgval = 255;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3037 bgval = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3038 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3039 fg->red = fg->green = fg->blue = fgval;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3040 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
3041 fg->ansi_index = bg->ansi_index = VTERM_ANSI_INDEX_DEFAULT;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3042
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3043 /* The "Terminal" highlight group overrules the defaults. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3044 id = syn_name2id((char_u *)"Terminal");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3045
12966
c5bccd50100e patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents: 12907
diff changeset
3046 /* 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
3047 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3048 if (0
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3049 # ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3050 || gui.in_use
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3051 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3052 # ifdef FEAT_TERMGUICOLORS
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3053 || p_tgc
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3054 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3055 )
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3056 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3057 guicolor_T fg_rgb = INVALCOLOR;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3058 guicolor_T bg_rgb = INVALCOLOR;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3059
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3060 if (id != 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3061 syn_id2colors(id, &fg_rgb, &bg_rgb);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3062
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3063 # ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3064 if (gui.in_use)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3065 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3066 if (fg_rgb == INVALCOLOR)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3067 fg_rgb = gui.norm_pixel;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3068 if (bg_rgb == INVALCOLOR)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3069 bg_rgb = gui.back_pixel;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3070 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3071 # ifdef FEAT_TERMGUICOLORS
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3072 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3073 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3074 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3075 # ifdef FEAT_TERMGUICOLORS
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3076 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3077 if (fg_rgb == INVALCOLOR)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3078 fg_rgb = cterm_normal_fg_gui_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3079 if (bg_rgb == INVALCOLOR)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3080 bg_rgb = cterm_normal_bg_gui_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3081 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3082 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3083 if (fg_rgb != INVALCOLOR)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3084 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3085 long_u rgb = GUI_MCH_GET_RGB(fg_rgb);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3086
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3087 fg->red = (unsigned)(rgb >> 16);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3088 fg->green = (unsigned)(rgb >> 8) & 255;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3089 fg->blue = (unsigned)rgb & 255;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3090 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3091 if (bg_rgb != INVALCOLOR)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3092 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3093 long_u rgb = GUI_MCH_GET_RGB(bg_rgb);
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 bg->red = (unsigned)(rgb >> 16);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3096 bg->green = (unsigned)(rgb >> 8) & 255;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3097 bg->blue = (unsigned)rgb & 255;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3098 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3099 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3100 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3101 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3102 if (id != 0 && t_colors >= 16)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3103 {
12973
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3104 if (term_default_cterm_fg >= 0)
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3105 cterm_color2rgb(term_default_cterm_fg, fg);
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3106 if (term_default_cterm_bg >= 0)
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3107 cterm_color2rgb(term_default_cterm_bg, bg);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3108 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3109 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3110 {
12632
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
3111 #if defined(WIN3264) && !defined(FEAT_GUI_W32)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3112 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
3113 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3114
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3115 /* In an MS-Windows console we know the normal colors. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3116 if (cterm_normal_fg_color > 0)
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 cterm_color2rgb(cterm_normal_fg_color - 1, fg);
12632
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
3119 # if defined(WIN3264) && !defined(FEAT_GUI_W32)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3120 tmp = fg->red;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3121 fg->red = fg->blue;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3122 fg->blue = tmp;
12632
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
3123 # endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3124 }
12634
94566ecb55f0 patch 8.0.1195: can't build on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 12632
diff changeset
3125 # 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
3126 else
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
3127 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
3128 # 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
3129
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3130 if (cterm_normal_bg_color > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3131 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3132 cterm_color2rgb(cterm_normal_bg_color - 1, bg);
12632
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
3133 # if defined(WIN3264) && !defined(FEAT_GUI_W32)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3134 tmp = bg->red;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3135 bg->red = bg->blue;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3136 bg->blue = tmp;
12632
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
3137 # endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3138 }
12634
94566ecb55f0 patch 8.0.1195: can't build on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 12632
diff changeset
3139 # 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
3140 else
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
3141 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
3142 # endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3143 }
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3144 }
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3145
13626
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3146 #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
3147 /*
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3148 * 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
3149 */
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3150 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
3151 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
3152 {
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3153 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
3154 VTermState *state = vterm_obtain_state(vterm);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3155 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
3156 {
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3157 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
3158 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
3159 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
3160 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
3161 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
3162 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3163 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3164
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3165 /*
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3166 * 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
3167 */
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3168 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
3169 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
3170 {
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3171 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
3172 long_u rgb[16];
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3173 listitem_T *li = list->lv_first;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3174
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3175 for (; li != NULL && n < 16; li = li->li_next, n++)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3176 {
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3177 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
3178 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
3179
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3180 color_name = get_tv_string_chk(&li->li_tv);
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3181 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
3182 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
3183
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3184 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
3185 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
3186 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
3187
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3188 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
3189 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3190
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3191 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
3192 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
3193
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3194 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
3195
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3196 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
3197 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3198
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3199 /*
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3200 * 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
3201 */
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3202 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
3203 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
3204 {
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3205 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
3206
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3207 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
3208 && (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
3209 || var->di_tv.vval.v_list == NULL
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3210 || set_ansi_colors_list(vterm, var->di_tv.vval.v_list) == FAIL))
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3211 EMSG2(_(e_invarg2), "g:terminal_ansi_colors");
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3212 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3213 #endif
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3214
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3215 /*
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3216 * 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
3217 * "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
3218 */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3219 static void
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3220 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
3221 {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3222 char_u *fname = get_tv_string(&item->li_tv);
13575
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3223 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
3224 int bufnr;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3225 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
3226 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
3227 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
3228 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
3229
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3230 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
3231 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
3232 {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3233 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
3234 {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3235 /* buffer is in a window already, go there */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3236 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
3237 return;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3238 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3239 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3240
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3241 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
3242
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3243 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
3244 && 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
3245 {
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3246 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
3247 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
3248
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3249 p = get_dict_string(dict, (char_u *)"ff", FALSE);
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3250 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
3251 p = get_dict_string(dict, (char_u *)"fileformat", FALSE);
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3252 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
3253 {
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3254 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
3255 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
3256 else
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3257 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
3258 }
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3259 p = get_dict_string(dict, (char_u *)"enc", FALSE);
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3260 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
3261 p = get_dict_string(dict, (char_u *)"encoding", FALSE);
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3262 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
3263 {
13583
200ef826e7dd patch 8.0.1664: test failure because of not allocating enough space
Christian Brabandt <cb@256bit.org>
parents: 13579
diff changeset
3264 ea.cmd = alloc((int)STRLEN(p) + 12);
13575
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3265 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
3266 {
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3267 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
3268 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
3269 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
3270 }
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3271 }
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3272
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3273 p = get_dict_string(dict, (char_u *)"bad", FALSE);
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3274 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
3275 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
3276
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3277 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
3278 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
3279 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
3280 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
3281 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
3282 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
3283 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
3284 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
3285 }
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3286
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3287 /* open in new window, like ":split fname" */
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3288 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
3289 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
3290 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
3291 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
3292 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
3293
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13557
diff changeset
3294 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
3295 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3296
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3297 /*
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3298 * 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
3299 * "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
3300 */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3301 static void
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3302 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
3303 {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3304 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
3305 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
3306 typval_T rettv;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3307 int doesrange;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3308
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3309 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
3310 {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3311 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
3312 return;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3313 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3314 func = get_tv_string(&item->li_tv);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3315
13547
87a9c1be0ae3 patch 8.0.1647: terminal API may call any user function
Christian Brabandt <cb@256bit.org>
parents: 13535
diff changeset
3316 if (STRNCMP(func, "Tapi_", 5) != 0)
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3317 {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3318 ch_log(channel, "Invalid function name: %s", func);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3319 return;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3320 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3321
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3322 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
3323 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
3324 argvars[1] = item->li_next->li_tv;
13577
4cb743db55b3 patch 8.0.1661: warnings from 64 bit compiler
Christian Brabandt <cb@256bit.org>
parents: 13575
diff changeset
3325 if (call_func(func, (int)STRLEN(func), &rettv,
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3326 2, argvars, /* argv_func */ NULL,
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3327 /* firstline */ 1, /* lastline */ 1,
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3328 &doesrange, /* evaluate */ TRUE,
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3329 /* partial */ NULL, /* selfdict */ NULL) == OK)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3330 {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3331 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
3332 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
3333 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3334 else
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3335 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
3336 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3337
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3338 /*
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3339 * 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
3340 * 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
3341 */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3342 static int
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3343 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
3344 {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3345 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
3346 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
3347 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
3348 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
3349 : 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
3350
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3351 /* We recognize only OSC 5 1 ; {command} */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3352 if (cmdlen < 3 || STRNCMP(command, "51;", 3) != 0)
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3353 return 0; /* not handled */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3354
13577
4cb743db55b3 patch 8.0.1661: warnings from 64 bit compiler
Christian Brabandt <cb@256bit.org>
parents: 13575
diff changeset
3355 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
3356 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
3357 return 1;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3358 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
3359 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
3360 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
3361 && 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
3362 && 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
3363 {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3364 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
3365
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3366 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
3367 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
3368 else
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3369 {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3370 char_u *cmd = get_tv_string(&item->li_tv);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3371
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3372 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
3373 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
3374 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
3375 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
3376 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
3377 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
3378 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
3379 else
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3380 ch_log(channel, "Invalid command received: %s", cmd);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3381 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3382 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3383 else
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3384 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
3385
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3386 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
3387 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
3388 return 1;
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3389 }
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3390
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3391 static VTermParserCallbacks parser_fallbacks = {
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3392 NULL, /* text */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3393 NULL, /* control */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3394 NULL, /* escape */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3395 NULL, /* csi */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3396 parse_osc, /* osc */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3397 NULL, /* dcs */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3398 NULL /* resize */
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3399 };
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3400
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3401 /*
13616
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3402 * 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
3403 */
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3404 static void *
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3405 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
3406 {
13630
fd3389d64825 patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents: 13626
diff changeset
3407 return alloc_clear((unsigned) size);
13616
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3408 }
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3409
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3410 static void
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3411 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
3412 {
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3413 vim_free(ptr);
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3414 }
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3415
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3416 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
3417 &vterm_malloc,
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3418 &vterm_memfree
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3419 };
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3420
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3421 /*
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3422 * Create a new vterm and initialize it.
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3423 */
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3424 static void
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3425 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
3426 {
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3427 VTerm *vterm;
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3428 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
3429 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
3430 VTermValue value;
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3431
13616
b6998c6374e1 patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents: 13583
diff changeset
3432 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
3433 term->tl_vterm = vterm;
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3434 screen = vterm_obtain_screen(vterm);
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3435 vterm_screen_set_callbacks(screen, &screen_callbacks, term);
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3436 /* TODO: depends on 'encoding'. */
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3437 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
3438
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3439 init_default_colors(term);
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3440
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3441 vterm_state_set_default_colors(
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3442 vterm_obtain_state(vterm),
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
3443 &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
3444 &term->tl_default_color.bg);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3445
13626
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3446 if (t_colors >= 16)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
3447 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
3448
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3449 /* Required to initialize most things. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3450 vterm_screen_reset(screen, 1 /* hard */);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3451
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3452 /* Allow using alternate screen. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3453 vterm_screen_enable_altscreen(screen, 1);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3454
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3455 /* For unix do not use a blinking cursor. In an xterm this causes the
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3456 * cursor to blink if it's blinking in the xterm.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3457 * For Windows we respect the system wide setting. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3458 #ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3459 if (GetCaretBlinkTime() == INFINITE)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3460 value.boolean = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3461 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3462 value.boolean = 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3463 #else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3464 value.boolean = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3465 #endif
13535
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3466 state = vterm_obtain_state(vterm);
e9ffb5b35266 patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents: 13517
diff changeset
3467 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
3468 vterm_state_set_unrecognised_fallbacks(state, &parser_fallbacks, term);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3469 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3470
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3471 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3472 * Return the text to show for the buffer name and status.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3473 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3474 char_u *
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3475 term_get_status_text(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3476 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3477 if (term->tl_status_text == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3478 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3479 char_u *txt;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3480 size_t len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3481
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3482 if (term->tl_normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3483 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3484 if (term_job_running(term))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3485 txt = (char_u *)_("Terminal");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3486 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3487 txt = (char_u *)_("Terminal-finished");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3488 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3489 else if (term->tl_title != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3490 txt = term->tl_title;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3491 else if (term_none_open(term))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3492 txt = (char_u *)_("active");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3493 else if (term_job_running(term))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3494 txt = (char_u *)_("running");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3495 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3496 txt = (char_u *)_("finished");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3497 len = 9 + STRLEN(term->tl_buffer->b_fname) + STRLEN(txt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3498 term->tl_status_text = alloc((int)len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3499 if (term->tl_status_text != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3500 vim_snprintf((char *)term->tl_status_text, len, "%s [%s]",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3501 term->tl_buffer->b_fname, txt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3502 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3503 return term->tl_status_text;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3504 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3505
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3506 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3507 * Mark references in jobs of terminals.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3508 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3509 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3510 set_ref_in_term(int copyID)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3511 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3512 int abort = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3513 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3514 typval_T tv;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3515
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3516 for (term = first_term; term != NULL; term = term->tl_next)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3517 if (term->tl_job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3518 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3519 tv.v_type = VAR_JOB;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3520 tv.vval.v_job = term->tl_job;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3521 abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3522 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3523 return abort;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3524 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3525
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3526 /*
12973
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3527 * 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
3528 */
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3529 void
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3530 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
3531 {
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3532 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
3533 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
3534 }
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3535
418941f0df08 patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents: 12969
diff changeset
3536 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3537 * 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
3538 * 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
3539 * with "where".
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3540 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3541 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
3542 term_get_buf(typval_T *argvars, char *where)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3543 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3544 buf_T *buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3545
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3546 (void)get_tv_number(&argvars[0]); /* issue errmsg if type error */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3547 ++emsg_off;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3548 buf = get_buf_tv(&argvars[0], FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3549 --emsg_off;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3550 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
3551 {
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
3552 ch_log(NULL, "%s: invalid buffer argument", where);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3553 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
3554 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3555 return buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3556 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3557
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3558 static int
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3559 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
3560 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3561 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
3562 && a->green == b->green
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3563 && a->blue == b->blue
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3564 && 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
3565 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3566
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3567 static void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3568 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
3569 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3570 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
3571 (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
3572 (int)color->ansi_index);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3573 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3574
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3575 /*
13329
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3576 * "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
3577 *
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3578 * 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
3579 * |{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
3580 * {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
3581 * 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
3582 * skipped.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3583 * {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
3584 * 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
3585 * {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
3586 * {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
3587 * {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
3588 *
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3589 * 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
3590 * |{characters}
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3591 *
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3592 * 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
3593 *
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3594 * 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
3595 * @{count}
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3596 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3597 void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3598 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
3599 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
3600 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
3601 term_T *term;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3602 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
3603 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
3604 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
3605 stat_T st;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3606 FILE *fd;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3607 VTermPos pos;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3608 VTermScreen *screen;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3609 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
3610 VTermState *state;
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
3611 VTermPos cursor_pos;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3612
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3613 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
3614 return;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3615 if (buf == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3616 return;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3617 term = buf->b_term;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3618
13329
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3619 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
3620 {
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3621 dict_T *d;
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3622
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3623 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
3624 {
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3625 EMSG(_(e_dictreq));
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3626 return;
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3627 }
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3628 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
3629 if (d != NULL)
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3630 {
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3631 max_height = get_dict_number(d, (char_u *)"rows");
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3632 max_width = get_dict_number(d, (char_u *)"columns");
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3633 }
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3634 }
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3635
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3636 fname = get_tv_string_chk(&argvars[1]);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3637 if (fname == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3638 return;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3639 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
3640 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3641 EMSG2(_("E953: File exists: %s"), fname);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3642 return;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3643 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3644
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3645 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
3646 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3647 EMSG2(_(e_notcreate), *fname == NUL ? (char_u *)_("<empty>") : fname);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3648 return;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3649 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3650
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3651 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
3652
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3653 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
3654 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
3655 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
3656
13329
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3657 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
3658 && 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
3659 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3660 int repeat = 0;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3661
13329
424321d6eea7 patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents: 13304
diff changeset
3662 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
3663 && 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
3664 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3665 VTermScreenCell cell;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3666 int same_attr;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3667 int same_chars = TRUE;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3668 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
3669 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
3670 && 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
3671
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3672 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
3673 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
3674
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3675 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
3676 {
13517
d0d66898e98b patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents: 13505
diff changeset
3677 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
3678 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
3679
d0d66898e98b patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents: 13505
diff changeset
3680 /* For the first character NUL is the same as space. */
d0d66898e98b patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents: 13505
diff changeset
3681 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
3682 {
d0d66898e98b patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents: 13505
diff changeset
3683 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
3684 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
3685 }
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3686 if (cell.chars[i] != prev_cell.chars[i])
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3687 same_chars = FALSE;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3688 if (cell.chars[i] == NUL || prev_cell.chars[i] == NUL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3689 break;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3690 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3691 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
3692 == vtermAttr2hl(prev_cell.attrs)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3693 && 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
3694 && 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
3695 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
3696 && !is_cursor_pos)
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3697 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3698 ++repeat;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3699 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3700 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3701 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3702 if (repeat > 0)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3703 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3704 fprintf(fd, "@%d", repeat);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3705 repeat = 0;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3706 }
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
3707 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
3708
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3709 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
3710 fputs(" ", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3711 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3712 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3713 char_u charbuf[10];
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3714 int len;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3715
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3716 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
3717 && 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
3718 {
13557
4911058c43eb patch 8.0.1652: term_dumpwrite() does not output composing characters
Christian Brabandt <cb@256bit.org>
parents: 13547
diff changeset
3719 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
3720 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
3721 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3722 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3723
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3724 /* When only the characters differ we don't write anything, the
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3725 * following "|", "@" or NL will indicate using the same
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3726 * attributes. */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3727 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
3728 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3729 if (cell.width == 2)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3730 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3731 fputs("*", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3732 ++pos.col;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3733 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3734 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3735 fputs("+", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3736
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3737 if (same_attr)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3738 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3739 fputs("&", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3740 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3741 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3742 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3743 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
3744 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
3745 fputs("&", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3746 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3747 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3748 fputs("#", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3749 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
3750 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3751 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
3752 fputs("&", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3753 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3754 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3755 fputs("#", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3756 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
3757 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3758 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3759 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3760
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3761 prev_cell = cell;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3762 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3763 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3764 if (repeat > 0)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3765 fprintf(fd, "@%d", repeat);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3766 fputs("\n", fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3767 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3768
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3769 fclose(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3770 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3771
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3772 /*
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3773 * 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
3774 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3775 static void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3776 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
3777 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3778 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
3779 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3780
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3781 static void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3782 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
3783 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3784 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
3785 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3786 *(((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
3787 ++gap->ga_len;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3788 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3789 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3790
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3791 /*
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3792 * 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
3793 * 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
3794 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3795 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
3796 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
3797 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3798 int c;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3799 garray_T ga_text;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3800 garray_T ga_cell;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3801 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
3802 int attr = 0;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3803 cellattr_T cell;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3804 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
3805 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
3806 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
3807
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3808 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
3809 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
3810 vim_memset(&cell, 0, sizeof(cell));
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
3811 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
3812 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
3813
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3814 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3815 for (;;)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3816 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3817 if (c == EOF)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3818 break;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3819 if (c == '\n')
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3820 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3821 /* End of a line: append it to the buffer. */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3822 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
3823 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
3824 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
3825 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3826 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
3827 + 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
3828
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3829 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
3830 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
3831 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
3832 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
3833 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
3834 ++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
3835 ga_init(&ga_cell);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3836
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3837 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
3838 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
3839 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
3840 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3841 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3842 ga_clear(&ga_cell);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3843 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
3844
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3845 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3846 }
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
3847 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
3848 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3849 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
3850
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
3851 if (c == '>')
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
3852 {
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
3853 if (cursor_pos->row != -1)
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
3854 dump_is_corrupt(&ga_text); /* duplicate cursor */
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
3855 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
3856 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
3857 }
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
3858
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3859 /* normal character(s) followed by "+", "*", "|", "@" or NL */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3860 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3861 if (c != EOF)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3862 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
3863 for (;;)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3864 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3865 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
3866 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
3867 || c == EOF || c == '\n')
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3868 break;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3869 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
3870 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3871
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3872 /* save the character for repeating it */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3873 vim_free(prev_char);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3874 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
3875 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
3876 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
3877
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
3878 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
3879 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3880 /* use all attributes from previous cell */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3881 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3882 else if (c == '+' || c == '*')
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3883 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3884 int is_bg;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3885
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3886 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
3887
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3888 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3889 if (c == '&')
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3890 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3891 /* use same attr as previous cell */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3892 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3893 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3894 else if (isdigit(c))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3895 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3896 /* get the decimal attribute */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3897 attr = 0;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3898 while (isdigit(c))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3899 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3900 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
3901 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3902 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3903 hl2vtermAttr(attr, &cell);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3904 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3905 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3906 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
3907
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3908 /* is_bg == 0: fg, is_bg == 1: bg */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3909 for (is_bg = 0; is_bg <= 1; ++is_bg)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3910 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3911 if (c == '&')
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3912 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3913 /* use same color as previous cell */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3914 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3915 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3916 else if (c == '#')
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3917 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3918 int red, green, blue, index = 0;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3919
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3920 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3921 red = hex2nr(c);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3922 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3923 red = (red << 4) + hex2nr(c);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3924 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3925 green = hex2nr(c);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3926 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3927 green = (green << 4) + hex2nr(c);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3928 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3929 blue = hex2nr(c);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3930 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3931 blue = (blue << 4) + hex2nr(c);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3932 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3933 if (!isdigit(c))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3934 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
3935 while (isdigit(c))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3936 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3937 index = index * 10 + (c - '0');
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3938 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3939 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3940
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3941 if (is_bg)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3942 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3943 cell.bg.red = red;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3944 cell.bg.green = green;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3945 cell.bg.blue = blue;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3946 cell.bg.ansi_index = index;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3947 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3948 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3949 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3950 cell.fg.red = red;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3951 cell.fg.green = green;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3952 cell.fg.blue = blue;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3953 cell.fg.ansi_index = index;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3954 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3955 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3956 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3957 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
3958 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3959 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3960 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3961 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
3962
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3963 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
3964 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3965 else if (c == '@')
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3966 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3967 if (prev_char == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3968 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
3969 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3970 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3971 int count = 0;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3972
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3973 /* repeat previous character, get the count */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3974 for (;;)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3975 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3976 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3977 if (!isdigit(c))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3978 break;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3979 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
3980 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3981
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3982 while (count-- > 0)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3983 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3984 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
3985 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
3986 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3987 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3988 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3989 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3990 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3991 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
3992 c = fgetc(fd);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3993 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3994 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3995
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3996 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
3997 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3998 /* trailing characters after last NL */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
3999 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
4000 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
4001 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
4002 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
4003 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4004
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4005 ga_clear(&ga_text);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4006 vim_free(prev_char);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4007
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4008 return max_cells;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4009 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4010
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4011 /*
13579
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4012 * 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
4013 * "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
4014 */
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4015 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
4016 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
4017 {
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4018 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
4019 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
4020 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
4021 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
4022 int i;
13630
fd3389d64825 patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents: 13626
diff changeset
4023 size_t off;
fd3389d64825 patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents: 13626
diff changeset
4024
fd3389d64825 patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents: 13626
diff changeset
4025 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
4026 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
4027 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
4028
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4029 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
4030 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
4031 {
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4032 /* enough room, don't use the full window width */
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4033 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
4034 }
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4035 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
4036 {
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4037 /* full name doesn't fit, use only the tail */
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4038 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
4039 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
4040 }
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4041 /* skip characters until the name fits */
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4042 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
4043 {
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4044 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
4045 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
4046 }
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4047
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4048 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
4049 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
4050 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
4051
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4052 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
4053 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
4054 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
4055 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
4056 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
4057 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
4058
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4059 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
4060 }
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4061
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4062 /*
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4063 * 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
4064 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4065 static void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4066 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
4067 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4068 jobopt_T opt;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4069 buf_T *buf;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4070 char_u buf1[NUMBUFLEN];
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4071 char_u buf2[NUMBUFLEN];
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4072 char_u *fname1;
13300
803294329951 patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents: 13298
diff changeset
4073 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
4074 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
4075 FILE *fd1;
13300
803294329951 patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents: 13298
diff changeset
4076 FILE *fd2 = NULL;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4077 char_u *textline = NULL;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4078
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4079 /* First open the files. If this fails bail out. */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4080 fname1 = get_tv_string_buf_chk(&argvars[0], buf1);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4081 if (do_diff)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4082 fname2 = get_tv_string_buf_chk(&argvars[1], buf2);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4083 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
4084 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4085 EMSG(_(e_invarg));
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4086 return;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4087 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4088 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
4089 if (fd1 == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4090 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4091 EMSG2(_(e_notread), fname1);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4092 return;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4093 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4094 if (do_diff)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4095 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4096 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
4097 if (fd2 == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4098 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4099 fclose(fd1);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4100 EMSG2(_(e_notread), fname2);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4101 return;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4102 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4103 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4104
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4105 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
4106 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
4107 && 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
4108 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
4109 + 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
4110 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
4111
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4112 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
4113 {
13505
a784ef72b617 patch 8.0.1626: compiler warning for possible loss of data
Christian Brabandt <cb@256bit.org>
parents: 13501
diff changeset
4114 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
4115
a784ef72b617 patch 8.0.1626: compiler warning for possible loss of data
Christian Brabandt <cb@256bit.org>
parents: 13501
diff changeset
4116 fname_tofree = alloc((int)len);
13501
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4117 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
4118 {
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4119 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
4120 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
4121 }
a4a559e08798 patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents: 13483
diff changeset
4122 }
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4123
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
4124 buf = term_start(&argvars[0], NULL, &opt, TERM_START_NOJOB);
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4125 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
4126 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4127 int i;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4128 linenr_T bot_lnum;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4129 linenr_T lnum;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4130 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
4131 int width;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4132 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
4133 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
4134 VTermPos cursor_pos2;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4135
13483
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
4136 init_default_colors(term);
f7ef5d579758 patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents: 13476
diff changeset
4137
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4138 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
4139
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4140 /* 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
4141 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
4142
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4143 /* position the cursor */
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4144 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
4145 {
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4146 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
4147 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
4148 }
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4149
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4150 /* Delete the empty line that was in the empty buffer. */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4151 ml_delete(1, FALSE);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4152
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4153 /* For term_dumpload() we are done here. */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4154 if (!do_diff)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4155 goto theend;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4156
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4157 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
4158
13579
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4159 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
4160 if (textline == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4161 goto theend;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4162 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
4163 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
4164 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
4165
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4166 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
4167 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
4168 goto theend;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4169 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
4170 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
4171 textline[width] = NUL;
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4172
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4173 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
4174 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
4175 if (width2 > width)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4176 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4177 vim_free(textline);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4178 textline = alloc(width2 + 1);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4179 if (textline == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4180 goto theend;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4181 width = width2;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4182 textline[width] = NUL;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4183 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4184 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
4185
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4186 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
4187 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4188 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
4189 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4190 /* bottom part has fewer rows, fill with "-" */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4191 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
4192 textline[i] = '-';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4193 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4194 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4195 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4196 char_u *line1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4197 char_u *line2;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4198 char_u *p1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4199 char_u *p2;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4200 int col;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4201 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
4202 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
4203 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
4204 ->sb_cells;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4205
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4206 /* Make a copy, getting the second line will invalidate it. */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4207 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
4208 if (line1 == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4209 break;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4210 p1 = line1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4211
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4212 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
4213 p2 = line2;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4214 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
4215 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4216 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
4217 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
4218
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4219 textline[col] = ' ';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4220 if (len1 != len2 || STRNCMP(p1, p2, len1) != 0)
13335
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4221 /* text differs */
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4222 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
4223 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
4224 && 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
4225 && (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
4226 || cursor_pos1.col != cursor_pos2.col))
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4227 /* cursor in first but not in second */
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4228 textline[col] = '>';
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4229 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
4230 && 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
4231 && (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
4232 || cursor_pos1.col != cursor_pos2.col))
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4233 /* cursor in second but not in first */
73325d39591a patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents: 13329
diff changeset
4234 textline[col] = '<';
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4235 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
4236 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4237 if ((cellattr1 + col)->width
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4238 != (cellattr2 + col)->width)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4239 textline[col] = 'w';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4240 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
4241 &(cellattr2 + col)->fg))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4242 textline[col] = 'f';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4243 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
4244 &(cellattr2 + col)->bg))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4245 textline[col] = 'b';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4246 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
4247 != vtermAttr2hl(((cellattr2 + col)->attrs)))
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4248 textline[col] = 'a';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4249 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4250 p1 += len1;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4251 p2 += len2;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4252 /* TODO: handle different width */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4253 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4254 vim_free(line1);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4255
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4256 while (col < width)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4257 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4258 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
4259 textline[col] = '?';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4260 else if (*p1 == NUL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4261 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4262 textline[col] = '+';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4263 p2 += utfc_ptr2len(p2);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4264 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4265 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4266 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4267 textline[col] = '-';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4268 p1 += utfc_ptr2len(p1);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4269 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4270 ++col;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4271 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4272 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4273 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
4274 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
4275 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
4276 ++bot_lnum;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4277 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4278
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4279 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
4280 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4281 /* bottom part has more rows, fill with "+" */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4282 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
4283 textline[i] = '+';
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4284 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
4285 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
4286 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
4287 ++lnum;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4288 ++bot_lnum;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4289 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4290
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4291 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
4292
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4293 /* looks better without wrapping */
486ad9fd9038 patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents: 13577
diff changeset
4294 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
4295 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4296
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4297 theend:
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4298 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
4299 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
4300 fclose(fd1);
13300
803294329951 patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents: 13298
diff changeset
4301 if (fd2 != NULL)
13298
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4302 fclose(fd2);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4303 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4304
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4305 /*
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4306 * 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
4307 * bottom files.
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4308 * 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
4309 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4310 int
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4311 term_swap_diff()
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4312 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4313 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
4314 linenr_T line_count;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4315 linenr_T top_rows;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4316 linenr_T bot_rows;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4317 linenr_T bot_start;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4318 linenr_T lnum;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4319 char_u *p;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4320 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
4321
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4322 if (term == NULL
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4323 || !term_is_finished(curbuf)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4324 || 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
4325 || 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
4326 return FAIL;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4327
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4328 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
4329 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
4330 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
4331 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
4332 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
4333
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4334 /* move lines from top to above the bottom part */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4335 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
4336 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4337 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
4338 if (p == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4339 return OK;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4340 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
4341 ml_delete(1, FALSE);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4342 vim_free(p);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4343 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4344
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4345 /* move lines from bottom to the top */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4346 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
4347 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4348 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
4349 if (p == NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4350 return OK;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4351 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
4352 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
4353 vim_free(p);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4354 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4355
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4356 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
4357 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4358 /* rows counts are equal, can swap cell properties */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4359 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
4360 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4361 sb_line_T temp;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4362
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4363 temp = *(sb_line + lnum);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4364 *(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
4365 *(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
4366 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4367 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4368 else
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4369 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4370 size_t size = sizeof(sb_line_T) * term->tl_scrollback.ga_len;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4371 sb_line_T *temp = (sb_line_T *)alloc((int)size);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4372
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4373 /* need to copy cell properties into temp memory */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4374 if (temp != NULL)
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4375 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4376 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
4377 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
4378 temp + bot_start,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4379 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
4380 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
4381 temp + top_rows,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4382 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
4383 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
4384 + line_count - top_rows,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4385 temp,
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4386 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
4387 vim_free(temp);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4388 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4389 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4390
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4391 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
4392 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
4393
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4394 update_screen(NOT_VALID);
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4395 return OK;
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4396 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4397
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4398 /*
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4399 * "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
4400 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4401 void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4402 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
4403 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4404 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
4405 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4406
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4407 /*
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4408 * "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
4409 */
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4410 void
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4411 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
4412 {
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4413 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
4414 }
a88c5e12b860 patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents: 13294
diff changeset
4415
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4416 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4417 * "term_getaltscreen(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4418 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4419 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4420 f_term_getaltscreen(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4421 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4422 buf_T *buf = term_get_buf(argvars, "term_getaltscreen()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4423
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4424 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4425 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4426 rettv->vval.v_number = buf->b_term->tl_using_altscreen;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4427 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4428
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4429 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4430 * "term_getattr(attr, name)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4431 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4432 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4433 f_term_getattr(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4434 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4435 int attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4436 size_t i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4437 char_u *name;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4438
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4439 static struct {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4440 char *name;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4441 int attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4442 } attrs[] = {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4443 {"bold", HL_BOLD},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4444 {"italic", HL_ITALIC},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4445 {"underline", HL_UNDERLINE},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4446 {"strike", HL_STRIKETHROUGH},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4447 {"reverse", HL_INVERSE},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4448 };
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4449
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4450 attr = get_tv_number(&argvars[0]);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4451 name = get_tv_string_chk(&argvars[1]);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4452 if (name == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4453 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4454
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4455 for (i = 0; i < sizeof(attrs)/sizeof(attrs[0]); ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4456 if (STRCMP(name, attrs[i].name) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4457 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4458 rettv->vval.v_number = (attr & attrs[i].attr) != 0 ? 1 : 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4459 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4460 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4461 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4462
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4463 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4464 * "term_getcursor(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4465 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4466 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4467 f_term_getcursor(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4468 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4469 buf_T *buf = term_get_buf(argvars, "term_getcursor()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4470 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4471 list_T *l;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4472 dict_T *d;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4473
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4474 if (rettv_list_alloc(rettv) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4475 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4476 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4477 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4478 term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4479
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4480 l = rettv->vval.v_list;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4481 list_append_number(l, term->tl_cursor_pos.row + 1);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4482 list_append_number(l, term->tl_cursor_pos.col + 1);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4483
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4484 d = dict_alloc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4485 if (d != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4486 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4487 dict_add_nr_str(d, "visible", term->tl_cursor_visible, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4488 dict_add_nr_str(d, "blink", blink_state_is_inverted()
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4489 ? !term->tl_cursor_blink : term->tl_cursor_blink, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4490 dict_add_nr_str(d, "shape", term->tl_cursor_shape, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4491 dict_add_nr_str(d, "color", 0L, term->tl_cursor_color == NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4492 ? (char_u *)"" : term->tl_cursor_color);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4493 list_append_dict(l, d);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4494 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4495 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4496
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4497 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4498 * "term_getjob(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4499 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4500 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4501 f_term_getjob(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4502 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4503 buf_T *buf = term_get_buf(argvars, "term_getjob()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4504
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4505 rettv->v_type = VAR_JOB;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4506 rettv->vval.v_job = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4507 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4508 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4509
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4510 rettv->vval.v_job = buf->b_term->tl_job;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4511 if (rettv->vval.v_job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4512 ++rettv->vval.v_job->jv_refcount;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4513 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4514
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4515 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4516 get_row_number(typval_T *tv, term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4517 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4518 if (tv->v_type == VAR_STRING
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4519 && tv->vval.v_string != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4520 && STRCMP(tv->vval.v_string, ".") == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4521 return term->tl_cursor_pos.row;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4522 return (int)get_tv_number(tv) - 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4523 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4524
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4525 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4526 * "term_getline(buf, row)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4527 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4528 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4529 f_term_getline(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4530 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4531 buf_T *buf = term_get_buf(argvars, "term_getline()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4532 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4533 int row;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4534
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4535 rettv->v_type = VAR_STRING;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4536 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4537 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4538 term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4539 row = get_row_number(&argvars[1], term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4540
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4541 if (term->tl_vterm == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4542 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4543 linenr_T lnum = row + term->tl_scrollback_scrolled + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4544
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4545 /* vterm is finished, get the text from the buffer */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4546 if (lnum > 0 && lnum <= buf->b_ml.ml_line_count)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4547 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
4548 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4549 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4550 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4551 VTermScreen *screen = vterm_obtain_screen(term->tl_vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4552 VTermRect rect;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4553 int len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4554 char_u *p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4555
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4556 if (row < 0 || row >= term->tl_rows)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4557 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4558 len = term->tl_cols * MB_MAXBYTES + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4559 p = alloc(len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4560 if (p == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4561 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4562 rettv->vval.v_string = p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4563
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4564 rect.start_col = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4565 rect.end_col = term->tl_cols;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4566 rect.start_row = row;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4567 rect.end_row = row + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4568 p[vterm_screen_get_text(screen, (char *)p, len, rect)] = NUL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4569 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4570 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4571
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4572 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4573 * "term_getscrolled(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4574 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4575 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4576 f_term_getscrolled(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4577 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4578 buf_T *buf = term_get_buf(argvars, "term_getscrolled()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4579
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4580 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4581 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4582 rettv->vval.v_number = buf->b_term->tl_scrollback_scrolled;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4583 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4584
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4585 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4586 * "term_getsize(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4587 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4588 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4589 f_term_getsize(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4590 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4591 buf_T *buf = term_get_buf(argvars, "term_getsize()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4592 list_T *l;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4593
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4594 if (rettv_list_alloc(rettv) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4595 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4596 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4597 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4598
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4599 l = rettv->vval.v_list;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4600 list_append_number(l, buf->b_term->tl_rows);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4601 list_append_number(l, buf->b_term->tl_cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4602 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4603
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4604 /*
13678
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4605 * "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
4606 */
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4607 void
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4608 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
4609 {
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4610 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
4611 term_T *term;
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4612 varnumber_T rows, cols;
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4613
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4614 if (buf == NULL || buf->b_term->tl_vterm == NULL)
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4615 return;
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4616 term = buf->b_term;
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4617 rows = get_tv_number(&argvars[1]);
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4618 rows = rows <= 0 ? term->tl_rows : rows;
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4619 cols = get_tv_number(&argvars[2]);
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4620 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
4621 vterm_set_size(term->tl_vterm, rows, cols);
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4622 /* handle_resize() will resize the windows */
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4623
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4624 /* Get and remember the size we ended up with. Update the pty. */
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4625 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
4626 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
4627 }
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4628
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
4629 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4630 * "term_getstatus(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4631 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4632 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4633 f_term_getstatus(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4634 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4635 buf_T *buf = term_get_buf(argvars, "term_getstatus()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4636 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4637 char_u val[100];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4638
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4639 rettv->v_type = VAR_STRING;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4640 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4641 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4642 term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4643
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4644 if (term_job_running(term))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4645 STRCPY(val, "running");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4646 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4647 STRCPY(val, "finished");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4648 if (term->tl_normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4649 STRCAT(val, ",normal");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4650 rettv->vval.v_string = vim_strsave(val);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4651 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4652
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4653 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4654 * "term_gettitle(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4655 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4656 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4657 f_term_gettitle(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4658 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4659 buf_T *buf = term_get_buf(argvars, "term_gettitle()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4660
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4661 rettv->v_type = VAR_STRING;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4662 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4663 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4664
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4665 if (buf->b_term->tl_title != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4666 rettv->vval.v_string = vim_strsave(buf->b_term->tl_title);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4667 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4668
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4669 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4670 * "term_gettty(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4671 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4672 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4673 f_term_gettty(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4674 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4675 buf_T *buf = term_get_buf(argvars, "term_gettty()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4676 char_u *p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4677 int num = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4678
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4679 rettv->v_type = VAR_STRING;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4680 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4681 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4682 if (argvars[1].v_type != VAR_UNKNOWN)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4683 num = get_tv_number(&argvars[1]);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4684
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4685 switch (num)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4686 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4687 case 0:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4688 if (buf->b_term->tl_job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4689 p = buf->b_term->tl_job->jv_tty_out;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4690 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4691 p = buf->b_term->tl_tty_out;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4692 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4693 case 1:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4694 if (buf->b_term->tl_job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4695 p = buf->b_term->tl_job->jv_tty_in;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4696 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4697 p = buf->b_term->tl_tty_in;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4698 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4699 default:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4700 EMSG2(_(e_invarg2), get_tv_string(&argvars[1]));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4701 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4702 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4703 if (p != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4704 rettv->vval.v_string = vim_strsave(p);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4705 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4706
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4707 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4708 * "term_list()" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4709 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4710 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4711 f_term_list(typval_T *argvars UNUSED, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4712 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4713 term_T *tp;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4714 list_T *l;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4715
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4716 if (rettv_list_alloc(rettv) == FAIL || first_term == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4717 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4718
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4719 l = rettv->vval.v_list;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4720 for (tp = first_term; tp != NULL; tp = tp->tl_next)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4721 if (tp != NULL && tp->tl_buffer != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4722 if (list_append_number(l,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4723 (varnumber_T)tp->tl_buffer->b_fnum) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4724 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4725 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4726
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4727 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4728 * "term_scrape(buf, row)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4729 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4730 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4731 f_term_scrape(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4732 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4733 buf_T *buf = term_get_buf(argvars, "term_scrape()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4734 VTermScreen *screen = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4735 VTermPos pos;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4736 list_T *l;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4737 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4738 char_u *p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4739 sb_line_T *line;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4740
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4741 if (rettv_list_alloc(rettv) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4742 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4743 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4744 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4745 term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4746
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4747 l = rettv->vval.v_list;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4748 pos.row = get_row_number(&argvars[1], term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4749
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4750 if (term->tl_vterm != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4751 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4752 screen = vterm_obtain_screen(term->tl_vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4753 p = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4754 line = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4755 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4756 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4757 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4758 linenr_T lnum = pos.row + term->tl_scrollback_scrolled;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4759
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4760 if (lnum < 0 || lnum >= term->tl_scrollback.ga_len)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4761 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4762 p = ml_get_buf(buf, lnum + 1, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4763 line = (sb_line_T *)term->tl_scrollback.ga_data + lnum;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4764 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4765
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4766 for (pos.col = 0; pos.col < term->tl_cols; )
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4767 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4768 dict_T *dcell;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4769 int width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4770 VTermScreenCellAttrs attrs;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4771 VTermColor fg, bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4772 char_u rgb[8];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4773 char_u mbs[MB_MAXBYTES * VTERM_MAX_CHARS_PER_CELL + 1];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4774 int off = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4775 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4776
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4777 if (screen == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4778 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4779 cellattr_T *cellattr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4780 int len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4781
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4782 /* vterm has finished, get the cell from scrollback */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4783 if (pos.col >= line->sb_cols)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4784 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4785 cellattr = line->sb_cells + pos.col;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4786 width = cellattr->width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4787 attrs = cellattr->attrs;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4788 fg = cellattr->fg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4789 bg = cellattr->bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4790 len = MB_PTR2LEN(p);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4791 mch_memmove(mbs, p, len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4792 mbs[len] = NUL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4793 p += len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4794 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4795 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4796 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4797 VTermScreenCell cell;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4798 if (vterm_screen_get_cell(screen, pos, &cell) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4799 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4800 for (i = 0; i < VTERM_MAX_CHARS_PER_CELL; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4801 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4802 if (cell.chars[i] == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4803 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4804 off += (*utf_char2bytes)((int)cell.chars[i], mbs + off);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4805 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4806 mbs[off] = NUL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4807 width = cell.width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4808 attrs = cell.attrs;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4809 fg = cell.fg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4810 bg = cell.bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4811 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4812 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
4813 if (dcell == NULL)
fc33325c91c1 patch 8.0.1499: out-of-memory situation not correctly handled
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
4814 break;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4815 list_append_dict(l, dcell);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4816
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4817 dict_add_nr_str(dcell, "chars", 0, mbs);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4818
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4819 vim_snprintf((char *)rgb, 8, "#%02x%02x%02x",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4820 fg.red, fg.green, fg.blue);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4821 dict_add_nr_str(dcell, "fg", 0, rgb);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4822 vim_snprintf((char *)rgb, 8, "#%02x%02x%02x",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4823 bg.red, bg.green, bg.blue);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4824 dict_add_nr_str(dcell, "bg", 0, rgb);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4825
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4826 dict_add_nr_str(dcell, "attr",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4827 cell2attr(attrs, fg, bg), NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4828 dict_add_nr_str(dcell, "width", width, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4829
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4830 ++pos.col;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4831 if (width == 2)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4832 ++pos.col;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4833 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4834 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4835
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4836 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4837 * "term_sendkeys(buf, keys)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4838 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4839 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4840 f_term_sendkeys(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4841 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4842 buf_T *buf = term_get_buf(argvars, "term_sendkeys()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4843 char_u *msg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4844 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4845
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4846 rettv->v_type = VAR_UNKNOWN;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4847 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4848 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4849
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4850 msg = get_tv_string_chk(&argvars[1]);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4851 if (msg == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4852 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4853 term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4854 if (term->tl_vterm == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4855 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4856
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4857 while (*msg != NUL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4858 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4859 send_keys_to_term(term, PTR2CHAR(msg), FALSE);
12650
f58755eb453e patch 8.0.1203: terminal window mistreats composing characters
Christian Brabandt <cb@256bit.org>
parents: 12634
diff changeset
4860 msg += MB_CPTR2LEN(msg);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4861 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4862 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4863
13626
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4864 #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
4865 /*
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4866 * "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
4867 */
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4868 void
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4869 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
4870 {
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4871 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
4872 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
4873 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
4874 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
4875 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
4876 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
4877 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
4878
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4879 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
4880 return;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4881
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4882 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
4883 return;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4884 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
4885 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
4886 return;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4887
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4888 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
4889 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
4890 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
4891 {
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4892 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
4893 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
4894 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
4895 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
4896 return;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4897 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4898 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4899
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4900 /*
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4901 * "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
4902 */
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4903 void
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4904 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
4905 {
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4906 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
4907 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
4908
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4909 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
4910 return;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4911 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
4912 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
4913 return;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4914
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4915 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
4916 {
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4917 EMSG(_(e_listreq));
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4918 return;
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4919 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4920
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4921 if (set_ansi_colors_list(term->tl_vterm, argvars[1].vval.v_list) == FAIL)
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4922 EMSG(_(e_invarg));
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4923 }
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4924 #endif
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4925
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4926 /*
13435
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
4927 * "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
4928 */
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
4929 void
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
4930 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
4931 {
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
4932 #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
4933 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
4934 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
4935 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
4936
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
4937 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
4938 return;
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
4939 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
4940 vim_free(term->tl_command);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
4941 cmd = get_tv_string_chk(&argvars[1]);
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
4942 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
4943 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
4944 else
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
4945 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
4946 #endif
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
4947 }
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
4948
fa198b71bab2 patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
4949 /*
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4950 * "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
4951 */
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4952 void
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4953 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
4954 {
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4955 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
4956 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
4957 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
4958
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4959 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
4960 return;
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4961 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
4962 vim_free(term->tl_kill);
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4963 how = get_tv_string_chk(&argvars[1]);
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4964 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
4965 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
4966 else
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4967 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
4968 }
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4969
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
4970 /*
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4971 * "term_start(command, options)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4972 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4973 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4974 f_term_start(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4975 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4976 jobopt_T opt;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4977 buf_T *buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4978
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4979 init_job_options(&opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4980 if (argvars[1].v_type != VAR_UNKNOWN
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4981 && get_job_options(&argvars[1], &opt,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4982 JO_TIMEOUT_ALL + JO_STOPONEXIT
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4983 + JO_CALLBACK + JO_OUT_CALLBACK + JO_ERR_CALLBACK
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4984 + JO_EXIT_CB + JO_CLOSE_CALLBACK + JO_OUT_IO,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4985 JO2_TERM_NAME + JO2_TERM_FINISH + JO2_HIDDEN + JO2_TERM_OPENCMD
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4986 + 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
4987 + 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
4988 + JO2_NORESTORE + JO2_TERM_KILL
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
4989 + JO2_ANSI_COLORS) == FAIL)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4990 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4991
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
4992 buf = term_start(&argvars[0], NULL, &opt, 0);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4993
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4994 if (buf != NULL && buf->b_term != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4995 rettv->vval.v_number = buf->b_fnum;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4996 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4997
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4998 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4999 * "term_wait" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5000 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5001 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5002 f_term_wait(typval_T *argvars, typval_T *rettv UNUSED)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5003 {
13438
33eea5ce5415 patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents: 13435
diff changeset
5004 buf_T *buf = term_get_buf(argvars, "term_wait()");
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5005
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5006 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5007 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5008 if (buf->b_term->tl_job == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5009 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5010 ch_log(NULL, "term_wait(): no job to wait for");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5011 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5012 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5013 if (buf->b_term->tl_job->jv_channel == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5014 /* channel is closed, nothing to do */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5015 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5016
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5017 /* 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
5018 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
5019 && STRCMP(job_status(buf->b_term->tl_job), "dead") == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5020 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5021 /* The job is dead, keep reading channel I/O until the channel is
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5022 * closed. buf->b_term may become NULL if the terminal was closed while
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5023 * waiting. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5024 ch_log(NULL, "term_wait(): waiting for channel to close");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5025 while (buf->b_term != NULL && !buf->b_term->tl_channel_closed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5026 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5027 mch_check_messages();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5028 parse_queued_messages();
12881
1c05b29ab125 patch 8.0.1317: accessing freed memory in term_wait()
Christian Brabandt <cb@256bit.org>
parents: 12865
diff changeset
5029 if (!buf_valid(buf))
1c05b29ab125 patch 8.0.1317: accessing freed memory in term_wait()
Christian Brabandt <cb@256bit.org>
parents: 12865
diff changeset
5030 /* If the terminal is closed when the channel is closed the
1c05b29ab125 patch 8.0.1317: accessing freed memory in term_wait()
Christian Brabandt <cb@256bit.org>
parents: 12865
diff changeset
5031 * buffer disappears. */
1c05b29ab125 patch 8.0.1317: accessing freed memory in term_wait()
Christian Brabandt <cb@256bit.org>
parents: 12865
diff changeset
5032 break;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5033 ui_delay(10L, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5034 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5035 mch_check_messages();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5036 parse_queued_messages();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5037 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5038 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5039 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5040 long wait = 10L;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5041
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5042 mch_check_messages();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5043 parse_queued_messages();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5044
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5045 /* Wait for some time for any channel I/O. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5046 if (argvars[1].v_type != VAR_UNKNOWN)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5047 wait = get_tv_number(&argvars[1]);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5048 ui_delay(wait, TRUE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5049 mch_check_messages();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5050
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5051 /* Flushing messages on channels is hopefully sufficient.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5052 * TODO: is there a better way? */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5053 parse_queued_messages();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5054 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5055 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5056
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5057 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5058 * 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
5059 * Send a CTRL-D to mark the end of the text.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5060 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5061 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5062 term_send_eof(channel_T *ch)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5063 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5064 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5065
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5066 for (term = first_term; term != NULL; term = term->tl_next)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5067 if (term->tl_job == ch->ch_job)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5068 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5069 if (term->tl_eof_chars != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5070 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5071 channel_send(ch, PART_IN, term->tl_eof_chars,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5072 (int)STRLEN(term->tl_eof_chars), NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5073 channel_send(ch, PART_IN, (char_u *)"\r", 1, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5074 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5075 # ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5076 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5077 /* Default: CTRL-D */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5078 channel_send(ch, PART_IN, (char_u *)"\004\r", 2, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5079 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5080 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5081 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5082
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5083 # if defined(WIN3264) || defined(PROTO)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5084
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5085 /**************************************
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5086 * 2. MS-Windows implementation.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5087 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5088
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5089 # ifndef PROTO
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5090
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5091 #define WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN 1ul
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5092 #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
5093 #define WINPTY_MOUSE_MODE_FORCE 2
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5094
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5095 void* (*winpty_config_new)(UINT64, void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5096 void* (*winpty_open)(void*, void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5097 void* (*winpty_spawn_config_new)(UINT64, void*, LPCWSTR, void*, void*, void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5098 BOOL (*winpty_spawn)(void*, void*, HANDLE*, HANDLE*, DWORD*, void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5099 void (*winpty_config_set_mouse_mode)(void*, int);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5100 void (*winpty_config_set_initial_size)(void*, int, int);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5101 LPCWSTR (*winpty_conin_name)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5102 LPCWSTR (*winpty_conout_name)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5103 LPCWSTR (*winpty_conerr_name)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5104 void (*winpty_free)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5105 void (*winpty_config_free)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5106 void (*winpty_spawn_config_free)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5107 void (*winpty_error_free)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5108 LPCWSTR (*winpty_error_msg)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5109 BOOL (*winpty_set_size)(void*, int, int, void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5110 HANDLE (*winpty_agent_process)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5111
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5112 #define WINPTY_DLL "winpty.dll"
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5113
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5114 static HINSTANCE hWinPtyDLL = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5115 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5116
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5117 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5118 dyn_winpty_init(int verbose)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5119 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5120 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5121 static struct
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5122 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5123 char *name;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5124 FARPROC *ptr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5125 } winpty_entry[] =
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5126 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5127 {"winpty_conerr_name", (FARPROC*)&winpty_conerr_name},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5128 {"winpty_config_free", (FARPROC*)&winpty_config_free},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5129 {"winpty_config_new", (FARPROC*)&winpty_config_new},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5130 {"winpty_config_set_mouse_mode",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5131 (FARPROC*)&winpty_config_set_mouse_mode},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5132 {"winpty_config_set_initial_size",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5133 (FARPROC*)&winpty_config_set_initial_size},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5134 {"winpty_conin_name", (FARPROC*)&winpty_conin_name},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5135 {"winpty_conout_name", (FARPROC*)&winpty_conout_name},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5136 {"winpty_error_free", (FARPROC*)&winpty_error_free},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5137 {"winpty_free", (FARPROC*)&winpty_free},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5138 {"winpty_open", (FARPROC*)&winpty_open},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5139 {"winpty_spawn", (FARPROC*)&winpty_spawn},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5140 {"winpty_spawn_config_free", (FARPROC*)&winpty_spawn_config_free},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5141 {"winpty_spawn_config_new", (FARPROC*)&winpty_spawn_config_new},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5142 {"winpty_error_msg", (FARPROC*)&winpty_error_msg},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5143 {"winpty_set_size", (FARPROC*)&winpty_set_size},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5144 {"winpty_agent_process", (FARPROC*)&winpty_agent_process},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5145 {NULL, NULL}
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5146 };
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5147
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5148 /* No need to initialize twice. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5149 if (hWinPtyDLL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5150 return OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5151 /* Load winpty.dll, prefer using the 'winptydll' option, fall back to just
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5152 * winpty.dll. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5153 if (*p_winptydll != NUL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5154 hWinPtyDLL = vimLoadLib((char *)p_winptydll);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5155 if (!hWinPtyDLL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5156 hWinPtyDLL = vimLoadLib(WINPTY_DLL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5157 if (!hWinPtyDLL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5158 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5159 if (verbose)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5160 EMSG2(_(e_loadlib), *p_winptydll != NUL ? p_winptydll
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5161 : (char_u *)WINPTY_DLL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5162 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5163 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5164 for (i = 0; winpty_entry[i].name != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5165 && winpty_entry[i].ptr != NULL; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5166 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5167 if ((*winpty_entry[i].ptr = (FARPROC)GetProcAddress(hWinPtyDLL,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5168 winpty_entry[i].name)) == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5169 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5170 if (verbose)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5171 EMSG2(_(e_loadfunc), winpty_entry[i].name);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5172 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5173 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5174 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5175
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5176 return OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5177 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5178
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5179 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5180 * Create a new terminal of "rows" by "cols" cells.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5181 * Store a reference in "term".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5182 * Return OK or FAIL.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5183 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5184 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5185 term_and_job_init(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5186 term_T *term,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5187 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
5188 char **argv UNUSED,
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5189 jobopt_T *opt)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5190 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5191 WCHAR *cmd_wchar = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5192 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
5193 WCHAR *env_wchar = NULL;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5194 channel_T *channel = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5195 job_T *job = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5196 DWORD error;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5197 HANDLE jo = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5198 HANDLE child_process_handle;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5199 HANDLE child_thread_handle;
13111
149347fda678 patch 8.0.1430: crash when term_start() fails
Christian Brabandt <cb@256bit.org>
parents: 13109
diff changeset
5200 void *winpty_err = NULL;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5201 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
5202 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
5203 char_u *cmd = NULL;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5204
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5205 if (dyn_winpty_init(TRUE) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5206 return FAIL;
13109
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
5207 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
5208 ga_init2(&ga_env, (int)sizeof(char*), 20);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5209
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5210 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
5211 {
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5212 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
5213 }
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
5214 else if (argvar->v_type == VAR_LIST)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5215 {
12724
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
5216 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
5217 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
5218 cmd = ga_cmd.ga_data;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5219 }
13109
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
5220 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
5221 {
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
5222 EMSG(_(e_invarg));
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
5223 goto failed;
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
5224 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5225
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5226 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
5227 ga_clear(&ga_cmd);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5228 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
5229 goto failed;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5230 if (opt->jo_cwd != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5231 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
5232
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
5233 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
5234 env_wchar = ga_env.ga_data;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5235
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5236 job = job_alloc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5237 if (job == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5238 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5239
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5240 channel = add_channel();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5241 if (channel == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5242 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5243
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5244 term->tl_winpty_config = winpty_config_new(0, &winpty_err);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5245 if (term->tl_winpty_config == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5246 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5247
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5248 winpty_config_set_mouse_mode(term->tl_winpty_config,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5249 WINPTY_MOUSE_MODE_FORCE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5250 winpty_config_set_initial_size(term->tl_winpty_config,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5251 term->tl_cols, term->tl_rows);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5252 term->tl_winpty = winpty_open(term->tl_winpty_config, &winpty_err);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5253 if (term->tl_winpty == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5254 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5255
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5256 spawn_config = winpty_spawn_config_new(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5257 WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN |
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5258 WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5259 NULL,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5260 cmd_wchar,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5261 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
5262 env_wchar,
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5263 &winpty_err);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5264 if (spawn_config == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5265 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5266
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5267 channel = add_channel();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5268 if (channel == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5269 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5270
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5271 job = job_alloc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5272 if (job == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5273 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5274
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5275 if (opt->jo_set & JO_IN_BUF)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5276 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
5277
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5278 if (!winpty_spawn(term->tl_winpty, spawn_config, &child_process_handle,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5279 &child_thread_handle, &error, &winpty_err))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5280 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5281
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5282 channel_set_pipes(channel,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5283 (sock_T)CreateFileW(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5284 winpty_conin_name(term->tl_winpty),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5285 GENERIC_WRITE, 0, NULL,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5286 OPEN_EXISTING, 0, NULL),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5287 (sock_T)CreateFileW(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5288 winpty_conout_name(term->tl_winpty),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5289 GENERIC_READ, 0, NULL,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5290 OPEN_EXISTING, 0, NULL),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5291 (sock_T)CreateFileW(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5292 winpty_conerr_name(term->tl_winpty),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5293 GENERIC_READ, 0, NULL,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5294 OPEN_EXISTING, 0, NULL));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5295
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5296 /* Write lines with CR instead of NL. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5297 channel->ch_write_text_mode = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5298
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5299 jo = CreateJobObject(NULL, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5300 if (jo == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5301 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5302
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5303 if (!AssignProcessToJobObject(jo, child_process_handle))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5304 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5305 /* Failed, switch the way to terminate process with TerminateProcess. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5306 CloseHandle(jo);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5307 jo = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5308 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5309
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5310 winpty_spawn_config_free(spawn_config);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5311 vim_free(cmd_wchar);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5312 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
5313 vim_free(env_wchar);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5314
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5315 create_vterm(term, term->tl_rows, term->tl_cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5316
13626
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5317 #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
5318 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
5319 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
5320 else
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5321 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
5322 #endif
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5323
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5324 channel_set_job(channel, job, opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5325 job_set_options(job, opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5326
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5327 job->jv_channel = channel;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5328 job->jv_proc_info.hProcess = child_process_handle;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5329 job->jv_proc_info.dwProcessId = GetProcessId(child_process_handle);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5330 job->jv_job_object = jo;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5331 job->jv_status = JOB_STARTED;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5332 job->jv_tty_in = utf16_to_enc(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5333 (short_u*)winpty_conin_name(term->tl_winpty), NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5334 job->jv_tty_out = utf16_to_enc(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5335 (short_u*)winpty_conout_name(term->tl_winpty), NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5336 ++job->jv_refcount;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5337 term->tl_job = job;
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 return OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5340
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5341 failed:
13109
fb1b162cdcf6 patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents: 13000
diff changeset
5342 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
5343 ga_clear(&ga_env);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5344 vim_free(cmd_wchar);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5345 vim_free(cwd_wchar);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5346 if (spawn_config != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5347 winpty_spawn_config_free(spawn_config);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5348 if (channel != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5349 channel_clear(channel);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5350 if (job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5351 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5352 job->jv_channel = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5353 job_cleanup(job);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5354 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5355 term->tl_job = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5356 if (jo != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5357 CloseHandle(jo);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5358 if (term->tl_winpty != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5359 winpty_free(term->tl_winpty);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5360 term->tl_winpty = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5361 if (term->tl_winpty_config != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5362 winpty_config_free(term->tl_winpty_config);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5363 term->tl_winpty_config = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5364 if (winpty_err != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5365 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5366 char_u *msg = utf16_to_enc(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5367 (short_u *)winpty_error_msg(winpty_err), NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5368
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5369 EMSG(msg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5370 winpty_error_free(winpty_err);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5371 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5372 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5373 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5374
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5375 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5376 create_pty_only(term_T *term, jobopt_T *options)
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 HANDLE hPipeIn = INVALID_HANDLE_VALUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5379 HANDLE hPipeOut = INVALID_HANDLE_VALUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5380 char in_name[80], out_name[80];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5381 channel_T *channel = NULL;
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 create_vterm(term, term->tl_rows, term->tl_cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5384
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5385 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
5386 GetCurrentProcessId(),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5387 curbuf->b_fnum);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5388 hPipeIn = CreateNamedPipe(in_name, PIPE_ACCESS_OUTBOUND,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5389 PIPE_TYPE_MESSAGE | PIPE_NOWAIT,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5390 PIPE_UNLIMITED_INSTANCES,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5391 0, 0, NMPWAIT_NOWAIT, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5392 if (hPipeIn == INVALID_HANDLE_VALUE)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5393 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5394
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5395 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
5396 GetCurrentProcessId(),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5397 curbuf->b_fnum);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5398 hPipeOut = CreateNamedPipe(out_name, PIPE_ACCESS_INBOUND,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5399 PIPE_TYPE_MESSAGE | PIPE_NOWAIT,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5400 PIPE_UNLIMITED_INSTANCES,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5401 0, 0, 0, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5402 if (hPipeOut == INVALID_HANDLE_VALUE)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5403 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5404
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5405 ConnectNamedPipe(hPipeIn, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5406 ConnectNamedPipe(hPipeOut, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5407
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5408 term->tl_job = job_alloc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5409 if (term->tl_job == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5410 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5411 ++term->tl_job->jv_refcount;
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 /* behave like the job is already finished */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5414 term->tl_job->jv_status = JOB_FINISHED;
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 channel = add_channel();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5417 if (channel == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5418 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5419 term->tl_job->jv_channel = channel;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5420 channel->ch_keep_open = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5421 channel->ch_named_pipe = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5422
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5423 channel_set_pipes(channel,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5424 (sock_T)hPipeIn,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5425 (sock_T)hPipeOut,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5426 (sock_T)hPipeOut);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5427 channel_set_job(channel, term->tl_job, options);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5428 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
5429 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
5430
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5431 return OK;
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 failed:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5434 if (hPipeIn != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5435 CloseHandle(hPipeIn);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5436 if (hPipeOut != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5437 CloseHandle(hPipeOut);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5438 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5439 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5440
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5441 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5442 * Free the terminal emulator part of "term".
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 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5445 term_free_vterm(term_T *term)
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 if (term->tl_winpty != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5448 winpty_free(term->tl_winpty);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5449 term->tl_winpty = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5450 if (term->tl_winpty_config != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5451 winpty_config_free(term->tl_winpty_config);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5452 term->tl_winpty_config = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5453 if (term->tl_vterm != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5454 vterm_free(term->tl_vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5455 term->tl_vterm = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5456 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5457
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5458 /*
13678
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
5459 * Report the size to the terminal.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5460 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5461 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5462 term_report_winsize(term_T *term, int rows, int cols)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5463 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5464 if (term->tl_winpty)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5465 winpty_set_size(term->tl_winpty, cols, rows, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5466 }
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 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5469 terminal_enabled(void)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5470 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5471 return dyn_winpty_init(FALSE) == OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5472 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5473
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5474 # else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5475
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5476 /**************************************
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5477 * 3. Unix-like implementation.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5478 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5479
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5480 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5481 * Create a new terminal of "rows" by "cols" cells.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5482 * Start job for "cmd".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5483 * 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
5484 * When "argv" is not NULL then "argvar" is not used.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5485 * Return OK or FAIL.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5486 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5487 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5488 term_and_job_init(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5489 term_T *term,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5490 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
5491 char **argv,
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5492 jobopt_T *opt)
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 create_vterm(term, term->tl_rows, term->tl_cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5495
13626
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5496 #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
5497 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
5498 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
5499 else
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5500 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
5501 #endif
ab89131d30e0 patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents: 13624
diff changeset
5502
13470
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
5503 /* This may change a string in "argvar". */
6faef782f50b patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents: 13458
diff changeset
5504 term->tl_job = job_start(argvar, argv, opt);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5505 if (term->tl_job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5506 ++term->tl_job->jv_refcount;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5507
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5508 return term->tl_job != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5509 && term->tl_job->jv_channel != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5510 && term->tl_job->jv_status != JOB_FAILED ? OK : FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5511 }
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 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5514 create_pty_only(term_T *term, jobopt_T *opt)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5515 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5516 create_vterm(term, term->tl_rows, term->tl_cols);
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 term->tl_job = job_alloc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5519 if (term->tl_job == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5520 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5521 ++term->tl_job->jv_refcount;
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 /* behave like the job is already finished */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5524 term->tl_job->jv_status = JOB_FINISHED;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5525
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5526 return mch_create_pty_channel(term->tl_job, opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5527 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5528
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5529 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5530 * Free the terminal emulator part of "term".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5531 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5532 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5533 term_free_vterm(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5534 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5535 if (term->tl_vterm != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5536 vterm_free(term->tl_vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5537 term->tl_vterm = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5538 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5539
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5540 /*
13678
39fcaaa973db patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents: 13668
diff changeset
5541 * Report the size to the terminal.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5542 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5543 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5544 term_report_winsize(term_T *term, int rows, int cols)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5545 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5546 /* Use an ioctl() to report the new window size to the job. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5547 if (term->tl_job != NULL && term->tl_job->jv_channel != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5548 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5549 int fd = -1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5550 int part;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5551
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5552 for (part = PART_OUT; part < PART_COUNT; ++part)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5553 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5554 fd = term->tl_job->jv_channel->ch_part[part].ch_fd;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5555 if (isatty(fd))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5556 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5557 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5558 if (part < PART_COUNT && mch_report_winsize(fd, rows, cols) == OK)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5559 mch_signal_job(term->tl_job, (char_u *)"winch");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5560 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5561 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5562
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5563 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5564
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5565 #endif /* FEAT_TERMINAL */