annotate src/terminal.c @ 12871:1a450ce6980c v8.0.1312

patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI commit https://github.com/vim/vim/commit/c3719bd87beca9f72d2e9f11e36d561c2c3b57b0 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Nov 18 22:13:31 2017 +0100 patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI Problem: balloon_show() only works in terminal when compiled with the GUI. Solution: Add FEAT_BEVAL_GUI and refactor to move common code out of the GUI specific file.
author Christian Brabandt <cb@256bit.org>
date Sat, 18 Nov 2017 22:15:05 +0100
parents ebb4f6c93598
children 1c05b29ab125
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:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 * - in GUI vertical split causes problems. Cursor is flickering. (Hirohito
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 * Higashi, 2017 Sep 19)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 * - Shift-Tab does not work.
12578
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
44 * - after resizing windows overlap. (Boris Staletic, #2164)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 * - 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
46 * is disabled.
12541
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
47 * - 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
48 * - When closing gvim with an active terminal buffer, the dialog suggests
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
49 * saving the buffer. Should say something else. (Manas Thakur, #2215)
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
50 * Also: #2223
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 * - implement term_setsize()
12724
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
52 * - 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
53 * - MS-Windows GUI: WinBar has tearoff item
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 * - 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
55 * - After executing a shell command the status line isn't redraw.
12724
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
56 * - What to store in a session file? Shell at the prompt would be OK to
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
57 * restore, but others may not. Open the window and let the user start the
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
58 * command?
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59 * - add test for giving error for invalid 'termsize' value.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 * - support minimal size when 'termsize' is "rows*cols".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 * - support minimal size when 'termsize' is empty?
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 * - GUI: when using tabs, focus in terminal, click on tab does not work.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 * - GUI: when 'confirm' is set and trying to exit Vim, dialog offers to save
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 * changes to "!shell".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 * (justrajdeep, 2017 Aug 22)
12632
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
66 * - 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
67 * - For the GUI fill termios with default values, perhaps like pangoterm:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 * 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
69 * - if the job in the terminal does not support the mouse, we can use the
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 * mouse in the Terminal window for copy/paste.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71 * - 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
72 * conversions.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73 * - In the GUI use a terminal emulator for :!cmd. Make the height the same as
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 * the window and position it higher up when it gets filled, so it looks like
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75 * the text scrolls up.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
76 * - Copy text in the vterm to the Vim buffer once in a while, so that
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
77 * completion works.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78 * - add an optional limit for the scrollback size. When reaching it remove
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 * 10% at the start.
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
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82 #include "vim.h"
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 #if defined(FEAT_TERMINAL) || defined(PROTO)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86 #ifndef MIN
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87 # define MIN(x,y) ((x) < (y) ? (x) : (y))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89 #ifndef MAX
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
90 # define MAX(x,y) ((x) > (y) ? (x) : (y))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 #include "libvterm/include/vterm.h"
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 /* This is VTermScreenCell without the characters, thus much smaller. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
96 typedef struct {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
97 VTermScreenCellAttrs attrs;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
98 char width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
99 VTermColor fg, bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
100 } cellattr_T;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
101
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
102 typedef struct sb_line_S {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
103 int sb_cols; /* can differ per line */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
104 cellattr_T *sb_cells; /* allocated */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
105 cellattr_T sb_fill_attr; /* for short line */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
106 } sb_line_T;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
107
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
108 /* typedef term_T in structs.h */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
109 struct terminal_S {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
110 term_T *tl_next;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
111
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
112 VTerm *tl_vterm;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
113 job_T *tl_job;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
114 buf_T *tl_buffer;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
115
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
116 /* Set when setting the size of a vterm, reset after redrawing. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
117 int tl_vterm_size_changed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
118
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
119 /* 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
120 int tl_tty_fd;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
121 char_u *tl_tty_in;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
122 char_u *tl_tty_out;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
123
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
124 int tl_normal_mode; /* TRUE: Terminal-Normal mode */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
125 int tl_channel_closed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
126 int tl_finish; /* 'c' for ++close, 'o' for ++open */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
127 char_u *tl_opencmd;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
128 char_u *tl_eof_chars;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
129
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
130 #ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
131 void *tl_winpty_config;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
132 void *tl_winpty;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
133 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
134
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
135 /* last known vterm size */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
136 int tl_rows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
137 int tl_cols;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
138 /* vterm size does not follow window size */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
139 int tl_rows_fixed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
140 int tl_cols_fixed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
141
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
142 char_u *tl_title; /* NULL or allocated */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
143 char_u *tl_status_text; /* NULL or allocated */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
144
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
145 /* 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
146 int tl_dirty_row_start; /* MAX_ROW if nothing dirty */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
147 int tl_dirty_row_end; /* row below last one to update */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
148
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
149 garray_T tl_scrollback;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
150 int tl_scrollback_scrolled;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
151 cellattr_T tl_default_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
152
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
153 VTermPos tl_cursor_pos;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
154 int tl_cursor_visible;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
155 int tl_cursor_blink;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
156 int tl_cursor_shape; /* 1: block, 2: underline, 3: bar */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
157 char_u *tl_cursor_color; /* NULL or allocated */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
158
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
159 int tl_using_altscreen;
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
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
162 #define TMODE_ONCE 1 /* CTRL-\ CTRL-N used */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
163 #define TMODE_LOOP 2 /* CTRL-W N used */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
164
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
165 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
166 * List of all active terminals.
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 static term_T *first_term = NULL;
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 /* Terminal active in terminal_loop(). */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
171 static term_T *in_terminal_loop = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
172
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
173 #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
174 #define KEY_BUF_LEN 200
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
175
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
176 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
177 * Functions with separate implementation for MS-Windows and Unix-like systems.
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 static int term_and_job_init(term_T *term, typval_T *argvar, jobopt_T *opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
180 static int create_pty_only(term_T *term, jobopt_T *opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
181 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
182 static void term_free_vterm(term_T *term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
183
12800
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
184 /* 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
185 * backspace key. */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
186 static int term_backspace_char = BS;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
187
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
188
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
189 /**************************************
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
190 * 1. Generic code for all systems.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
191 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
192
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
193 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
194 * Determine the terminal size from 'termsize' and the current window.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
195 * Assumes term->tl_rows and term->tl_cols are zero.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
196 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
197 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
198 set_term_and_win_size(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
199 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
200 if (*curwin->w_p_tms != NUL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
201 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
202 char_u *p = vim_strchr(curwin->w_p_tms, 'x') + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
203
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
204 term->tl_rows = atoi((char *)curwin->w_p_tms);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
205 term->tl_cols = atoi((char *)p);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
206 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
207 if (term->tl_rows == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
208 term->tl_rows = curwin->w_height;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
209 else
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 win_setheight_win(term->tl_rows, curwin);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
212 term->tl_rows_fixed = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
213 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
214 if (term->tl_cols == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
215 term->tl_cols = curwin->w_width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
216 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
217 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
218 win_setwidth_win(term->tl_cols, curwin);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
219 term->tl_cols_fixed = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
220 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
221 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
222
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
223 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
224 * Initialize job options for a terminal job.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
225 * Caller may overrule some of them.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
226 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
227 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
228 init_job_options(jobopt_T *opt)
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 clear_job_options(opt);
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 opt->jo_mode = MODE_RAW;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
233 opt->jo_out_mode = MODE_RAW;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
234 opt->jo_err_mode = MODE_RAW;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
235 opt->jo_set = JO_MODE | JO_OUT_MODE | JO_ERR_MODE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
236 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
237
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 * Set job options mandatory for a terminal job.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
240 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
241 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
242 setup_job_options(jobopt_T *opt, int rows, int cols)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
243 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
244 if (!(opt->jo_set & JO_OUT_IO))
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 /* Connect stdout to the terminal. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
247 opt->jo_io[PART_OUT] = JIO_BUFFER;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
248 opt->jo_io_buf[PART_OUT] = curbuf->b_fnum;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
249 opt->jo_modifiable[PART_OUT] = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
250 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
251 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
252
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
253 if (!(opt->jo_set & JO_ERR_IO))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
254 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
255 /* Connect stderr to the terminal. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
256 opt->jo_io[PART_ERR] = JIO_BUFFER;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
257 opt->jo_io_buf[PART_ERR] = curbuf->b_fnum;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
258 opt->jo_modifiable[PART_ERR] = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
259 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
260 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
261
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
262 opt->jo_pty = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
263 if ((opt->jo_set2 & JO2_TERM_ROWS) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
264 opt->jo_term_rows = rows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
265 if ((opt->jo_set2 & JO2_TERM_COLS) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
266 opt->jo_term_cols = cols;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
267 }
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 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
270 * Start a terminal window and return its buffer.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
271 * Returns NULL when failed.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
272 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
273 static buf_T *
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
274 term_start(typval_T *argvar, jobopt_T *opt, int forceit)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
275 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
276 exarg_T split_ea;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
277 win_T *old_curwin = curwin;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
278 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
279 buf_T *old_curbuf = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
280 int res;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
281 buf_T *newbuf;
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 if (check_restricted() || check_secure())
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
284 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
285
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
286 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
287 == (JO_IN_IO + JO_OUT_IO + JO_ERR_IO)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
288 || (!(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
289 || (!(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
290 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
291 EMSG(_(e_invarg));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
292 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
293 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
294
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
295 term = (term_T *)alloc_clear(sizeof(term_T));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
296 if (term == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
297 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
298 term->tl_dirty_row_end = MAX_ROW;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
299 term->tl_cursor_visible = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
300 term->tl_cursor_shape = VTERM_PROP_CURSORSHAPE_BLOCK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
301 term->tl_finish = opt->jo_term_finish;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
302 ga_init2(&term->tl_scrollback, sizeof(sb_line_T), 300);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
303
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
304 vim_memset(&split_ea, 0, sizeof(split_ea));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
305 if (opt->jo_curwin)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
306 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
307 /* Create a new buffer in the current window. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
308 if (!can_abandon(curbuf, forceit))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
309 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
310 no_write_message();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
311 vim_free(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
312 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
313 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
314 if (do_ecmd(0, NULL, NULL, &split_ea, ECMD_ONE,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
315 ECMD_HIDE + (forceit ? ECMD_FORCEIT : 0), curwin) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
316 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
317 vim_free(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
318 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
319 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
320 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
321 else if (opt->jo_hidden)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
322 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
323 buf_T *buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
324
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
325 /* 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
326 * a moment to be able to do the initialisations. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
327 buf = buflist_new((char_u *)"", NULL, (linenr_T)0,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
328 BLN_NEW | BLN_LISTED);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
329 if (buf == NULL || ml_open(buf) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
330 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
331 vim_free(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
332 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
333 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
334 old_curbuf = curbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
335 --curbuf->b_nwindows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
336 curbuf = buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
337 curwin->w_buffer = buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
338 ++curbuf->b_nwindows;
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 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
341 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
342 /* Open a new window or tab. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
343 split_ea.cmdidx = CMD_new;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
344 split_ea.cmd = (char_u *)"new";
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
345 split_ea.arg = (char_u *)"";
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
346 if (opt->jo_term_rows > 0 && !(cmdmod.split & WSP_VERT))
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 split_ea.line2 = opt->jo_term_rows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
349 split_ea.addr_count = 1;
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 if (opt->jo_term_cols > 0 && (cmdmod.split & WSP_VERT))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
352 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
353 split_ea.line2 = opt->jo_term_cols;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
354 split_ea.addr_count = 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
355 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
356
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
357 ex_splitview(&split_ea);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
358 if (curwin == old_curwin)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
359 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
360 /* split failed */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
361 vim_free(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
362 return NULL;
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 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
365 term->tl_buffer = curbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
366 curbuf->b_term = term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
367
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
368 if (!opt->jo_hidden)
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 /* only one size was taken care of with :new, do the other one */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
371 if (opt->jo_term_rows > 0 && (cmdmod.split & WSP_VERT))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
372 win_setheight(opt->jo_term_rows);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
373 if (opt->jo_term_cols > 0 && !(cmdmod.split & WSP_VERT))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
374 win_setwidth(opt->jo_term_cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
375 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
376
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
377 /* Link the new terminal in the list of active terminals. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
378 term->tl_next = first_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
379 first_term = term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
380
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
381 if (opt->jo_term_name != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
382 curbuf->b_ffname = vim_strsave(opt->jo_term_name);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
383 else
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 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
386 size_t len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
387 char_u *cmd, *p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
388
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
389 if (argvar->v_type == VAR_STRING)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
390 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
391 cmd = argvar->vval.v_string;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
392 if (cmd == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
393 cmd = (char_u *)"";
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
394 else if (STRCMP(cmd, "NONE") == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
395 cmd = (char_u *)"pty";
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
396 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
397 else if (argvar->v_type != VAR_LIST
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
398 || argvar->vval.v_list == NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
399 || argvar->vval.v_list->lv_len < 1
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
400 || (cmd = get_tv_string_chk(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
401 &argvar->vval.v_list->lv_first->li_tv)) == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
402 cmd = (char_u*)"";
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 len = STRLEN(cmd) + 10;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
405 p = alloc((int)len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
406
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
407 for (i = 0; p != NULL; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
408 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
409 /* 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
410 * the executable, otherwise ":w!" would overwrite it. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
411 if (i == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
412 vim_snprintf((char *)p, len, "!%s", cmd);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
413 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
414 vim_snprintf((char *)p, len, "!%s (%d)", cmd, i);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
415 if (buflist_findname(p) == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
416 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
417 vim_free(curbuf->b_ffname);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
418 curbuf->b_ffname = p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
419 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
420 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
421 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
422 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
423 curbuf->b_fname = curbuf->b_ffname;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
424
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
425 if (opt->jo_term_opencmd != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
426 term->tl_opencmd = vim_strsave(opt->jo_term_opencmd);
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 if (opt->jo_eof_chars != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
429 term->tl_eof_chars = vim_strsave(opt->jo_eof_chars);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
430
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
431 set_string_option_direct((char_u *)"buftype", -1,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
432 (char_u *)"terminal", OPT_FREE|OPT_LOCAL, 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
433
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
434 /* 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
435 * the job finished. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
436 curbuf->b_p_ma = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
437
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
438 set_term_and_win_size(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
439 setup_job_options(opt, term->tl_rows, term->tl_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 /* System dependent: setup the vterm and maybe start the job in it. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
442 if (argvar->v_type == VAR_STRING
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
443 && argvar->vval.v_string != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
444 && STRCMP(argvar->vval.v_string, "NONE") == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
445 res = create_pty_only(term, opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
446 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
447 res = term_and_job_init(term, argvar, opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
448
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
449 newbuf = curbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
450 if (res == OK)
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 /* 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
453 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
454 term_report_winsize(term, term->tl_rows, term->tl_cols);
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 /* 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
457 * a deadlock if the job is waiting for Vim to read. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
458 channel_set_nonblock(term->tl_job->jv_channel, PART_IN);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
459
12509
1fd4594eb74a Missing part of 8.0.1131.
Christian Brabandt <cb@256bit.org>
parents: 12502
diff changeset
460 #ifdef FEAT_AUTOCMD
1fd4594eb74a Missing part of 8.0.1131.
Christian Brabandt <cb@256bit.org>
parents: 12502
diff changeset
461 ++curbuf->b_locked;
1fd4594eb74a Missing part of 8.0.1131.
Christian Brabandt <cb@256bit.org>
parents: 12502
diff changeset
462 apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf);
1fd4594eb74a Missing part of 8.0.1131.
Christian Brabandt <cb@256bit.org>
parents: 12502
diff changeset
463 --curbuf->b_locked;
1fd4594eb74a Missing part of 8.0.1131.
Christian Brabandt <cb@256bit.org>
parents: 12502
diff changeset
464 #endif
1fd4594eb74a Missing part of 8.0.1131.
Christian Brabandt <cb@256bit.org>
parents: 12502
diff changeset
465
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
466 if (old_curbuf != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
467 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
468 --curbuf->b_nwindows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
469 curbuf = old_curbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
470 curwin->w_buffer = curbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
471 ++curbuf->b_nwindows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
472 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
473 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
474 else
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 buf_T *buf = curbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
477
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
478 free_terminal(curbuf);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
479 if (old_curbuf != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
480 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
481 --curbuf->b_nwindows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
482 curbuf = old_curbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
483 curwin->w_buffer = curbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
484 ++curbuf->b_nwindows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
485 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
486
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
487 /* Wiping out the buffer will also close the window and call
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
488 * free_terminal(). */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
489 do_buffer(DOBUF_WIPE, DOBUF_FIRST, FORWARD, buf->b_fnum, TRUE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
490 return NULL;
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 return newbuf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
493 }
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 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
496 * ":terminal": open a terminal window and execute a job in it.
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 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
499 ex_terminal(exarg_T *eap)
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 typval_T argvar[2];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
502 jobopt_T opt;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
503 char_u *cmd;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
504 char_u *tofree = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
505
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
506 init_job_options(&opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
507
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
508 cmd = eap->arg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
509 while (*cmd && *cmd == '+' && *(cmd + 1) == '+')
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
510 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
511 char_u *p, *ep;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
512
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
513 cmd += 2;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
514 p = skiptowhite(cmd);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
515 ep = vim_strchr(cmd, '=');
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
516 if (ep != NULL && ep < p)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
517 p = ep;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
518
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
519 if ((int)(p - cmd) == 5 && STRNICMP(cmd, "close", 5) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
520 opt.jo_term_finish = 'c';
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
521 else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "open", 4) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
522 opt.jo_term_finish = 'o';
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
523 else if ((int)(p - cmd) == 6 && STRNICMP(cmd, "curwin", 6) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
524 opt.jo_curwin = 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
525 else if ((int)(p - cmd) == 6 && STRNICMP(cmd, "hidden", 6) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
526 opt.jo_hidden = 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
527 else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "rows", 4) == 0
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
528 && ep != NULL && isdigit(ep[1]))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
529 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
530 opt.jo_set2 |= JO2_TERM_ROWS;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
531 opt.jo_term_rows = atoi((char *)ep + 1);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
532 p = skiptowhite(cmd);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
533 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
534 else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "cols", 4) == 0
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
535 && ep != NULL && isdigit(ep[1]))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
536 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
537 opt.jo_set2 |= JO2_TERM_COLS;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
538 opt.jo_term_cols = atoi((char *)ep + 1);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
539 p = skiptowhite(cmd);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
540 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
541 else if ((int)(p - cmd) == 3 && STRNICMP(cmd, "eof", 3) == 0
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
542 && ep != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
543 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
544 char_u *buf = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
545 char_u *keys;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
546
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
547 p = skiptowhite(cmd);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
548 *p = NUL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
549 keys = replace_termcodes(ep + 1, &buf, TRUE, TRUE, TRUE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
550 opt.jo_set2 |= JO2_EOF_CHARS;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
551 opt.jo_eof_chars = vim_strsave(keys);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
552 vim_free(buf);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
553 *p = ' ';
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
554 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
555 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
556 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
557 if (*p)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
558 *p = NUL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
559 EMSG2(_("E181: Invalid attribute: %s"), cmd);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
560 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
561 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
562 cmd = skipwhite(p);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
563 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
564 if (*cmd == NUL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
565 /* Make a copy of 'shell', an autocommand may change the option. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
566 tofree = cmd = vim_strsave(p_sh);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
567
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
568 if (eap->addr_count > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
569 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
570 /* Write lines from current buffer to the job. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
571 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
572 opt.jo_io[PART_IN] = JIO_BUFFER;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
573 opt.jo_io_buf[PART_IN] = curbuf->b_fnum;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
574 opt.jo_in_top = eap->line1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
575 opt.jo_in_bot = eap->line2;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
576 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
577
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
578 argvar[0].v_type = VAR_STRING;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
579 argvar[0].vval.v_string = cmd;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
580 argvar[1].v_type = VAR_UNKNOWN;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
581 term_start(argvar, &opt, eap->forceit);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
582 vim_free(tofree);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
583 vim_free(opt.jo_eof_chars);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
584 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
585
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
586 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
587 * Free the scrollback buffer for "term".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
588 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
589 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
590 free_scrollback(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
591 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
592 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
593
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
594 for (i = 0; i < term->tl_scrollback.ga_len; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
595 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
596 ga_clear(&term->tl_scrollback);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
597 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
598
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
599 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
600 * Free a terminal and everything it refers to.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
601 * Kills the job if there is one.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
602 * Called when wiping out a buffer.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
603 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
604 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
605 free_terminal(buf_T *buf)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
606 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
607 term_T *term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
608 term_T *tp;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
609
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
610 if (term == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
611 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
612 if (first_term == term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
613 first_term = term->tl_next;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
614 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
615 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
616 if (tp->tl_next == term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
617 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
618 tp->tl_next = term->tl_next;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
619 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
620 }
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 if (term->tl_job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
623 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
624 if (term->tl_job->jv_status != JOB_ENDED
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
625 && term->tl_job->jv_status != JOB_FINISHED
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
626 && term->tl_job->jv_status != JOB_FAILED)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
627 job_stop(term->tl_job, NULL, "kill");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
628 job_unref(term->tl_job);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
629 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
630
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
631 free_scrollback(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
632
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
633 term_free_vterm(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
634 vim_free(term->tl_title);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
635 vim_free(term->tl_status_text);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
636 vim_free(term->tl_opencmd);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
637 vim_free(term->tl_eof_chars);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
638 vim_free(term->tl_cursor_color);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
639 vim_free(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
640 buf->b_term = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
641 if (in_terminal_loop == term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
642 in_terminal_loop = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
643 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
644
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
645 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
646 * Write job output "msg[len]" to the vterm.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
647 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
648 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
649 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
650 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
651 VTerm *vterm = term->tl_vterm;
12800
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
652
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
653 vterm_input_write(vterm, (char *)msg, len);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
654
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
655 /* this invokes the damage callbacks */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
656 vterm_screen_flush_damage(vterm_obtain_screen(vterm));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
657 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
658
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
659 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
660 update_cursor(term_T *term, int redraw)
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 if (term->tl_normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
663 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
664 setcursor();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
665 if (redraw)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
666 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
667 if (term->tl_buffer == curbuf && term->tl_cursor_visible)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
668 cursor_on();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
669 out_flush();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
670 #ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
671 if (gui.in_use)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
672 gui_update_cursor(FALSE, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
673 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
674 }
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
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
677 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
678 * 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
679 * of "buffer".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
680 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
681 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
682 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
683 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
684 size_t len = STRLEN(msg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
685 term_T *term = buffer->b_term;
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 if (term->tl_vterm == NULL)
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 ch_log(channel, "NOT writing %d bytes to terminal", (int)len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
690 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
691 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
692 ch_log(channel, "writing %d bytes to terminal", (int)len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
693 term_write_job_output(term, msg, len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
694
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
695 /* 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
696 * contents, thus no screen update is needed. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
697 if (!term->tl_normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
698 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
699 /* TODO: only update once in a while. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
700 ch_log(term->tl_job->jv_channel, "updating screen");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
701 if (buffer == curbuf)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
702 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
703 update_screen(0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
704 update_cursor(term, TRUE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
705 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
706 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
707 redraw_after_callback(TRUE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
708 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
709 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
710
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
711 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
712 * Send a mouse position and click to the vterm
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
713 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
714 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
715 term_send_mouse(VTerm *vterm, int button, int pressed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
716 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
717 VTermModifier mod = VTERM_MOD_NONE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
718
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
719 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
720 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
721 if (button != 0)
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12845
diff changeset
722 vterm_mouse_button(vterm, button, pressed, mod);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
723 return TRUE;
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
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
726 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
727 * Convert typed key "c" into bytes to send to the job.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
728 * Return the number of bytes in "buf".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
729 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
730 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
731 term_convert_key(term_T *term, int c, char *buf)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
732 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
733 VTerm *vterm = term->tl_vterm;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
734 VTermKey key = VTERM_KEY_NONE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
735 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
736 int other = FALSE;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
737
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
738 switch (c)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
739 {
12800
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
740 /* 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
741
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
742 /* don't use VTERM_KEY_BACKSPACE, it always
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
743 * becomes 0x7f DEL */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
744 case K_BS: c = term_backspace_char; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
745
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
746 case ESC: key = VTERM_KEY_ESCAPE; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
747 case K_DEL: key = VTERM_KEY_DEL; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
748 case K_DOWN: key = VTERM_KEY_DOWN; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
749 case K_S_DOWN: mod = VTERM_MOD_SHIFT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
750 key = VTERM_KEY_DOWN; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
751 case K_END: key = VTERM_KEY_END; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
752 case K_S_END: mod = VTERM_MOD_SHIFT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
753 key = VTERM_KEY_END; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
754 case K_C_END: mod = VTERM_MOD_CTRL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
755 key = VTERM_KEY_END; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
756 case K_F10: key = VTERM_KEY_FUNCTION(10); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
757 case K_F11: key = VTERM_KEY_FUNCTION(11); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
758 case K_F12: key = VTERM_KEY_FUNCTION(12); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
759 case K_F1: key = VTERM_KEY_FUNCTION(1); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
760 case K_F2: key = VTERM_KEY_FUNCTION(2); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
761 case K_F3: key = VTERM_KEY_FUNCTION(3); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
762 case K_F4: key = VTERM_KEY_FUNCTION(4); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
763 case K_F5: key = VTERM_KEY_FUNCTION(5); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
764 case K_F6: key = VTERM_KEY_FUNCTION(6); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
765 case K_F7: key = VTERM_KEY_FUNCTION(7); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
766 case K_F8: key = VTERM_KEY_FUNCTION(8); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
767 case K_F9: key = VTERM_KEY_FUNCTION(9); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
768 case K_HOME: key = VTERM_KEY_HOME; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
769 case K_S_HOME: mod = VTERM_MOD_SHIFT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
770 key = VTERM_KEY_HOME; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
771 case K_C_HOME: mod = VTERM_MOD_CTRL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
772 key = VTERM_KEY_HOME; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
773 case K_INS: key = VTERM_KEY_INS; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
774 case K_K0: key = VTERM_KEY_KP_0; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
775 case K_K1: key = VTERM_KEY_KP_1; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
776 case K_K2: key = VTERM_KEY_KP_2; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
777 case K_K3: key = VTERM_KEY_KP_3; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
778 case K_K4: key = VTERM_KEY_KP_4; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
779 case K_K5: key = VTERM_KEY_KP_5; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
780 case K_K6: key = VTERM_KEY_KP_6; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
781 case K_K7: key = VTERM_KEY_KP_7; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
782 case K_K8: key = VTERM_KEY_KP_8; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
783 case K_K9: key = VTERM_KEY_KP_9; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
784 case K_KDEL: key = VTERM_KEY_DEL; break; /* TODO */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
785 case K_KDIVIDE: key = VTERM_KEY_KP_DIVIDE; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
786 case K_KEND: key = VTERM_KEY_KP_1; break; /* TODO */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
787 case K_KENTER: key = VTERM_KEY_KP_ENTER; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
788 case K_KHOME: key = VTERM_KEY_KP_7; break; /* TODO */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
789 case K_KINS: key = VTERM_KEY_KP_0; break; /* TODO */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
790 case K_KMINUS: key = VTERM_KEY_KP_MINUS; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
791 case K_KMULTIPLY: key = VTERM_KEY_KP_MULT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
792 case K_KPAGEDOWN: key = VTERM_KEY_KP_3; break; /* TODO */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
793 case K_KPAGEUP: key = VTERM_KEY_KP_9; break; /* TODO */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
794 case K_KPLUS: key = VTERM_KEY_KP_PLUS; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
795 case K_KPOINT: key = VTERM_KEY_KP_PERIOD; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
796 case K_LEFT: key = VTERM_KEY_LEFT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
797 case K_S_LEFT: mod = VTERM_MOD_SHIFT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
798 key = VTERM_KEY_LEFT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
799 case K_C_LEFT: mod = VTERM_MOD_CTRL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
800 key = VTERM_KEY_LEFT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
801 case K_PAGEDOWN: key = VTERM_KEY_PAGEDOWN; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
802 case K_PAGEUP: key = VTERM_KEY_PAGEUP; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
803 case K_RIGHT: key = VTERM_KEY_RIGHT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
804 case K_S_RIGHT: mod = VTERM_MOD_SHIFT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
805 key = VTERM_KEY_RIGHT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
806 case K_C_RIGHT: mod = VTERM_MOD_CTRL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
807 key = VTERM_KEY_RIGHT; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
808 case K_UP: key = VTERM_KEY_UP; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
809 case K_S_UP: mod = VTERM_MOD_SHIFT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
810 key = VTERM_KEY_UP; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
811 case TAB: key = VTERM_KEY_TAB; break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
812
12845
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
813 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
814 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
815 case K_MOUSELEFT: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
816 case K_MOUSERIGHT: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
817
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
818 case K_LEFTMOUSE:
12845
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
819 case K_LEFTMOUSE_NM: other = term_send_mouse(vterm, 1, 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
820 case K_LEFTDRAG: other = term_send_mouse(vterm, 1, 1); break;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
821 case K_LEFTRELEASE:
12845
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
822 case K_LEFTRELEASE_NM: other = term_send_mouse(vterm, 1, 0); break;
12865
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12845
diff changeset
823 case K_MOUSEMOVE: other = term_send_mouse(vterm, 0, 0); break;
12845
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
824 case K_MIDDLEMOUSE: other = term_send_mouse(vterm, 2, 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
825 case K_MIDDLEDRAG: other = term_send_mouse(vterm, 2, 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
826 case K_MIDDLERELEASE: other = term_send_mouse(vterm, 2, 0); break;
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
827 case K_RIGHTMOUSE: other = term_send_mouse(vterm, 3, 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
828 case K_RIGHTDRAG: other = term_send_mouse(vterm, 3, 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
829 case K_RIGHTRELEASE: other = term_send_mouse(vterm, 3, 0); break;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
830 case K_X1MOUSE: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
831 case K_X1DRAG: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
832 case K_X1RELEASE: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
833 case K_X2MOUSE: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
834 case K_X2DRAG: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
835 case K_X2RELEASE: /* TODO */ return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
836
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
837 case K_IGNORE: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
838 case K_NOP: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
839 case K_UNDO: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
840 case K_HELP: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
841 case K_XF1: key = VTERM_KEY_FUNCTION(1); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
842 case K_XF2: key = VTERM_KEY_FUNCTION(2); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
843 case K_XF3: key = VTERM_KEY_FUNCTION(3); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
844 case K_XF4: key = VTERM_KEY_FUNCTION(4); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
845 case K_SELECT: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
846 #ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
847 case K_VER_SCROLLBAR: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
848 case K_HOR_SCROLLBAR: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
849 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
850 #ifdef FEAT_GUI_TABLINE
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
851 case K_TABLINE: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
852 case K_TABMENU: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
853 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
854 #ifdef FEAT_NETBEANS_INTG
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
855 case K_F21: key = VTERM_KEY_FUNCTION(21); break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
856 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
857 #ifdef FEAT_DND
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
858 case K_DROP: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
859 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
860 #ifdef FEAT_AUTOCMD
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
861 case K_CURSORHOLD: return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
862 #endif
12845
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
863 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
864 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
865 break;
15696054bc6c patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents: 12800
diff changeset
866 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
867 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
868 break;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
869 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
870
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
871 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
872 * Convert special keys to vterm keys:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
873 * - Write keys to vterm: vterm_keyboard_key()
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
874 * - Write output to channel.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
875 * TODO: use mod_mask
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
876 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
877 if (key != VTERM_KEY_NONE)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
878 /* Special key, let vterm convert it. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
879 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
880 else if (!other)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
881 /* Normal character, let vterm convert it. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
882 vterm_keyboard_unichar(vterm, c, mod);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
883
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
884 /* Read back the converted escape sequence. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
885 return (int)vterm_output_read(vterm, buf, KEY_BUF_LEN);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
886 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
887
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
888 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
889 * Return TRUE if the job for "term" is still running.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
890 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
891 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
892 term_job_running(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
893 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
894 /* 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
895 * race condition when updating the title. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
896 return term != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
897 && term->tl_job != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
898 && channel_is_open(term->tl_job->jv_channel)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
899 && (term->tl_job->jv_status == JOB_STARTED
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
900 || term->tl_job->jv_channel->ch_keep_open);
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 * 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
905 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
906 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
907 term_none_open(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
908 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
909 /* 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
910 * race condition when updating the title. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
911 return term != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
912 && term->tl_job != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
913 && channel_is_open(term->tl_job->jv_channel)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
914 && term->tl_job->jv_channel->ch_keep_open;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
915 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
916
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 * 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
919 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
920 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
921 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
922 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
923 buf_T *buf = term->tl_buffer;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
924 int empty = (buf->b_ml.ml_flags & ML_EMPTY);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
925 linenr_T lnum = buf->b_ml.ml_line_count;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
926
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
927 #ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
928 if (!enc_utf8 && enc_codepage > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
929 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
930 WCHAR *ret = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
931 int length = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
932
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
933 MultiByteToWideChar_alloc(CP_UTF8, 0, (char*)text, len + 1,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
934 &ret, &length);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
935 if (ret != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
936 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
937 WideCharToMultiByte_alloc(enc_codepage, 0,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
938 ret, length, (char **)&text, &len, 0, 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
939 vim_free(ret);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
940 ml_append_buf(term->tl_buffer, lnum, text, len, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
941 vim_free(text);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
942 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
943 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
944 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
945 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
946 ml_append_buf(term->tl_buffer, lnum, text, len + 1, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
947 if (empty)
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 /* Delete the empty line that was in the empty buffer. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
950 curbuf = buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
951 ml_delete(1, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
952 curbuf = curwin->w_buffer;
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 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
955
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
956 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
957 cell2cellattr(const VTermScreenCell *cell, cellattr_T *attr)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
958 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
959 attr->width = cell->width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
960 attr->attrs = cell->attrs;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
961 attr->fg = cell->fg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
962 attr->bg = cell->bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
963 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
964
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
965 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
966 equal_celattr(cellattr_T *a, cellattr_T *b)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
967 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
968 /* Comparing the colors should be sufficient. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
969 return a->fg.red == b->fg.red
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
970 && a->fg.green == b->fg.green
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
971 && a->fg.blue == b->fg.blue
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
972 && a->bg.red == b->bg.red
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
973 && a->bg.green == b->bg.green
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
974 && a->bg.blue == b->bg.blue;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
975 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
976
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
977
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
978 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
979 * 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
980 * 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
981 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
982 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
983 move_terminal_to_buffer(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
984 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
985 win_T *wp;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
986 int len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
987 int lines_skipped = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
988 VTermPos pos;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
989 VTermScreenCell cell;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
990 cellattr_T fill_attr, new_fill_attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
991 cellattr_T *p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
992 VTermScreen *screen;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
993
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
994 if (term->tl_vterm == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
995 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
996 screen = vterm_obtain_screen(term->tl_vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
997 fill_attr = new_fill_attr = term->tl_default_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
998
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
999 for (pos.row = 0; pos.row < term->tl_rows; ++pos.row)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1000 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1001 len = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1002 for (pos.col = 0; pos.col < term->tl_cols; ++pos.col)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1003 if (vterm_screen_get_cell(screen, pos, &cell) != 0
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1004 && cell.chars[0] != NUL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1005 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1006 len = pos.col + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1007 new_fill_attr = term->tl_default_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1008 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1009 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1010 /* Assume the last attr is the filler attr. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1011 cell2cellattr(&cell, &new_fill_attr);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1012
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1013 if (len == 0 && equal_celattr(&new_fill_attr, &fill_attr))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1014 ++lines_skipped;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1015 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1016 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1017 while (lines_skipped > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1018 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1019 /* Line was skipped, add an empty line. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1020 --lines_skipped;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1021 if (ga_grow(&term->tl_scrollback, 1) == OK)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1022 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1023 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
1024 + term->tl_scrollback.ga_len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1025
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1026 line->sb_cols = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1027 line->sb_cells = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1028 line->sb_fill_attr = fill_attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1029 ++term->tl_scrollback.ga_len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1030
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1031 add_scrollback_line_to_buffer(term, (char_u *)"", 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1032 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1033 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1034
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1035 if (len == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1036 p = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1037 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1038 p = (cellattr_T *)alloc((int)sizeof(cellattr_T) * len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1039 if ((p != NULL || len == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1040 && ga_grow(&term->tl_scrollback, 1) == OK)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1041 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1042 garray_T ga;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1043 int width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1044 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
1045 + term->tl_scrollback.ga_len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1046
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1047 ga_init2(&ga, 1, 100);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1048 for (pos.col = 0; pos.col < len; pos.col += width)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1049 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1050 if (vterm_screen_get_cell(screen, pos, &cell) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1051 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1052 width = 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1053 vim_memset(p + pos.col, 0, sizeof(cellattr_T));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1054 if (ga_grow(&ga, 1) == OK)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1055 ga.ga_len += utf_char2bytes(' ',
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1056 (char_u *)ga.ga_data + ga.ga_len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1057 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1058 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1059 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1060 width = cell.width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1061
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1062 cell2cellattr(&cell, &p[pos.col]);
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 if (ga_grow(&ga, MB_MAXBYTES) == OK)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1065 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1066 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1067 int c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1068
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1069 for (i = 0; (c = cell.chars[i]) > 0 || i == 0; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1070 ga.ga_len += utf_char2bytes(c == NUL ? ' ' : c,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1071 (char_u *)ga.ga_data + ga.ga_len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1072 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1073 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1074 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1075 line->sb_cols = len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1076 line->sb_cells = p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1077 line->sb_fill_attr = new_fill_attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1078 fill_attr = new_fill_attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1079 ++term->tl_scrollback.ga_len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1080
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1081 if (ga_grow(&ga, 1) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1082 add_scrollback_line_to_buffer(term, (char_u *)"", 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1083 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1084 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1085 *((char_u *)ga.ga_data + ga.ga_len) = NUL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1086 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
1087 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1088 ga_clear(&ga);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1089 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1090 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1091 vim_free(p);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1092 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1093 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1094
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1095 /* Obtain the current background color. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1096 vterm_state_get_default_colors(vterm_obtain_state(term->tl_vterm),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1097 &term->tl_default_color.fg, &term->tl_default_color.bg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1098
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1099 FOR_ALL_WINDOWS(wp)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1100 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1101 if (wp->w_buffer == term->tl_buffer)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1102 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1103 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
1104 wp->w_cursor.col = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1105 wp->w_valid = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1106 if (wp->w_cursor.lnum >= wp->w_height)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1107 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1108 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
1109
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1110 if (wp->w_topline < min_topline)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1111 wp->w_topline = min_topline;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1112 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1113 redraw_win_later(wp, NOT_VALID);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1114 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1115 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1116 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1117
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1118 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1119 set_terminal_mode(term_T *term, int normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1120 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1121 term->tl_normal_mode = normal_mode;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1122 vim_free(term->tl_status_text);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1123 term->tl_status_text = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1124 if (term->tl_buffer == curbuf)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1125 maketitle();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1126 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1127
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1128 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1129 * 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
1130 * 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
1131 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1132 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1133 cleanup_vterm(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1134 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1135 if (term->tl_finish != 'c')
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1136 move_terminal_to_buffer(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1137 term_free_vterm(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1138 set_terminal_mode(term, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1139 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1140
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1141 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1142 * Switch from Terminal-Job mode to Terminal-Normal mode.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1143 * Suspends updating the terminal window.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1144 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1145 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1146 term_enter_normal_mode(void)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1147 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1148 term_T *term = curbuf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1149
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1150 /* Append the current terminal contents to the buffer. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1151 move_terminal_to_buffer(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1152
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1153 set_terminal_mode(term, TRUE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1154
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1155 /* 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
1156 * terminal. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1157 curwin->w_cursor.lnum = term->tl_scrollback_scrolled
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1158 + term->tl_cursor_pos.row + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1159 check_cursor();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1160 coladvance(term->tl_cursor_pos.col);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1161
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1162 /* Display the same lines as in the terminal. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1163 curwin->w_topline = term->tl_scrollback_scrolled + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1164 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1165
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1166 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1167 * 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
1168 * Terminal-Normal mode.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1169 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1170 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1171 term_in_normal_mode(void)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1172 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1173 term_T *term = curbuf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1174
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1175 return term != NULL && term->tl_normal_mode;
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
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1178 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1179 * Switch from Terminal-Normal mode to Terminal-Job mode.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1180 * Restores updating the terminal window.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1181 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1182 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1183 term_enter_job_mode()
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1184 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1185 term_T *term = curbuf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1186 sb_line_T *line;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1187 garray_T *gap;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1188
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1189 /* Remove the terminal contents from the scrollback and the buffer. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1190 gap = &term->tl_scrollback;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1191 while (curbuf->b_ml.ml_line_count > term->tl_scrollback_scrolled
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1192 && gap->ga_len > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1193 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1194 ml_delete(curbuf->b_ml.ml_line_count, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1195 line = (sb_line_T *)gap->ga_data + gap->ga_len - 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1196 vim_free(line->sb_cells);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1197 --gap->ga_len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1198 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1199 check_cursor();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1200
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1201 set_terminal_mode(term, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1202
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1203 if (term->tl_channel_closed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1204 cleanup_vterm(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1205 redraw_buf_and_status_later(curbuf, NOT_VALID);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1206 }
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 * Get a key from the user without mapping.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1210 * 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
1211 * closed and ++close was used.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1212 * Uses terminal mode mappings.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1213 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1214 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1215 term_vgetc()
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1216 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1217 int c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1218 int save_State = State;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1219
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1220 State = TERMINAL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1221 got_int = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1222 #ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1223 ctrl_break_was_pressed = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1224 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1225 c = vgetc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1226 got_int = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1227 State = save_State;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1228 return c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1229 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1230
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 * Get the part that is connected to the tty. Normally this is PART_IN, but
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1233 * when writing buffer lines to the job it can be another. This makes it
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1234 * possible to do "1,5term vim -".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1235 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1236 static ch_part_T
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1237 get_tty_part(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1238 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1239 #ifdef UNIX
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1240 ch_part_T parts[3] = {PART_IN, PART_OUT, PART_ERR};
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1241 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1242
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1243 for (i = 0; i < 3; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1244 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1245 int fd = term->tl_job->jv_channel->ch_part[parts[i]].ch_fd;
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 if (isatty(fd))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1248 return parts[i];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1249 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1250 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1251 return PART_IN;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1252 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1253
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1254 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1255 * Send keys to terminal.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1256 * 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
1257 * 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
1258 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1259 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1260 send_keys_to_term(term_T *term, int c, int typed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1261 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1262 char msg[KEY_BUF_LEN];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1263 size_t len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1264 static int mouse_was_outside = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1265 int dragging_outside = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1266
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1267 /* Catch keys that need to be handled as in Normal mode. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1268 switch (c)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1269 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1270 case NUL:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1271 case K_ZERO:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1272 if (typed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1273 stuffcharReadbuff(c);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1274 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1275
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1276 case K_IGNORE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1277 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1278
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1279 case K_LEFTDRAG:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1280 case K_MIDDLEDRAG:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1281 case K_RIGHTDRAG:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1282 case K_X1DRAG:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1283 case K_X2DRAG:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1284 dragging_outside = mouse_was_outside;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1285 /* FALLTHROUGH */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1286 case K_LEFTMOUSE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1287 case K_LEFTMOUSE_NM:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1288 case K_LEFTRELEASE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1289 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
1290 case K_MOUSEMOVE:
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1291 case K_MIDDLEMOUSE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1292 case K_MIDDLERELEASE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1293 case K_RIGHTMOUSE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1294 case K_RIGHTRELEASE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1295 case K_X1MOUSE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1296 case K_X1RELEASE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1297 case K_X2MOUSE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1298 case K_X2RELEASE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1299
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1300 case K_MOUSEUP:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1301 case K_MOUSEDOWN:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1302 case K_MOUSELEFT:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1303 case K_MOUSERIGHT:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1304 if (mouse_row < W_WINROW(curwin)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1305 || 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
1306 || mouse_col < curwin->w_wincol
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1307 || mouse_col >= W_ENDCOL(curwin)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1308 || dragging_outside)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1309 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1310 /* click or scroll outside the current window */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1311 if (typed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1312 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1313 stuffcharReadbuff(c);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1314 mouse_was_outside = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1315 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1316 return FAIL;
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 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1319 if (typed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1320 mouse_was_outside = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1321
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1322 /* 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
1323 len = term_convert_key(term, c, msg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1324 if (len > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1325 /* TODO: if FAIL is returned, stop? */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1326 channel_send(term->tl_job->jv_channel, get_tty_part(term),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1327 (char_u *)msg, (int)len, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1328
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1329 return OK;
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 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1333 position_cursor(win_T *wp, VTermPos *pos)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1334 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1335 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
1336 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
1337 wp->w_valid |= (VALID_WCOL|VALID_WROW);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1338 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1339
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1340 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1341 * Handle CTRL-W "": send register contents to the job.
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 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1344 term_paste_register(int prev_c UNUSED)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1345 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1346 int c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1347 list_T *l;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1348 listitem_T *item;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1349 long reglen = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1350 int type;
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 #ifdef FEAT_CMDL_INFO
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1353 if (add_to_showcmd(prev_c))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1354 if (add_to_showcmd('"'))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1355 out_flush();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1356 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1357 c = term_vgetc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1358 #ifdef FEAT_CMDL_INFO
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1359 clear_showcmd();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1360 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1361 if (!term_use_loop())
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1362 /* job finished while waiting for a character */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1363 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1364
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1365 /* CTRL-W "= prompt for expression to evaluate. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1366 if (c == '=' && get_expr_register() != '=')
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1367 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1368 if (!term_use_loop())
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1369 /* job finished while waiting for a character */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1370 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1371
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1372 l = (list_T *)get_reg_contents(c, GREG_LIST);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1373 if (l != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1374 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1375 type = get_reg_type(c, &reglen);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1376 for (item = l->lv_first; item != NULL; item = item->li_next)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1377 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1378 char_u *s = get_tv_string(&item->li_tv);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1379 #ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1380 char_u *tmp = s;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1381
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1382 if (!enc_utf8 && enc_codepage > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1383 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1384 WCHAR *ret = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1385 int length = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1386
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1387 MultiByteToWideChar_alloc(enc_codepage, 0, (char *)s,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1388 (int)STRLEN(s), &ret, &length);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1389 if (ret != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1390 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1391 WideCharToMultiByte_alloc(CP_UTF8, 0,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1392 ret, length, (char **)&s, &length, 0, 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1393 vim_free(ret);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1394 }
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 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1397 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1398 s, (int)STRLEN(s), NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1399 #ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1400 if (tmp != s)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1401 vim_free(s);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1402 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1403
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1404 if (item->li_next != NULL || type == MLINE)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1405 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1406 (char_u *)"\r", 1, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1407 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1408 list_free(l);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1409 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1410 }
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 defined(FEAT_GUI) || defined(PROTO)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1413 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1414 * Return TRUE when the cursor of the terminal should be displayed.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1415 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1416 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1417 terminal_is_active()
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 return in_terminal_loop != NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1420 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1421
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1422 cursorentry_T *
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1423 term_get_cursor_shape(guicolor_T *fg, guicolor_T *bg)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1424 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1425 term_T *term = in_terminal_loop;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1426 static cursorentry_T entry;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1427
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1428 vim_memset(&entry, 0, sizeof(entry));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1429 entry.shape = entry.mshape =
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1430 term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_UNDERLINE ? SHAPE_HOR :
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1431 term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_BAR_LEFT ? SHAPE_VER :
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1432 SHAPE_BLOCK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1433 entry.percentage = 20;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1434 if (term->tl_cursor_blink)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1435 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1436 entry.blinkwait = 700;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1437 entry.blinkon = 400;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1438 entry.blinkoff = 250;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1439 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1440 *fg = gui.back_pixel;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1441 if (term->tl_cursor_color == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1442 *bg = gui.norm_pixel;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1443 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1444 *bg = color_name2handle(term->tl_cursor_color);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1445 entry.name = "n";
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1446 entry.used_for = SHAPE_CURSOR;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1447
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1448 return &entry;
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 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1451
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1452 static int did_change_cursor = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1453
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1454 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1455 may_set_cursor_props(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1456 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1457 #ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1458 /* For the GUI the cursor properties are obtained with
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1459 * term_get_cursor_shape(). */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1460 if (gui.in_use)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1461 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1462 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1463 if (in_terminal_loop == term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1464 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1465 did_change_cursor = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1466 if (term->tl_cursor_color != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1467 term_cursor_color(term->tl_cursor_color);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1468 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1469 term_cursor_color((char_u *)"");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1470 term_cursor_shape(term->tl_cursor_shape, term->tl_cursor_blink);
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 }
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 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1475 may_restore_cursor_props(void)
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 #ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1478 if (gui.in_use)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1479 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1480 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1481 if (did_change_cursor)
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 did_change_cursor = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1484 term_cursor_color((char_u *)"");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1485 /* this will restore the initial cursor style, if possible */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1486 ui_cursor_shape_forced(TRUE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1487 }
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
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1490 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1491 * 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
1492 * keys to the job.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1493 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1494 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1495 term_use_loop(void)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1496 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1497 term_T *term = curbuf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1498
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1499 return term != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1500 && !term->tl_normal_mode
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1501 && term->tl_vterm != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1502 && term_job_running(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1503 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1504
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1505 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1506 * Wait for input and send it to the job.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1507 * 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
1508 * when there is no more typahead.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1509 * 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
1510 * should be handled as a Normal mode command.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1511 * 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
1512 * the terminal was closed.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1513 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1514 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1515 terminal_loop(int blocking)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1516 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1517 int c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1518 int termkey = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1519 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
1520 #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
1521 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
1522 ->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
1523 #endif
12502
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 /* Remember the terminal we are sending keys to. However, the terminal
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1526 * 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
1527 * 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
1528 * stored reference. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1529 in_terminal_loop = curbuf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1530
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1531 if (*curwin->w_p_tk != NUL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1532 termkey = string_to_key(curwin->w_p_tk, TRUE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1533 position_cursor(curwin, &curbuf->b_term->tl_cursor_pos);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1534 may_set_cursor_props(curbuf->b_term);
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 while (blocking || vpeekc() != NUL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1537 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1538 /* TODO: skip screen update when handling a sequence of keys. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1539 /* Repeat redrawing in case a message is received while redrawing. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1540 while (must_redraw != 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1541 if (update_screen(0) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1542 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1543 update_cursor(curbuf->b_term, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1544
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1545 c = term_vgetc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1546 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
1547 {
12800
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
1548 /* 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
1549 * 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
1550 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
1551 vungetc(c);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1552 break;
12798
5ae0d05e046a patch 8.0.1276: key lost when window closed in exit callback
Christian Brabandt <cb@256bit.org>
parents: 12767
diff changeset
1553 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1554 if (c == K_IGNORE)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1555 continue;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1556
12800
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
1557 #ifdef UNIX
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
1558 /*
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
1559 * 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
1560 * 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
1561 * 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
1562 */
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
1563 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
1564 {
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
1565 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
1566
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
1567 /* 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
1568 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
1569 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
1570 }
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
1571 #endif
8dfeed7e07e7 patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents: 12798
diff changeset
1572
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1573 #ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1574 /* 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
1575 * Use CTRL-BREAK to kill the job. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1576 if (ctrl_break_was_pressed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1577 mch_signal_job(curbuf->b_term->tl_job, (char_u *)"kill");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1578 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1579 /* Was either CTRL-W (termkey) or CTRL-\ pressed? */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1580 if (c == (termkey == 0 ? Ctrl_W : termkey) || c == Ctrl_BSL)
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 int prev_c = c;
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 #ifdef FEAT_CMDL_INFO
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1585 if (add_to_showcmd(c))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1586 out_flush();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1587 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1588 c = term_vgetc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1589 #ifdef FEAT_CMDL_INFO
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1590 clear_showcmd();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1591 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1592 if (!term_use_loop())
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1593 /* job finished while waiting for a character */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1594 break;
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 if (prev_c == Ctrl_BSL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1597 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1598 if (c == Ctrl_N)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1599 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1600 /* CTRL-\ CTRL-N : go to Terminal-Normal mode. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1601 term_enter_normal_mode();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1602 ret = FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1603 goto theend;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1604 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1605 /* Send both keys to the terminal. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1606 send_keys_to_term(curbuf->b_term, prev_c, TRUE);
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 else if (c == Ctrl_C)
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 /* "CTRL-W CTRL-C" or 'termkey' CTRL-C: end the job */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1611 mch_signal_job(curbuf->b_term->tl_job, (char_u *)"kill");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1612 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1613 else if (termkey == 0 && c == '.')
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 /* "CTRL-W .": send CTRL-W to the job */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1616 c = Ctrl_W;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1617 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1618 else if (c == 'N')
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 /* CTRL-W N : go to Terminal-Normal mode. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1621 term_enter_normal_mode();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1622 ret = FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1623 goto theend;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1624 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1625 else if (c == '"')
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1626 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1627 term_paste_register(prev_c);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1628 continue;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1629 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1630 else if (termkey == 0 || c != termkey)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1631 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1632 stuffcharReadbuff(Ctrl_W);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1633 stuffcharReadbuff(c);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1634 ret = OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1635 goto theend;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1636 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1637 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1638 # ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1639 if (!enc_utf8 && has_mbyte && c >= 0x80)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1640 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1641 WCHAR wc;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1642 char_u mb[3];
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 mb[0] = (unsigned)c >> 8;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1645 mb[1] = c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1646 if (MultiByteToWideChar(GetACP(), 0, (char*)mb, 2, &wc, 1) > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1647 c = wc;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1648 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1649 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1650 if (send_keys_to_term(curbuf->b_term, c, TRUE) != OK)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1651 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1652 ret = OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1653 goto theend;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1654 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1655 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1656 ret = FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1657
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1658 theend:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1659 in_terminal_loop = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1660 may_restore_cursor_props();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1661 return ret;
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
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1664 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1665 * Called when a job has finished.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1666 * 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
1667 * there might still be pending output in the channel.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1668 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1669 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1670 term_job_ended(job_T *job)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1671 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1672 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1673 int did_one = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1674
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1675 for (term = first_term; term != NULL; term = term->tl_next)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1676 if (term->tl_job == job)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1677 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1678 vim_free(term->tl_title);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1679 term->tl_title = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1680 vim_free(term->tl_status_text);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1681 term->tl_status_text = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1682 redraw_buf_and_status_later(term->tl_buffer, VALID);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1683 did_one = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1684 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1685 if (did_one)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1686 redraw_statuslines();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1687 if (curbuf->b_term != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1688 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1689 if (curbuf->b_term->tl_job == job)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1690 maketitle();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1691 update_cursor(curbuf->b_term, TRUE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1692 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1693 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1694
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1695 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1696 may_toggle_cursor(term_T *term)
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 if (in_terminal_loop == term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1699 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1700 if (term->tl_cursor_visible)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1701 cursor_on();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1702 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1703 cursor_off();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1704 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1705 }
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 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1708 * Reverse engineer the RGB value into a cterm color index.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1709 * First color is 1. Return 0 if no match found.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1710 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1711 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1712 color2index(VTermColor *color, int fg, int *boldp)
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 int red = color->red;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1715 int blue = color->blue;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1716 int green = color->green;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1717
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1718 /* The argument for lookup_color() is for the color_names[] table. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1719 if (red == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1720 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1721 if (green == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1722 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1723 if (blue == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1724 return lookup_color(0, fg, boldp) + 1; /* black */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1725 if (blue == 224)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1726 return lookup_color(1, fg, boldp) + 1; /* dark blue */
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 else if (green == 224)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1729 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1730 if (blue == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1731 return lookup_color(2, fg, boldp) + 1; /* dark green */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1732 if (blue == 224)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1733 return lookup_color(3, fg, boldp) + 1; /* dark cyan */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1734 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1735 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1736 else if (red == 224)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1737 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1738 if (green == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1739 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1740 if (blue == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1741 return lookup_color(4, fg, boldp) + 1; /* dark red */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1742 if (blue == 224)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1743 return lookup_color(5, fg, boldp) + 1; /* dark magenta */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1744 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1745 else if (green == 224)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1746 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1747 if (blue == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1748 return lookup_color(6, fg, boldp) + 1; /* dark yellow / brown */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1749 if (blue == 224)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1750 return lookup_color(8, fg, boldp) + 1; /* white / light grey */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1751 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1752 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1753 else if (red == 128)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1754 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1755 if (green == 128 && blue == 128)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1756 return lookup_color(12, fg, boldp) + 1; /* dark grey */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1757 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1758 else if (red == 255)
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 if (green == 64)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1761 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1762 if (blue == 64)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1763 return lookup_color(20, fg, boldp) + 1; /* light red */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1764 if (blue == 255)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1765 return lookup_color(22, fg, boldp) + 1; /* light magenta */
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 else if (green == 255)
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 if (blue == 64)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1770 return lookup_color(24, fg, boldp) + 1; /* yellow */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1771 if (blue == 255)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1772 return lookup_color(26, fg, boldp) + 1; /* white */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1773 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1774 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1775 else if (red == 64)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1776 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1777 if (green == 64)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1778 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1779 if (blue == 255)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1780 return lookup_color(14, fg, boldp) + 1; /* light blue */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1781 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1782 else if (green == 255)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1783 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1784 if (blue == 64)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1785 return lookup_color(16, fg, boldp) + 1; /* light green */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1786 if (blue == 255)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1787 return lookup_color(18, fg, boldp) + 1; /* light cyan */
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 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1790 if (t_colors >= 256)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1791 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1792 if (red == blue && red == green)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1793 {
12541
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
1794 /* 24-color greyscale plus white and black */
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1795 static int cutoff[23] = {
12541
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
1796 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
1797 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
1798 0xD5, 0xDF, 0xE9};
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1799 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1800
12541
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
1801 if (red < 5)
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
1802 return 17; /* 00/00/00 */
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
1803 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
1804 return 232;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1805 for (i = 0; i < 23; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1806 if (red < cutoff[i])
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1807 return i + 233;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1808 return 256;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1809 }
12541
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
1810 {
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
1811 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
1812 int ri, gi, bi;
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
1813
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
1814 /* 216-color cube */
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
1815 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
1816 if (red < cutoff[ri])
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
1817 break;
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
1818 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
1819 if (green < cutoff[gi])
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
1820 break;
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
1821 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
1822 if (blue < cutoff[bi])
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
1823 break;
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
1824 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
1825 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1826 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1827 return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1828 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1829
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1830 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1831 * Convert the attributes of a vterm cell into an attribute index.
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 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1834 cell2attr(VTermScreenCellAttrs cellattrs, VTermColor cellfg, VTermColor cellbg)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1835 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1836 int attr = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1837
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1838 if (cellattrs.bold)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1839 attr |= HL_BOLD;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1840 if (cellattrs.underline)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1841 attr |= HL_UNDERLINE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1842 if (cellattrs.italic)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1843 attr |= HL_ITALIC;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1844 if (cellattrs.strike)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1845 attr |= HL_STRIKETHROUGH;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1846 if (cellattrs.reverse)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1847 attr |= HL_INVERSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1848
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1849 #ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1850 if (gui.in_use)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1851 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1852 guicolor_T fg, bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1853
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1854 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
1855 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
1856 return get_gui_attr_idx(attr, fg, bg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1857 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1858 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1859 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1860 #ifdef FEAT_TERMGUICOLORS
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1861 if (p_tgc)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1862 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1863 guicolor_T fg, bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1864
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1865 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
1866 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
1867
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1868 return get_tgc_attr_idx(attr, fg, bg);
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 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1871 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1872 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1873 int bold = MAYBE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1874 int fg = color2index(&cellfg, TRUE, &bold);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1875 int bg = color2index(&cellbg, FALSE, &bold);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1876
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1877 /* 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
1878 if (bold == TRUE)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1879 attr |= HL_BOLD;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1880 return get_cterm_attr_idx(attr, fg, bg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1881 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1882 return 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1883 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1884
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1885 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1886 handle_damage(VTermRect rect, void *user)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1887 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1888 term_T *term = (term_T *)user;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1889
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1890 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
1891 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
1892 redraw_buf_later(term->tl_buffer, NOT_VALID);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1893 return 1;
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 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1897 handle_moverect(VTermRect dest, VTermRect src, void *user)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1898 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1899 term_T *term = (term_T *)user;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1900
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1901 /* 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
1902 * redrawing the text. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1903 if (dest.start_col == src.start_col
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1904 && dest.end_col == src.end_col
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1905 && dest.start_row < src.start_row)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1906 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1907 win_T *wp;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1908 VTermColor fg, bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1909 VTermScreenCellAttrs attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1910 int clear_attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1911
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1912 /* Set the color to clear lines with. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1913 vterm_state_get_default_colors(vterm_obtain_state(term->tl_vterm),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1914 &fg, &bg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1915 vim_memset(&attr, 0, sizeof(attr));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1916 clear_attr = cell2attr(attr, fg, bg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1917
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1918 FOR_ALL_WINDOWS(wp)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1919 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1920 if (wp->w_buffer == term->tl_buffer)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1921 win_del_lines(wp, dest.start_row,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1922 src.start_row - dest.start_row, FALSE, FALSE,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1923 clear_attr);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1924 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1925 }
12578
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
1926
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
1927 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
1928 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
1929
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1930 redraw_buf_later(term->tl_buffer, NOT_VALID);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1931 return 1;
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 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1935 handle_movecursor(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1936 VTermPos pos,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1937 VTermPos oldpos UNUSED,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1938 int visible,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1939 void *user)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1940 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1941 term_T *term = (term_T *)user;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1942 win_T *wp;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1943
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1944 term->tl_cursor_pos = pos;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1945 term->tl_cursor_visible = visible;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1946
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1947 FOR_ALL_WINDOWS(wp)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1948 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1949 if (wp->w_buffer == term->tl_buffer)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1950 position_cursor(wp, &pos);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1951 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1952 if (term->tl_buffer == curbuf && !term->tl_normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1953 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1954 may_toggle_cursor(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1955 update_cursor(term, term->tl_cursor_visible);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1956 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1957
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1958 return 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1959 }
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 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1962 handle_settermprop(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1963 VTermProp prop,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1964 VTermValue *value,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1965 void *user)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1966 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1967 term_T *term = (term_T *)user;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1968
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1969 switch (prop)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1970 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1971 case VTERM_PROP_TITLE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1972 vim_free(term->tl_title);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1973 /* 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
1974 * displayed */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1975 if (*skipwhite((char_u *)value->string) == NUL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1976 term->tl_title = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1977 #ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1978 else if (!enc_utf8 && enc_codepage > 0)
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 WCHAR *ret = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1981 int length = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1982
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1983 MultiByteToWideChar_alloc(CP_UTF8, 0,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1984 (char*)value->string, (int)STRLEN(value->string),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1985 &ret, &length);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1986 if (ret != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1987 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1988 WideCharToMultiByte_alloc(enc_codepage, 0,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1989 ret, length, (char**)&term->tl_title,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1990 &length, 0, 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1991 vim_free(ret);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1992 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1993 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1994 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1995 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1996 term->tl_title = vim_strsave((char_u *)value->string);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1997 vim_free(term->tl_status_text);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1998 term->tl_status_text = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1999 if (term == curbuf->b_term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2000 maketitle();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2001 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2002
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2003 case VTERM_PROP_CURSORVISIBLE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2004 term->tl_cursor_visible = value->boolean;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2005 may_toggle_cursor(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2006 out_flush();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2007 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2008
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2009 case VTERM_PROP_CURSORBLINK:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2010 term->tl_cursor_blink = value->boolean;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2011 may_set_cursor_props(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2012 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2013
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2014 case VTERM_PROP_CURSORSHAPE:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2015 term->tl_cursor_shape = value->number;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2016 may_set_cursor_props(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2017 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2018
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2019 case VTERM_PROP_CURSORCOLOR:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2020 vim_free(term->tl_cursor_color);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2021 if (*value->string == NUL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2022 term->tl_cursor_color = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2023 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2024 term->tl_cursor_color = vim_strsave((char_u *)value->string);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2025 may_set_cursor_props(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2026 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2027
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2028 case VTERM_PROP_ALTSCREEN:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2029 /* TODO: do anything else? */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2030 term->tl_using_altscreen = value->boolean;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2031 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2032
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2033 default:
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 /* Always return 1, otherwise vterm doesn't store the value internally. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2037 return 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2038 }
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 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2041 * The job running in the terminal resized the terminal.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2042 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2043 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2044 handle_resize(int rows, int cols, void *user)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2045 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2046 term_T *term = (term_T *)user;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2047 win_T *wp;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2048
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2049 term->tl_rows = rows;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2050 term->tl_cols = cols;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2051 if (term->tl_vterm_size_changed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2052 /* 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
2053 term->tl_vterm_size_changed = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2054 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2055 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2056 FOR_ALL_WINDOWS(wp)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2057 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2058 if (wp->w_buffer == term->tl_buffer)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2059 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2060 win_setheight_win(rows, wp);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2061 win_setwidth_win(cols, wp);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2062 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2063 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2064 redraw_buf_later(term->tl_buffer, NOT_VALID);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2065 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2066 return 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2067 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2068
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 * 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
2071 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2072 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2073 handle_pushline(int cols, const VTermScreenCell *cells, void *user)
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 term_T *term = (term_T *)user;
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 /* TODO: Limit the number of lines that are stored. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2078 if (ga_grow(&term->tl_scrollback, 1) == OK)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2079 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2080 cellattr_T *p = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2081 int len = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2082 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2083 int c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2084 int col;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2085 sb_line_T *line;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2086 garray_T ga;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2087 cellattr_T fill_attr = term->tl_default_color;
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 /* do not store empty cells at the end */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2090 for (i = 0; i < cols; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2091 if (cells[i].chars[0] != 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2092 len = i + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2093 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2094 cell2cellattr(&cells[i], &fill_attr);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2095
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2096 ga_init2(&ga, 1, 100);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2097 if (len > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2098 p = (cellattr_T *)alloc((int)sizeof(cellattr_T) * len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2099 if (p != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2100 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2101 for (col = 0; col < len; col += cells[col].width)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2102 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2103 if (ga_grow(&ga, MB_MAXBYTES) == FAIL)
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 ga.ga_len = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2106 break;
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 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
2109 ga.ga_len += utf_char2bytes(c == NUL ? ' ' : c,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2110 (char_u *)ga.ga_data + ga.ga_len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2111 cell2cellattr(&cells[col], &p[col]);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2112 }
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 if (ga_grow(&ga, 1) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2115 add_scrollback_line_to_buffer(term, (char_u *)"", 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2116 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2117 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2118 *((char_u *)ga.ga_data + ga.ga_len) = NUL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2119 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
2120 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2121 ga_clear(&ga);
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 line = (sb_line_T *)term->tl_scrollback.ga_data
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2124 + term->tl_scrollback.ga_len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2125 line->sb_cols = len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2126 line->sb_cells = p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2127 line->sb_fill_attr = fill_attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2128 ++term->tl_scrollback.ga_len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2129 ++term->tl_scrollback_scrolled;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2130 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2131 return 0; /* ignored */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2132 }
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 static VTermScreenCallbacks screen_callbacks = {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2135 handle_damage, /* damage */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2136 handle_moverect, /* moverect */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2137 handle_movecursor, /* movecursor */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2138 handle_settermprop, /* settermprop */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2139 NULL, /* bell */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2140 handle_resize, /* resize */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2141 handle_pushline, /* sb_pushline */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2142 NULL /* sb_popline */
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
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2145 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2146 * Called when a channel has been closed.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2147 * 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
2148 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2149 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2150 term_channel_closed(channel_T *ch)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2151 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2152 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2153 int did_one = FALSE;
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 for (term = first_term; term != NULL; term = term->tl_next)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2156 if (term->tl_job == ch->ch_job)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2157 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2158 term->tl_channel_closed = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2159 did_one = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2160
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2161 vim_free(term->tl_title);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2162 term->tl_title = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2163 vim_free(term->tl_status_text);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2164 term->tl_status_text = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2165
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2166 /* Unless in Terminal-Normal mode: clear the vterm. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2167 if (!term->tl_normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2168 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2169 int fnum = term->tl_buffer->b_fnum;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2170
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2171 cleanup_vterm(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2172
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2173 if (term->tl_finish == 'c')
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2174 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2175 /* ++close or term_finish == "close" */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2176 ch_log(NULL, "terminal job finished, closing window");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2177 curbuf = term->tl_buffer;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2178 do_bufdel(DOBUF_WIPE, (char_u *)"", 1, fnum, fnum, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2179 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2180 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2181 if (term->tl_finish == 'o' && term->tl_buffer->b_nwindows == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2182 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2183 char buf[50];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2184
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2185 /* TODO: use term_opencmd */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2186 ch_log(NULL, "terminal job finished, opening window");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2187 vim_snprintf(buf, sizeof(buf),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2188 term->tl_opencmd == NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2189 ? "botright sbuf %d"
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2190 : (char *)term->tl_opencmd, fnum);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2191 do_cmdline_cmd((char_u *)buf);
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 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2194 ch_log(NULL, "terminal job finished");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2195 }
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 redraw_buf_and_status_later(term->tl_buffer, NOT_VALID);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2198 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2199 if (did_one)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2200 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2201 redraw_statuslines();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2202
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2203 /* Need to break out of vgetc(). */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2204 ins_char_typebuf(K_IGNORE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2205 typebuf_was_filled = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2206
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2207 term = curbuf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2208 if (term != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2209 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2210 if (term->tl_job == ch->ch_job)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2211 maketitle();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2212 update_cursor(term, term->tl_cursor_visible);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2213 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2214 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2215 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2216
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2217 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2218 * Called to update a window that contains an active terminal.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2219 * 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
2220 * Terminal-Normal mode.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2221 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2222 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2223 term_update_window(win_T *wp)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2224 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2225 term_T *term = wp->w_buffer->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2226 VTerm *vterm;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2227 VTermScreen *screen;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2228 VTermState *state;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2229 VTermPos pos;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2230
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2231 if (term == NULL || term->tl_vterm == NULL || term->tl_normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2232 return FAIL;
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 vterm = term->tl_vterm;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2235 screen = vterm_obtain_screen(vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2236 state = vterm_obtain_state(vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2237
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
2238 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
2239 {
3c46dcf3b335 patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents: 12578
diff changeset
2240 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
2241 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
2242 }
3c46dcf3b335 patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents: 12578
diff changeset
2243
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2244 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2245 * 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
2246 * 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
2247 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2248 if ((!term->tl_rows_fixed && term->tl_rows != wp->w_height)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2249 || (!term->tl_cols_fixed && term->tl_cols != wp->w_width))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2250 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2251 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
2252 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
2253 win_T *twp;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2254
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2255 FOR_ALL_WINDOWS(twp)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2256 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2257 /* When more than one window shows the same terminal, use the
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2258 * smallest size. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2259 if (twp->w_buffer == term->tl_buffer)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2260 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2261 if (!term->tl_rows_fixed && rows > twp->w_height)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2262 rows = twp->w_height;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2263 if (!term->tl_cols_fixed && cols > twp->w_width)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2264 cols = twp->w_width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2265 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2266 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2267
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2268 term->tl_vterm_size_changed = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2269 vterm_set_size(vterm, rows, cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2270 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
2271 rows);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2272 term_report_winsize(term, rows, cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2273 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2274
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2275 /* The cursor may have been moved when resizing. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2276 vterm_state_get_cursorpos(state, &pos);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2277 position_cursor(wp, &pos);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2278
12578
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
2279 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
2280 && pos.row < wp->w_height; ++pos.row)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2281 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2282 int off = screen_get_current_line_off();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2283 int max_col = MIN(wp->w_width, term->tl_cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2284
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2285 if (pos.row < term->tl_rows)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2286 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2287 for (pos.col = 0; pos.col < max_col; )
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2288 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2289 VTermScreenCell cell;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2290 int c;
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 if (vterm_screen_get_cell(screen, pos, &cell) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2293 vim_memset(&cell, 0, sizeof(cell));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2294
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2295 c = cell.chars[0];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2296 if (c == NUL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2297 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2298 ScreenLines[off] = ' ';
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2299 if (enc_utf8)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2300 ScreenLinesUC[off] = NUL;
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 else
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 if (enc_utf8)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2305 {
12650
f58755eb453e patch 8.0.1203: terminal window mistreats composing characters
Christian Brabandt <cb@256bit.org>
parents: 12634
diff changeset
2306 int i;
f58755eb453e patch 8.0.1203: terminal window mistreats composing characters
Christian Brabandt <cb@256bit.org>
parents: 12634
diff changeset
2307
f58755eb453e patch 8.0.1203: terminal window mistreats composing characters
Christian Brabandt <cb@256bit.org>
parents: 12634
diff changeset
2308 /* composing chars */
f58755eb453e patch 8.0.1203: terminal window mistreats composing characters
Christian Brabandt <cb@256bit.org>
parents: 12634
diff changeset
2309 for (i = 0; i < Screen_mco
f58755eb453e patch 8.0.1203: terminal window mistreats composing characters
Christian Brabandt <cb@256bit.org>
parents: 12634
diff changeset
2310 && i + 1 < VTERM_MAX_CHARS_PER_CELL; ++i)
f58755eb453e patch 8.0.1203: terminal window mistreats composing characters
Christian Brabandt <cb@256bit.org>
parents: 12634
diff changeset
2311 {
f58755eb453e patch 8.0.1203: terminal window mistreats composing characters
Christian Brabandt <cb@256bit.org>
parents: 12634
diff changeset
2312 ScreenLinesC[i][off] = cell.chars[i + 1];
f58755eb453e patch 8.0.1203: terminal window mistreats composing characters
Christian Brabandt <cb@256bit.org>
parents: 12634
diff changeset
2313 if (cell.chars[i + 1] == 0)
f58755eb453e patch 8.0.1203: terminal window mistreats composing characters
Christian Brabandt <cb@256bit.org>
parents: 12634
diff changeset
2314 break;
f58755eb453e patch 8.0.1203: terminal window mistreats composing characters
Christian Brabandt <cb@256bit.org>
parents: 12634
diff changeset
2315 }
f58755eb453e patch 8.0.1203: terminal window mistreats composing characters
Christian Brabandt <cb@256bit.org>
parents: 12634
diff changeset
2316 if (c >= 0x80 || (Screen_mco > 0
f58755eb453e patch 8.0.1203: terminal window mistreats composing characters
Christian Brabandt <cb@256bit.org>
parents: 12634
diff changeset
2317 && ScreenLinesC[0][off] != 0))
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2318 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2319 ScreenLines[off] = ' ';
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2320 ScreenLinesUC[off] = c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2321 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2322 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2323 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2324 ScreenLines[off] = c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2325 ScreenLinesUC[off] = NUL;
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 #ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2329 else if (has_mbyte && c >= 0x80)
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 char_u mb[MB_MAXBYTES+1];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2332 WCHAR wc = c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2333
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2334 if (WideCharToMultiByte(GetACP(), 0, &wc, 1,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2335 (char*)mb, 2, 0, 0) > 1)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2336 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2337 ScreenLines[off] = mb[0];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2338 ScreenLines[off + 1] = mb[1];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2339 cell.width = mb_ptr2cells(mb);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2340 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2341 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2342 ScreenLines[off] = c;
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 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2345 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2346 ScreenLines[off] = c;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2347 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2348 ScreenAttrs[off] = cell2attr(cell.attrs, cell.fg, cell.bg);
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 ++pos.col;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2351 ++off;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2352 if (cell.width == 2)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2353 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2354 if (enc_utf8)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2355 ScreenLinesUC[off] = NUL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2356
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2357 /* don't set the second byte to NUL for a DBCS encoding, it
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2358 * has been set above */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2359 if (enc_utf8 || !has_mbyte)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2360 ScreenLines[off] = NUL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2361
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2362 ++pos.col;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2363 ++off;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2364 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2365 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2366 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2367 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2368 pos.col = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2369
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2370 screen_line(wp->w_winrow + pos.row, wp->w_wincol,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2371 pos.col, wp->w_width, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2372 }
12578
f8beecfea2c4 patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents: 12541
diff changeset
2373 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
2374 term->tl_dirty_row_end = 0;
12502
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 return OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2377 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2378
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2379 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2380 * 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
2381 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2382 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2383 term_is_finished(buf_T *buf)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2384 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2385 return buf->b_term != NULL && buf->b_term->tl_vterm == NULL;
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
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2388 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2389 * 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
2390 * are in Terminal-Normal mode, thus we show the buffer contents.
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 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2393 term_show_buffer(buf_T *buf)
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 term_T *term = buf->b_term;
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 return term != NULL && (term->tl_vterm == NULL || term->tl_normal_mode);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2398 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2399
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 * 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
2402 * highlighting remove it now.
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 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2405 term_change_in_curbuf(void)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2406 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2407 term_T *term = curbuf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2408
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2409 if (term_is_finished(curbuf) && term->tl_scrollback.ga_len > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2410 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2411 free_scrollback(term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2412 redraw_buf_later(term->tl_buffer, NOT_VALID);
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 /* 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
2415 * abandoned when changed. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2416 set_string_option_direct((char_u *)"buftype", -1,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2417 (char_u *)"", OPT_FREE|OPT_LOCAL, 0);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2418 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2419 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2420
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2421 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2422 * Get the screen attribute for a position in the buffer.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2423 * Use a negative "col" to get the filler background color.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2424 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2425 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2426 term_get_attr(buf_T *buf, linenr_T lnum, int col)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2427 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2428 term_T *term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2429 sb_line_T *line;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2430 cellattr_T *cellattr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2431
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2432 if (lnum > term->tl_scrollback.ga_len)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2433 cellattr = &term->tl_default_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2434 else
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 line = (sb_line_T *)term->tl_scrollback.ga_data + lnum - 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2437 if (col < 0 || col >= line->sb_cols)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2438 cellattr = &line->sb_fill_attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2439 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2440 cellattr = line->sb_cells + col;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2441 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2442 return cell2attr(cellattr->attrs, cellattr->fg, cellattr->bg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2443 }
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 static VTermColor ansi_table[16] = {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2446 { 0, 0, 0}, /* black */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2447 {224, 0, 0}, /* dark red */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2448 { 0, 224, 0}, /* dark green */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2449 {224, 224, 0}, /* dark yellow / brown */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2450 { 0, 0, 224}, /* dark blue */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2451 {224, 0, 224}, /* dark magenta */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2452 { 0, 224, 224}, /* dark cyan */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2453 {224, 224, 224}, /* light grey */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2454
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2455 {128, 128, 128}, /* dark grey */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2456 {255, 64, 64}, /* light red */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2457 { 64, 255, 64}, /* light green */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2458 {255, 255, 64}, /* yellow */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2459 { 64, 64, 255}, /* light blue */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2460 {255, 64, 255}, /* light magenta */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2461 { 64, 255, 255}, /* light cyan */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2462 {255, 255, 255}, /* white */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2463 };
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2464
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2465 static int cube_value[] = {
12541
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2466 0x00, 0x5F, 0x87, 0xAF, 0xD7, 0xFF
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2467 };
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2468
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2469 static int grey_ramp[] = {
12541
fcb11cfca8b3 patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
2470 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
2471 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
2472 };
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2473
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2474 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2475 * 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
2476 * This is compatible with xterm.
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2477 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2478 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2479 cterm_color2rgb(int nr, VTermColor *rgb)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2480 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2481 int idx;
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 if (nr < 16)
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 *rgb = ansi_table[nr];
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 else if (nr < 232)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2488 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2489 /* 216 color cube */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2490 idx = nr - 16;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2491 rgb->blue = cube_value[idx % 6];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2492 rgb->green = cube_value[idx / 6 % 6];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2493 rgb->red = cube_value[idx / 36 % 6];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2494 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2495 else if (nr < 256)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2496 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2497 /* 24 grey scale ramp */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2498 idx = nr - 232;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2499 rgb->blue = grey_ramp[idx];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2500 rgb->green = grey_ramp[idx];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2501 rgb->red = grey_ramp[idx];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2502 }
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
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2505 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2506 * Create a new vterm and initialize it.
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 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2509 create_vterm(term_T *term, int rows, int cols)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2510 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2511 VTerm *vterm;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2512 VTermScreen *screen;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2513 VTermValue value;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2514 VTermColor *fg, *bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2515 int fgval, bgval;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2516 int id;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2517
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2518 vterm = vterm_new(rows, cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2519 term->tl_vterm = vterm;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2520 screen = vterm_obtain_screen(vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2521 vterm_screen_set_callbacks(screen, &screen_callbacks, term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2522 /* TODO: depends on 'encoding'. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2523 vterm_set_utf8(vterm, 1);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2524
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2525 vim_memset(&term->tl_default_color.attrs, 0, sizeof(VTermScreenCellAttrs));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2526 term->tl_default_color.width = 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2527 fg = &term->tl_default_color.fg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2528 bg = &term->tl_default_color.bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2529
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2530 /* Vterm uses a default black background. Set it to white when
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2531 * 'background' is "light". */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2532 if (*p_bg == 'l')
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2533 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2534 fgval = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2535 bgval = 255;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2536 }
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 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2539 fgval = 255;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2540 bgval = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2541 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2542 fg->red = fg->green = fg->blue = fgval;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2543 bg->red = bg->green = bg->blue = bgval;
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 /* The "Terminal" highlight group overrules the defaults. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2546 id = syn_name2id((char_u *)"Terminal");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2547
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2548 /* Use the actual color for the GUI and when 'guitermcolors' is set. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2549 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2550 if (0
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2551 # ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2552 || gui.in_use
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2553 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2554 # ifdef FEAT_TERMGUICOLORS
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2555 || p_tgc
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2556 # endif
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 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2559 guicolor_T fg_rgb = INVALCOLOR;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2560 guicolor_T bg_rgb = INVALCOLOR;
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 if (id != 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2563 syn_id2colors(id, &fg_rgb, &bg_rgb);
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 # ifdef FEAT_GUI
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2566 if (gui.in_use)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2567 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2568 if (fg_rgb == INVALCOLOR)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2569 fg_rgb = gui.norm_pixel;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2570 if (bg_rgb == INVALCOLOR)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2571 bg_rgb = gui.back_pixel;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2572 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2573 # ifdef FEAT_TERMGUICOLORS
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2574 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2575 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2576 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2577 # ifdef FEAT_TERMGUICOLORS
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2578 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2579 if (fg_rgb == INVALCOLOR)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2580 fg_rgb = cterm_normal_fg_gui_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2581 if (bg_rgb == INVALCOLOR)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2582 bg_rgb = cterm_normal_bg_gui_color;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2583 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2584 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2585 if (fg_rgb != INVALCOLOR)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2586 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2587 long_u rgb = GUI_MCH_GET_RGB(fg_rgb);
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 fg->red = (unsigned)(rgb >> 16);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2590 fg->green = (unsigned)(rgb >> 8) & 255;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2591 fg->blue = (unsigned)rgb & 255;
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 if (bg_rgb != INVALCOLOR)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2594 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2595 long_u rgb = GUI_MCH_GET_RGB(bg_rgb);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2596
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2597 bg->red = (unsigned)(rgb >> 16);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2598 bg->green = (unsigned)(rgb >> 8) & 255;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2599 bg->blue = (unsigned)rgb & 255;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2600 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2601 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2602 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2603 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2604 if (id != 0 && t_colors >= 16)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2605 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2606 int cterm_fg, cterm_bg;
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 syn_id2cterm_bg(id, &cterm_fg, &cterm_bg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2609 if (cterm_fg >= 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2610 cterm_color2rgb(cterm_fg, fg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2611 if (cterm_bg >= 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2612 cterm_color2rgb(cterm_bg, bg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2613 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2614 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2615 {
12632
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
2616 #if defined(WIN3264) && !defined(FEAT_GUI_W32)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2617 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
2618 #endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2619
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2620 /* In an MS-Windows console we know the normal colors. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2621 if (cterm_normal_fg_color > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2622 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2623 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
2624 # if defined(WIN3264) && !defined(FEAT_GUI_W32)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2625 tmp = fg->red;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2626 fg->red = fg->blue;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2627 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
2628 # endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2629 }
12634
94566ecb55f0 patch 8.0.1195: can't build on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 12632
diff changeset
2630 # 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
2631 else
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
2632 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
2633 # 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
2634
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2635 if (cterm_normal_bg_color > 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2636 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2637 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
2638 # if defined(WIN3264) && !defined(FEAT_GUI_W32)
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2639 tmp = bg->red;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2640 bg->red = bg->blue;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2641 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
2642 # endif
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2643 }
12634
94566ecb55f0 patch 8.0.1195: can't build on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 12632
diff changeset
2644 # 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
2645 else
b1a7e3968a31 patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents: 12598
diff changeset
2646 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
2647 # endif
12502
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
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2650 vterm_state_set_default_colors(vterm_obtain_state(vterm), fg, bg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2651
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2652 /* Required to initialize most things. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2653 vterm_screen_reset(screen, 1 /* hard */);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2654
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2655 /* Allow using alternate screen. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2656 vterm_screen_enable_altscreen(screen, 1);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2657
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2658 /* 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
2659 * cursor to blink if it's blinking in the xterm.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2660 * For Windows we respect the system wide setting. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2661 #ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2662 if (GetCaretBlinkTime() == INFINITE)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2663 value.boolean = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2664 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2665 value.boolean = 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2666 #else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2667 value.boolean = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2668 #endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2669 vterm_state_set_termprop(vterm_obtain_state(vterm),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2670 VTERM_PROP_CURSORBLINK, &value);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2671 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2672
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2673 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2674 * Return the text to show for the buffer name and status.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2675 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2676 char_u *
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2677 term_get_status_text(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2678 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2679 if (term->tl_status_text == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2680 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2681 char_u *txt;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2682 size_t len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2683
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2684 if (term->tl_normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2685 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2686 if (term_job_running(term))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2687 txt = (char_u *)_("Terminal");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2688 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2689 txt = (char_u *)_("Terminal-finished");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2690 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2691 else if (term->tl_title != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2692 txt = term->tl_title;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2693 else if (term_none_open(term))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2694 txt = (char_u *)_("active");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2695 else if (term_job_running(term))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2696 txt = (char_u *)_("running");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2697 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2698 txt = (char_u *)_("finished");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2699 len = 9 + STRLEN(term->tl_buffer->b_fname) + STRLEN(txt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2700 term->tl_status_text = alloc((int)len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2701 if (term->tl_status_text != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2702 vim_snprintf((char *)term->tl_status_text, len, "%s [%s]",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2703 term->tl_buffer->b_fname, txt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2704 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2705 return term->tl_status_text;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2706 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2707
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2708 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2709 * Mark references in jobs of terminals.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2710 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2711 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2712 set_ref_in_term(int copyID)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2713 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2714 int abort = FALSE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2715 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2716 typval_T tv;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2717
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2718 for (term = first_term; term != NULL; term = term->tl_next)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2719 if (term->tl_job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2720 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2721 tv.v_type = VAR_JOB;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2722 tv.vval.v_job = term->tl_job;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2723 abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2724 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2725 return abort;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2726 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2727
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2728 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2729 * Get the buffer from the first argument in "argvars".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2730 * Returns NULL when the buffer is not for a terminal window.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2731 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2732 static buf_T *
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2733 term_get_buf(typval_T *argvars)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2734 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2735 buf_T *buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2736
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2737 (void)get_tv_number(&argvars[0]); /* issue errmsg if type error */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2738 ++emsg_off;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2739 buf = get_buf_tv(&argvars[0], FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2740 --emsg_off;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2741 if (buf == NULL || buf->b_term == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2742 return NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2743 return buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2744 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2745
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2746 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2747 * "term_getaltscreen(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2748 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2749 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2750 f_term_getaltscreen(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2751 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2752 buf_T *buf = term_get_buf(argvars);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2753
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2754 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2755 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2756 rettv->vval.v_number = buf->b_term->tl_using_altscreen;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2757 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2758
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2759 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2760 * "term_getattr(attr, name)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2761 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2762 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2763 f_term_getattr(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2764 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2765 int attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2766 size_t i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2767 char_u *name;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2768
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2769 static struct {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2770 char *name;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2771 int attr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2772 } attrs[] = {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2773 {"bold", HL_BOLD},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2774 {"italic", HL_ITALIC},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2775 {"underline", HL_UNDERLINE},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2776 {"strike", HL_STRIKETHROUGH},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2777 {"reverse", HL_INVERSE},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2778 };
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2779
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2780 attr = get_tv_number(&argvars[0]);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2781 name = get_tv_string_chk(&argvars[1]);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2782 if (name == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2783 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2784
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2785 for (i = 0; i < sizeof(attrs)/sizeof(attrs[0]); ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2786 if (STRCMP(name, attrs[i].name) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2787 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2788 rettv->vval.v_number = (attr & attrs[i].attr) != 0 ? 1 : 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2789 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2790 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2791 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2792
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2793 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2794 * "term_getcursor(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2795 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2796 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2797 f_term_getcursor(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2798 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2799 buf_T *buf = term_get_buf(argvars);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2800 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2801 list_T *l;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2802 dict_T *d;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2803
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2804 if (rettv_list_alloc(rettv) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2805 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2806 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2807 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2808 term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2809
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2810 l = rettv->vval.v_list;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2811 list_append_number(l, term->tl_cursor_pos.row + 1);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2812 list_append_number(l, term->tl_cursor_pos.col + 1);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2813
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2814 d = dict_alloc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2815 if (d != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2816 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2817 dict_add_nr_str(d, "visible", term->tl_cursor_visible, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2818 dict_add_nr_str(d, "blink", blink_state_is_inverted()
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2819 ? !term->tl_cursor_blink : term->tl_cursor_blink, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2820 dict_add_nr_str(d, "shape", term->tl_cursor_shape, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2821 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
2822 ? (char_u *)"" : term->tl_cursor_color);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2823 list_append_dict(l, d);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2824 }
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
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2827 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2828 * "term_getjob(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2829 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2830 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2831 f_term_getjob(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2832 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2833 buf_T *buf = term_get_buf(argvars);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2834
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2835 rettv->v_type = VAR_JOB;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2836 rettv->vval.v_job = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2837 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2838 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2839
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2840 rettv->vval.v_job = buf->b_term->tl_job;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2841 if (rettv->vval.v_job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2842 ++rettv->vval.v_job->jv_refcount;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2843 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2844
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2845 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2846 get_row_number(typval_T *tv, term_T *term)
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 if (tv->v_type == VAR_STRING
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2849 && tv->vval.v_string != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2850 && STRCMP(tv->vval.v_string, ".") == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2851 return term->tl_cursor_pos.row;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2852 return (int)get_tv_number(tv) - 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2853 }
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 * "term_getline(buf, row)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2857 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2858 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2859 f_term_getline(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2860 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2861 buf_T *buf = term_get_buf(argvars);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2862 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2863 int row;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2864
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2865 rettv->v_type = VAR_STRING;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2866 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2867 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2868 term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2869 row = get_row_number(&argvars[1], term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2870
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2871 if (term->tl_vterm == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2872 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2873 linenr_T lnum = row + term->tl_scrollback_scrolled + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2874
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2875 /* vterm is finished, get the text from the buffer */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2876 if (lnum > 0 && lnum <= buf->b_ml.ml_line_count)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2877 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
2878 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2879 else
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 VTermScreen *screen = vterm_obtain_screen(term->tl_vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2882 VTermRect rect;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2883 int len;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2884 char_u *p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2885
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2886 if (row < 0 || row >= term->tl_rows)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2887 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2888 len = term->tl_cols * MB_MAXBYTES + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2889 p = alloc(len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2890 if (p == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2891 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2892 rettv->vval.v_string = p;
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 rect.start_col = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2895 rect.end_col = term->tl_cols;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2896 rect.start_row = row;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2897 rect.end_row = row + 1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2898 p[vterm_screen_get_text(screen, (char *)p, len, rect)] = NUL;
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 }
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 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2903 * "term_getscrolled(buf)" function
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 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2906 f_term_getscrolled(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2907 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2908 buf_T *buf = term_get_buf(argvars);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2909
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2910 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2911 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2912 rettv->vval.v_number = buf->b_term->tl_scrollback_scrolled;
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
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 * "term_getsize(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2917 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2918 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2919 f_term_getsize(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2920 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2921 buf_T *buf = term_get_buf(argvars);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2922 list_T *l;
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 if (rettv_list_alloc(rettv) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2925 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2926 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2927 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2928
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2929 l = rettv->vval.v_list;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2930 list_append_number(l, buf->b_term->tl_rows);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2931 list_append_number(l, buf->b_term->tl_cols);
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
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2934 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2935 * "term_getstatus(buf)" function
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 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2938 f_term_getstatus(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2939 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2940 buf_T *buf = term_get_buf(argvars);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2941 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2942 char_u val[100];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2943
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2944 rettv->v_type = VAR_STRING;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2945 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2946 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2947 term = buf->b_term;
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 if (term_job_running(term))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2950 STRCPY(val, "running");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2951 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2952 STRCPY(val, "finished");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2953 if (term->tl_normal_mode)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2954 STRCAT(val, ",normal");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2955 rettv->vval.v_string = vim_strsave(val);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2956 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2957
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2958 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2959 * "term_gettitle(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2960 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2961 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2962 f_term_gettitle(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2963 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2964 buf_T *buf = term_get_buf(argvars);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2965
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2966 rettv->v_type = VAR_STRING;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2967 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2968 return;
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 if (buf->b_term->tl_title != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2971 rettv->vval.v_string = vim_strsave(buf->b_term->tl_title);
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 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2975 * "term_gettty(buf)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2976 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2977 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2978 f_term_gettty(typval_T *argvars, typval_T *rettv)
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 buf_T *buf = term_get_buf(argvars);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2981 char_u *p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2982 int num = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2983
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2984 rettv->v_type = VAR_STRING;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2985 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2986 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2987 if (argvars[1].v_type != VAR_UNKNOWN)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2988 num = get_tv_number(&argvars[1]);
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 switch (num)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2991 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2992 case 0:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2993 if (buf->b_term->tl_job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2994 p = buf->b_term->tl_job->jv_tty_out;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2995 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2996 p = buf->b_term->tl_tty_out;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2997 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2998 case 1:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2999 if (buf->b_term->tl_job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3000 p = buf->b_term->tl_job->jv_tty_in;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3001 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3002 p = buf->b_term->tl_tty_in;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3003 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3004 default:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3005 EMSG2(_(e_invarg2), get_tv_string(&argvars[1]));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3006 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3007 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3008 if (p != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3009 rettv->vval.v_string = vim_strsave(p);
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 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3013 * "term_list()" function
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 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3016 f_term_list(typval_T *argvars UNUSED, typval_T *rettv)
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 term_T *tp;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3019 list_T *l;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3020
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3021 if (rettv_list_alloc(rettv) == FAIL || first_term == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3022 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3023
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3024 l = rettv->vval.v_list;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3025 for (tp = first_term; tp != NULL; tp = tp->tl_next)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3026 if (tp != NULL && tp->tl_buffer != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3027 if (list_append_number(l,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3028 (varnumber_T)tp->tl_buffer->b_fnum) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3029 return;
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
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3032 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3033 * "term_scrape(buf, row)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3034 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3035 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3036 f_term_scrape(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3037 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3038 buf_T *buf = term_get_buf(argvars);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3039 VTermScreen *screen = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3040 VTermPos pos;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3041 list_T *l;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3042 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3043 char_u *p;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3044 sb_line_T *line;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3045
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3046 if (rettv_list_alloc(rettv) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3047 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3048 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3049 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3050 term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3051
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3052 l = rettv->vval.v_list;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3053 pos.row = get_row_number(&argvars[1], term);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3054
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3055 if (term->tl_vterm != NULL)
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 screen = vterm_obtain_screen(term->tl_vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3058 p = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3059 line = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3060 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3061 else
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 linenr_T lnum = pos.row + term->tl_scrollback_scrolled;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3064
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3065 if (lnum < 0 || lnum >= term->tl_scrollback.ga_len)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3066 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3067 p = ml_get_buf(buf, lnum + 1, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3068 line = (sb_line_T *)term->tl_scrollback.ga_data + lnum;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3069 }
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 for (pos.col = 0; pos.col < term->tl_cols; )
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3072 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3073 dict_T *dcell;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3074 int width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3075 VTermScreenCellAttrs attrs;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3076 VTermColor fg, bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3077 char_u rgb[8];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3078 char_u mbs[MB_MAXBYTES * VTERM_MAX_CHARS_PER_CELL + 1];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3079 int off = 0;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3080 int i;
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 if (screen == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3083 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3084 cellattr_T *cellattr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3085 int len;
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 /* vterm has finished, get the cell from scrollback */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3088 if (pos.col >= line->sb_cols)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3089 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3090 cellattr = line->sb_cells + pos.col;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3091 width = cellattr->width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3092 attrs = cellattr->attrs;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3093 fg = cellattr->fg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3094 bg = cellattr->bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3095 len = MB_PTR2LEN(p);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3096 mch_memmove(mbs, p, len);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3097 mbs[len] = NUL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3098 p += len;
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 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3102 VTermScreenCell cell;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3103 if (vterm_screen_get_cell(screen, pos, &cell) == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3104 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3105 for (i = 0; i < VTERM_MAX_CHARS_PER_CELL; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3106 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3107 if (cell.chars[i] == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3108 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3109 off += (*utf_char2bytes)((int)cell.chars[i], mbs + off);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3110 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3111 mbs[off] = NUL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3112 width = cell.width;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3113 attrs = cell.attrs;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3114 fg = cell.fg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3115 bg = cell.bg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3116 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3117 dcell = dict_alloc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3118 list_append_dict(l, dcell);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3119
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3120 dict_add_nr_str(dcell, "chars", 0, mbs);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3121
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3122 vim_snprintf((char *)rgb, 8, "#%02x%02x%02x",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3123 fg.red, fg.green, fg.blue);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3124 dict_add_nr_str(dcell, "fg", 0, rgb);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3125 vim_snprintf((char *)rgb, 8, "#%02x%02x%02x",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3126 bg.red, bg.green, bg.blue);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3127 dict_add_nr_str(dcell, "bg", 0, rgb);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3128
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3129 dict_add_nr_str(dcell, "attr",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3130 cell2attr(attrs, fg, bg), NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3131 dict_add_nr_str(dcell, "width", width, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3132
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3133 ++pos.col;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3134 if (width == 2)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3135 ++pos.col;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3136 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3137 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3138
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3139 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3140 * "term_sendkeys(buf, keys)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3141 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3142 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3143 f_term_sendkeys(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3144 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3145 buf_T *buf = term_get_buf(argvars);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3146 char_u *msg;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3147 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3148
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3149 rettv->v_type = VAR_UNKNOWN;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3150 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3151 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3152
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3153 msg = get_tv_string_chk(&argvars[1]);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3154 if (msg == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3155 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3156 term = buf->b_term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3157 if (term->tl_vterm == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3158 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3159
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3160 while (*msg != NUL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3161 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3162 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
3163 msg += MB_CPTR2LEN(msg);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3164 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3165 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3166
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3167 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3168 * "term_start(command, options)" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3169 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3170 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3171 f_term_start(typval_T *argvars, typval_T *rettv)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3172 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3173 jobopt_T opt;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3174 buf_T *buf;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3175
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3176 init_job_options(&opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3177 if (argvars[1].v_type != VAR_UNKNOWN
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3178 && get_job_options(&argvars[1], &opt,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3179 JO_TIMEOUT_ALL + JO_STOPONEXIT
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3180 + JO_CALLBACK + JO_OUT_CALLBACK + JO_ERR_CALLBACK
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3181 + JO_EXIT_CB + JO_CLOSE_CALLBACK + JO_OUT_IO,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3182 JO2_TERM_NAME + JO2_TERM_FINISH + JO2_HIDDEN + JO2_TERM_OPENCMD
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3183 + JO2_TERM_COLS + JO2_TERM_ROWS + JO2_VERTICAL + JO2_CURWIN
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3184 + JO2_CWD + JO2_ENV + JO2_EOF_CHARS) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3185 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3186
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3187 if (opt.jo_vertical)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3188 cmdmod.split = WSP_VERT;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3189 buf = term_start(&argvars[0], &opt, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3190
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3191 if (buf != NULL && buf->b_term != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3192 rettv->vval.v_number = buf->b_fnum;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3193 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3194
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3195 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3196 * "term_wait" function
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3197 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3198 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3199 f_term_wait(typval_T *argvars, typval_T *rettv UNUSED)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3200 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3201 buf_T *buf = term_get_buf(argvars);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3202
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3203 if (buf == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3204 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3205 ch_log(NULL, "term_wait(): invalid argument");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3206 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3207 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3208 if (buf->b_term->tl_job == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3209 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3210 ch_log(NULL, "term_wait(): no job to wait for");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3211 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3212 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3213 if (buf->b_term->tl_job->jv_channel == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3214 /* channel is closed, nothing to do */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3215 return;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3216
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3217 /* Get the job status, this will detect a job that finished. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3218 if ((buf->b_term->tl_job->jv_channel == NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3219 || !buf->b_term->tl_job->jv_channel->ch_keep_open)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3220 && STRCMP(job_status(buf->b_term->tl_job), "dead") == 0)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3221 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3222 /* 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
3223 * 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
3224 * waiting. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3225 ch_log(NULL, "term_wait(): waiting for channel to close");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3226 while (buf->b_term != NULL && !buf->b_term->tl_channel_closed)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3227 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3228 mch_check_messages();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3229 parse_queued_messages();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3230 ui_delay(10L, FALSE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3231 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3232 mch_check_messages();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3233 parse_queued_messages();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3234 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3235 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3236 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3237 long wait = 10L;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3238
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3239 mch_check_messages();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3240 parse_queued_messages();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3241
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3242 /* Wait for some time for any channel I/O. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3243 if (argvars[1].v_type != VAR_UNKNOWN)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3244 wait = get_tv_number(&argvars[1]);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3245 ui_delay(wait, TRUE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3246 mch_check_messages();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3247
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3248 /* Flushing messages on channels is hopefully sufficient.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3249 * TODO: is there a better way? */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3250 parse_queued_messages();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3251 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3252 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3253
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3254 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3255 * 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
3256 * Send a CTRL-D to mark the end of the text.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3257 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3258 void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3259 term_send_eof(channel_T *ch)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3260 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3261 term_T *term;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3262
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3263 for (term = first_term; term != NULL; term = term->tl_next)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3264 if (term->tl_job == ch->ch_job)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3265 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3266 if (term->tl_eof_chars != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3267 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3268 channel_send(ch, PART_IN, term->tl_eof_chars,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3269 (int)STRLEN(term->tl_eof_chars), NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3270 channel_send(ch, PART_IN, (char_u *)"\r", 1, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3271 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3272 # ifdef WIN3264
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3273 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3274 /* Default: CTRL-D */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3275 channel_send(ch, PART_IN, (char_u *)"\004\r", 2, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3276 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3277 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3278 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3279
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3280 # if defined(WIN3264) || defined(PROTO)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3281
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3282 /**************************************
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3283 * 2. MS-Windows implementation.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3284 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3285
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3286 # ifndef PROTO
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3287
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3288 #define WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN 1ul
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3289 #define WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN 2ull
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3290 #define WINPTY_MOUSE_MODE_FORCE 2
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3291
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3292 void* (*winpty_config_new)(UINT64, void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3293 void* (*winpty_open)(void*, void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3294 void* (*winpty_spawn_config_new)(UINT64, void*, LPCWSTR, void*, void*, void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3295 BOOL (*winpty_spawn)(void*, void*, HANDLE*, HANDLE*, DWORD*, void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3296 void (*winpty_config_set_mouse_mode)(void*, int);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3297 void (*winpty_config_set_initial_size)(void*, int, int);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3298 LPCWSTR (*winpty_conin_name)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3299 LPCWSTR (*winpty_conout_name)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3300 LPCWSTR (*winpty_conerr_name)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3301 void (*winpty_free)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3302 void (*winpty_config_free)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3303 void (*winpty_spawn_config_free)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3304 void (*winpty_error_free)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3305 LPCWSTR (*winpty_error_msg)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3306 BOOL (*winpty_set_size)(void*, int, int, void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3307 HANDLE (*winpty_agent_process)(void*);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3308
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3309 #define WINPTY_DLL "winpty.dll"
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3310
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3311 static HINSTANCE hWinPtyDLL = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3312 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3313
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3314 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3315 dyn_winpty_init(int verbose)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3316 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3317 int i;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3318 static struct
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3319 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3320 char *name;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3321 FARPROC *ptr;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3322 } winpty_entry[] =
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3323 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3324 {"winpty_conerr_name", (FARPROC*)&winpty_conerr_name},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3325 {"winpty_config_free", (FARPROC*)&winpty_config_free},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3326 {"winpty_config_new", (FARPROC*)&winpty_config_new},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3327 {"winpty_config_set_mouse_mode",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3328 (FARPROC*)&winpty_config_set_mouse_mode},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3329 {"winpty_config_set_initial_size",
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3330 (FARPROC*)&winpty_config_set_initial_size},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3331 {"winpty_conin_name", (FARPROC*)&winpty_conin_name},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3332 {"winpty_conout_name", (FARPROC*)&winpty_conout_name},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3333 {"winpty_error_free", (FARPROC*)&winpty_error_free},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3334 {"winpty_free", (FARPROC*)&winpty_free},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3335 {"winpty_open", (FARPROC*)&winpty_open},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3336 {"winpty_spawn", (FARPROC*)&winpty_spawn},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3337 {"winpty_spawn_config_free", (FARPROC*)&winpty_spawn_config_free},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3338 {"winpty_spawn_config_new", (FARPROC*)&winpty_spawn_config_new},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3339 {"winpty_error_msg", (FARPROC*)&winpty_error_msg},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3340 {"winpty_set_size", (FARPROC*)&winpty_set_size},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3341 {"winpty_agent_process", (FARPROC*)&winpty_agent_process},
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3342 {NULL, NULL}
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3343 };
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3344
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3345 /* No need to initialize twice. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3346 if (hWinPtyDLL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3347 return OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3348 /* 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
3349 * winpty.dll. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3350 if (*p_winptydll != NUL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3351 hWinPtyDLL = vimLoadLib((char *)p_winptydll);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3352 if (!hWinPtyDLL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3353 hWinPtyDLL = vimLoadLib(WINPTY_DLL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3354 if (!hWinPtyDLL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3355 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3356 if (verbose)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3357 EMSG2(_(e_loadlib), *p_winptydll != NUL ? p_winptydll
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3358 : (char_u *)WINPTY_DLL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3359 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3360 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3361 for (i = 0; winpty_entry[i].name != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3362 && winpty_entry[i].ptr != NULL; ++i)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3363 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3364 if ((*winpty_entry[i].ptr = (FARPROC)GetProcAddress(hWinPtyDLL,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3365 winpty_entry[i].name)) == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3366 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3367 if (verbose)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3368 EMSG2(_(e_loadfunc), winpty_entry[i].name);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3369 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3370 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3371 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3372
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3373 return OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3374 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3375
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3376 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3377 * Create a new terminal of "rows" by "cols" cells.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3378 * Store a reference in "term".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3379 * Return OK or FAIL.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3380 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3381 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3382 term_and_job_init(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3383 term_T *term,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3384 typval_T *argvar,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3385 jobopt_T *opt)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3386 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3387 WCHAR *cmd_wchar = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3388 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
3389 WCHAR *env_wchar = NULL;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3390 channel_T *channel = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3391 job_T *job = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3392 DWORD error;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3393 HANDLE jo = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3394 HANDLE child_process_handle;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3395 HANDLE child_thread_handle;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3396 void *winpty_err;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3397 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
3398 garray_T ga_cmd, ga_env;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3399 char_u *cmd;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3400
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3401 if (dyn_winpty_init(TRUE) == FAIL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3402 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3403
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3404 if (argvar->v_type == VAR_STRING)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3405 cmd = argvar->vval.v_string;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3406 else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3407 {
12724
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
3408 ga_init2(&ga_cmd, (int)sizeof(char*), 20);
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
3409 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
3410 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
3411 cmd = ga_cmd.ga_data;
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3412 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3413
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3414 cmd_wchar = enc_to_utf16(cmd, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3415 if (cmd_wchar == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3416 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3417 if (opt->jo_cwd != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3418 cwd_wchar = enc_to_utf16(opt->jo_cwd, NULL);
12724
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
3419 if (opt->jo_env != NULL)
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
3420 {
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
3421 ga_init2(&ga_env, (int)sizeof(char*), 20);
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
3422 win32_build_env(opt->jo_env, &ga_env);
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
3423 env_wchar = ga_env.ga_data;
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
3424 }
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3425
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3426 job = job_alloc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3427 if (job == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3428 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3429
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3430 channel = add_channel();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3431 if (channel == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3432 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3433
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3434 term->tl_winpty_config = winpty_config_new(0, &winpty_err);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3435 if (term->tl_winpty_config == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3436 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3437
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3438 winpty_config_set_mouse_mode(term->tl_winpty_config,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3439 WINPTY_MOUSE_MODE_FORCE);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3440 winpty_config_set_initial_size(term->tl_winpty_config,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3441 term->tl_cols, term->tl_rows);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3442 term->tl_winpty = winpty_open(term->tl_winpty_config, &winpty_err);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3443 if (term->tl_winpty == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3444 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3445
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3446 spawn_config = winpty_spawn_config_new(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3447 WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN |
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3448 WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3449 NULL,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3450 cmd_wchar,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3451 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
3452 env_wchar,
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3453 &winpty_err);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3454 if (spawn_config == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3455 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3456
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3457 channel = add_channel();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3458 if (channel == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3459 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3460
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3461 job = job_alloc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3462 if (job == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3463 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3464
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3465 if (opt->jo_set & JO_IN_BUF)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3466 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
3467
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3468 if (!winpty_spawn(term->tl_winpty, spawn_config, &child_process_handle,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3469 &child_thread_handle, &error, &winpty_err))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3470 goto failed;
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 channel_set_pipes(channel,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3473 (sock_T)CreateFileW(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3474 winpty_conin_name(term->tl_winpty),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3475 GENERIC_WRITE, 0, NULL,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3476 OPEN_EXISTING, 0, NULL),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3477 (sock_T)CreateFileW(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3478 winpty_conout_name(term->tl_winpty),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3479 GENERIC_READ, 0, NULL,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3480 OPEN_EXISTING, 0, NULL),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3481 (sock_T)CreateFileW(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3482 winpty_conerr_name(term->tl_winpty),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3483 GENERIC_READ, 0, NULL,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3484 OPEN_EXISTING, 0, NULL));
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3485
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3486 /* Write lines with CR instead of NL. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3487 channel->ch_write_text_mode = TRUE;
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 jo = CreateJobObject(NULL, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3490 if (jo == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3491 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3492
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3493 if (!AssignProcessToJobObject(jo, child_process_handle))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3494 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3495 /* Failed, switch the way to terminate process with TerminateProcess. */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3496 CloseHandle(jo);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3497 jo = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3498 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3499
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3500 winpty_spawn_config_free(spawn_config);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3501 vim_free(cmd_wchar);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3502 vim_free(cwd_wchar);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3503
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3504 create_vterm(term, term->tl_rows, term->tl_cols);
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 channel_set_job(channel, job, opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3507 job_set_options(job, opt);
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 job->jv_channel = channel;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3510 job->jv_proc_info.hProcess = child_process_handle;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3511 job->jv_proc_info.dwProcessId = GetProcessId(child_process_handle);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3512 job->jv_job_object = jo;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3513 job->jv_status = JOB_STARTED;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3514 job->jv_tty_in = utf16_to_enc(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3515 (short_u*)winpty_conin_name(term->tl_winpty), NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3516 job->jv_tty_out = utf16_to_enc(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3517 (short_u*)winpty_conout_name(term->tl_winpty), NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3518 ++job->jv_refcount;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3519 term->tl_job = job;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3520
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3521 return OK;
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 failed:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3524 if (argvar->v_type == VAR_LIST)
12724
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
3525 vim_free(ga_cmd.ga_data);
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
3526 if (opt->jo_env != NULL)
17c257dd2438 patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents: 12650
diff changeset
3527 vim_free(ga_env.ga_data);
12502
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3528 vim_free(cmd_wchar);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3529 vim_free(cwd_wchar);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3530 if (spawn_config != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3531 winpty_spawn_config_free(spawn_config);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3532 if (channel != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3533 channel_clear(channel);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3534 if (job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3535 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3536 job->jv_channel = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3537 job_cleanup(job);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3538 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3539 term->tl_job = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3540 if (jo != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3541 CloseHandle(jo);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3542 if (term->tl_winpty != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3543 winpty_free(term->tl_winpty);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3544 term->tl_winpty = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3545 if (term->tl_winpty_config != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3546 winpty_config_free(term->tl_winpty_config);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3547 term->tl_winpty_config = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3548 if (winpty_err != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3549 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3550 char_u *msg = utf16_to_enc(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3551 (short_u *)winpty_error_msg(winpty_err), NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3552
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3553 EMSG(msg);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3554 winpty_error_free(winpty_err);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3555 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3556 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3557 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3558
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3559 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3560 create_pty_only(term_T *term, jobopt_T *options)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3561 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3562 HANDLE hPipeIn = INVALID_HANDLE_VALUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3563 HANDLE hPipeOut = INVALID_HANDLE_VALUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3564 char in_name[80], out_name[80];
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3565 channel_T *channel = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3566
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3567 create_vterm(term, term->tl_rows, term->tl_cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3568
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3569 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
3570 GetCurrentProcessId(),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3571 curbuf->b_fnum);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3572 hPipeIn = CreateNamedPipe(in_name, PIPE_ACCESS_OUTBOUND,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3573 PIPE_TYPE_MESSAGE | PIPE_NOWAIT,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3574 PIPE_UNLIMITED_INSTANCES,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3575 0, 0, NMPWAIT_NOWAIT, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3576 if (hPipeIn == INVALID_HANDLE_VALUE)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3577 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3578
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3579 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
3580 GetCurrentProcessId(),
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3581 curbuf->b_fnum);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3582 hPipeOut = CreateNamedPipe(out_name, PIPE_ACCESS_INBOUND,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3583 PIPE_TYPE_MESSAGE | PIPE_NOWAIT,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3584 PIPE_UNLIMITED_INSTANCES,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3585 0, 0, 0, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3586 if (hPipeOut == INVALID_HANDLE_VALUE)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3587 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3588
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3589 ConnectNamedPipe(hPipeIn, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3590 ConnectNamedPipe(hPipeOut, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3591
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3592 term->tl_job = job_alloc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3593 if (term->tl_job == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3594 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3595 ++term->tl_job->jv_refcount;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3596
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3597 /* behave like the job is already finished */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3598 term->tl_job->jv_status = JOB_FINISHED;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3599
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3600 channel = add_channel();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3601 if (channel == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3602 goto failed;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3603 term->tl_job->jv_channel = channel;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3604 channel->ch_keep_open = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3605 channel->ch_named_pipe = TRUE;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3606
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3607 channel_set_pipes(channel,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3608 (sock_T)hPipeIn,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3609 (sock_T)hPipeOut,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3610 (sock_T)hPipeOut);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3611 channel_set_job(channel, term->tl_job, options);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3612 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
3613 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
3614
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3615 return OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3616
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3617 failed:
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3618 if (hPipeIn != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3619 CloseHandle(hPipeIn);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3620 if (hPipeOut != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3621 CloseHandle(hPipeOut);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3622 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3623 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3624
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3625 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3626 * Free the terminal emulator part of "term".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3627 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3628 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3629 term_free_vterm(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3630 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3631 if (term->tl_winpty != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3632 winpty_free(term->tl_winpty);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3633 term->tl_winpty = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3634 if (term->tl_winpty_config != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3635 winpty_config_free(term->tl_winpty_config);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3636 term->tl_winpty_config = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3637 if (term->tl_vterm != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3638 vterm_free(term->tl_vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3639 term->tl_vterm = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3640 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3641
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3642 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3643 * Request size to terminal.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3644 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3645 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3646 term_report_winsize(term_T *term, int rows, int cols)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3647 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3648 if (term->tl_winpty)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3649 winpty_set_size(term->tl_winpty, cols, rows, NULL);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3650 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3651
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3652 int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3653 terminal_enabled(void)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3654 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3655 return dyn_winpty_init(FALSE) == OK;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3656 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3657
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3658 # else
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3659
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3660 /**************************************
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3661 * 3. Unix-like implementation.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3662 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3663
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3664 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3665 * Create a new terminal of "rows" by "cols" cells.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3666 * Start job for "cmd".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3667 * Store the pointers in "term".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3668 * Return OK or FAIL.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3669 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3670 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3671 term_and_job_init(
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3672 term_T *term,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3673 typval_T *argvar,
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3674 jobopt_T *opt)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3675 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3676 create_vterm(term, term->tl_rows, term->tl_cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3677
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3678 term->tl_job = job_start(argvar, opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3679 if (term->tl_job != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3680 ++term->tl_job->jv_refcount;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3681
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3682 return term->tl_job != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3683 && term->tl_job->jv_channel != NULL
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3684 && term->tl_job->jv_status != JOB_FAILED ? OK : FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3685 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3686
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3687 static int
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3688 create_pty_only(term_T *term, jobopt_T *opt)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3689 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3690 create_vterm(term, term->tl_rows, term->tl_cols);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3691
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3692 term->tl_job = job_alloc();
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3693 if (term->tl_job == NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3694 return FAIL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3695 ++term->tl_job->jv_refcount;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3696
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3697 /* behave like the job is already finished */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3698 term->tl_job->jv_status = JOB_FINISHED;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3699
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3700 return mch_create_pty_channel(term->tl_job, opt);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3701 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3702
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3703 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3704 * Free the terminal emulator part of "term".
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3705 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3706 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3707 term_free_vterm(term_T *term)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3708 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3709 if (term->tl_vterm != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3710 vterm_free(term->tl_vterm);
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3711 term->tl_vterm = NULL;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3712 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3713
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3714 /*
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3715 * Request size to terminal.
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3716 */
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3717 static void
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3718 term_report_winsize(term_T *term, int rows, int cols)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3719 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3720 /* 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
3721 if (term->tl_job != NULL && term->tl_job->jv_channel != NULL)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3722 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3723 int fd = -1;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3724 int part;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3725
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3726 for (part = PART_OUT; part < PART_COUNT; ++part)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3727 {
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3728 fd = term->tl_job->jv_channel->ch_part[part].ch_fd;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3729 if (isatty(fd))
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3730 break;
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3731 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3732 if (part < PART_COUNT && mch_report_winsize(fd, rows, cols) == OK)
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3733 mch_signal_job(term->tl_job, (char_u *)"winch");
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3734 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3735 }
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3736
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3737 # endif
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3738
ed85dd1b8c80 Add back terminal.c
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3739 #endif /* FEAT_TERMINAL */